diff options
author | kinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-29 07:44:40 +0000 |
---|---|---|
committer | kinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-29 07:44:40 +0000 |
commit | 22dea52cdc3fd2eac4781f1eb2993550ea2b0dba (patch) | |
tree | 3fe1542b84e742e62aab2185d2b2eefdac877ce0 | |
parent | 8f8345c550c59f55f9e795bfad503e404b1291e3 (diff) | |
download | chromium_src-22dea52cdc3fd2eac4781f1eb2993550ea2b0dba.zip chromium_src-22dea52cdc3fd2eac4781f1eb2993550ea2b0dba.tar.gz chromium_src-22dea52cdc3fd2eac4781f1eb2993550ea2b0dba.tar.bz2 |
Rename FileSystemMountPointProvider::ValidateFileSystemRoot to OpenFileSystem
This patch does:
- Rename ValidateFileSystemRoot() to OpenFileSystem() to make it clearer
what the method does (as the method is called in response to OpenFileSystem
request from the renderer)
- Also change boolean 'create' parameter to an enum (OpenFileSystemMode)
BUG=243216
R=benjhayden@chromium.org, kinaba@chromium.org, tzik@chromium.org
Review URL: https://codereview.chromium.org/16043006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@202801 0039d316-1c4b-4281-b951-d872f2087c98
32 files changed, 174 insertions, 115 deletions
diff --git a/chrome/browser/browsing_data/browsing_data_file_system_helper_unittest.cc b/chrome/browser/browsing_data/browsing_data_file_system_helper_unittest.cc index 8d57ae5..983c021 100644 --- a/chrome/browser/browsing_data/browsing_data_file_system_helper_unittest.cc +++ b/chrome/browser/browsing_data/browsing_data_file_system_helper_unittest.cc @@ -100,25 +100,26 @@ class BrowsingDataFileSystemHelperTest : public testing::Test { } // Callback that should be executed in response to - // fileapi::SandboxMountPointProvider::ValidateFileSystemRoot - void ValidateFileSystemCallback(base::PlatformFileError error) { - validate_file_system_result_ = error; + // fileapi::SandboxMountPointProvider::OpenFileSystem. + void OpenFileSystemCallback(base::PlatformFileError error) { + open_file_system_result_ = error; Notify(); } - // Calls fileapi::SandboxMountPointProvider::ValidateFileSystemRootAndGetURL + // Calls fileapi::SandboxMountPointProvider::OpenFileSystem // to verify the existence of a file system for a specified type and origin, // blocks until a response is available, then returns the result // synchronously to it's caller. bool FileSystemContainsOriginAndType(const GURL& origin, fileapi::FileSystemType type) { - sandbox_->ValidateFileSystemRoot( - origin, type, false, + sandbox_->OpenFileSystem( + origin, type, + fileapi::OPEN_FILE_SYSTEM_FAIL_IF_NONEXISTENT, base::Bind( - &BrowsingDataFileSystemHelperTest::ValidateFileSystemCallback, + &BrowsingDataFileSystemHelperTest::OpenFileSystemCallback, base::Unretained(this))); BlockUntilNotified(); - return validate_file_system_result_ == base::PLATFORM_FILE_OK; + return open_file_system_result_ == base::PLATFORM_FILE_OK; } // Callback that should be executed in response to StartFetching(), and stores @@ -186,7 +187,7 @@ class BrowsingDataFileSystemHelperTest : public testing::Test { // Temporary storage to pass information back from callbacks. - base::PlatformFileError validate_file_system_result_; + base::PlatformFileError open_file_system_result_; ScopedFileSystemInfoList file_system_info_list_; scoped_refptr<BrowsingDataFileSystemHelper> helper_; diff --git a/chrome/browser/chromeos/extensions/file_manager/file_browser_handler_api.cc b/chrome/browser/chromeos/extensions/file_manager/file_browser_handler_api.cc index e05f818..4a9c082 100644 --- a/chrome/browser/chromeos/extensions/file_manager/file_browser_handler_api.cc +++ b/chrome/browser/chromeos/extensions/file_manager/file_browser_handler_api.cc @@ -339,7 +339,8 @@ void FileBrowserHandlerInternalSelectFileFunction::OnFilePathSelected( content::SiteInstance* site_instance = render_view_host()->GetSiteInstance(); BrowserContext::GetStoragePartition(profile_, site_instance)-> GetFileSystemContext()->OpenFileSystem( - source_url_.GetOrigin(), fileapi::kFileSystemTypeExternal, false, + source_url_.GetOrigin(), fileapi::kFileSystemTypeExternal, + fileapi::OPEN_FILE_SYSTEM_FAIL_IF_NONEXISTENT, base::Bind( &RunOpenFileSystemCallback, base::Bind(&FileBrowserHandlerInternalSelectFileFunction:: diff --git a/chrome/browser/chromeos/extensions/file_manager/file_browser_private_api.cc b/chrome/browser/chromeos/extensions/file_manager/file_browser_private_api.cc index e928cf4d..6d67d59 100644 --- a/chrome/browser/chromeos/extensions/file_manager/file_browser_private_api.cc +++ b/chrome/browser/chromeos/extensions/file_manager/file_browser_private_api.cc @@ -616,7 +616,8 @@ void RequestLocalFileSystemFunction::RequestOnFileThread( int child_id) { GURL origin_url = source_url.GetOrigin(); file_system_context->OpenFileSystem( - origin_url, fileapi::kFileSystemTypeExternal, false, // create + origin_url, fileapi::kFileSystemTypeExternal, + fileapi::OPEN_FILE_SYSTEM_FAIL_IF_NONEXISTENT, LocalFileSystemCallbackDispatcher::CreateCallback( this, file_system_context, diff --git a/chrome/browser/chromeos/extensions/file_manager/file_handler_util.cc b/chrome/browser/chromeos/extensions/file_manager/file_handler_util.cc index d38eaeb..594cc51 100644 --- a/chrome/browser/chromeos/extensions/file_manager/file_handler_util.cc +++ b/chrome/browser/chromeos/extensions/file_manager/file_handler_util.cc @@ -824,7 +824,8 @@ bool ExtensionTaskExecutor::ExecuteAndNotify( BrowserThread::FILE, FROM_HERE, base::Bind(&fileapi::FileSystemContext::OpenFileSystem, file_system_context_handler, - origin_url, fileapi::kFileSystemTypeExternal, false, // create + origin_url, fileapi::kFileSystemTypeExternal, + fileapi::OPEN_FILE_SYSTEM_FAIL_IF_NONEXISTENT, ExecuteTasksFileSystemCallbackDispatcher::CreateCallback( this, file_system_context_handler, diff --git a/chrome/browser/extensions/api/downloads/downloads_api_unittest.cc b/chrome/browser/extensions/api/downloads/downloads_api_unittest.cc index d3b2cc2..5d78e13 100644 --- a/chrome/browser/extensions/api/downloads/downloads_api_unittest.cc +++ b/chrome/browser/extensions/api/downloads/downloads_api_unittest.cc @@ -770,7 +770,7 @@ class HTML5FileWriter { fs_->OpenFileSystem( GURL(origin_), fileapi::kFileSystemTypeTemporary, - kCreateFileSystem, + fileapi::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, base::Bind(&HTML5FileWriter::OpenFileSystemCallback, base::Unretained(this))); return events_listener_->WaitFor(profile_, kHTML5FileWritten, filename_); @@ -780,7 +780,6 @@ class HTML5FileWriter { static const char kHTML5FileWritten[]; static const char kURLRequestContextToreDown[]; static const bool kExclusive = true; - static const bool kCreateFileSystem = true; GURL blob_url() const { return GURL("blob:" + filename_); } diff --git a/chrome/browser/extensions/api/sync_file_system/sync_file_system_api.cc b/chrome/browser/extensions/api/sync_file_system/sync_file_system_api.cc index 396c097..64e2295 100644 --- a/chrome/browser/extensions/api/sync_file_system/sync_file_system_api.cc +++ b/chrome/browser/extensions/api/sync_file_system/sync_file_system_api.cc @@ -160,7 +160,7 @@ void SyncFileSystemRequestFileSystemFunction::DidInitializeFileSystemContext( service_name, source_url().GetOrigin(), fileapi::kFileSystemTypeSyncable, - true, /* create */ + fileapi::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, base::Bind(&self::DidOpenFileSystem, this))); } diff --git a/chrome/browser/media_galleries/fileapi/media_file_system_mount_point_provider.cc b/chrome/browser/media_galleries/fileapi/media_file_system_mount_point_provider.cc index ccdaad4..e3ac980 100644 --- a/chrome/browser/media_galleries/fileapi/media_file_system_mount_point_provider.cc +++ b/chrome/browser/media_galleries/fileapi/media_file_system_mount_point_provider.cc @@ -72,11 +72,11 @@ bool MediaFileSystemMountPointProvider::CanHandleType( } } -void MediaFileSystemMountPointProvider::ValidateFileSystemRoot( +void MediaFileSystemMountPointProvider::OpenFileSystem( const GURL& origin_url, fileapi::FileSystemType type, - bool create, - const ValidateFileSystemCallback& callback) { + fileapi::OpenFileSystemMode mode, + const OpenFileSystemCallback& callback) { // We never allow opening a new isolated FileSystem via usual OpenFileSystem. base::MessageLoopProxy::current()->PostTask( FROM_HERE, diff --git a/chrome/browser/media_galleries/fileapi/media_file_system_mount_point_provider.h b/chrome/browser/media_galleries/fileapi/media_file_system_mount_point_provider.h index 01df9d6..5b6605d 100644 --- a/chrome/browser/media_galleries/fileapi/media_file_system_mount_point_provider.h +++ b/chrome/browser/media_galleries/fileapi/media_file_system_mount_point_provider.h @@ -30,11 +30,11 @@ class MediaFileSystemMountPointProvider // FileSystemMountPointProvider implementation. virtual bool CanHandleType(fileapi::FileSystemType type) const OVERRIDE; - virtual void ValidateFileSystemRoot( + virtual void OpenFileSystem( const GURL& origin_url, fileapi::FileSystemType type, - bool create, - const ValidateFileSystemCallback& callback) OVERRIDE; + fileapi::OpenFileSystemMode mode, + const OpenFileSystemCallback& callback) OVERRIDE; virtual fileapi::FileSystemFileUtil* GetFileUtil( fileapi::FileSystemType type) OVERRIDE; virtual fileapi::AsyncFileUtil* GetAsyncFileUtil( diff --git a/content/browser/fileapi/fileapi_message_filter.cc b/content/browser/fileapi/fileapi_message_filter.cc index 1627ddd..0ec6a0c 100644 --- a/content/browser/fileapi/fileapi_message_filter.cc +++ b/content/browser/fileapi/fileapi_message_filter.cc @@ -195,7 +195,11 @@ void FileAPIMessageFilter::OnOpen( } else if (type == fileapi::kFileSystemTypePersistent) { RecordAction(UserMetricsAction("OpenFileSystemPersistent")); } - context_->OpenFileSystem(origin_url, type, create, base::Bind( + // TODO(kinuko): Use this mode for IPC too. + fileapi::OpenFileSystemMode mode = + create ? fileapi::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT + : fileapi::OPEN_FILE_SYSTEM_FAIL_IF_NONEXISTENT; + context_->OpenFileSystem(origin_url, type, mode, base::Bind( &FileAPIMessageFilter::DidOpenFileSystem, this, request_id)); } diff --git a/webkit/browser/blob/blob_url_request_job_unittest.cc b/webkit/browser/blob/blob_url_request_job_unittest.cc index 9eff4fa..d580f97 100644 --- a/webkit/browser/blob/blob_url_request_job_unittest.cc +++ b/webkit/browser/blob/blob_url_request_job_unittest.cc @@ -172,7 +172,7 @@ class BlobURLRequestJobTest : public testing::Test { file_system_context_->OpenFileSystem( GURL(kFileSystemURLOrigin), kFileSystemType, - true, // create + fileapi::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, base::Bind(&BlobURLRequestJobTest::OnValidateFileSystem, base::Unretained(this))); base::MessageLoop::current()->RunUntilIdle(); diff --git a/webkit/browser/chromeos/fileapi/cros_mount_point_provider.cc b/webkit/browser/chromeos/fileapi/cros_mount_point_provider.cc index 5f36f6e..aa279d2 100644 --- a/webkit/browser/chromeos/fileapi/cros_mount_point_provider.cc +++ b/webkit/browser/chromeos/fileapi/cros_mount_point_provider.cc @@ -90,11 +90,11 @@ bool CrosMountPointProvider::CanHandleType(fileapi::FileSystemType type) const { } } -void CrosMountPointProvider::ValidateFileSystemRoot( +void CrosMountPointProvider::OpenFileSystem( const GURL& origin_url, fileapi::FileSystemType type, - bool create, - const ValidateFileSystemCallback& callback) { + fileapi::OpenFileSystemMode mode, + const OpenFileSystemCallback& callback) { DCHECK(fileapi::IsolatedContext::IsIsolatedType(type)); // Nothing to validate for external filesystem. callback.Run(base::PLATFORM_FILE_OK); diff --git a/webkit/browser/chromeos/fileapi/cros_mount_point_provider.h b/webkit/browser/chromeos/fileapi/cros_mount_point_provider.h index 09ac76d..48cba9c 100644 --- a/webkit/browser/chromeos/fileapi/cros_mount_point_provider.h +++ b/webkit/browser/chromeos/fileapi/cros_mount_point_provider.h @@ -35,7 +35,7 @@ class FileAccessPermissions; class WEBKIT_STORAGE_EXPORT CrosMountPointProvider : public fileapi::ExternalFileSystemMountPointProvider { public: - using fileapi::FileSystemMountPointProvider::ValidateFileSystemCallback; + using fileapi::FileSystemMountPointProvider::OpenFileSystemCallback; using fileapi::FileSystemMountPointProvider::DeleteFileSystemCallback; // CrosMountPointProvider will take an ownership of a |mount_points| @@ -54,11 +54,11 @@ class WEBKIT_STORAGE_EXPORT CrosMountPointProvider // fileapi::FileSystemMountPointProvider overrides. virtual bool CanHandleType(fileapi::FileSystemType type) const OVERRIDE; - virtual void ValidateFileSystemRoot( + virtual void OpenFileSystem( const GURL& origin_url, fileapi::FileSystemType type, - bool create, - const ValidateFileSystemCallback& callback) OVERRIDE; + fileapi::OpenFileSystemMode mode, + const OpenFileSystemCallback& callback) OVERRIDE; virtual fileapi::FileSystemFileUtil* GetFileUtil( fileapi::FileSystemType type) OVERRIDE; virtual fileapi::AsyncFileUtil* GetAsyncFileUtil( 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 5dce741..fb523a4 100644 --- a/webkit/browser/fileapi/copy_or_move_file_validator_unittest.cc +++ b/webkit/browser/fileapi/copy_or_move_file_validator_unittest.cc @@ -61,8 +61,10 @@ class CopyOrMoveFileValidatorTestHelper { // Sets up source. FileSystemMountPointProvider* src_mount_point_provider = file_system_context_->GetMountPointProvider(src_type_); - src_mount_point_provider->ValidateFileSystemRoot( - origin_, src_type_, true /* create */, base::Bind(&ExpectOk)); + src_mount_point_provider->OpenFileSystem( + origin_, src_type_, + OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, + base::Bind(&ExpectOk)); base::MessageLoop::current()->RunUntilIdle(); ASSERT_EQ(base::PLATFORM_FILE_OK, CreateDirectory(SourceURL(""))); diff --git a/webkit/browser/fileapi/file_system_context.cc b/webkit/browser/fileapi/file_system_context.cc index 4664a85..676d251 100644 --- a/webkit/browser/fileapi/file_system_context.cc +++ b/webkit/browser/fileapi/file_system_context.cc @@ -213,7 +213,7 @@ FileSystemContext::external_provider() const { void FileSystemContext::OpenFileSystem( const GURL& origin_url, FileSystemType type, - bool create, + OpenFileSystemMode mode, const OpenFileSystemCallback& callback) { DCHECK(!callback.is_null()); @@ -227,8 +227,8 @@ void FileSystemContext::OpenFileSystem( GURL root_url = GetFileSystemRootURI(origin_url, type); std::string name = GetFileSystemName(origin_url, type); - mount_point_provider->ValidateFileSystemRoot( - origin_url, type, create, + mount_point_provider->OpenFileSystem( + origin_url, type, mode, base::Bind(&DidOpenFileSystem, callback, root_url, name)); } @@ -236,7 +236,7 @@ void FileSystemContext::OpenSyncableFileSystem( const std::string& mount_name, const GURL& origin_url, FileSystemType type, - bool create, + OpenFileSystemMode mode, const OpenFileSystemCallback& callback) { DCHECK(!callback.is_null()); @@ -249,8 +249,8 @@ void FileSystemContext::OpenSyncableFileSystem( FileSystemMountPointProvider* mount_point_provider = GetMountPointProvider(type); DCHECK(mount_point_provider); - mount_point_provider->ValidateFileSystemRoot( - origin_url, type, create, + mount_point_provider->OpenFileSystem( + origin_url, type, mode, base::Bind(&DidOpenFileSystem, callback, root_url, name)); } diff --git a/webkit/browser/fileapi/file_system_context.h b/webkit/browser/fileapi/file_system_context.h index f3d9356..64104dc 100644 --- a/webkit/browser/fileapi/file_system_context.h +++ b/webkit/browser/fileapi/file_system_context.h @@ -16,6 +16,7 @@ #include "base/platform_file.h" #include "base/sequenced_task_runner_helpers.h" #include "webkit/browser/fileapi/file_system_url.h" +#include "webkit/browser/fileapi/open_file_system_mode.h" #include "webkit/browser/fileapi/task_runner_bound_observer_list.h" #include "webkit/common/fileapi/file_system_types.h" #include "webkit/storage/webkit_storage_export.h" @@ -157,18 +158,19 @@ class WEBKIT_STORAGE_EXPORT FileSystemContext void OpenFileSystem( const GURL& origin_url, FileSystemType type, - bool create, + OpenFileSystemMode mode, const OpenFileSystemCallback& callback); // Opens a syncable filesystem for the given |origin_url|. // The file system is internally mounted as an external file system at the // given |mount_name|. // Currently only kFileSystemTypeSyncable type is supported. + // TODO(kinuko): Deprecate this method. (http://crbug.com/177137) void OpenSyncableFileSystem( const std::string& mount_name, const GURL& origin_url, FileSystemType type, - bool create, + OpenFileSystemMode mode, const OpenFileSystemCallback& callback); // Deletes the filesystem for the given |origin_url| and |type|. This should diff --git a/webkit/browser/fileapi/file_system_dir_url_request_job_unittest.cc b/webkit/browser/fileapi/file_system_dir_url_request_job_unittest.cc index 7de553a..e031b9a 100644 --- a/webkit/browser/fileapi/file_system_dir_url_request_job_unittest.cc +++ b/webkit/browser/fileapi/file_system_dir_url_request_job_unittest.cc @@ -53,9 +53,10 @@ class FileSystemDirURLRequestJobTest : public testing::Test { file_system_context_ = CreateFileSystemContextForTesting( NULL, temp_dir_.path()); - file_system_context_->sandbox_provider()->ValidateFileSystemRoot( - GURL("http://remote/"), kFileSystemTypeTemporary, true, // create - base::Bind(&FileSystemDirURLRequestJobTest::OnValidateFileSystem, + file_system_context_->sandbox_provider()->OpenFileSystem( + GURL("http://remote/"), kFileSystemTypeTemporary, + OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, + base::Bind(&FileSystemDirURLRequestJobTest::OnOpenFileSystem, weak_factory_.GetWeakPtr())); base::MessageLoop::current()->RunUntilIdle(); @@ -72,7 +73,7 @@ class FileSystemDirURLRequestJobTest : public testing::Test { ClearUnusedJob(); } - void OnValidateFileSystem(base::PlatformFileError result) { + void OnOpenFileSystem(base::PlatformFileError result) { ASSERT_EQ(base::PLATFORM_FILE_OK, result); } diff --git a/webkit/browser/fileapi/file_system_file_stream_reader_unittest.cc b/webkit/browser/fileapi/file_system_file_stream_reader_unittest.cc index 466acda..68a7132 100644 --- a/webkit/browser/fileapi/file_system_file_stream_reader_unittest.cc +++ b/webkit/browser/fileapi/file_system_file_stream_reader_unittest.cc @@ -70,9 +70,10 @@ class FileSystemFileStreamReaderTest : public testing::Test { file_system_context_ = CreateFileSystemContextForTesting( NULL, temp_dir_.path()); - file_system_context_->sandbox_provider()->ValidateFileSystemRoot( - GURL(kURLOrigin), kFileSystemTypeTemporary, true, // create - base::Bind(&OnValidateFileSystem)); + file_system_context_->sandbox_provider()->OpenFileSystem( + GURL(kURLOrigin), kFileSystemTypeTemporary, + OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, + base::Bind(&OnOpenFileSystem)); base::MessageLoop::current()->RunUntilIdle(); WriteFile(kTestFileName, kTestData, kTestDataSize, @@ -133,7 +134,7 @@ class FileSystemFileStreamReaderTest : public testing::Test { } private: - static void OnValidateFileSystem(base::PlatformFileError result) { + static void OnOpenFileSystem(base::PlatformFileError result) { ASSERT_EQ(base::PLATFORM_FILE_OK, result); } diff --git a/webkit/browser/fileapi/file_system_mount_point_provider.h b/webkit/browser/fileapi/file_system_mount_point_provider.h index dfbb441..bb70c10 100644 --- a/webkit/browser/fileapi/file_system_mount_point_provider.h +++ b/webkit/browser/fileapi/file_system_mount_point_provider.h @@ -13,6 +13,7 @@ #include "base/memory/scoped_ptr.h" #include "base/platform_file.h" #include "webkit/browser/fileapi/file_permission_policy.h" +#include "webkit/browser/fileapi/open_file_system_mode.h" #include "webkit/common/fileapi/file_system_types.h" #include "webkit/storage/webkit_storage_export.h" @@ -40,9 +41,9 @@ class RemoteFileSystemProxyInterface; // class WEBKIT_STORAGE_EXPORT FileSystemMountPointProvider { public: - // Callback for ValidateFileSystemRoot. + // Callback for OpenFileSystem. typedef base::Callback<void(base::PlatformFileError error)> - ValidateFileSystemCallback; + OpenFileSystemCallback; typedef base::Callback<void(base::PlatformFileError error)> DeleteFileSystemCallback; virtual ~FileSystemMountPointProvider() {} @@ -51,16 +52,17 @@ class WEBKIT_STORAGE_EXPORT FileSystemMountPointProvider { // One mount point provider may be able to handle multiple filesystem types. virtual bool CanHandleType(FileSystemType type) const = 0; - // Validates the filesystem for the given |origin_url| and |type|. + // Initializes 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 |create| is true this may also create the root directory for + // 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 ValidateFileSystemRoot( + virtual void OpenFileSystem( const GURL& origin_url, FileSystemType type, - bool create, - const ValidateFileSystemCallback& callback) = 0; + OpenFileSystemMode mode, + 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_url_request_job_unittest.cc b/webkit/browser/fileapi/file_system_url_request_job_unittest.cc index 5b4c2ec..ce59f3c 100644 --- a/webkit/browser/fileapi/file_system_url_request_job_unittest.cc +++ b/webkit/browser/fileapi/file_system_url_request_job_unittest.cc @@ -62,9 +62,10 @@ class FileSystemURLRequestJobTest : public testing::Test { file_system_context_ = CreateFileSystemContextForTesting(NULL, temp_dir_.path()); - file_system_context_->sandbox_provider()->ValidateFileSystemRoot( - GURL("http://remote/"), kFileSystemTypeTemporary, true, // create - base::Bind(&FileSystemURLRequestJobTest::OnValidateFileSystem, + file_system_context_->sandbox_provider()->OpenFileSystem( + GURL("http://remote/"), kFileSystemTypeTemporary, + OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, + base::Bind(&FileSystemURLRequestJobTest::OnOpenFileSystem, weak_factory_.GetWeakPtr())); base::MessageLoop::current()->RunUntilIdle(); @@ -83,7 +84,7 @@ class FileSystemURLRequestJobTest : public testing::Test { base::MessageLoop::current()->RunUntilIdle(); } - void OnValidateFileSystem(base::PlatformFileError result) { + void OnOpenFileSystem(base::PlatformFileError result) { ASSERT_EQ(base::PLATFORM_FILE_OK, result); } diff --git a/webkit/browser/fileapi/isolated_mount_point_provider.cc b/webkit/browser/fileapi/isolated_mount_point_provider.cc index 888be30..7d6c2ab 100644 --- a/webkit/browser/fileapi/isolated_mount_point_provider.cc +++ b/webkit/browser/fileapi/isolated_mount_point_provider.cc @@ -56,11 +56,11 @@ bool IsolatedMountPointProvider::CanHandleType(FileSystemType type) const { } } -void IsolatedMountPointProvider::ValidateFileSystemRoot( +void IsolatedMountPointProvider::OpenFileSystem( const GURL& origin_url, FileSystemType type, - bool create, - const ValidateFileSystemCallback& callback) { + OpenFileSystemMode mode, + 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_mount_point_provider.h b/webkit/browser/fileapi/isolated_mount_point_provider.h index 240042f..653478b 100644 --- a/webkit/browser/fileapi/isolated_mount_point_provider.h +++ b/webkit/browser/fileapi/isolated_mount_point_provider.h @@ -19,11 +19,11 @@ class IsolatedMountPointProvider : public FileSystemMountPointProvider { // FileSystemMountPointProvider implementation. virtual bool CanHandleType(FileSystemType type) const OVERRIDE; - virtual void ValidateFileSystemRoot( + virtual void OpenFileSystem( const GURL& origin_url, FileSystemType type, - bool create, - const ValidateFileSystemCallback& callback) OVERRIDE; + OpenFileSystemMode mode, + 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/local_file_system_cross_operation_unittest.cc b/webkit/browser/fileapi/local_file_system_cross_operation_unittest.cc index 41c9ff4..7a31908 100644 --- a/webkit/browser/fileapi/local_file_system_cross_operation_unittest.cc +++ b/webkit/browser/fileapi/local_file_system_cross_operation_unittest.cc @@ -71,12 +71,16 @@ class CrossOperationTestHelper { // Prepare the origin's root directory. FileSystemMountPointProvider* mount_point_provider = file_system_context_->GetMountPointProvider(src_type_); - mount_point_provider->ValidateFileSystemRoot( - origin_, src_type_, true /* create */, base::Bind(&ExpectOk)); + mount_point_provider->OpenFileSystem( + origin_, src_type_, + OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, + base::Bind(&ExpectOk)); mount_point_provider = file_system_context_->GetMountPointProvider(dest_type_); - mount_point_provider->ValidateFileSystemRoot( - origin_, dest_type_, true /* create */, base::Bind(&ExpectOk)); + mount_point_provider->OpenFileSystem( + origin_, dest_type_, + OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, + base::Bind(&ExpectOk)); base::MessageLoop::current()->RunUntilIdle(); // Grant relatively big quota initially. diff --git a/webkit/browser/fileapi/open_file_system_mode.h b/webkit/browser/fileapi/open_file_system_mode.h new file mode 100644 index 0000000..72a2bcb --- /dev/null +++ b/webkit/browser/fileapi/open_file_system_mode.h @@ -0,0 +1,22 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef WEBKIT_BROWSER_FILEAPI_OPEN_FILE_SYSTEM_MODE_H_ +#define WEBKIT_BROWSER_FILEAPI_OPEN_FILE_SYSTEM_MODE_H_ + +namespace fileapi { + +// Determines the behavior on OpenFileSystem when a specified +// FileSystem does not exist. +// Specifying CREATE_IF_NONEXISTENT may make actual modification on +// disk (e.g. creating a root directory, setting up a metadata database etc) +// if the filesystem hasn't been initialized. +enum OpenFileSystemMode { + OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, + OPEN_FILE_SYSTEM_FAIL_IF_NONEXISTENT, +}; + +} // namespace fileapi + +#endif // WEBKIT_BROWSER_FILEAPI_OPEN_FILE_SYSTEM_MODE_H_ diff --git a/webkit/browser/fileapi/sandbox_mount_point_provider.cc b/webkit/browser/fileapi/sandbox_mount_point_provider.cc index 85c5df6..37d5383 100644 --- a/webkit/browser/fileapi/sandbox_mount_point_provider.cc +++ b/webkit/browser/fileapi/sandbox_mount_point_provider.cc @@ -94,23 +94,24 @@ class ObfuscatedOriginEnumerator scoped_ptr<ObfuscatedFileUtil::AbstractOriginEnumerator> enum_; }; -void DidValidateFileSystemRoot( +void DidOpenFileSystem( base::WeakPtr<SandboxMountPointProvider> mount_point_provider, - const FileSystemMountPointProvider::ValidateFileSystemCallback& callback, + const FileSystemMountPointProvider::OpenFileSystemCallback& callback, base::PlatformFileError* error) { if (mount_point_provider) mount_point_provider.get()->CollectOpenFileSystemMetrics(*error); callback.Run(*error); } -void ValidateRootOnFileThread( +void OpenFileSystemOnFileThread( ObfuscatedFileUtil* file_util, const GURL& origin_url, FileSystemType type, - bool create, + OpenFileSystemMode mode, base::PlatformFileError* error_ptr) { DCHECK(error_ptr); + const bool create = (mode == OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT); base::FilePath root_path = file_util->GetDirectoryForOriginAndType( origin_url, type, create, error_ptr); @@ -197,9 +198,10 @@ bool SandboxMountPointProvider::CanHandleType(FileSystemType type) const { return IsSandboxType(type); } -void SandboxMountPointProvider::ValidateFileSystemRoot( - const GURL& origin_url, fileapi::FileSystemType type, bool create, - const ValidateFileSystemCallback& callback) { +void SandboxMountPointProvider::OpenFileSystem( + const GURL& origin_url, fileapi::FileSystemType type, + OpenFileSystemMode mode, + const OpenFileSystemCallback& callback) { if (file_system_options_.is_incognito() && !(type == kFileSystemTypeTemporary && enable_temporary_file_system_in_incognito_)) { @@ -222,11 +224,11 @@ void SandboxMountPointProvider::ValidateFileSystemRoot( base::PlatformFileError* error_ptr = new base::PlatformFileError; file_task_runner_->PostTaskAndReply( FROM_HERE, - base::Bind(&ValidateRootOnFileThread, + base::Bind(&OpenFileSystemOnFileThread, sandbox_sync_file_util(), - origin_url, type, create, + origin_url, type, mode, base::Unretained(error_ptr)), - base::Bind(&DidValidateFileSystemRoot, + base::Bind(&DidOpenFileSystem, weak_factory_.GetWeakPtr(), callback, base::Owned(error_ptr))); diff --git a/webkit/browser/fileapi/sandbox_mount_point_provider.h b/webkit/browser/fileapi/sandbox_mount_point_provider.h index 52190e6..fd944fd 100644 --- a/webkit/browser/fileapi/sandbox_mount_point_provider.h +++ b/webkit/browser/fileapi/sandbox_mount_point_provider.h @@ -83,11 +83,11 @@ class WEBKIT_STORAGE_EXPORT SandboxMountPointProvider // FileSystemMountPointProvider overrides. virtual bool CanHandleType(FileSystemType type) const OVERRIDE; - virtual void ValidateFileSystemRoot( + virtual void OpenFileSystem( const GURL& origin_url, FileSystemType type, - bool create, - const ValidateFileSystemCallback& callback) OVERRIDE; + OpenFileSystemMode mode, + 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_mount_point_provider_unittest.cc b/webkit/browser/fileapi/sandbox_mount_point_provider_unittest.cc index 99ef11a..41ead3a 100644 --- a/webkit/browser/fileapi/sandbox_mount_point_provider_unittest.cc +++ b/webkit/browser/fileapi/sandbox_mount_point_provider_unittest.cc @@ -71,8 +71,8 @@ FileSystemURL CreateFileSystemURL(const char* path) { kOrigin, kFileSystemTypeTemporary, base::FilePath::FromUTF8Unsafe(path)); } -void DidValidateFileSystemRoot(base::PlatformFileError* error_out, - base::PlatformFileError error) { +void DidOpenFileSystem(base::PlatformFileError* error_out, + base::PlatformFileError error) { *error_out = error; } @@ -108,13 +108,13 @@ class SandboxMountPointProviderTest : public testing::Test { bool GetRootPath(const GURL& origin_url, fileapi::FileSystemType type, - bool create, + OpenFileSystemMode mode, base::FilePath* root_path) { base::PlatformFileError* error = new base::PlatformFileError( base::PLATFORM_FILE_OK); - provider_->ValidateFileSystemRoot( - origin_url, type, create, - base::Bind(&DidValidateFileSystemRoot, error)); + provider_->OpenFileSystem( + origin_url, type, mode, + base::Bind(&DidOpenFileSystem, error)); base::MessageLoop::current()->RunUntilIdle(); if (*error != base::PLATFORM_FILE_OK) return false; @@ -285,7 +285,8 @@ TEST_F(SandboxMountPointProviderTest, GetRootPathCreateAndExamine) { base::FilePath root_path; EXPECT_TRUE(GetRootPath(GURL(kRootPathTestCases[i].origin_url), kRootPathTestCases[i].type, - true /* create */, &root_path)); + OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, + &root_path)); base::FilePath expected = file_system_path().AppendASCII( kRootPathTestCases[i].expected_path); @@ -304,7 +305,8 @@ TEST_F(SandboxMountPointProviderTest, GetRootPathCreateAndExamine) { base::FilePath root_path; EXPECT_TRUE(GetRootPath(GURL(kRootPathTestCases[i].origin_url), kRootPathTestCases[i].type, - false /* create */, &root_path)); + OPEN_FILE_SYSTEM_FAIL_IF_NONEXISTENT, + &root_path)); ASSERT_TRUE(returned_root_path.size() > i); EXPECT_EQ(returned_root_path[i].value(), root_path.value()); } @@ -319,13 +321,15 @@ TEST_F(SandboxMountPointProviderTest, GURL origin_url("http://foo.com:1/"); base::FilePath root_path1; - EXPECT_TRUE(GetRootPath(origin_url, - kFileSystemTypeTemporary, true, &root_path1)); + EXPECT_TRUE(GetRootPath(origin_url, kFileSystemTypeTemporary, + OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, + &root_path1)); SetUpNewProvider(CreateDisallowFileAccessOptions()); base::FilePath root_path2; - EXPECT_TRUE(GetRootPath(origin_url, - kFileSystemTypeTemporary, false, &root_path2)); + EXPECT_TRUE(GetRootPath(origin_url, kFileSystemTypeTemporary, + OPEN_FILE_SYSTEM_FAIL_IF_NONEXISTENT, + &root_path2)); EXPECT_EQ(root_path1.value(), root_path2.value()); } @@ -339,7 +343,8 @@ TEST_F(SandboxMountPointProviderTest, GetRootPathGetWithoutCreate) { << kRootPathTestCases[i].expected_path); EXPECT_FALSE(GetRootPath(GURL(kRootPathTestCases[i].origin_url), kRootPathTestCases[i].type, - false /* create */, NULL)); + OPEN_FILE_SYSTEM_FAIL_IF_NONEXISTENT, + NULL)); } } @@ -350,9 +355,11 @@ TEST_F(SandboxMountPointProviderTest, GetRootPathInIncognito) { for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kRootPathTestCases); ++i) { SCOPED_TRACE(testing::Message() << "RootPath (incognito) #" << i << " " << kRootPathTestCases[i].expected_path); - EXPECT_FALSE(GetRootPath(GURL(kRootPathTestCases[i].origin_url), - kRootPathTestCases[i].type, - true /* create */, NULL)); + EXPECT_FALSE( + GetRootPath(GURL(kRootPathTestCases[i].origin_url), + kRootPathTestCases[i].type, + OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, + NULL)); } } @@ -361,9 +368,11 @@ TEST_F(SandboxMountPointProviderTest, GetRootPathFileURI) { for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kRootPathFileURITestCases); ++i) { SCOPED_TRACE(testing::Message() << "RootPathFileURI (disallow) #" << i << " " << kRootPathFileURITestCases[i].expected_path); - EXPECT_FALSE(GetRootPath(GURL(kRootPathFileURITestCases[i].origin_url), - kRootPathFileURITestCases[i].type, - true /* create */, NULL)); + EXPECT_FALSE( + GetRootPath(GURL(kRootPathFileURITestCases[i].origin_url), + kRootPathFileURITestCases[i].type, + OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, + NULL)); } } @@ -375,7 +384,8 @@ TEST_F(SandboxMountPointProviderTest, GetRootPathFileURIWithAllowFlag) { base::FilePath root_path; EXPECT_TRUE(GetRootPath(GURL(kRootPathFileURITestCases[i].origin_url), kRootPathFileURITestCases[i].type, - true /* create */, &root_path)); + OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, + &root_path)); base::FilePath expected = file_system_path().AppendASCII( kRootPathFileURITestCases[i].expected_path); EXPECT_EQ(expected.value(), root_path.value()); diff --git a/webkit/browser/fileapi/syncable/canned_syncable_file_system.cc b/webkit/browser/fileapi/syncable/canned_syncable_file_system.cc index 19857f0..53f3430 100644 --- a/webkit/browser/fileapi/syncable/canned_syncable_file_system.cc +++ b/webkit/browser/fileapi/syncable/canned_syncable_file_system.cc @@ -249,7 +249,8 @@ PlatformFileError CannedSyncableFileSystem::OpenFileSystem() { EXPECT_TRUE(is_filesystem_set_up_); EXPECT_FALSE(is_filesystem_opened_); file_system_context_->OpenSyncableFileSystem( - service_name_, origin_, type_, true /* create */, + service_name_, origin_, type_, + fileapi::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, base::Bind(&CannedSyncableFileSystem::DidOpenFileSystem, base::Unretained(this))); base::MessageLoop::current()->Run(); diff --git a/webkit/browser/fileapi/test_mount_point_provider.cc b/webkit/browser/fileapi/test_mount_point_provider.cc index 0973541..53a37a1 100644 --- a/webkit/browser/fileapi/test_mount_point_provider.cc +++ b/webkit/browser/fileapi/test_mount_point_provider.cc @@ -91,11 +91,11 @@ bool TestMountPointProvider::CanHandleType(FileSystemType type) const { return (type == kFileSystemTypeTest); } -void TestMountPointProvider::ValidateFileSystemRoot( +void TestMountPointProvider::OpenFileSystem( const GURL& origin_url, FileSystemType type, - bool create, - const ValidateFileSystemCallback& callback) { + OpenFileSystemMode mode, + const OpenFileSystemCallback& callback) { callback.Run(base::PLATFORM_FILE_OK); } diff --git a/webkit/browser/fileapi/test_mount_point_provider.h b/webkit/browser/fileapi/test_mount_point_provider.h index 83b809f..7151896 100644 --- a/webkit/browser/fileapi/test_mount_point_provider.h +++ b/webkit/browser/fileapi/test_mount_point_provider.h @@ -35,11 +35,11 @@ class WEBKIT_STORAGE_EXPORT_PRIVATE TestMountPointProvider // FileSystemMountPointProvider implementation. virtual bool CanHandleType(FileSystemType type) const OVERRIDE; - virtual void ValidateFileSystemRoot( + virtual void OpenFileSystem( const GURL& origin_url, FileSystemType type, - bool create, - const ValidateFileSystemCallback& callback) OVERRIDE; + OpenFileSystemMode mode, + 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/upload_file_system_file_element_reader_unittest.cc b/webkit/browser/fileapi/upload_file_system_file_element_reader_unittest.cc index fb993c8..6337d50 100644 --- a/webkit/browser/fileapi/upload_file_system_file_element_reader_unittest.cc +++ b/webkit/browser/fileapi/upload_file_system_file_element_reader_unittest.cc @@ -40,8 +40,8 @@ class UploadFileSystemFileElementReaderTest : public testing::Test { file_system_context_->OpenFileSystem( GURL(kFileSystemURLOrigin), kFileSystemType, - true, // create - base::Bind(&UploadFileSystemFileElementReaderTest::OnValidateFileSystem, + OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, + base::Bind(&UploadFileSystemFileElementReaderTest::OnOpenFileSystem, base::Unretained(this))); base::MessageLoop::current()->RunUntilIdle(); ASSERT_TRUE(file_system_root_url_.is_valid()); @@ -109,9 +109,9 @@ class UploadFileSystemFileElementReaderTest : public testing::Test { *modification_time = file_info.last_modified; } - void OnValidateFileSystem(base::PlatformFileError result, - const std::string& name, - const GURL& root) { + void OnOpenFileSystem(base::PlatformFileError result, + const std::string& name, + const GURL& root) { ASSERT_EQ(base::PLATFORM_FILE_OK, result); ASSERT_TRUE(root.is_valid()); file_system_root_url_ = root; diff --git a/webkit/browser/fileapi/webkit_browser_fileapi.gypi b/webkit/browser/fileapi/webkit_browser_fileapi.gypi index 7502072..576e515 100644 --- a/webkit/browser/fileapi/webkit_browser_fileapi.gypi +++ b/webkit/browser/fileapi/webkit_browser_fileapi.gypi @@ -64,6 +64,7 @@ '../browser/fileapi/native_file_util.h', '../browser/fileapi/obfuscated_file_util.cc', '../browser/fileapi/obfuscated_file_util.h', + '../browser/fileapi/open_file_system_mode.h', '../browser/fileapi/recursive_operation_delegate.cc', '../browser/fileapi/recursive_operation_delegate.h', '../browser/fileapi/remote_file_system_proxy.h', diff --git a/webkit/tools/test_shell/simple_file_system.cc b/webkit/tools/test_shell/simple_file_system.cc index fc973c7..962c67b 100644 --- a/webkit/tools/test_shell/simple_file_system.cc +++ b/webkit/tools/test_shell/simple_file_system.cc @@ -99,9 +99,12 @@ void SimpleFileSystem::OpenFileSystem( return; } + fileapi::OpenFileSystemMode mode = + create ? fileapi::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT + : fileapi::OPEN_FILE_SYSTEM_FAIL_IF_NONEXISTENT; GURL origin_url(frame->document().securityOrigin().toString()); file_system_context_->OpenFileSystem( - origin_url, static_cast<fileapi::FileSystemType>(type), create, + origin_url, static_cast<fileapi::FileSystemType>(type), mode, OpenFileSystemHandler(callbacks)); } |