Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1991)

Unified Diff: webkit/fileapi/file_system_context.cc

Issue 14096022: Make MountPointProvider pluggable from outside webkit/fileapi (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webkit/fileapi/file_system_context.cc
diff --git a/webkit/fileapi/file_system_context.cc b/webkit/fileapi/file_system_context.cc
index 72558d9522434e606dfe2c76e5dacea702188a3a..e00ae6165a6fa0d98b7899777b05993d50566237 100644
--- a/webkit/fileapi/file_system_context.cc
+++ b/webkit/fileapi/file_system_context.cc
@@ -28,11 +28,6 @@
#include "webkit/fileapi/syncable/syncable_file_system_util.h"
#include "webkit/fileapi/test_mount_point_provider.h"
#include "webkit/quota/quota_manager.h"
-#include "webkit/quota/special_storage_policy.h"
-
-#if defined(OS_CHROMEOS)
-#include "webkit/chromeos/fileapi/cros_mount_point_provider.h"
-#endif
using quota::QuotaClient;
@@ -58,9 +53,9 @@ void DidOpenFileSystem(
FileSystemContext::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 std::vector<MountPoints*>& additional_mount_points,
const base::FilePath& partition_path,
const FileSystemOptions& options)
: task_runners_(task_runners.Pass()),
@@ -72,28 +67,33 @@ FileSystemContext::FileSystemContext(
partition_path,
options)),
isolated_provider_(new IsolatedMountPointProvider(partition_path)),
- external_mount_points_(external_mount_points),
+ additional_providers_(additional_providers.Pass()),
partition_path_(partition_path) {
DCHECK(task_runners_.get());
+ RegisterMountPointProvider(sandbox_provider_.get());
+ RegisterMountPointProvider(isolated_provider_.get());
+
+ for (ScopedVector<FileSystemMountPointProvider>::const_iterator iter =
+ additional_providers_.begin();
+ iter != additional_providers_.end(); ++iter) {
+ RegisterMountPointProvider(*iter);
+ }
+
if (quota_manager_proxy) {
quota_manager_proxy->RegisterClient(CreateQuotaClient(
this, options.is_incognito()));
}
-#if defined(OS_CHROMEOS)
- DCHECK(external_mount_points);
- external_provider_.reset(
- new chromeos::CrosMountPointProvider(
- special_storage_policy,
- external_mount_points,
- ExternalMountPoints::GetSystemInstance()));
-#endif
-
- if (external_mount_points)
- url_crackers_.push_back(external_mount_points);
- url_crackers_.push_back(ExternalMountPoints::GetSystemInstance());
- url_crackers_.push_back(IsolatedContext::GetInstance());
+ // Additional mount points must be added before regular system-wide
+ // mount points.
+ for (std::vector<fileapi::MountPoints*>::const_iterator iter =
+ additional_mount_points.begin();
+ iter != additional_mount_points.end(); ++iter) {
+ url_crackers_.push_back(*iter);
+ }
+ url_crackers_.push_back(fileapi::ExternalMountPoints::GetSystemInstance());
+ url_crackers_.push_back(fileapi::IsolatedContext::GetInstance());
}
bool FileSystemContext::DeleteDataForOriginOnFileThread(
@@ -151,35 +151,10 @@ 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;
- }
+ if (provider_map_.find(type) != provider_map_.end())
+ return provider_map_.find(type)->second;
tzik 2013/04/17 12:06:04 could you reuse the result of find(type)?
kinuko 2013/04/17 14:27:29 Done.
+ NOTREACHED() << "Unknown filesystem type: " << type;
+ return NULL;
}
const UpdateObserverList* FileSystemContext::GetUpdateObservers(
@@ -189,7 +164,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;
@@ -206,7 +181,11 @@ FileSystemContext::sandbox_provider() const {
ExternalFileSystemMountPointProvider*
FileSystemContext::external_provider() const {
- return external_provider_.get();
+ ExternalFileSystemMountPointProvider* external_provider =
+ static_cast<ExternalFileSystemMountPointProvider*>(
+ GetMountPointProvider(kFileSystemTypeExternal));
+ DCHECK(external_provider);
+ return external_provider;
}
void FileSystemContext::OpenFileSystem(
@@ -320,12 +299,13 @@ scoped_ptr<FileStreamWriter> FileSystemContext::CreateFileStreamWriter(
return mount_point_provider->CreateFileStreamWriter(url, offset, this);
}
-void FileSystemContext::RegisterMountPointProvider(
+void FileSystemContext::RegisterMountPointProviderForTesting(
FileSystemType type,
FileSystemMountPointProvider* provider) {
DCHECK(provider);
DCHECK(provider_map_.find(type) == provider_map_.end());
provider_map_[type] = provider;
+ additional_providers_.push_back(provider);
}
void FileSystemContext::SetLocalFileChangeTracker(
@@ -367,8 +347,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 +386,26 @@ FileSystemFileUtil* FileSystemContext::GetFileUtil(
return mount_point_provider->GetFileUtil(type);
}
+void FileSystemContext::RegisterMountPointProvider(
+ FileSystemMountPointProvider* provider) {
+ static const FileSystemType mount_types[] = {
tzik 2013/04/17 12:06:04 could you move this to the top of the file?
kinuko 2013/04/17 14:27:29 It's only referred in this method-- I just dropped
+ 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]))
+ provider_map_.insert(std::make_pair(mount_types[j], provider));
tzik 2013/04/17 12:06:04 could you add DCHECK the .second of the result?
kinuko 2013/04/17 14:27:29 Done.
+ }
+ // Register mount point providers for internal types.
+ for (int t = kFileSystemInternalTypeEnumStart;
tzik 2013/04/17 12:06:04 kFileSystemInternalTypeEnumStart + 1?
kinuko 2013/04/17 14:27:29 Done.
+ t < kFileSystemInternalTypeEnumEnd; ++t) {
tzik 2013/04/17 12:06:04 indent?
kinuko 2013/04/17 14:27:29 Done.
+ FileSystemType type = static_cast<FileSystemType>(t);
+ if (provider->CanHandleType(type))
+ provider_map_.insert(std::make_pair(type, provider));
+ }
+}
+
} // namespace fileapi

Powered by Google App Engine
This is Rietveld 408576698