diff options
author | kinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-18 01:46:34 +0000 |
---|---|---|
committer | kinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-18 01:46:34 +0000 |
commit | 420fb56759f0ac2d0291ea47397ffb7eb87ade04 (patch) | |
tree | 705c9e6d3b8be986e6e6724605f5573ad1588ddb | |
parent | e3dcf9e71a7c5867a0c3cbbc9c7420d0821d3206 (diff) | |
download | chromium_src-420fb56759f0ac2d0291ea47397ffb7eb87ade04.zip chromium_src-420fb56759f0ac2d0291ea47397ffb7eb87ade04.tar.gz chromium_src-420fb56759f0ac2d0291ea47397ffb7eb87ade04.tar.bz2 |
Make MountPointProvider pluggable from outside webkit/fileapi
Currently we have some layering leakages under webkit/ because
we have several FS modules (e.g. media modules) that
should not be known by WebKit/FileAPI (or content) layer.
Also some module implementors are forced to add extra glue interfaces
just to across layering boundaries from webkit.
This patch changes to:
- Add CanHandleType method to each MountPointProvider
- Make FileSystemContext's ctor take additional MountPointProviders and
MountPoints, so that FS module implementors can implement their own
provider outside webkit/ and plug it into FileAPI layer.
This is the 1st cut of a couple of planned changes.
Brief change plan (internal): https://docs.google.com/a/google.com/document/d/1XEtX0OO_RIA_c0KuKvd9yqK5l3XtsTulwXs3c-mAQ1o/view
BUG=175936
TEST=content_unittests:.*File.*
TEST=content_unittests:.*MountPointProvider.*
Review URL: https://codereview.chromium.org/14096022
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@194747 0039d316-1c4b-4281-b951-d872f2087c98
41 files changed, 262 insertions, 204 deletions
diff --git a/chrome/browser/chromeos/drive/drive_file_system_util_unittest.cc b/chrome/browser/chromeos/drive/drive_file_system_util_unittest.cc index c55c1ba..bdc6be8 100644 --- a/chrome/browser/chromeos/drive/drive_file_system_util_unittest.cc +++ b/chrome/browser/chromeos/drive/drive_file_system_util_unittest.cc @@ -11,6 +11,7 @@ #include "testing/gtest/include/gtest/gtest.h" #include "webkit/fileapi/external_mount_points.h" #include "webkit/fileapi/file_system_context.h" +#include "webkit/fileapi/file_system_mount_point_provider.h" #include "webkit/fileapi/file_system_task_runners.h" #include "webkit/fileapi/file_system_url.h" #include "webkit/fileapi/isolated_context.h" @@ -98,6 +99,7 @@ TEST(DriveFileSystemUtilTest, ExtractDrivePathFromFileSystemUrl) { mount_points, NULL, // special_storage_policy NULL, // quota_manager_proxy, + ScopedVector<fileapi::FileSystemMountPointProvider>(), temp_dir_.path(), // partition_path fileapi::CreateAllowFileAccessOptions())); diff --git a/content/browser/fileapi/browser_file_system_helper.cc b/content/browser/fileapi/browser_file_system_helper.cc index 485d96a..a273712 100644 --- a/content/browser/fileapi/browser_file_system_helper.cc +++ b/content/browser/fileapi/browser_file_system_helper.cc @@ -47,10 +47,11 @@ FileSystemOptions CreateBrowserFileSystemOptions(bool is_incognito) { } // namespace scoped_refptr<fileapi::FileSystemContext> CreateFileSystemContext( - const base::FilePath& profile_path, bool is_incognito, - fileapi::ExternalMountPoints* external_mount_points, - quota::SpecialStoragePolicy* special_storage_policy, - quota::QuotaManagerProxy* quota_manager_proxy) { + const base::FilePath& profile_path, + bool is_incognito, + fileapi::ExternalMountPoints* external_mount_points, + quota::SpecialStoragePolicy* special_storage_policy, + quota::QuotaManagerProxy* quota_manager_proxy) { base::SequencedWorkerPool* pool = BrowserThread::GetBlockingPool(); base::SequencedWorkerPool::SequenceToken media_sequence_token = pool->GetNamedSequenceToken(fileapi::kMediaTaskRunnerName); @@ -61,11 +62,14 @@ scoped_refptr<fileapi::FileSystemContext> CreateFileSystemContext( BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE), pool->GetSequencedTaskRunner(media_sequence_token))); + // Setting up additional mount point providers. + ScopedVector<fileapi::FileSystemMountPointProvider> additional_providers; return new fileapi::FileSystemContext( task_runners.Pass(), external_mount_points, special_storage_policy, quota_manager_proxy, + ScopedVector<fileapi::FileSystemMountPointProvider>(), profile_path, CreateBrowserFileSystemOptions(is_incognito)); } diff --git a/content/browser/fileapi/fileapi_message_filter.cc b/content/browser/fileapi/fileapi_message_filter.cc index 41b2711..d735e31 100644 --- a/content/browser/fileapi/fileapi_message_filter.cc +++ b/content/browser/fileapi/fileapi_message_filter.cc @@ -756,7 +756,7 @@ void FileAPIMessageFilter::DidCreateSnapshot( // already been granted read permission for the file's nominal path, but // for drive files, platform paths differ from the nominal paths. DCHECK(snapshot_file || - fileapi::SandboxMountPointProvider::CanHandleType(url.type()) || + fileapi::SandboxMountPointProvider::IsSandboxType(url.type()) || url.type() == fileapi::kFileSystemTypeDrive); ChildProcessSecurityPolicyImpl::GetInstance()->GrantReadFile( process_id_, platform_path); diff --git a/content/content_tests.gypi b/content/content_tests.gypi index be5392c..bf3dc2c 100644 --- a/content/content_tests.gypi +++ b/content/content_tests.gypi @@ -139,8 +139,6 @@ # test support target. '../webkit/appcache/appcache_test_helper.cc', '../webkit/appcache/appcache_test_helper.h', - '../webkit/quota/mock_special_storage_policy.cc', - '../webkit/quota/mock_special_storage_policy.h', ], 'conditions': [ ['OS == "ios"', { diff --git a/webkit/blob/blob_url_request_job_unittest.cc b/webkit/blob/blob_url_request_job_unittest.cc index b6f66db..12ef885 100644 --- a/webkit/blob/blob_url_request_job_unittest.cc +++ b/webkit/blob/blob_url_request_job_unittest.cc @@ -19,13 +19,11 @@ #include "testing/gtest/include/gtest/gtest.h" #include "webkit/blob/blob_data.h" #include "webkit/blob/blob_url_request_job.h" -#include "webkit/fileapi/external_mount_points.h" #include "webkit/fileapi/file_system_context.h" #include "webkit/fileapi/file_system_file_util.h" #include "webkit/fileapi/file_system_operation_context.h" -#include "webkit/fileapi/file_system_task_runners.h" #include "webkit/fileapi/file_system_url.h" -#include "webkit/fileapi/mock_file_system_options.h" +#include "webkit/fileapi/mock_file_system_context.h" namespace webkit_blob { @@ -169,13 +167,8 @@ class BlobURLRequestJobTest : public testing::Test { void SetUpFileSystem() { // Prepare file system. - file_system_context_ = new fileapi::FileSystemContext( - fileapi::FileSystemTaskRunners::CreateMockTaskRunners(), - fileapi::ExternalMountPoints::CreateRefCounted().get(), - NULL, - NULL, - temp_dir_.path(), - fileapi::CreateDisallowFileAccessOptions()); + file_system_context_ = fileapi::CreateFileSystemContextForTesting( + NULL, temp_dir_.path()); file_system_context_->OpenFileSystem( GURL(kFileSystemURLOrigin), diff --git a/webkit/chromeos/fileapi/cros_mount_point_provider.cc b/webkit/chromeos/fileapi/cros_mount_point_provider.cc index 11cf6f7..2533bfa 100644 --- a/webkit/chromeos/fileapi/cros_mount_point_provider.cc +++ b/webkit/chromeos/fileapi/cros_mount_point_provider.cc @@ -77,6 +77,19 @@ CrosMountPointProvider::CrosMountPointProvider( CrosMountPointProvider::~CrosMountPointProvider() { } +bool CrosMountPointProvider::CanHandleType(fileapi::FileSystemType type) const { + switch (type) { + case fileapi::kFileSystemTypeExternal: + case fileapi::kFileSystemTypeDrive: + case fileapi::kFileSystemTypeRestrictedNativeLocal: + case fileapi::kFileSystemTypeNativeLocal: + case fileapi::kFileSystemTypeNativeForPlatformApp: + return true; + default: + return false; + } +} + void CrosMountPointProvider::ValidateFileSystemRoot( const GURL& origin_url, fileapi::FileSystemType type, diff --git a/webkit/chromeos/fileapi/cros_mount_point_provider.h b/webkit/chromeos/fileapi/cros_mount_point_provider.h index 7f83280..698825a 100644 --- a/webkit/chromeos/fileapi/cros_mount_point_provider.h +++ b/webkit/chromeos/fileapi/cros_mount_point_provider.h @@ -14,6 +14,7 @@ #include "base/memory/scoped_ptr.h" #include "base/synchronization/lock.h" #include "webkit/fileapi/file_system_mount_point_provider.h" +#include "webkit/fileapi/file_system_types.h" #include "webkit/quota/special_storage_policy.h" #include "webkit/storage/webkit_storage_export.h" @@ -52,6 +53,7 @@ class WEBKIT_STORAGE_EXPORT CrosMountPointProvider static bool CanHandleURL(const fileapi::FileSystemURL& url); // fileapi::FileSystemMountPointProvider overrides. + virtual bool CanHandleType(fileapi::FileSystemType type) const OVERRIDE; virtual void ValidateFileSystemRoot( const GURL& origin_url, fileapi::FileSystemType type, diff --git a/webkit/fileapi/copy_or_move_file_validator_unittest.cc b/webkit/fileapi/copy_or_move_file_validator_unittest.cc index 6aafa88..5852d6c 100644 --- a/webkit/fileapi/copy_or_move_file_validator_unittest.cc +++ b/webkit/fileapi/copy_or_move_file_validator_unittest.cc @@ -13,11 +13,10 @@ #include "webkit/fileapi/external_mount_points.h" #include "webkit/fileapi/file_system_context.h" #include "webkit/fileapi/file_system_mount_point_provider.h" -#include "webkit/fileapi/file_system_task_runners.h" #include "webkit/fileapi/file_system_url.h" #include "webkit/fileapi/file_system_util.h" #include "webkit/fileapi/isolated_context.h" -#include "webkit/fileapi/mock_file_system_options.h" +#include "webkit/fileapi/mock_file_system_context.h" #include "webkit/quota/mock_special_storage_policy.h" namespace fileapi { @@ -40,13 +39,7 @@ class CopyOrMoveFileValidatorTestHelper { void SetUp() { ASSERT_TRUE(base_.CreateUniqueTempDir()); base::FilePath base_dir = base_.path(); - file_system_context_ = new FileSystemContext( - FileSystemTaskRunners::CreateMockTaskRunners(), - ExternalMountPoints::CreateRefCounted().get(), - make_scoped_refptr(new quota::MockSpecialStoragePolicy), - NULL, - base_dir, - CreateAllowFileAccessOptions()); + file_system_context_ = CreateFileSystemContextForTesting(NULL, base_dir); // Prepare the origin's root directory. if (src_type_ == kFileSystemTypeNativeMedia) { diff --git a/webkit/fileapi/file_system_context.cc b/webkit/fileapi/file_system_context.cc index 72558d9..9d753b6 100644 --- a/webkit/fileapi/file_system_context.cc +++ b/webkit/fileapi/file_system_context.cc @@ -61,6 +61,7 @@ FileSystemContext::FileSystemContext( ExternalMountPoints* external_mount_points, quota::SpecialStoragePolicy* special_storage_policy, quota::QuotaManagerProxy* quota_manager_proxy, + ScopedVector<FileSystemMountPointProvider> additional_providers, const base::FilePath& partition_path, const FileSystemOptions& options) : task_runners_(task_runners.Pass()), @@ -72,6 +73,7 @@ FileSystemContext::FileSystemContext( partition_path, options)), isolated_provider_(new IsolatedMountPointProvider(partition_path)), + additional_providers_(additional_providers.Pass()), external_mount_points_(external_mount_points), partition_path_(partition_path) { DCHECK(task_runners_.get()); @@ -81,15 +83,28 @@ FileSystemContext::FileSystemContext( this, options.is_incognito())); } + RegisterMountPointProvider(sandbox_provider_.get()); + RegisterMountPointProvider(isolated_provider_.get()); + #if defined(OS_CHROMEOS) + // TODO(kinuko): Move this out of webkit/fileapi layer. DCHECK(external_mount_points); external_provider_.reset( new chromeos::CrosMountPointProvider( special_storage_policy, external_mount_points, ExternalMountPoints::GetSystemInstance())); + RegisterMountPointProvider(external_provider_.get()); #endif + for (ScopedVector<FileSystemMountPointProvider>::const_iterator iter = + additional_providers_.begin(); + iter != additional_providers_.end(); ++iter) { + RegisterMountPointProvider(*iter); + } + + // Additional mount points must be added before regular system-wide + // mount points. if (external_mount_points) url_crackers_.push_back(external_mount_points); url_crackers_.push_back(ExternalMountPoints::GetSystemInstance()); @@ -151,35 +166,11 @@ FileSystemContext::GetCopyOrMoveFileValidatorFactory( FileSystemMountPointProvider* FileSystemContext::GetMountPointProvider( FileSystemType type) const { - switch (type) { - case kFileSystemTypeTemporary: - case kFileSystemTypePersistent: - case kFileSystemTypeSyncable: - return sandbox_provider_.get(); - case kFileSystemTypeExternal: - case kFileSystemTypeDrive: - case kFileSystemTypeRestrictedNativeLocal: - return external_provider_.get(); - case kFileSystemTypeIsolated: - case kFileSystemTypeDragged: - case kFileSystemTypeNativeMedia: - case kFileSystemTypeDeviceMedia: - return isolated_provider_.get(); - case kFileSystemTypeNativeLocal: - case kFileSystemTypeNativeForPlatformApp: -#if defined(OS_CHROMEOS) - return external_provider_.get(); -#else - return isolated_provider_.get(); -#endif - default: - if (provider_map_.find(type) != provider_map_.end()) - return provider_map_.find(type)->second; - // Fall through. - case kFileSystemTypeUnknown: - NOTREACHED(); - return NULL; - } + MountPointProviderMap::const_iterator found = provider_map_.find(type); + if (found != provider_map_.end()) + return found->second; + NOTREACHED() << "Unknown filesystem type: " << type; + return NULL; } const UpdateObserverList* FileSystemContext::GetUpdateObservers( @@ -189,7 +180,7 @@ const UpdateObserverList* FileSystemContext::GetUpdateObservers( // TODO(kinuko): Probably GetUpdateObservers() virtual method should be // added to FileSystemMountPointProvider interface and be called like // other GetFoo() methods do. - if (SandboxMountPointProvider::CanHandleType(type)) + if (SandboxMountPointProvider::IsSandboxType(type)) return sandbox_provider()->GetUpdateObservers(type); if (type != kFileSystemTypeTest) return NULL; @@ -320,14 +311,6 @@ scoped_ptr<FileStreamWriter> FileSystemContext::CreateFileStreamWriter( return mount_point_provider->CreateFileStreamWriter(url, offset, this); } -void FileSystemContext::RegisterMountPointProvider( - FileSystemType type, - FileSystemMountPointProvider* provider) { - DCHECK(provider); - DCHECK(provider_map_.find(type) == provider_map_.end()); - provider_map_[type] = provider; -} - void FileSystemContext::SetLocalFileChangeTracker( scoped_ptr<sync_file_system::LocalFileChangeTracker> tracker) { DCHECK(!change_tracker_.get()); @@ -367,8 +350,6 @@ void FileSystemContext::DeleteOnCorrectThread() const { task_runners_->io_task_runner()->DeleteSoon(FROM_HERE, this)) { return; } - STLDeleteContainerPairSecondPointers(provider_map_.begin(), - provider_map_.end()); delete this; } @@ -408,4 +389,32 @@ FileSystemFileUtil* FileSystemContext::GetFileUtil( return mount_point_provider->GetFileUtil(type); } +void FileSystemContext::RegisterMountPointProvider( + FileSystemMountPointProvider* provider) { + const FileSystemType mount_types[] = { + kFileSystemTypeTemporary, + kFileSystemTypePersistent, + kFileSystemTypeIsolated, + kFileSystemTypeExternal, + }; + // Register mount point providers for public mount types. + for (size_t j = 0; j < ARRAYSIZE_UNSAFE(mount_types); ++j) { + if (provider->CanHandleType(mount_types[j])) { + const bool inserted = provider_map_.insert( + std::make_pair(mount_types[j], provider)).second; + DCHECK(inserted); + } + } + // Register mount point providers for internal types. + for (int t = kFileSystemInternalTypeEnumStart + 1; + t < kFileSystemInternalTypeEnumEnd; ++t) { + FileSystemType type = static_cast<FileSystemType>(t); + if (provider->CanHandleType(type)) { + const bool inserted = provider_map_.insert( + std::make_pair(type, provider)).second; + DCHECK(inserted); + } + } +} + } // namespace fileapi diff --git a/webkit/fileapi/file_system_context.h b/webkit/fileapi/file_system_context.h index 0225a21..95e736a 100644 --- a/webkit/fileapi/file_system_context.h +++ b/webkit/fileapi/file_system_context.h @@ -12,6 +12,7 @@ #include "base/callback.h" #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" +#include "base/memory/scoped_vector.h" #include "base/platform_file.h" #include "base/sequenced_task_runner_helpers.h" #include "webkit/fileapi/file_system_types.h" @@ -77,11 +78,17 @@ class WEBKIT_STORAGE_EXPORT FileSystemContext // ChromeOS, it will be passed to external_mount_point_provider. // |external_mount_points| may be NULL only on platforms different from // ChromeOS (i.e. platforms that don't use external_mount_point_provider). + // + // |additional_providers| are added to the internal provider map + // to serve filesystem requests for non-regular types. + // If none is given, this context only handles HTML5 Sandbox FileSystem + // and Drag-and-drop Isolated FileSystem requests. FileSystemContext( scoped_ptr<FileSystemTaskRunners> task_runners, ExternalMountPoints* external_mount_points, quota::SpecialStoragePolicy* special_storage_policy, quota::QuotaManagerProxy* quota_manager_proxy, + ScopedVector<FileSystemMountPointProvider> additional_providers, const base::FilePath& partition_path, const FileSystemOptions& options); @@ -192,11 +199,6 @@ class WEBKIT_STORAGE_EXPORT FileSystemContext const FileSystemURL& url, int64 offset); - // Register a filesystem provider. The ownership of |provider| is - // transferred to this instance. - void RegisterMountPointProvider(FileSystemType type, - FileSystemMountPointProvider* provider); - FileSystemTaskRunners* task_runners() { return task_runners_.get(); } sync_file_system::LocalFileChangeTracker* change_tracker() { @@ -221,6 +223,9 @@ class WEBKIT_STORAGE_EXPORT FileSystemContext const base::FilePath& path) const; private: + typedef std::map<FileSystemType, FileSystemMountPointProvider*> + MountPointProviderMap; + // Friended for GetFileUtil. // These classes know the target filesystem (i.e. sandbox filesystem) // supports synchronous FileUtil. @@ -260,6 +265,10 @@ class WEBKIT_STORAGE_EXPORT FileSystemContext // does not support synchronous file operations. FileSystemFileUtil* GetFileUtil(FileSystemType type) const; + // For initial provider_map construction. This must be called only from + // the constructor. + void RegisterMountPointProvider(FileSystemMountPointProvider* provider); + scoped_ptr<FileSystemTaskRunners> task_runners_; scoped_refptr<quota::QuotaManagerProxy> quota_manager_proxy_; @@ -269,9 +278,14 @@ class WEBKIT_STORAGE_EXPORT FileSystemContext scoped_ptr<IsolatedMountPointProvider> isolated_provider_; scoped_ptr<ExternalFileSystemMountPointProvider> external_provider_; - // Registered mount point providers. - std::map<FileSystemType, FileSystemMountPointProvider*> provider_map_; + // Additional mount point providers. + ScopedVector<FileSystemMountPointProvider> additional_providers_; + // Registered mount point providers. + // The map must be constructed in the constructor since it can be accessed + // on multiple threads. + // The ownership of each provider is held by mount_point_providers_. + MountPointProviderMap provider_map_; // External mount points visible in the file system context (excluding system // external mount points). scoped_refptr<ExternalMountPoints> external_mount_points_; diff --git a/webkit/fileapi/file_system_context_unittest.cc b/webkit/fileapi/file_system_context_unittest.cc index b72929c..ed0d999 100644 --- a/webkit/fileapi/file_system_context_unittest.cc +++ b/webkit/fileapi/file_system_context_unittest.cc @@ -9,6 +9,7 @@ #include "base/stringprintf.h" #include "testing/gtest/include/gtest/gtest.h" #include "webkit/fileapi/external_mount_points.h" +#include "webkit/fileapi/file_system_mount_point_provider.h" #include "webkit/fileapi/file_system_task_runners.h" #include "webkit/fileapi/isolated_context.h" #include "webkit/fileapi/mock_file_system_options.h" @@ -64,6 +65,7 @@ class FileSystemContextTest : public testing::Test { external_mount_points, storage_policy_, mock_quota_manager_->proxy(), + ScopedVector<FileSystemMountPointProvider>(), data_dir_.path(), CreateAllowFileAccessOptions()); } @@ -134,7 +136,8 @@ TEST_F(FileSystemContextTest, NullExternalMountPoints) { GURL(kTestOrigin), kFileSystemTypeExternal, kFileSystemTypeNativeLocal, - base::FilePath(DRIVE FPL("/test/sys/root/file")).NormalizePathSeparators(), + base::FilePath( + DRIVE FPL("/test/sys/root/file")).NormalizePathSeparators(), base::FilePath(FPL("system/root/file")).NormalizePathSeparators(), "system"); @@ -170,7 +173,8 @@ TEST_F(FileSystemContextTest, FileSystemContextKeepsMountPointsAlive) { GURL(kTestOrigin), kFileSystemTypeExternal, kFileSystemTypeNativeLocal, - base::FilePath(DRIVE FPL("/test/sys/root/file")).NormalizePathSeparators(), + base::FilePath( + DRIVE FPL("/test/sys/root/file")).NormalizePathSeparators(), base::FilePath(FPL("system/root/file")).NormalizePathSeparators(), "system"); diff --git a/webkit/fileapi/file_system_dir_url_request_job_unittest.cc b/webkit/fileapi/file_system_dir_url_request_job_unittest.cc index f922d81..94075d1 100644 --- a/webkit/fileapi/file_system_dir_url_request_job_unittest.cc +++ b/webkit/fileapi/file_system_dir_url_request_job_unittest.cc @@ -22,13 +22,11 @@ #include "net/url_request/url_request_test_util.h" #include "testing/gtest/include/gtest/gtest.h" #include "third_party/icu/public/i18n/unicode/regex.h" -#include "webkit/fileapi/external_mount_points.h" #include "webkit/fileapi/file_system_context.h" #include "webkit/fileapi/file_system_file_util.h" #include "webkit/fileapi/file_system_operation_context.h" -#include "webkit/fileapi/file_system_task_runners.h" #include "webkit/fileapi/file_system_url.h" -#include "webkit/fileapi/mock_file_system_options.h" +#include "webkit/fileapi/mock_file_system_context.h" #include "webkit/fileapi/sandbox_mount_point_provider.h" #include "webkit/quota/mock_special_storage_policy.h" @@ -52,13 +50,8 @@ class FileSystemDirURLRequestJobTest : public testing::Test { ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); special_storage_policy_ = new quota::MockSpecialStoragePolicy; - file_system_context_ = - new FileSystemContext( - FileSystemTaskRunners::CreateMockTaskRunners(), - ExternalMountPoints::CreateRefCounted().get(), - special_storage_policy_, NULL, - temp_dir_.path(), - CreateAllowFileAccessOptions()); + file_system_context_ = CreateFileSystemContextForTesting( + NULL, temp_dir_.path()); file_system_context_->sandbox_provider()->ValidateFileSystemRoot( GURL("http://remote/"), kFileSystemTypeTemporary, true, // create diff --git a/webkit/fileapi/file_system_file_stream_reader_unittest.cc b/webkit/fileapi/file_system_file_stream_reader_unittest.cc index f54be18..e06c753 100644 --- a/webkit/fileapi/file_system_file_stream_reader_unittest.cc +++ b/webkit/fileapi/file_system_file_stream_reader_unittest.cc @@ -19,10 +19,8 @@ #include "webkit/fileapi/file_system_context.h" #include "webkit/fileapi/file_system_file_util.h" #include "webkit/fileapi/file_system_operation_context.h" -#include "webkit/fileapi/file_system_task_runners.h" -#include "webkit/fileapi/mock_file_system_options.h" +#include "webkit/fileapi/mock_file_system_context.h" #include "webkit/fileapi/sandbox_mount_point_provider.h" -#include "webkit/quota/mock_special_storage_policy.h" namespace fileapi { @@ -69,15 +67,8 @@ class FileSystemFileStreamReaderTest : public testing::Test { virtual void SetUp() OVERRIDE { ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); - special_storage_policy_ = new quota::MockSpecialStoragePolicy; - file_system_context_ = - new FileSystemContext( - FileSystemTaskRunners::CreateMockTaskRunners(), - ExternalMountPoints::CreateRefCounted().get(), - special_storage_policy_, - NULL, - temp_dir_.path(), - CreateDisallowFileAccessOptions()); + file_system_context_ = CreateFileSystemContextForTesting( + NULL, temp_dir_.path()); file_system_context_->sandbox_provider()->ValidateFileSystemRoot( GURL(kURLOrigin), kFileSystemTypeTemporary, true, // create @@ -155,7 +146,6 @@ class FileSystemFileStreamReaderTest : public testing::Test { MessageLoop message_loop_; base::ScopedTempDir temp_dir_; - scoped_refptr<quota::MockSpecialStoragePolicy> special_storage_policy_; scoped_refptr<FileSystemContext> file_system_context_; base::Time test_file_modification_time_; }; diff --git a/webkit/fileapi/file_system_mount_point_provider.h b/webkit/fileapi/file_system_mount_point_provider.h index 9ca3997..98e7e80 100644 --- a/webkit/fileapi/file_system_mount_point_provider.h +++ b/webkit/fileapi/file_system_mount_point_provider.h @@ -43,6 +43,10 @@ class WEBKIT_STORAGE_EXPORT FileSystemMountPointProvider { DeleteFileSystemCallback; virtual ~FileSystemMountPointProvider() {} + // 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; + // Validates 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. diff --git a/webkit/fileapi/file_system_mount_point_provider_unittest.cc b/webkit/fileapi/file_system_mount_point_provider_unittest.cc index 6e4a8e8..5c913ae 100644 --- a/webkit/fileapi/file_system_mount_point_provider_unittest.cc +++ b/webkit/fileapi/file_system_mount_point_provider_unittest.cc @@ -128,6 +128,7 @@ class FileSystemMountPointProviderTest : public testing::Test { external_mount_points.get(), special_storage_policy_, NULL, + ScopedVector<FileSystemMountPointProvider>(), data_dir_.path(), options); #if defined(OS_CHROMEOS) diff --git a/webkit/fileapi/file_system_quota_client_unittest.cc b/webkit/fileapi/file_system_quota_client_unittest.cc index 7de2d9f..e636fb9 100644 --- a/webkit/fileapi/file_system_quota_client_unittest.cc +++ b/webkit/fileapi/file_system_quota_client_unittest.cc @@ -11,15 +11,13 @@ #include "base/platform_file.h" #include "googleurl/src/gurl.h" #include "testing/gtest/include/gtest/gtest.h" -#include "webkit/fileapi/external_mount_points.h" #include "webkit/fileapi/file_system_context.h" #include "webkit/fileapi/file_system_operation_context.h" #include "webkit/fileapi/file_system_quota_client.h" -#include "webkit/fileapi/file_system_task_runners.h" #include "webkit/fileapi/file_system_types.h" #include "webkit/fileapi/file_system_usage_cache.h" #include "webkit/fileapi/file_system_util.h" -#include "webkit/fileapi/mock_file_system_options.h" +#include "webkit/fileapi/mock_file_system_context.h" #include "webkit/fileapi/obfuscated_file_util.h" #include "webkit/fileapi/sandbox_mount_point_provider.h" #include "webkit/quota/quota_types.h" @@ -47,13 +45,8 @@ class FileSystemQuotaClientTest : public testing::Test { virtual void SetUp() { ASSERT_TRUE(data_dir_.CreateUniqueTempDir()); - file_system_context_ = - new FileSystemContext( - FileSystemTaskRunners::CreateMockTaskRunners(), - ExternalMountPoints::CreateRefCounted().get(), - NULL, NULL, - data_dir_.path(), - CreateDisallowFileAccessOptions()); + file_system_context_ = CreateFileSystemContextForTesting( + NULL, data_dir_.path()); } struct TestFile { diff --git a/webkit/fileapi/file_system_types.h b/webkit/fileapi/file_system_types.h index 11b5fa3..073f67e 100644 --- a/webkit/fileapi/file_system_types.h +++ b/webkit/fileapi/file_system_types.h @@ -37,6 +37,9 @@ enum FileSystemType { kFileSystemTypeExternal = WebKit::WebFileSystemTypeExternal, // ------------------------------------------------------------------------ + // Marks the beginning of internal type enum. (This is not the actual fs type) + kFileSystemInternalTypeEnumStart = 99, + // Private FileSystem types, that should not appear in filesystem: URL as // WebKit has no idea how to handle those types. // @@ -47,7 +50,7 @@ enum FileSystemType { // See the comments for IsolatedContext and/or FileSystemURL for more details. // Should be used only for testing. - kFileSystemTypeTest = 100, + kFileSystemTypeTest, // Indicates a local filesystem where we can access files using native // local path. @@ -82,6 +85,11 @@ enum FileSystemType { // kFileSystemTypeNativeLocal. On Chrome OS, the path is parsed by // the handlers of kFileSystemTypeExternal. kFileSystemTypeNativeForPlatformApp, + + // -------------------------------------------------------------------- + // Marks the end of internal type enum. (This is not the actual fs type) + // New internal filesystem types must be added above this line. + kFileSystemInternalTypeEnumEnd, }; } // namespace fileapi diff --git a/webkit/fileapi/file_system_url_request_job_unittest.cc b/webkit/fileapi/file_system_url_request_job_unittest.cc index fba2703..9bc6ee6 100644 --- a/webkit/fileapi/file_system_url_request_job_unittest.cc +++ b/webkit/fileapi/file_system_url_request_job_unittest.cc @@ -28,14 +28,11 @@ #include "net/url_request/url_request_context.h" #include "net/url_request/url_request_test_util.h" #include "testing/gtest/include/gtest/gtest.h" -#include "webkit/fileapi/external_mount_points.h" #include "webkit/fileapi/file_system_context.h" #include "webkit/fileapi/file_system_file_util.h" #include "webkit/fileapi/file_system_operation_context.h" -#include "webkit/fileapi/file_system_task_runners.h" -#include "webkit/fileapi/mock_file_system_options.h" +#include "webkit/fileapi/mock_file_system_context.h" #include "webkit/fileapi/sandbox_mount_point_provider.h" -#include "webkit/quota/mock_special_storage_policy.h" namespace fileapi { namespace { @@ -60,16 +57,10 @@ class FileSystemURLRequestJobTest : public testing::Test { virtual void SetUp() OVERRIDE { ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); - special_storage_policy_ = new quota::MockSpecialStoragePolicy; // We use the main thread so that we can get the root path synchronously. // TODO(adamk): Run this on the FILE thread we've created as well. file_system_context_ = - new FileSystemContext( - FileSystemTaskRunners::CreateMockTaskRunners(), - ExternalMountPoints::CreateRefCounted().get(), - special_storage_policy_, NULL, - temp_dir_.path(), - CreateDisallowFileAccessOptions()); + CreateFileSystemContextForTesting(NULL, temp_dir_.path()); file_system_context_->sandbox_provider()->ValidateFileSystemRoot( GURL("http://remote/"), kFileSystemTypeTemporary, true, // create @@ -200,7 +191,6 @@ class FileSystemURLRequestJobTest : public testing::Test { MessageLoop message_loop_; base::ScopedTempDir temp_dir_; - scoped_refptr<quota::MockSpecialStoragePolicy> special_storage_policy_; scoped_refptr<FileSystemContext> file_system_context_; base::WeakPtrFactory<FileSystemURLRequestJobTest> weak_factory_; diff --git a/webkit/fileapi/file_system_util.cc b/webkit/fileapi/file_system_util.cc index 468abcf..3918ce0 100644 --- a/webkit/fileapi/file_system_util.cc +++ b/webkit/fileapi/file_system_util.cc @@ -241,6 +241,10 @@ std::string GetFileSystemTypeString(FileSystemType type) { return "Syncable"; case kFileSystemTypeNativeForPlatformApp: return "NativeForPlatformApp"; + case kFileSystemInternalTypeEnumStart: + case kFileSystemInternalTypeEnumEnd: + NOTREACHED(); + // Fall through. case kFileSystemTypeUnknown: return "Unknown"; } diff --git a/webkit/fileapi/isolated_file_util_unittest.cc b/webkit/fileapi/isolated_file_util_unittest.cc index 8c86fa5..67caff6 100644 --- a/webkit/fileapi/isolated_file_util_unittest.cc +++ b/webkit/fileapi/isolated_file_util_unittest.cc @@ -16,7 +16,6 @@ #include "base/time.h" #include "testing/gtest/include/gtest/gtest.h" #include "webkit/fileapi/async_file_test_helper.h" -#include "webkit/fileapi/external_mount_points.h" #include "webkit/fileapi/file_system_context.h" #include "webkit/fileapi/file_system_operation_context.h" #include "webkit/fileapi/file_system_task_runners.h" @@ -25,10 +24,9 @@ #include "webkit/fileapi/local_file_system_operation.h" #include "webkit/fileapi/local_file_system_test_helper.h" #include "webkit/fileapi/local_file_util.h" -#include "webkit/fileapi/mock_file_system_options.h" +#include "webkit/fileapi/mock_file_system_context.h" #include "webkit/fileapi/native_file_util.h" #include "webkit/fileapi/test_file_set.h" -#include "webkit/quota/mock_special_storage_policy.h" using file_util::FileEnumerator; @@ -108,13 +106,9 @@ class IsolatedFileUtilTest : public testing::Test { // root paths) as dropped files. SimulateDropFiles(); - file_system_context_ = new FileSystemContext( - FileSystemTaskRunners::CreateMockTaskRunners(), - ExternalMountPoints::CreateRefCounted().get(), - make_scoped_refptr(new quota::MockSpecialStoragePolicy()), + file_system_context_ = CreateFileSystemContextForTesting( NULL /* quota_manager */, - partition_dir_.path(), - CreateAllowFileAccessOptions()); + partition_dir_.path()); isolated_context()->AddReference(filesystem_id_); } diff --git a/webkit/fileapi/isolated_mount_point_provider.cc b/webkit/fileapi/isolated_mount_point_provider.cc index 3dc57ac..ddbff29 100644 --- a/webkit/fileapi/isolated_mount_point_provider.cc +++ b/webkit/fileapi/isolated_mount_point_provider.cc @@ -55,6 +55,23 @@ IsolatedMountPointProvider::IsolatedMountPointProvider( IsolatedMountPointProvider::~IsolatedMountPointProvider() { } +bool IsolatedMountPointProvider::CanHandleType(FileSystemType type) const { + switch (type) { + case kFileSystemTypeIsolated: + case kFileSystemTypeDragged: + case kFileSystemTypeNativeMedia: + case kFileSystemTypeDeviceMedia: + return true; +#if !defined(OS_CHROMEOS) + case kFileSystemTypeNativeLocal: + case kFileSystemTypeNativeForPlatformApp: + return true; +#endif + default: + return false; + } +} + void IsolatedMountPointProvider::ValidateFileSystemRoot( const GURL& origin_url, FileSystemType type, diff --git a/webkit/fileapi/isolated_mount_point_provider.h b/webkit/fileapi/isolated_mount_point_provider.h index f2d8d39..57a8c37 100644 --- a/webkit/fileapi/isolated_mount_point_provider.h +++ b/webkit/fileapi/isolated_mount_point_provider.h @@ -25,6 +25,7 @@ class IsolatedMountPointProvider : public FileSystemMountPointProvider { virtual ~IsolatedMountPointProvider(); // FileSystemMountPointProvider implementation. + virtual bool CanHandleType(FileSystemType type) const OVERRIDE; virtual void ValidateFileSystemRoot( const GURL& origin_url, FileSystemType type, diff --git a/webkit/fileapi/local_file_system_cross_operation_unittest.cc b/webkit/fileapi/local_file_system_cross_operation_unittest.cc index 5466069..c813875 100644 --- a/webkit/fileapi/local_file_system_cross_operation_unittest.cc +++ b/webkit/fileapi/local_file_system_cross_operation_unittest.cc @@ -13,17 +13,14 @@ #include "base/stl_util.h" #include "testing/gtest/include/gtest/gtest.h" #include "webkit/fileapi/async_file_test_helper.h" -#include "webkit/fileapi/external_mount_points.h" #include "webkit/fileapi/file_system_context.h" #include "webkit/fileapi/file_system_mount_point_provider.h" #include "webkit/fileapi/file_system_operation.h" -#include "webkit/fileapi/file_system_task_runners.h" #include "webkit/fileapi/file_system_url.h" #include "webkit/fileapi/file_system_util.h" -#include "webkit/fileapi/mock_file_system_options.h" +#include "webkit/fileapi/mock_file_system_context.h" #include "webkit/fileapi/test_file_set.h" #include "webkit/quota/mock_quota_manager.h" -#include "webkit/quota/mock_special_storage_policy.h" #include "webkit/quota/quota_manager.h" namespace fileapi { @@ -59,13 +56,9 @@ class CrossOperationTestHelper { quota_manager_proxy_ = new quota::MockQuotaManagerProxy( quota_manager_, base::MessageLoopProxy::current()); - file_system_context_ = new FileSystemContext( - FileSystemTaskRunners::CreateMockTaskRunners(), - ExternalMountPoints::CreateRefCounted().get(), - make_scoped_refptr(new quota::MockSpecialStoragePolicy), + file_system_context_ = CreateFileSystemContextForTesting( quota_manager_proxy_, - base_dir, - CreateAllowFileAccessOptions()); + base_dir); // Prepare the origin's root directory. FileSystemMountPointProvider* mount_point_provider = diff --git a/webkit/fileapi/local_file_system_operation_unittest.cc b/webkit/fileapi/local_file_system_operation_unittest.cc index aaba405..2d228bb 100644 --- a/webkit/fileapi/local_file_system_operation_unittest.cc +++ b/webkit/fileapi/local_file_system_operation_unittest.cc @@ -65,9 +65,7 @@ class LocalFileSystemOperationTest quota_manager_proxy_ = new quota::MockQuotaManagerProxy( quota_manager(), base::MessageLoopProxy::current()); - test_helper_.SetUp(base_dir, - false /* unlimited quota */, - quota_manager_proxy_.get()); + test_helper_.SetUp(base_dir, quota_manager_proxy_.get()); } virtual void TearDown() OVERRIDE { diff --git a/webkit/fileapi/local_file_system_operation_write_unittest.cc b/webkit/fileapi/local_file_system_operation_write_unittest.cc index b94362c..6f0a228 100644 --- a/webkit/fileapi/local_file_system_operation_write_unittest.cc +++ b/webkit/fileapi/local_file_system_operation_write_unittest.cc @@ -90,9 +90,7 @@ class LocalFileSystemOperationWriteTest base::FilePath base_dir = dir_.path().AppendASCII("filesystem"); quota_manager_ = new MockQuotaManager(base_dir, 1024); - test_helper_.SetUp(base_dir, - false /* unlimited quota */, - quota_manager_->proxy()); + test_helper_.SetUp(base_dir, quota_manager_->proxy()); virtual_path_ = base::FilePath(FILE_PATH_LITERAL("temporary file")); NewOperation()->CreateFile( diff --git a/webkit/fileapi/local_file_system_quota_unittest.cc b/webkit/fileapi/local_file_system_quota_unittest.cc index 54768ac..9571cd6 100644 --- a/webkit/fileapi/local_file_system_quota_unittest.cc +++ b/webkit/fileapi/local_file_system_quota_unittest.cc @@ -63,9 +63,7 @@ class LocalFileSystemQuotaTest base::MessageLoopProxy::current(), NULL); - test_helper_.SetUp(filesystem_dir_path, - false /* unlimited quota */, - quota_manager_->proxy()); + test_helper_.SetUp(filesystem_dir_path, quota_manager_->proxy()); } virtual void TearDown() OVERRIDE { diff --git a/webkit/fileapi/local_file_system_test_helper.cc b/webkit/fileapi/local_file_system_test_helper.cc index 7d46922..7ea8957 100644 --- a/webkit/fileapi/local_file_system_test_helper.cc +++ b/webkit/fileapi/local_file_system_test_helper.cc @@ -8,7 +8,6 @@ #include "base/message_loop.h" #include "base/message_loop_proxy.h" #include "googleurl/src/gurl.h" -#include "webkit/fileapi/external_mount_points.h" #include "webkit/fileapi/file_system_context.h" #include "webkit/fileapi/file_system_file_util.h" #include "webkit/fileapi/file_system_operation_context.h" @@ -17,9 +16,8 @@ #include "webkit/fileapi/file_system_usage_cache.h" #include "webkit/fileapi/file_system_util.h" #include "webkit/fileapi/local_file_system_operation.h" -#include "webkit/fileapi/mock_file_system_options.h" +#include "webkit/fileapi/mock_file_system_context.h" #include "webkit/fileapi/sandbox_mount_point_provider.h" -#include "webkit/fileapi/test_mount_point_provider.h" #include "webkit/quota/mock_special_storage_policy.h" namespace fileapi { @@ -39,7 +37,7 @@ LocalFileSystemTestOriginHelper::~LocalFileSystemTestOriginHelper() { } void LocalFileSystemTestOriginHelper::SetUp(const base::FilePath& base_dir) { - SetUp(base_dir, false, NULL); + SetUp(base_dir, NULL); } void LocalFileSystemTestOriginHelper::SetUp( @@ -61,18 +59,9 @@ void LocalFileSystemTestOriginHelper::SetUp( void LocalFileSystemTestOriginHelper::SetUp( const base::FilePath& base_dir, - bool unlimited_quota, quota::QuotaManagerProxy* quota_manager_proxy) { - scoped_refptr<quota::MockSpecialStoragePolicy> special_storage_policy = - new quota::MockSpecialStoragePolicy; - special_storage_policy->SetAllUnlimited(unlimited_quota); - file_system_context_ = new FileSystemContext( - FileSystemTaskRunners::CreateMockTaskRunners(), - ExternalMountPoints::CreateRefCounted().get(), - special_storage_policy, - quota_manager_proxy, - base_dir, - CreateAllowFileAccessOptions()); + file_system_context_ = CreateFileSystemContextForTesting( + quota_manager_proxy, base_dir); SetUpFileUtil(); @@ -172,13 +161,6 @@ FileSystemUsageCache* LocalFileSystemTestOriginHelper::usage_cache() { void LocalFileSystemTestOriginHelper::SetUpFileUtil() { DCHECK(file_system_context_); - if (type_ == kFileSystemTypeTest) { - file_system_context_->RegisterMountPointProvider( - type_, - new TestMountPointProvider( - file_system_context_->task_runners()->file_task_runner(), - file_system_context_->partition_path())); - } file_util_ = file_system_context_->GetFileUtil(type_); DCHECK(file_util_); } diff --git a/webkit/fileapi/local_file_system_test_helper.h b/webkit/fileapi/local_file_system_test_helper.h index c60beb8..c2339da 100644 --- a/webkit/fileapi/local_file_system_test_helper.h +++ b/webkit/fileapi/local_file_system_test_helper.h @@ -47,7 +47,6 @@ class LocalFileSystemTestOriginHelper { // [deep down inside ObfuscatedFileUtil]. void SetUp(FileSystemContext* file_system_context); void SetUp(const base::FilePath& base_dir, - bool unlimited_quota, quota::QuotaManagerProxy* quota_manager_proxy); void TearDown(); diff --git a/webkit/fileapi/media/native_media_file_util_unittest.cc b/webkit/fileapi/media/native_media_file_util_unittest.cc index 71afc1c..c6fcfc2 100644 --- a/webkit/fileapi/media/native_media_file_util_unittest.cc +++ b/webkit/fileapi/media/native_media_file_util_unittest.cc @@ -14,6 +14,7 @@ #include "testing/gtest/include/gtest/gtest.h" #include "webkit/fileapi/external_mount_points.h" #include "webkit/fileapi/file_system_context.h" +#include "webkit/fileapi/file_system_mount_point_provider.h" #include "webkit/fileapi/file_system_operation.h" #include "webkit/fileapi/file_system_task_runners.h" #include "webkit/fileapi/file_system_url.h" @@ -117,6 +118,7 @@ class NativeMediaFileUtilTest : public testing::Test { ExternalMountPoints::CreateRefCounted().get(), storage_policy, NULL, + ScopedVector<FileSystemMountPointProvider>(), data_dir_.path(), CreateAllowFileAccessOptions()); diff --git a/webkit/fileapi/mock_file_system_context.cc b/webkit/fileapi/mock_file_system_context.cc new file mode 100644 index 0000000..669d431 --- /dev/null +++ b/webkit/fileapi/mock_file_system_context.cc @@ -0,0 +1,35 @@ +// Copyright (c) 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. + +#include "webkit/fileapi/mock_file_system_context.h" + +#include "base/memory/scoped_vector.h" +#include "webkit/fileapi/external_mount_points.h" +#include "webkit/fileapi/file_system_context.h" +#include "webkit/fileapi/file_system_mount_point_provider.h" +#include "webkit/fileapi/file_system_task_runners.h" +#include "webkit/fileapi/mock_file_system_options.h" +#include "webkit/fileapi/test_mount_point_provider.h" +#include "webkit/quota/mock_special_storage_policy.h" + +namespace fileapi { + +FileSystemContext* CreateFileSystemContextForTesting( + quota::QuotaManagerProxy* quota_manager_proxy, + const base::FilePath& base_path) { + ScopedVector<FileSystemMountPointProvider> additional_providers; + additional_providers.push_back( + new TestMountPointProvider( + base::MessageLoopProxy::current(), base_path)); + return new FileSystemContext( + FileSystemTaskRunners::CreateMockTaskRunners(), + ExternalMountPoints::CreateRefCounted().get(), + make_scoped_refptr(new quota::MockSpecialStoragePolicy()), + quota_manager_proxy, + additional_providers.Pass(), + base_path, + CreateAllowFileAccessOptions()); +} + +} // namespace fileapi diff --git a/webkit/fileapi/mock_file_system_context.h b/webkit/fileapi/mock_file_system_context.h new file mode 100644 index 0000000..4b59d4e --- /dev/null +++ b/webkit/fileapi/mock_file_system_context.h @@ -0,0 +1,25 @@ +// Copyright (c) 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_FILEAPI_MOCK_FILE_SYSTEM_CONTEXT_H_ +#define WEBKIT_FILEAPI_MOCK_FILE_SYSTEM_CONTEXT_H_ + +#include "base/files/file_path.h" + +namespace quota { +class QuotaManagerProxy; +class SpecialStoragePolicy; +} + +namespace fileapi { + +class FileSystemContext; + +FileSystemContext* CreateFileSystemContextForTesting( + quota::QuotaManagerProxy* quota_manager_proxy, + const base::FilePath& base_path); + +} // namespace fileapi + +#endif // WEBKIT_FILEAPI_MOCK_FILE_SYSTEM_CONTEXT_H_ diff --git a/webkit/fileapi/obfuscated_file_util_unittest.cc b/webkit/fileapi/obfuscated_file_util_unittest.cc index 98472a5..d05b854 100644 --- a/webkit/fileapi/obfuscated_file_util_unittest.cc +++ b/webkit/fileapi/obfuscated_file_util_unittest.cc @@ -17,12 +17,13 @@ #include "webkit/fileapi/async_file_test_helper.h" #include "webkit/fileapi/external_mount_points.h" #include "webkit/fileapi/file_system_context.h" +#include "webkit/fileapi/file_system_mount_point_provider.h" #include "webkit/fileapi/file_system_operation_context.h" #include "webkit/fileapi/file_system_task_runners.h" #include "webkit/fileapi/file_system_usage_cache.h" #include "webkit/fileapi/local_file_system_test_helper.h" #include "webkit/fileapi/mock_file_change_observer.h" -#include "webkit/fileapi/mock_file_system_options.h" +#include "webkit/fileapi/mock_file_system_context.h" #include "webkit/fileapi/obfuscated_file_util.h" #include "webkit/fileapi/test_file_set.h" #include "webkit/quota/mock_special_storage_policy.h" @@ -141,13 +142,9 @@ class ObfuscatedFileUtilTest : public testing::Test { // Every time we create a new helper, it creates another context, which // creates another path manager, another sandbox_mount_point_provider, and // another OFU. We need to pass in the context to skip all that. - file_system_context_ = new FileSystemContext( - FileSystemTaskRunners::CreateMockTaskRunners(), - ExternalMountPoints::CreateRefCounted().get(), - storage_policy, + file_system_context_ = CreateFileSystemContextForTesting( quota_manager_->proxy(), - data_dir_.path(), - CreateAllowFileAccessOptions()); + data_dir_.path()); test_helper_.SetUp(file_system_context_.get()); diff --git a/webkit/fileapi/sandbox_mount_point_provider.cc b/webkit/fileapi/sandbox_mount_point_provider.cc index 93f574b..9d65b49 100644 --- a/webkit/fileapi/sandbox_mount_point_provider.cc +++ b/webkit/fileapi/sandbox_mount_point_provider.cc @@ -131,7 +131,7 @@ SandboxMountPointProvider::kFileSystemDirectory[] = FILE_PATH_LITERAL("File System"); // static -bool SandboxMountPointProvider::CanHandleType(FileSystemType type) { +bool SandboxMountPointProvider::IsSandboxType(FileSystemType type) { return type == kFileSystemTypeTemporary || type == kFileSystemTypePersistent || type == kFileSystemTypeSyncable; @@ -188,6 +188,10 @@ SandboxMountPointProvider::~SandboxMountPointProvider() { } } +bool SandboxMountPointProvider::CanHandleType(FileSystemType type) const { + return IsSandboxType(type); +} + void SandboxMountPointProvider::ValidateFileSystemRoot( const GURL& origin_url, fileapi::FileSystemType type, bool create, const ValidateFileSystemCallback& callback) { diff --git a/webkit/fileapi/sandbox_mount_point_provider.h b/webkit/fileapi/sandbox_mount_point_provider.h index 126c2a7..dd7c38d 100644 --- a/webkit/fileapi/sandbox_mount_point_provider.h +++ b/webkit/fileapi/sandbox_mount_point_provider.h @@ -67,7 +67,7 @@ class WEBKIT_STORAGE_EXPORT SandboxMountPointProvider // The FileSystem directory name. static const base::FilePath::CharType kFileSystemDirectory[]; - static bool CanHandleType(FileSystemType type); + static bool IsSandboxType(FileSystemType type); // |file_task_runner| is used to validate the root directory and delete the // obfuscated file util. @@ -79,6 +79,7 @@ class WEBKIT_STORAGE_EXPORT SandboxMountPointProvider virtual ~SandboxMountPointProvider(); // FileSystemMountPointProvider overrides. + virtual bool CanHandleType(FileSystemType type) const OVERRIDE; virtual void ValidateFileSystemRoot( const GURL& origin_url, FileSystemType type, diff --git a/webkit/fileapi/sandbox_quota_observer.cc b/webkit/fileapi/sandbox_quota_observer.cc index 727b28a..b5ef192 100644 --- a/webkit/fileapi/sandbox_quota_observer.cc +++ b/webkit/fileapi/sandbox_quota_observer.cc @@ -29,7 +29,7 @@ SandboxQuotaObserver::SandboxQuotaObserver( SandboxQuotaObserver::~SandboxQuotaObserver() {} void SandboxQuotaObserver::OnStartUpdate(const FileSystemURL& url) { - DCHECK(SandboxMountPointProvider::CanHandleType(url.type())); + DCHECK(SandboxMountPointProvider::IsSandboxType(url.type())); DCHECK(update_notify_runner_->RunsTasksOnCurrentThread()); base::FilePath usage_file_path = GetUsageCachePath(url); if (usage_file_path.empty()) @@ -39,7 +39,7 @@ void SandboxQuotaObserver::OnStartUpdate(const FileSystemURL& url) { void SandboxQuotaObserver::OnUpdate(const FileSystemURL& url, int64 delta) { - DCHECK(SandboxMountPointProvider::CanHandleType(url.type())); + DCHECK(SandboxMountPointProvider::IsSandboxType(url.type())); DCHECK(update_notify_runner_->RunsTasksOnCurrentThread()); if (quota_manager_proxy_) { @@ -64,7 +64,7 @@ void SandboxQuotaObserver::OnUpdate(const FileSystemURL& url, } void SandboxQuotaObserver::OnEndUpdate(const FileSystemURL& url) { - DCHECK(SandboxMountPointProvider::CanHandleType(url.type())); + DCHECK(SandboxMountPointProvider::IsSandboxType(url.type())); DCHECK(update_notify_runner_->RunsTasksOnCurrentThread()); base::FilePath usage_file_path = GetUsageCachePath(url); @@ -82,7 +82,7 @@ void SandboxQuotaObserver::OnEndUpdate(const FileSystemURL& url) { } void SandboxQuotaObserver::OnAccess(const FileSystemURL& url) { - DCHECK(SandboxMountPointProvider::CanHandleType(url.type())); + DCHECK(SandboxMountPointProvider::IsSandboxType(url.type())); if (quota_manager_proxy_) { quota_manager_proxy_->NotifyStorageAccessed( quota::QuotaClient::kFileSystem, diff --git a/webkit/fileapi/syncable/canned_syncable_file_system.cc b/webkit/fileapi/syncable/canned_syncable_file_system.cc index 89081d7..5c2e526 100644 --- a/webkit/fileapi/syncable/canned_syncable_file_system.cc +++ b/webkit/fileapi/syncable/canned_syncable_file_system.cc @@ -15,6 +15,7 @@ #include "webkit/blob/mock_blob_url_request_context.h" #include "webkit/fileapi/external_mount_points.h" #include "webkit/fileapi/file_system_context.h" +#include "webkit/fileapi/file_system_mount_point_provider.h" #include "webkit/fileapi/file_system_operation_context.h" #include "webkit/fileapi/file_system_task_runners.h" #include "webkit/fileapi/local_file_system_operation.h" @@ -213,6 +214,7 @@ void CannedSyncableFileSystem::SetUp() { fileapi::ExternalMountPoints::CreateRefCounted().get(), storage_policy, quota_manager_->proxy(), + ScopedVector<fileapi::FileSystemMountPointProvider>(), data_dir_.path(), fileapi::CreateAllowFileAccessOptions()); diff --git a/webkit/fileapi/test_mount_point_provider.cc b/webkit/fileapi/test_mount_point_provider.cc index e828f8f..c44ff59 100644 --- a/webkit/fileapi/test_mount_point_provider.cc +++ b/webkit/fileapi/test_mount_point_provider.cc @@ -81,6 +81,10 @@ TestMountPointProvider::TestMountPointProvider( TestMountPointProvider::~TestMountPointProvider() { } +bool TestMountPointProvider::CanHandleType(FileSystemType type) const { + return (type == kFileSystemTypeTest); +} + void TestMountPointProvider::ValidateFileSystemRoot( const GURL& origin_url, FileSystemType type, diff --git a/webkit/fileapi/test_mount_point_provider.h b/webkit/fileapi/test_mount_point_provider.h index b2a8087..375684e 100644 --- a/webkit/fileapi/test_mount_point_provider.h +++ b/webkit/fileapi/test_mount_point_provider.h @@ -34,6 +34,7 @@ class WEBKIT_STORAGE_EXPORT_PRIVATE TestMountPointProvider virtual ~TestMountPointProvider(); // FileSystemMountPointProvider implementation. + virtual bool CanHandleType(FileSystemType type) const OVERRIDE; virtual void ValidateFileSystemRoot( const GURL& origin_url, FileSystemType type, diff --git a/webkit/fileapi/upload_file_system_file_element_reader_unittest.cc b/webkit/fileapi/upload_file_system_file_element_reader_unittest.cc index d9ea383..03ab992 100644 --- a/webkit/fileapi/upload_file_system_file_element_reader_unittest.cc +++ b/webkit/fileapi/upload_file_system_file_element_reader_unittest.cc @@ -9,13 +9,12 @@ #include "net/base/io_buffer.h" #include "net/base/test_completion_callback.h" #include "testing/gtest/include/gtest/gtest.h" -#include "webkit/fileapi/external_mount_points.h" #include "webkit/fileapi/file_system_context.h" #include "webkit/fileapi/file_system_file_util.h" +#include "webkit/fileapi/file_system_mount_point_provider.h" #include "webkit/fileapi/file_system_operation_context.h" -#include "webkit/fileapi/file_system_task_runners.h" #include "webkit/fileapi/file_system_url.h" -#include "webkit/fileapi/mock_file_system_options.h" +#include "webkit/fileapi/mock_file_system_context.h" namespace fileapi { @@ -35,13 +34,8 @@ class UploadFileSystemFileElementReaderTest : public testing::Test { virtual void SetUp() OVERRIDE { ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); - file_system_context_ = new fileapi::FileSystemContext( - fileapi::FileSystemTaskRunners::CreateMockTaskRunners(), - ExternalMountPoints::CreateRefCounted().get(), - NULL, - NULL, - temp_dir_.path(), - fileapi::CreateDisallowFileAccessOptions()); + file_system_context_ = fileapi::CreateFileSystemContextForTesting( + NULL, temp_dir_.path()); file_system_context_->OpenFileSystem( GURL(kFileSystemURLOrigin), diff --git a/webkit/support/webkit_support.gypi b/webkit/support/webkit_support.gypi index f11e960..ea784ac 100644 --- a/webkit/support/webkit_support.gypi +++ b/webkit/support/webkit_support.gypi @@ -142,12 +142,16 @@ '<(DEPTH)/webkit/tools/test_shell/test_shell_webblobregistry_impl.h', '<(DEPTH)/webkit/tools/test_shell/test_shell_webmimeregistry_impl.cc', '<(DEPTH)/webkit/tools/test_shell/test_shell_webmimeregistry_impl.h', + '<(DEPTH)/webkit/fileapi/mock_file_system_context.cc', + '<(DEPTH)/webkit/fileapi/mock_file_system_context.h', '<(DEPTH)/webkit/fileapi/mock_file_system_options.cc', '<(DEPTH)/webkit/fileapi/mock_file_system_options.h', '<(DEPTH)/webkit/mocks/mock_webhyphenator.cc', '<(DEPTH)/webkit/mocks/mock_webhyphenator.h', '<(DEPTH)/webkit/mocks/test_media_stream_client.cc', '<(DEPTH)/webkit/mocks/test_media_stream_client.h', + '<(DEPTH)/webkit/quota/mock_special_storage_policy.cc', + '<(DEPTH)/webkit/quota/mock_special_storage_policy.h', 'simple_database_system.cc', 'simple_database_system.h', ], diff --git a/webkit/tools/test_shell/simple_file_system.cc b/webkit/tools/test_shell/simple_file_system.cc index 861ad5f..7afad8c 100644 --- a/webkit/tools/test_shell/simple_file_system.cc +++ b/webkit/tools/test_shell/simple_file_system.cc @@ -22,13 +22,11 @@ #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" #include "webkit/base/file_path_string_conversions.h" #include "webkit/blob/blob_storage_controller.h" -#include "webkit/fileapi/external_mount_points.h" #include "webkit/fileapi/file_permission_policy.h" #include "webkit/fileapi/file_system_mount_point_provider.h" -#include "webkit/fileapi/file_system_task_runners.h" #include "webkit/fileapi/file_system_url.h" #include "webkit/fileapi/file_system_util.h" -#include "webkit/fileapi/mock_file_system_options.h" +#include "webkit/fileapi/mock_file_system_context.h" #include "webkit/tools/test_shell/simple_file_writer.h" using base::WeakPtr; @@ -78,13 +76,9 @@ void RegisterBlob(const GURL& blob_url, const base::FilePath& file_path) { SimpleFileSystem::SimpleFileSystem() { if (file_system_dir_.CreateUniqueTempDir()) { - file_system_context_ = new FileSystemContext( - FileSystemTaskRunners::CreateMockTaskRunners(), - fileapi::ExternalMountPoints::CreateRefCounted().get(), - NULL /* special storage policy */, + file_system_context_ = fileapi::CreateFileSystemContextForTesting( NULL /* quota manager */, - file_system_dir_.path(), - fileapi::CreateAllowFileAccessOptions()); + file_system_dir_.path()); } else { LOG(WARNING) << "Failed to create a temp dir for the filesystem." "FileSystem feature will be disabled."; |