FileAPI: Add Initialize() function to FileSystemBackend
This is a preliminary change for adding SyncFileSystemBackend.
At first, we planed to do initializing process for SyncFileSystemBackend in
InitializeFileSystem(), but it revealed that there are some hassles on that
way (see [*]), so we decieded to introduce a separate initialze function and
to rename InitializeFileSystem() to its original name (i.e. OpenFileSystem()).
[*] https://codereview.chromium.org/18668003/
BUG=242422
TEST=should pass all existing tests
NOTRY=true
Review URL: https://chromiumcodereview.appspot.com/19632004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@213382 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/webkit/browser/fileapi/copy_or_move_file_validator_unittest.cc b/webkit/browser/fileapi/copy_or_move_file_validator_unittest.cc
index 31530e0..1190f7a 100644
--- a/webkit/browser/fileapi/copy_or_move_file_validator_unittest.cc
+++ b/webkit/browser/fileapi/copy_or_move_file_validator_unittest.cc
@@ -64,10 +64,9 @@
// Sets up source.
FileSystemBackend* src_file_system_backend =
file_system_context_->GetFileSystemBackend(src_type_);
- src_file_system_backend->InitializeFileSystem(
+ src_file_system_backend->OpenFileSystem(
origin_, src_type_,
OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT,
- NULL /* context */,
base::Bind(&ExpectOk));
base::MessageLoop::current()->RunUntilIdle();
ASSERT_EQ(base::PLATFORM_FILE_OK, CreateDirectory(SourceURL("")));
diff --git a/webkit/browser/fileapi/copy_or_move_operation_delegate_unittest.cc b/webkit/browser/fileapi/copy_or_move_operation_delegate_unittest.cc
index dbddb27..1b7c872 100644
--- a/webkit/browser/fileapi/copy_or_move_operation_delegate_unittest.cc
+++ b/webkit/browser/fileapi/copy_or_move_operation_delegate_unittest.cc
@@ -129,10 +129,9 @@
// Prepare the origin's root directory.
FileSystemBackend* mount_point_provider =
file_system_context_->GetFileSystemBackend(src_type_);
- mount_point_provider->InitializeFileSystem(
+ mount_point_provider->OpenFileSystem(
origin_, src_type_,
OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT,
- NULL /* context */,
base::Bind(&ExpectOk));
mount_point_provider =
file_system_context_->GetFileSystemBackend(dest_type_);
@@ -144,10 +143,9 @@
test_provider->set_require_copy_or_move_validator(true);
test_provider->InitializeCopyOrMoveFileValidatorFactory(factory.Pass());
}
- mount_point_provider->InitializeFileSystem(
+ mount_point_provider->OpenFileSystem(
origin_, dest_type_,
OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT,
- NULL /* context */,
base::Bind(&ExpectOk));
base::MessageLoop::current()->RunUntilIdle();
diff --git a/webkit/browser/fileapi/file_system_backend.h b/webkit/browser/fileapi/file_system_backend.h
index 37cb6b0..33b4627 100644
--- a/webkit/browser/fileapi/file_system_backend.h
+++ b/webkit/browser/fileapi/file_system_backend.h
@@ -46,25 +46,29 @@
typedef base::Callback<void(const GURL& root_url,
const std::string& name,
base::PlatformFileError error)>
- InitializeFileSystemCallback;
+ OpenFileSystemCallback;
virtual ~FileSystemBackend() {}
// Returns true if this mount point provider can handle |type|.
// One mount point provider may be able to handle multiple filesystem types.
virtual bool CanHandleType(FileSystemType type) const = 0;
- // Initializes the filesystem for the given |origin_url| and |type|.
+ // This method is called right after the backend is registered in the
+ // FileSystemContext and before any other methods are called. Each backend can
+ // do additional initialization which depends on FileSystemContext here.
+ virtual void Initialize(FileSystemContext* context) = 0;
+
+ // Opens the filesystem for the given |origin_url| and |type|.
// This verifies if it is allowed to request (or create) the filesystem
// and if it can access (or create) the root directory of the mount point.
// If |mode| is CREATE_IF_NONEXISTENT calling this may also create
// the root directory (and/or related database entries etc) for
// the filesystem if it doesn't exist.
- virtual void InitializeFileSystem(
+ virtual void OpenFileSystem(
const GURL& origin_url,
FileSystemType type,
OpenFileSystemMode mode,
- FileSystemContext* context,
- const InitializeFileSystemCallback& callback) = 0;
+ const OpenFileSystemCallback& callback) = 0;
// Returns the specialized FileSystemFileUtil for this mount point.
// It is ok to return NULL if the filesystem doesn't support synchronous
diff --git a/webkit/browser/fileapi/file_system_context.cc b/webkit/browser/fileapi/file_system_context.cc
index d994263..ecbb3ea 100644
--- a/webkit/browser/fileapi/file_system_context.cc
+++ b/webkit/browser/fileapi/file_system_context.cc
@@ -138,6 +138,14 @@
RegisterBackend(*iter);
}
+ sandbox_backend_->Initialize(this);
+ isolated_backend_->Initialize(this);
+ for (ScopedVector<FileSystemBackend>::const_iterator iter =
+ additional_backends_.begin();
+ iter != additional_backends_.end(); ++iter) {
+ (*iter)->Initialize(this);
+ }
+
// Additional mount points must be added before regular system-wide
// mount points.
if (external_mount_points)
@@ -269,8 +277,8 @@
return;
}
- backend->InitializeFileSystem(origin_url, type, mode, this,
- base::Bind(&DidOpenFileSystem, callback));
+ backend->OpenFileSystem(origin_url, type, mode,
+ base::Bind(&DidOpenFileSystem, callback));
}
void FileSystemContext::DeleteFileSystem(
diff --git a/webkit/browser/fileapi/isolated_file_system_backend.cc b/webkit/browser/fileapi/isolated_file_system_backend.cc
index 97c1962..4f35932 100644
--- a/webkit/browser/fileapi/isolated_file_system_backend.cc
+++ b/webkit/browser/fileapi/isolated_file_system_backend.cc
@@ -56,12 +56,14 @@
}
}
-void IsolatedFileSystemBackend::InitializeFileSystem(
+void IsolatedFileSystemBackend::Initialize(FileSystemContext* context) {
+}
+
+void IsolatedFileSystemBackend::OpenFileSystem(
const GURL& origin_url,
FileSystemType type,
OpenFileSystemMode mode,
- FileSystemContext* context,
- const InitializeFileSystemCallback& callback) {
+ const OpenFileSystemCallback& callback) {
// We never allow opening a new isolated FileSystem via usual OpenFileSystem.
base::MessageLoopProxy::current()->PostTask(
FROM_HERE,
diff --git a/webkit/browser/fileapi/isolated_file_system_backend.h b/webkit/browser/fileapi/isolated_file_system_backend.h
index 63cf4de..cdc70969 100644
--- a/webkit/browser/fileapi/isolated_file_system_backend.h
+++ b/webkit/browser/fileapi/isolated_file_system_backend.h
@@ -19,12 +19,12 @@
// FileSystemBackend implementation.
virtual bool CanHandleType(FileSystemType type) const OVERRIDE;
- virtual void InitializeFileSystem(
+ virtual void Initialize(FileSystemContext* context) OVERRIDE;
+ virtual void OpenFileSystem(
const GURL& origin_url,
FileSystemType type,
OpenFileSystemMode mode,
- FileSystemContext* context,
- const InitializeFileSystemCallback& callback) OVERRIDE;
+ const OpenFileSystemCallback& callback) OVERRIDE;
virtual FileSystemFileUtil* GetFileUtil(FileSystemType type) OVERRIDE;
virtual AsyncFileUtil* GetAsyncFileUtil(FileSystemType type) OVERRIDE;
virtual CopyOrMoveFileValidatorFactory* GetCopyOrMoveFileValidatorFactory(
diff --git a/webkit/browser/fileapi/sandbox_file_system_backend.cc b/webkit/browser/fileapi/sandbox_file_system_backend.cc
index fb8bea9..12f0705d 100644
--- a/webkit/browser/fileapi/sandbox_file_system_backend.cc
+++ b/webkit/browser/fileapi/sandbox_file_system_backend.cc
@@ -135,6 +135,19 @@
sandbox_context_(sandbox_context),
enable_temporary_file_system_in_incognito_(false),
weak_factory_(this) {
+}
+
+SandboxFileSystemBackend::~SandboxFileSystemBackend() {
+}
+
+bool SandboxFileSystemBackend::CanHandleType(FileSystemType type) const {
+ return type == kFileSystemTypeTemporary ||
+ type == kFileSystemTypePersistent ||
+ type == kFileSystemTypeSyncable ||
+ type == kFileSystemTypeSyncableForInternalSync;
+}
+
+void SandboxFileSystemBackend::Initialize(FileSystemContext* context) {
// Set quota observers.
if (sandbox_context_->is_usage_tracking_enabled()) {
update_observers_ = update_observers_.AddObserver(
@@ -156,22 +169,11 @@
}
}
-SandboxFileSystemBackend::~SandboxFileSystemBackend() {
-}
-
-bool SandboxFileSystemBackend::CanHandleType(FileSystemType type) const {
- return type == kFileSystemTypeTemporary ||
- type == kFileSystemTypePersistent ||
- type == kFileSystemTypeSyncable ||
- type == kFileSystemTypeSyncableForInternalSync;
-}
-
-void SandboxFileSystemBackend::InitializeFileSystem(
+void SandboxFileSystemBackend::OpenFileSystem(
const GURL& origin_url,
fileapi::FileSystemType type,
OpenFileSystemMode mode,
- FileSystemContext* context,
- const InitializeFileSystemCallback& callback) {
+ const OpenFileSystemCallback& callback) {
if (file_system_options_.is_incognito() &&
!(type == kFileSystemTypeTemporary &&
enable_temporary_file_system_in_incognito_)) {
diff --git a/webkit/browser/fileapi/sandbox_file_system_backend.h b/webkit/browser/fileapi/sandbox_file_system_backend.h
index 3bf6f29..f1a7a55 100644
--- a/webkit/browser/fileapi/sandbox_file_system_backend.h
+++ b/webkit/browser/fileapi/sandbox_file_system_backend.h
@@ -73,12 +73,12 @@
// FileSystemBackend overrides.
virtual bool CanHandleType(FileSystemType type) const OVERRIDE;
- virtual void InitializeFileSystem(
+ virtual void Initialize(FileSystemContext* context) OVERRIDE;
+ virtual void OpenFileSystem(
const GURL& origin_url,
FileSystemType type,
OpenFileSystemMode mode,
- FileSystemContext* context,
- const InitializeFileSystemCallback& callback) OVERRIDE;
+ const OpenFileSystemCallback& callback) OVERRIDE;
virtual FileSystemFileUtil* GetFileUtil(FileSystemType type) OVERRIDE;
virtual AsyncFileUtil* GetAsyncFileUtil(FileSystemType type) OVERRIDE;
virtual CopyOrMoveFileValidatorFactory* GetCopyOrMoveFileValidatorFactory(
diff --git a/webkit/browser/fileapi/sandbox_file_system_backend_unittest.cc b/webkit/browser/fileapi/sandbox_file_system_backend_unittest.cc
index ee4439c..5b0f8bc 100644
--- a/webkit/browser/fileapi/sandbox_file_system_backend_unittest.cc
+++ b/webkit/browser/fileapi/sandbox_file_system_backend_unittest.cc
@@ -113,8 +113,8 @@
OpenFileSystemMode mode,
base::FilePath* root_path) {
base::PlatformFileError error = base::PLATFORM_FILE_OK;
- backend_->InitializeFileSystem(
- origin_url, type, mode, NULL /* context */,
+ backend_->OpenFileSystem(
+ origin_url, type, mode,
base::Bind(&DidOpenFileSystem, &error));
base::MessageLoop::current()->RunUntilIdle();
if (error != base::PLATFORM_FILE_OK)
diff --git a/webkit/browser/fileapi/test_file_system_backend.cc b/webkit/browser/fileapi/test_file_system_backend.cc
index 4df22b7..547d6eb 100644
--- a/webkit/browser/fileapi/test_file_system_backend.cc
+++ b/webkit/browser/fileapi/test_file_system_backend.cc
@@ -148,12 +148,14 @@
return (type == kFileSystemTypeTest);
}
-void TestFileSystemBackend::InitializeFileSystem(
+void TestFileSystemBackend::Initialize(FileSystemContext* context) {
+}
+
+void TestFileSystemBackend::OpenFileSystem(
const GURL& origin_url,
FileSystemType type,
OpenFileSystemMode mode,
- FileSystemContext* context,
- const InitializeFileSystemCallback& callback) {
+ const OpenFileSystemCallback& callback) {
callback.Run(GetFileSystemRootURI(origin_url, type),
GetFileSystemName(origin_url, type),
base::PLATFORM_FILE_OK);
diff --git a/webkit/browser/fileapi/test_file_system_backend.h b/webkit/browser/fileapi/test_file_system_backend.h
index 21b4e433..ef252c1 100644
--- a/webkit/browser/fileapi/test_file_system_backend.h
+++ b/webkit/browser/fileapi/test_file_system_backend.h
@@ -35,12 +35,12 @@
// FileSystemBackend implementation.
virtual bool CanHandleType(FileSystemType type) const OVERRIDE;
- virtual void InitializeFileSystem(
+ virtual void Initialize(FileSystemContext* context) OVERRIDE;
+ virtual void OpenFileSystem(
const GURL& origin_url,
FileSystemType type,
OpenFileSystemMode mode,
- FileSystemContext* context,
- const InitializeFileSystemCallback& callback) OVERRIDE;
+ const OpenFileSystemCallback& callback) OVERRIDE;
virtual FileSystemFileUtil* GetFileUtil(FileSystemType type) OVERRIDE;
virtual AsyncFileUtil* GetAsyncFileUtil(FileSystemType type) OVERRIDE;
virtual CopyOrMoveFileValidatorFactory* GetCopyOrMoveFileValidatorFactory(