File System: Remove bare new operator usage.
Change-Id: I9ca833057c36b2c4242b79a4a536ca814f09c470 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2608759 Reviewed-by: Austin Sullivan <asully@chromium.org> Commit-Queue: Victor Costan <pwnall@chromium.org> Auto-Submit: Victor Costan <pwnall@chromium.org> Cr-Commit-Position: refs/heads/master@{#840491}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
78369f63f3
commit
cbbc7266c2
storage/browser/file_system
copy_or_move_file_validator_unittest.cccopy_or_move_operation_delegate.cccopy_or_move_operation_delegate_unittest.ccfile_system_context.ccfile_system_context_unittest.ccfile_system_operation_impl.ccfile_system_operation_impl_unittest.ccfile_system_operation_impl_write_unittest.ccfile_system_operation_runner.ccfile_system_quota_client.ccisolated_file_system_backend.cclocal_file_stream_reader.cclocal_file_stream_writer.cclocal_file_util.ccobfuscated_file_util.ccobfuscated_file_util_unittest.cc
quota
sandbox_directory_database_unittest.ccsandbox_file_system_backend_delegate.ccsandbox_file_system_backend_unittest.ccsandbox_origin_database_unittest.ccsandbox_prioritized_origin_database.cc@ -269,8 +269,7 @@ TEST(CopyOrMoveFileValidatorTest, AcceptAll) {
|
||||
CopyOrMoveFileValidatorTestHelper helper("http://foo", kNoValidatorType,
|
||||
kWithValidatorType);
|
||||
helper.SetUp();
|
||||
std::unique_ptr<CopyOrMoveFileValidatorFactory> factory(
|
||||
new TestCopyOrMoveFileValidatorFactory(VALID));
|
||||
auto factory = std::make_unique<TestCopyOrMoveFileValidatorFactory>(VALID);
|
||||
helper.SetMediaCopyOrMoveFileValidatorFactory(std::move(factory));
|
||||
|
||||
helper.CopyTest(base::File::FILE_OK);
|
||||
@ -281,8 +280,8 @@ TEST(CopyOrMoveFileValidatorTest, AcceptNone) {
|
||||
CopyOrMoveFileValidatorTestHelper helper("http://foo", kNoValidatorType,
|
||||
kWithValidatorType);
|
||||
helper.SetUp();
|
||||
std::unique_ptr<CopyOrMoveFileValidatorFactory> factory(
|
||||
new TestCopyOrMoveFileValidatorFactory(PRE_WRITE_INVALID));
|
||||
auto factory =
|
||||
std::make_unique<TestCopyOrMoveFileValidatorFactory>(PRE_WRITE_INVALID);
|
||||
helper.SetMediaCopyOrMoveFileValidatorFactory(std::move(factory));
|
||||
|
||||
helper.CopyTest(base::File::FILE_ERROR_SECURITY);
|
||||
@ -294,12 +293,12 @@ TEST(CopyOrMoveFileValidatorTest, OverrideValidator) {
|
||||
CopyOrMoveFileValidatorTestHelper helper("http://foo", kNoValidatorType,
|
||||
kWithValidatorType);
|
||||
helper.SetUp();
|
||||
std::unique_ptr<CopyOrMoveFileValidatorFactory> reject_factory(
|
||||
new TestCopyOrMoveFileValidatorFactory(PRE_WRITE_INVALID));
|
||||
auto reject_factory =
|
||||
std::make_unique<TestCopyOrMoveFileValidatorFactory>(PRE_WRITE_INVALID);
|
||||
helper.SetMediaCopyOrMoveFileValidatorFactory(std::move(reject_factory));
|
||||
|
||||
std::unique_ptr<CopyOrMoveFileValidatorFactory> accept_factory(
|
||||
new TestCopyOrMoveFileValidatorFactory(VALID));
|
||||
auto accept_factory =
|
||||
std::make_unique<TestCopyOrMoveFileValidatorFactory>(VALID);
|
||||
helper.SetMediaCopyOrMoveFileValidatorFactory(std::move(accept_factory));
|
||||
|
||||
helper.CopyTest(base::File::FILE_ERROR_SECURITY);
|
||||
@ -310,8 +309,8 @@ TEST(CopyOrMoveFileValidatorTest, RejectPostWrite) {
|
||||
CopyOrMoveFileValidatorTestHelper helper("http://foo", kNoValidatorType,
|
||||
kWithValidatorType);
|
||||
helper.SetUp();
|
||||
std::unique_ptr<CopyOrMoveFileValidatorFactory> factory(
|
||||
new TestCopyOrMoveFileValidatorFactory(POST_WRITE_INVALID));
|
||||
auto factory =
|
||||
std::make_unique<TestCopyOrMoveFileValidatorFactory>(POST_WRITE_INVALID);
|
||||
helper.SetMediaCopyOrMoveFileValidatorFactory(std::move(factory));
|
||||
|
||||
helper.CopyTest(base::File::FILE_ERROR_SECURITY);
|
||||
|
@ -499,12 +499,13 @@ class StreamCopyOrMoveImpl
|
||||
|
||||
NotifyOnStartUpdate(dest_url_);
|
||||
DCHECK(!copy_helper_);
|
||||
copy_helper_.reset(new CopyOrMoveOperationDelegate::StreamCopyHelper(
|
||||
std::move(reader_), std::move(writer_),
|
||||
dest_url_.mount_option().flush_policy(), kReadBufferSize,
|
||||
file_progress_callback_,
|
||||
base::TimeDelta::FromMilliseconds(
|
||||
kMinProgressCallbackInvocationSpanInMilliseconds)));
|
||||
copy_helper_ =
|
||||
std::make_unique<CopyOrMoveOperationDelegate::StreamCopyHelper>(
|
||||
std::move(reader_), std::move(writer_),
|
||||
dest_url_.mount_option().flush_policy(), kReadBufferSize,
|
||||
file_progress_callback_,
|
||||
base::TimeDelta::FromMilliseconds(
|
||||
kMinProgressCallbackInvocationSpanInMilliseconds));
|
||||
copy_helper_->Run(base::BindOnce(&StreamCopyOrMoveImpl::RunAfterStreamCopy,
|
||||
weak_factory_.GetWeakPtr(),
|
||||
std::move(callback), last_modified));
|
||||
|
@ -18,6 +18,7 @@
|
||||
#include "base/files/scoped_temp_dir.h"
|
||||
#include "base/location.h"
|
||||
#include "base/macros.h"
|
||||
#include "base/memory/scoped_refptr.h"
|
||||
#include "base/run_loop.h"
|
||||
#include "base/single_thread_task_runner.h"
|
||||
#include "base/test/task_environment.h"
|
||||
@ -191,11 +192,11 @@ class CopyOrMoveOperationTestHelper {
|
||||
bool init_copy_or_move_validator) {
|
||||
ASSERT_TRUE(base_.CreateUniqueTempDir());
|
||||
base::FilePath base_dir = base_.GetPath();
|
||||
quota_manager_ =
|
||||
new MockQuotaManager(false /* is_incognito */, base_dir,
|
||||
base::ThreadTaskRunnerHandle::Get().get(),
|
||||
nullptr /* special storage policy */);
|
||||
quota_manager_proxy_ = new MockQuotaManagerProxy(
|
||||
quota_manager_ = base::MakeRefCounted<MockQuotaManager>(
|
||||
false /* is_incognito */, base_dir,
|
||||
base::ThreadTaskRunnerHandle::Get().get(),
|
||||
nullptr /* special storage policy */);
|
||||
quota_manager_proxy_ = base::MakeRefCounted<MockQuotaManagerProxy>(
|
||||
quota_manager_.get(), base::ThreadTaskRunnerHandle::Get().get());
|
||||
file_system_context_ =
|
||||
CreateFileSystemContextForTesting(quota_manager_proxy_.get(), base_dir);
|
||||
@ -210,8 +211,7 @@ class CopyOrMoveOperationTestHelper {
|
||||
if (dest_type_ == kFileSystemTypeTest) {
|
||||
TestFileSystemBackend* test_backend =
|
||||
static_cast<TestFileSystemBackend*>(backend);
|
||||
std::unique_ptr<CopyOrMoveFileValidatorFactory> factory(
|
||||
new TestValidatorFactory);
|
||||
auto factory = std::make_unique<TestValidatorFactory>();
|
||||
test_backend->set_require_copy_or_move_validator(
|
||||
require_copy_or_move_validator);
|
||||
if (init_copy_or_move_validator)
|
||||
|
@ -150,28 +150,29 @@ FileSystemContext::FileSystemContext(
|
||||
io_task_runner_(io_task_runner),
|
||||
default_file_task_runner_(file_task_runner),
|
||||
quota_manager_proxy_(quota_manager_proxy),
|
||||
sandbox_delegate_(
|
||||
new SandboxFileSystemBackendDelegate(quota_manager_proxy,
|
||||
file_task_runner,
|
||||
partition_path,
|
||||
special_storage_policy,
|
||||
options,
|
||||
env_override_.get())),
|
||||
sandbox_backend_(new SandboxFileSystemBackend(sandbox_delegate_.get())),
|
||||
plugin_private_backend_(
|
||||
new PluginPrivateFileSystemBackend(file_task_runner,
|
||||
partition_path,
|
||||
special_storage_policy,
|
||||
options,
|
||||
env_override_.get())),
|
||||
sandbox_delegate_(std::make_unique<SandboxFileSystemBackendDelegate>(
|
||||
quota_manager_proxy,
|
||||
file_task_runner,
|
||||
partition_path,
|
||||
special_storage_policy,
|
||||
options,
|
||||
env_override_.get())),
|
||||
sandbox_backend_(
|
||||
std::make_unique<SandboxFileSystemBackend>(sandbox_delegate_.get())),
|
||||
plugin_private_backend_(std::make_unique<PluginPrivateFileSystemBackend>(
|
||||
file_task_runner,
|
||||
partition_path,
|
||||
special_storage_policy,
|
||||
options,
|
||||
env_override_.get())),
|
||||
additional_backends_(std::move(additional_backends)),
|
||||
auto_mount_handlers_(auto_mount_handlers),
|
||||
external_mount_points_(external_mount_points),
|
||||
partition_path_(partition_path),
|
||||
is_incognito_(options.is_incognito()),
|
||||
operation_runner_(
|
||||
new FileSystemOperationRunner(base::PassKey<FileSystemContext>(),
|
||||
this)) {
|
||||
operation_runner_(std::make_unique<FileSystemOperationRunner>(
|
||||
base::PassKey<FileSystemContext>(),
|
||||
this)) {
|
||||
RegisterBackend(sandbox_backend_.get());
|
||||
RegisterBackend(plugin_private_backend_.get());
|
||||
|
||||
@ -183,9 +184,9 @@ FileSystemContext::FileSystemContext(
|
||||
// IsolatedFileSystemBackend does not need to handle them. For example, on
|
||||
// Chrome OS the additional backend chromeos::FileSystemBackend handles these
|
||||
// types.
|
||||
isolated_backend_.reset(new IsolatedFileSystemBackend(
|
||||
isolated_backend_ = std::make_unique<IsolatedFileSystemBackend>(
|
||||
!base::Contains(backend_map_, kFileSystemTypeNativeLocal),
|
||||
!base::Contains(backend_map_, kFileSystemTypeNativeForPlatformApp)));
|
||||
!base::Contains(backend_map_, kFileSystemTypeNativeForPlatformApp));
|
||||
RegisterBackend(isolated_backend_.get());
|
||||
|
||||
if (quota_manager_proxy) {
|
||||
|
@ -8,6 +8,7 @@
|
||||
|
||||
#include "base/files/scoped_temp_dir.h"
|
||||
#include "base/macros.h"
|
||||
#include "base/memory/scoped_refptr.h"
|
||||
#include "base/stl_util.h"
|
||||
#include "base/strings/stringprintf.h"
|
||||
#include "base/test/task_environment.h"
|
||||
@ -51,9 +52,9 @@ class FileSystemContextTest : public testing::Test {
|
||||
void SetUp() override {
|
||||
ASSERT_TRUE(data_dir_.CreateUniqueTempDir());
|
||||
|
||||
storage_policy_ = new MockSpecialStoragePolicy();
|
||||
storage_policy_ = base::MakeRefCounted<MockSpecialStoragePolicy>();
|
||||
|
||||
mock_quota_manager_ = new MockQuotaManager(
|
||||
mock_quota_manager_ = base::MakeRefCounted<MockQuotaManager>(
|
||||
false /* is_incognito */, data_dir_.GetPath(),
|
||||
base::ThreadTaskRunnerHandle::Get().get(), storage_policy_.get());
|
||||
}
|
||||
|
@ -104,12 +104,12 @@ void FileSystemOperationImpl::Copy(
|
||||
DCHECK(SetPendingOperationType(kOperationCopy));
|
||||
DCHECK(!recursive_operation_delegate_);
|
||||
|
||||
recursive_operation_delegate_.reset(new CopyOrMoveOperationDelegate(
|
||||
recursive_operation_delegate_ = std::make_unique<CopyOrMoveOperationDelegate>(
|
||||
file_system_context(), src_url, dest_url,
|
||||
CopyOrMoveOperationDelegate::OPERATION_COPY, option, error_behavior,
|
||||
progress_callback,
|
||||
base::BindOnce(&FileSystemOperationImpl::DidFinishOperation,
|
||||
weak_factory_.GetWeakPtr(), std::move(callback))));
|
||||
weak_factory_.GetWeakPtr(), std::move(callback)));
|
||||
recursive_operation_delegate_->RunRecursively();
|
||||
}
|
||||
|
||||
@ -119,12 +119,12 @@ void FileSystemOperationImpl::Move(const FileSystemURL& src_url,
|
||||
StatusCallback callback) {
|
||||
DCHECK(SetPendingOperationType(kOperationMove));
|
||||
DCHECK(!recursive_operation_delegate_);
|
||||
recursive_operation_delegate_.reset(new CopyOrMoveOperationDelegate(
|
||||
recursive_operation_delegate_ = std::make_unique<CopyOrMoveOperationDelegate>(
|
||||
file_system_context(), src_url, dest_url,
|
||||
CopyOrMoveOperationDelegate::OPERATION_MOVE, option, ERROR_BEHAVIOR_ABORT,
|
||||
FileSystemOperation::CopyProgressCallback(),
|
||||
base::BindOnce(&FileSystemOperationImpl::DidFinishOperation,
|
||||
weak_factory_.GetWeakPtr(), std::move(callback))));
|
||||
weak_factory_.GetWeakPtr(), std::move(callback)));
|
||||
recursive_operation_delegate_->RunRecursively();
|
||||
}
|
||||
|
||||
@ -178,10 +178,10 @@ void FileSystemOperationImpl::Remove(const FileSystemURL& url,
|
||||
return;
|
||||
}
|
||||
|
||||
recursive_operation_delegate_.reset(new RemoveOperationDelegate(
|
||||
recursive_operation_delegate_ = std::make_unique<RemoveOperationDelegate>(
|
||||
file_system_context(), url,
|
||||
base::BindOnce(&FileSystemOperationImpl::DidFinishOperation,
|
||||
weak_factory_.GetWeakPtr(), std::move(callback))));
|
||||
weak_factory_.GetWeakPtr(), std::move(callback)));
|
||||
recursive_operation_delegate_->Run();
|
||||
}
|
||||
|
||||
@ -567,10 +567,10 @@ void FileSystemOperationImpl::DidDeleteRecursively(const FileSystemURL& url,
|
||||
if (rv == base::File::FILE_ERROR_INVALID_OPERATION) {
|
||||
// Recursive removal is not supported on this platform.
|
||||
DCHECK(!recursive_operation_delegate_);
|
||||
recursive_operation_delegate_.reset(new RemoveOperationDelegate(
|
||||
recursive_operation_delegate_ = std::make_unique<RemoveOperationDelegate>(
|
||||
file_system_context(), url,
|
||||
base::BindOnce(&FileSystemOperationImpl::DidFinishOperation, weak_ptr_,
|
||||
std::move(callback))));
|
||||
std::move(callback)));
|
||||
recursive_operation_delegate_->RunRecursively();
|
||||
return;
|
||||
}
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include "base/files/scoped_temp_dir.h"
|
||||
#include "base/macros.h"
|
||||
#include "base/memory/ptr_util.h"
|
||||
#include "base/memory/scoped_refptr.h"
|
||||
#include "base/memory/weak_ptr.h"
|
||||
#include "base/run_loop.h"
|
||||
#include "base/stl_util.h"
|
||||
@ -56,11 +57,11 @@ class FileSystemOperationImplTest : public testing::Test {
|
||||
update_observers_ = MockFileUpdateObserver::CreateList(&update_observer_);
|
||||
|
||||
base::FilePath base_dir = base_.GetPath().AppendASCII("filesystem");
|
||||
quota_manager_ =
|
||||
new MockQuotaManager(false /* is_incognito */, base_dir,
|
||||
base::ThreadTaskRunnerHandle::Get().get(),
|
||||
nullptr /* special storage policy */);
|
||||
quota_manager_proxy_ = new MockQuotaManagerProxy(
|
||||
quota_manager_ = base::MakeRefCounted<MockQuotaManager>(
|
||||
/* is_incognito= */ false, base_dir,
|
||||
base::ThreadTaskRunnerHandle::Get().get(),
|
||||
/* special storage policy= */ nullptr);
|
||||
quota_manager_proxy_ = base::MakeRefCounted<MockQuotaManagerProxy>(
|
||||
quota_manager(), base::ThreadTaskRunnerHandle::Get().get());
|
||||
sandbox_file_system_.SetUp(base_dir, quota_manager_proxy_.get());
|
||||
sandbox_file_system_.AddFileChangeObserver(&change_observer_);
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include "base/bind.h"
|
||||
#include "base/files/scoped_temp_dir.h"
|
||||
#include "base/macros.h"
|
||||
#include "base/memory/scoped_refptr.h"
|
||||
#include "base/memory/weak_ptr.h"
|
||||
#include "base/run_loop.h"
|
||||
#include "base/test/task_environment.h"
|
||||
@ -59,15 +60,15 @@ class FileSystemOperationImplWriteTest : public testing::Test {
|
||||
void SetUp() override {
|
||||
ASSERT_TRUE(dir_.CreateUniqueTempDir());
|
||||
|
||||
quota_manager_ =
|
||||
new MockQuotaManager(false /* is_incognito */, dir_.GetPath(),
|
||||
base::ThreadTaskRunnerHandle::Get().get(),
|
||||
nullptr /* special storage policy */);
|
||||
quota_manager_ = base::MakeRefCounted<MockQuotaManager>(
|
||||
/* is_incognito= */ false, dir_.GetPath(),
|
||||
base::ThreadTaskRunnerHandle::Get().get(),
|
||||
/* special storage policy= */ nullptr);
|
||||
virtual_path_ = base::FilePath(FILE_PATH_LITERAL("temporary file"));
|
||||
|
||||
file_system_context_ = CreateFileSystemContextForTesting(
|
||||
quota_manager_->proxy(), dir_.GetPath());
|
||||
blob_storage_context_.reset(new BlobStorageContext);
|
||||
blob_storage_context_ = std::make_unique<BlobStorageContext>();
|
||||
|
||||
file_system_context_->operation_runner()->CreateFile(
|
||||
URLForPath(virtual_path_), true /* exclusive */,
|
||||
|
@ -267,8 +267,8 @@ OperationID FileSystemOperationRunner::Write(
|
||||
return id;
|
||||
}
|
||||
|
||||
std::unique_ptr<FileWriterDelegate> writer_delegate(new FileWriterDelegate(
|
||||
std::move(writer), url.mount_option().flush_policy()));
|
||||
auto writer_delegate = std::make_unique<FileWriterDelegate>(
|
||||
std::move(writer), url.mount_option().flush_policy());
|
||||
|
||||
std::unique_ptr<BlobReader> blob_reader;
|
||||
if (blob)
|
||||
@ -306,8 +306,8 @@ OperationID FileSystemOperationRunner::WriteStream(
|
||||
return id;
|
||||
}
|
||||
|
||||
std::unique_ptr<FileWriterDelegate> writer_delegate(new FileWriterDelegate(
|
||||
std::move(writer), url.mount_option().flush_policy()));
|
||||
auto writer_delegate = std::make_unique<FileWriterDelegate>(
|
||||
std::move(writer), url.mount_option().flush_policy());
|
||||
|
||||
PrepareForWrite(id, url);
|
||||
operation_raw->Write(url, std::move(writer_delegate), std::move(data_pipe),
|
||||
|
@ -29,35 +29,29 @@ namespace storage {
|
||||
|
||||
namespace {
|
||||
|
||||
void GetOriginsForTypeOnFileTaskRunner(FileSystemContext* context,
|
||||
StorageType storage_type,
|
||||
std::vector<url::Origin>* origins_ptr) {
|
||||
std::vector<url::Origin> GetOriginsForTypeOnFileTaskRunner(
|
||||
FileSystemContext* context,
|
||||
StorageType storage_type) {
|
||||
FileSystemType type = QuotaStorageTypeToFileSystemType(storage_type);
|
||||
DCHECK(type != kFileSystemTypeUnknown);
|
||||
|
||||
FileSystemQuotaUtil* quota_util = context->GetQuotaUtil(type);
|
||||
if (!quota_util)
|
||||
return;
|
||||
*origins_ptr = quota_util->GetOriginsForTypeOnFileTaskRunner(type);
|
||||
return {};
|
||||
return quota_util->GetOriginsForTypeOnFileTaskRunner(type);
|
||||
}
|
||||
|
||||
void GetOriginsForHostOnFileTaskRunner(FileSystemContext* context,
|
||||
StorageType storage_type,
|
||||
const std::string& host,
|
||||
std::vector<url::Origin>* origins_ptr) {
|
||||
std::vector<url::Origin> GetOriginsForHostOnFileTaskRunner(
|
||||
FileSystemContext* context,
|
||||
StorageType storage_type,
|
||||
const std::string& host) {
|
||||
FileSystemType type = QuotaStorageTypeToFileSystemType(storage_type);
|
||||
DCHECK(type != kFileSystemTypeUnknown);
|
||||
|
||||
FileSystemQuotaUtil* quota_util = context->GetQuotaUtil(type);
|
||||
if (!quota_util)
|
||||
return;
|
||||
*origins_ptr = quota_util->GetOriginsForHostOnFileTaskRunner(type, host);
|
||||
}
|
||||
|
||||
void DidGetFileSystemQuotaClientOrigins(
|
||||
QuotaClient::GetOriginsForTypeCallback callback,
|
||||
std::vector<url::Origin>* origins_ptr) {
|
||||
std::move(callback).Run(*origins_ptr);
|
||||
return {};
|
||||
return quota_util->GetOriginsForHostOnFileTaskRunner(type, host);
|
||||
}
|
||||
|
||||
blink::mojom::QuotaStatusCode DeleteOriginOnFileTaskRunner(
|
||||
@ -120,14 +114,11 @@ void FileSystemQuotaClient::GetOriginsForType(
|
||||
GetOriginsForTypeCallback callback) {
|
||||
DCHECK(!callback.is_null());
|
||||
|
||||
auto* origins_ptr = new std::vector<url::Origin>();
|
||||
file_task_runner()->PostTaskAndReply(
|
||||
file_task_runner()->PostTaskAndReplyWithResult(
|
||||
FROM_HERE,
|
||||
base::BindOnce(&GetOriginsForTypeOnFileTaskRunner,
|
||||
base::RetainedRef(file_system_context_), storage_type,
|
||||
base::Unretained(origins_ptr)),
|
||||
base::BindOnce(&DidGetFileSystemQuotaClientOrigins, std::move(callback),
|
||||
base::Owned(origins_ptr)));
|
||||
base::RetainedRef(file_system_context_), storage_type),
|
||||
std::move(callback));
|
||||
}
|
||||
|
||||
void FileSystemQuotaClient::GetOriginsForHost(
|
||||
@ -136,14 +127,12 @@ void FileSystemQuotaClient::GetOriginsForHost(
|
||||
GetOriginsForHostCallback callback) {
|
||||
DCHECK(!callback.is_null());
|
||||
|
||||
auto* origins_ptr = new std::vector<url::Origin>();
|
||||
file_task_runner()->PostTaskAndReply(
|
||||
file_task_runner()->PostTaskAndReplyWithResult(
|
||||
FROM_HERE,
|
||||
base::BindOnce(&GetOriginsForHostOnFileTaskRunner,
|
||||
base::RetainedRef(file_system_context_), storage_type,
|
||||
host, base::Unretained(origins_ptr)),
|
||||
base::BindOnce(&DidGetFileSystemQuotaClientOrigins, std::move(callback),
|
||||
base::Owned(origins_ptr)));
|
||||
host),
|
||||
std::move(callback));
|
||||
}
|
||||
|
||||
void FileSystemQuotaClient::DeleteOriginData(
|
||||
|
@ -38,9 +38,12 @@ IsolatedFileSystemBackend::IsolatedFileSystemBackend(
|
||||
bool use_for_type_platform_app)
|
||||
: use_for_type_native_local_(use_for_type_native_local),
|
||||
use_for_type_platform_app_(use_for_type_platform_app),
|
||||
isolated_file_util_(new AsyncFileUtilAdapter(new LocalFileUtil())),
|
||||
dragged_file_util_(new AsyncFileUtilAdapter(new DraggedFileUtil())),
|
||||
transient_file_util_(new AsyncFileUtilAdapter(new TransientFileUtil())) {}
|
||||
isolated_file_util_(
|
||||
std::make_unique<AsyncFileUtilAdapter>(new LocalFileUtil())),
|
||||
dragged_file_util_(
|
||||
std::make_unique<AsyncFileUtilAdapter>(new DraggedFileUtil())),
|
||||
transient_file_util_(
|
||||
std::make_unique<AsyncFileUtilAdapter>(new TransientFileUtil())) {}
|
||||
|
||||
IsolatedFileSystemBackend::~IsolatedFileSystemBackend() = default;
|
||||
|
||||
|
@ -6,6 +6,7 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
#include "base/bind.h"
|
||||
@ -107,7 +108,7 @@ void LocalFileStreamReader::DidVerifyForOpen(
|
||||
return;
|
||||
}
|
||||
|
||||
stream_impl_.reset(new net::FileStream(task_runner_));
|
||||
stream_impl_ = std::make_unique<net::FileStream>(task_runner_);
|
||||
callback_ = std::move(callback);
|
||||
const int result = stream_impl_->Open(
|
||||
file_path_, kOpenFlagsForRead,
|
||||
|
@ -6,6 +6,8 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "base/bind.h"
|
||||
#include "base/memory/ptr_util.h"
|
||||
#include "net/base/file_stream.h"
|
||||
@ -103,7 +105,7 @@ int LocalFileStreamWriter::InitiateOpen(base::OnceClosure main_operation) {
|
||||
DCHECK(has_pending_operation_);
|
||||
DCHECK(!stream_impl_.get());
|
||||
|
||||
stream_impl_.reset(new net::FileStream(task_runner_));
|
||||
stream_impl_ = std::make_unique<net::FileStream>(task_runner_);
|
||||
|
||||
int open_flags = 0;
|
||||
switch (open_or_create_) {
|
||||
|
@ -136,7 +136,7 @@ LocalFileUtil::CreateFileEnumerator(FileSystemOperationContext* context,
|
||||
bool recursive) {
|
||||
base::FilePath file_path;
|
||||
if (GetLocalFilePath(context, root_url, &file_path) != base::File::FILE_OK) {
|
||||
return base::WrapUnique(new EmptyFileEnumerator);
|
||||
return std::make_unique<EmptyFileEnumerator>();
|
||||
}
|
||||
return std::make_unique<LocalFileEnumerator>(
|
||||
this, file_path, root_url.path(), recursive,
|
||||
|
@ -819,7 +819,7 @@ ObfuscatedFileUtil::CreateFileEnumerator(FileSystemOperationContext* context,
|
||||
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
|
||||
SandboxDirectoryDatabase* db = GetDirectoryDatabase(root_url, false);
|
||||
if (!db) {
|
||||
return base::WrapUnique(new EmptyFileEnumerator);
|
||||
return std::make_unique<EmptyFileEnumerator>();
|
||||
}
|
||||
return std::make_unique<ObfuscatedFileEnumerator>(
|
||||
db, context, this, root_url, recursive);
|
||||
|
@ -464,17 +464,17 @@ class ObfuscatedFileUtilTest : public testing::Test,
|
||||
std::unique_ptr<UsageVerifyHelper> AllowUsageIncrease(
|
||||
int64_t requested_growth) {
|
||||
int64_t usage = sandbox_file_system_.GetCachedOriginUsage();
|
||||
return std::unique_ptr<UsageVerifyHelper>(new UsageVerifyHelper(
|
||||
LimitedContext(requested_growth), &sandbox_file_system_,
|
||||
usage + requested_growth, this));
|
||||
return std::make_unique<UsageVerifyHelper>(LimitedContext(requested_growth),
|
||||
&sandbox_file_system_,
|
||||
usage + requested_growth, this);
|
||||
}
|
||||
|
||||
std::unique_ptr<UsageVerifyHelper> DisallowUsageIncrease(
|
||||
int64_t requested_growth) {
|
||||
int64_t usage = sandbox_file_system_.GetCachedOriginUsage();
|
||||
return std::unique_ptr<UsageVerifyHelper>(
|
||||
new UsageVerifyHelper(LimitedContext(requested_growth - 1),
|
||||
&sandbox_file_system_, usage, this));
|
||||
return std::make_unique<UsageVerifyHelper>(
|
||||
LimitedContext(requested_growth - 1), &sandbox_file_system_, usage,
|
||||
this);
|
||||
}
|
||||
|
||||
void FillTestDirectory(const FileSystemURL& root_url,
|
||||
|
@ -13,6 +13,7 @@
|
||||
#include "base/bind.h"
|
||||
#include "base/files/scoped_temp_dir.h"
|
||||
#include "base/macros.h"
|
||||
#include "base/memory/scoped_refptr.h"
|
||||
#include "base/run_loop.h"
|
||||
#include "base/test/task_environment.h"
|
||||
#include "base/threading/thread_task_runner_handle.h"
|
||||
@ -93,7 +94,7 @@ class QuotaBackendImplTest : public testing::Test,
|
||||
public:
|
||||
QuotaBackendImplTest()
|
||||
: file_system_usage_cache_(is_incognito()),
|
||||
quota_manager_proxy_(new MockQuotaManagerProxy) {}
|
||||
quota_manager_proxy_(base::MakeRefCounted<MockQuotaManagerProxy>()) {}
|
||||
|
||||
void SetUp() override {
|
||||
ASSERT_TRUE(data_dir_.CreateUniqueTempDir());
|
||||
|
@ -188,9 +188,9 @@ class QuotaReservationManagerTest : public testing::Test {
|
||||
file_path_ = work_dir_.GetPath().Append(FILE_PATH_LITERAL("hoge"));
|
||||
SetFileSize(file_path_, kInitialFileSize);
|
||||
|
||||
std::unique_ptr<QuotaReservationManager::QuotaBackend> backend(
|
||||
new FakeBackend);
|
||||
reservation_manager_.reset(new QuotaReservationManager(std::move(backend)));
|
||||
auto backend = std::make_unique<FakeBackend>();
|
||||
reservation_manager_ =
|
||||
std::make_unique<QuotaReservationManager>(std::move(backend));
|
||||
}
|
||||
|
||||
void TearDown() override { reservation_manager_.reset(); }
|
||||
|
@ -46,7 +46,7 @@ class SandboxDirectoryDatabaseTest : public testing::Test {
|
||||
// Call CloseDatabase() to avoid having multiple database instances for
|
||||
// single directory at once.
|
||||
CloseDatabase();
|
||||
db_.reset(new SandboxDirectoryDatabase(path(), nullptr));
|
||||
db_ = std::make_unique<SandboxDirectoryDatabase>(path(), nullptr);
|
||||
}
|
||||
|
||||
void CloseDatabase() { db_.reset(); }
|
||||
@ -98,7 +98,7 @@ class SandboxDirectoryDatabaseTest : public testing::Test {
|
||||
db_.reset();
|
||||
ASSERT_TRUE(base::DeletePathRecursively(path()));
|
||||
ASSERT_TRUE(base::CreateDirectory(path()));
|
||||
db_.reset(new SandboxDirectoryDatabase(path(), nullptr));
|
||||
db_ = std::make_unique<SandboxDirectoryDatabase>(path(), nullptr);
|
||||
}
|
||||
|
||||
bool RepairDatabase() {
|
||||
|
@ -113,17 +113,17 @@ class SandboxObfuscatedOriginEnumerator
|
||||
std::unique_ptr<ObfuscatedFileUtil::AbstractOriginEnumerator> enum_;
|
||||
};
|
||||
|
||||
void OpenSandboxFileSystemOnFileTaskRunner(ObfuscatedFileUtil* file_util,
|
||||
const GURL& origin_url,
|
||||
FileSystemType type,
|
||||
OpenFileSystemMode mode,
|
||||
base::File::Error* error_ptr) {
|
||||
DCHECK(error_ptr);
|
||||
base::File::Error OpenSandboxFileSystemOnFileTaskRunner(
|
||||
ObfuscatedFileUtil* file_util,
|
||||
const GURL& origin_url,
|
||||
FileSystemType type,
|
||||
OpenFileSystemMode mode) {
|
||||
const bool create = (mode == OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT);
|
||||
base::File::Error error;
|
||||
file_util->GetDirectoryForOriginAndType(
|
||||
url::Origin::Create(origin_url),
|
||||
SandboxFileSystemBackendDelegate::GetTypeString(type), create, error_ptr);
|
||||
if (*error_ptr != base::File::FILE_OK) {
|
||||
SandboxFileSystemBackendDelegate::GetTypeString(type), create, &error);
|
||||
if (error != base::File::FILE_OK) {
|
||||
UMA_HISTOGRAM_ENUMERATION(kOpenFileSystemLabel, kCreateDirectoryError,
|
||||
kFileSystemErrorMax);
|
||||
} else {
|
||||
@ -132,18 +132,20 @@ void OpenSandboxFileSystemOnFileTaskRunner(ObfuscatedFileUtil* file_util,
|
||||
// The reference of file_util will be derefed on the FILE thread
|
||||
// when the storage of this callback gets deleted regardless of whether
|
||||
// this method is called or not.
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
void DidOpenFileSystem(
|
||||
base::WeakPtr<SandboxFileSystemBackendDelegate> delegate,
|
||||
base::OnceClosure quota_callback,
|
||||
base::OnceCallback<void(base::File::Error error)> callback,
|
||||
base::File::Error* error) {
|
||||
base::File::Error error) {
|
||||
if (delegate)
|
||||
delegate->CollectOpenFileSystemMetrics(*error);
|
||||
if (*error == base::File::FILE_OK)
|
||||
delegate->CollectOpenFileSystemMetrics(error);
|
||||
if (error == base::File::FILE_OK)
|
||||
std::move(quota_callback).Run();
|
||||
std::move(callback).Run(*error);
|
||||
std::move(callback).Run(error);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
@ -195,11 +197,12 @@ SandboxFileSystemBackendDelegate::SandboxFileSystemBackendDelegate(
|
||||
file_system_options.is_incognito()))),
|
||||
file_system_usage_cache_(std::make_unique<FileSystemUsageCache>(
|
||||
file_system_options.is_incognito())),
|
||||
quota_observer_(new SandboxQuotaObserver(quota_manager_proxy,
|
||||
file_task_runner,
|
||||
obfuscated_file_util(),
|
||||
usage_cache())),
|
||||
quota_reservation_manager_(new QuotaReservationManager(
|
||||
quota_observer_(
|
||||
std::make_unique<SandboxQuotaObserver>(quota_manager_proxy,
|
||||
file_task_runner,
|
||||
obfuscated_file_util(),
|
||||
usage_cache())),
|
||||
quota_reservation_manager_(std::make_unique<QuotaReservationManager>(
|
||||
std::make_unique<QuotaBackendImpl>(file_task_runner_.get(),
|
||||
obfuscated_file_util(),
|
||||
usage_cache(),
|
||||
@ -273,16 +276,13 @@ void SandboxFileSystemBackendDelegate::OpenFileSystem(
|
||||
FileSystemTypeToQuotaStorageType(type))
|
||||
: base::DoNothing();
|
||||
|
||||
base::File::Error* error_ptr = new base::File::Error;
|
||||
file_task_runner_->PostTaskAndReply(
|
||||
file_task_runner_->PostTaskAndReplyWithResult(
|
||||
FROM_HERE,
|
||||
base::BindOnce(&OpenSandboxFileSystemOnFileTaskRunner,
|
||||
obfuscated_file_util(), origin.GetURL(), type, mode,
|
||||
base::Unretained(error_ptr)),
|
||||
obfuscated_file_util(), origin.GetURL(), type, mode),
|
||||
base::BindOnce(&DidOpenFileSystem, weak_factory_.GetWeakPtr(),
|
||||
std::move(quota_callback),
|
||||
base::BindOnce(std::move(callback), root_url, name),
|
||||
base::Owned(error_ptr)));
|
||||
base::BindOnce(std::move(callback), root_url, name)));
|
||||
|
||||
DETACH_FROM_THREAD(io_thread_checker_);
|
||||
is_filesystem_opened_ = true;
|
||||
@ -302,8 +302,8 @@ SandboxFileSystemBackendDelegate::CreateFileSystemOperationContext(
|
||||
const ChangeObserverList* change_observers = GetChangeObservers(url.type());
|
||||
DCHECK(update_observers);
|
||||
|
||||
std::unique_ptr<FileSystemOperationContext> operation_context(
|
||||
new FileSystemOperationContext(context));
|
||||
auto operation_context =
|
||||
std::make_unique<FileSystemOperationContext>(context);
|
||||
operation_context->set_update_observers(*update_observers);
|
||||
operation_context->set_change_observers(
|
||||
change_observers ? *change_observers : ChangeObserverList());
|
||||
|
@ -91,16 +91,16 @@ class SandboxFileSystemBackendTest
|
||||
|
||||
void SetUpNewDelegate(const FileSystemOptions& options) {
|
||||
incognito_env_override_ = leveldb_chrome::NewMemEnv("FileSystem");
|
||||
delegate_.reset(new SandboxFileSystemBackendDelegate(
|
||||
delegate_ = std::make_unique<SandboxFileSystemBackendDelegate>(
|
||||
nullptr /* quota_manager_proxy */,
|
||||
base::ThreadTaskRunnerHandle::Get().get(), data_dir_.GetPath(),
|
||||
nullptr /* special_storage_policy */, options,
|
||||
options.is_in_memory() ? incognito_env_override_.get() : nullptr));
|
||||
options.is_in_memory() ? incognito_env_override_.get() : nullptr);
|
||||
}
|
||||
|
||||
void SetUpNewBackend(const FileSystemOptions& options) {
|
||||
SetUpNewDelegate(options);
|
||||
backend_.reset(new SandboxFileSystemBackend(delegate_.get()));
|
||||
backend_ = std::make_unique<SandboxFileSystemBackend>(delegate_.get());
|
||||
}
|
||||
|
||||
SandboxFileSystemBackendDelegate::OriginEnumerator* CreateOriginEnumerator()
|
||||
|
@ -208,8 +208,7 @@ TEST(SandboxOriginDatabaseTest, DatabaseRecoveryTest) {
|
||||
"hoge.example.com", "fuga.example.com",
|
||||
};
|
||||
|
||||
std::unique_ptr<SandboxOriginDatabase> database(
|
||||
new SandboxOriginDatabase(kFSDir, nullptr));
|
||||
auto database = std::make_unique<SandboxOriginDatabase>(kFSDir, nullptr);
|
||||
for (size_t i = 0; i < base::size(kOrigins); ++i) {
|
||||
base::FilePath path;
|
||||
EXPECT_FALSE(database->HasOriginPath(kOrigins[i]));
|
||||
@ -238,7 +237,7 @@ TEST(SandboxOriginDatabaseTest, DatabaseRecoveryTest) {
|
||||
CorruptDatabase(kDBDir, leveldb::kLogFile, -1, 1);
|
||||
|
||||
base::FilePath path;
|
||||
database.reset(new SandboxOriginDatabase(kFSDir, nullptr));
|
||||
database = std::make_unique<SandboxOriginDatabase>(kFSDir, nullptr);
|
||||
std::vector<SandboxOriginDatabase::OriginRecord> origins_in_db;
|
||||
EXPECT_TRUE(database->ListAllOrigins(&origins_in_db));
|
||||
|
||||
@ -274,8 +273,7 @@ TEST(SandboxOriginDatabaseTest, DatabaseRecoveryForMissingDBFileTest) {
|
||||
const std::string kOrigin = "foo.example.com";
|
||||
base::FilePath path;
|
||||
|
||||
std::unique_ptr<SandboxOriginDatabase> database(
|
||||
new SandboxOriginDatabase(kFSDir, nullptr));
|
||||
auto database = std::make_unique<SandboxOriginDatabase>(kFSDir, nullptr);
|
||||
EXPECT_FALSE(database->HasOriginPath(kOrigin));
|
||||
EXPECT_TRUE(database->GetPathForOrigin(kOrigin, &path));
|
||||
EXPECT_FALSE(path.empty());
|
||||
@ -285,7 +283,7 @@ TEST(SandboxOriginDatabaseTest, DatabaseRecoveryForMissingDBFileTest) {
|
||||
|
||||
DeleteDatabaseFile(kDBDir, file_type);
|
||||
|
||||
database.reset(new SandboxOriginDatabase(kFSDir, nullptr));
|
||||
database = std::make_unique<SandboxOriginDatabase>(kFSDir, nullptr);
|
||||
std::vector<SandboxOriginDatabase::OriginRecord> origins_in_db;
|
||||
EXPECT_TRUE(database->ListAllOrigins(&origins_in_db));
|
||||
|
||||
|
@ -4,6 +4,8 @@
|
||||
|
||||
#include "storage/browser/file_system/sandbox_prioritized_origin_database.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "base/check.h"
|
||||
#include "base/files/file.h"
|
||||
#include "base/files/file_util.h"
|
||||
@ -65,8 +67,10 @@ bool SandboxPrioritizedOriginDatabase::InitializePrimaryOrigin(
|
||||
if (!primary_origin_database_ && !is_in_memory) {
|
||||
if (!MaybeLoadPrimaryOrigin() && ResetPrimaryOrigin(origin)) {
|
||||
MaybeMigrateDatabase(origin);
|
||||
primary_origin_database_.reset(new SandboxIsolatedOriginDatabase(
|
||||
origin, file_system_directory_, base::FilePath(kPrimaryDirectory)));
|
||||
primary_origin_database_ =
|
||||
std::make_unique<SandboxIsolatedOriginDatabase>(
|
||||
origin, file_system_directory_,
|
||||
base::FilePath(kPrimaryDirectory));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -151,8 +155,8 @@ bool SandboxPrioritizedOriginDatabase::MaybeLoadPrimaryOrigin() {
|
||||
std::string saved_origin;
|
||||
if (!ReadPrimaryOriginFile(primary_origin_file_, &saved_origin))
|
||||
return false;
|
||||
primary_origin_database_.reset(new SandboxIsolatedOriginDatabase(
|
||||
saved_origin, file_system_directory_, base::FilePath(kPrimaryDirectory)));
|
||||
primary_origin_database_ = std::make_unique<SandboxIsolatedOriginDatabase>(
|
||||
saved_origin, file_system_directory_, base::FilePath(kPrimaryDirectory));
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -207,8 +211,8 @@ void SandboxPrioritizedOriginDatabase::MaybeInitializeNonPrimaryDatabase(
|
||||
if (origin_database_)
|
||||
return;
|
||||
|
||||
origin_database_.reset(
|
||||
new SandboxOriginDatabase(file_system_directory_, env_override_));
|
||||
origin_database_ = std::make_unique<SandboxOriginDatabase>(
|
||||
file_system_directory_, env_override_);
|
||||
if (!create && !base::DirectoryExists(origin_database_->GetDatabasePath())) {
|
||||
origin_database_.reset();
|
||||
return;
|
||||
|
Reference in New Issue
Block a user