| Index: chrome/browser/chromeos/file_system_provider/service.cc
|
| diff --git a/chrome/browser/chromeos/file_system_provider/service.cc b/chrome/browser/chromeos/file_system_provider/service.cc
|
| index b764523b2ff4bf2cd1d207d6e7a41dcee8866c12..c9f486dcc8a7b3ea65141839eefe950dfbf4c0dd 100644
|
| --- a/chrome/browser/chromeos/file_system_provider/service.cc
|
| +++ b/chrome/browser/chromeos/file_system_provider/service.cc
|
| @@ -33,12 +33,13 @@ namespace {
|
| const size_t kMaxFileSystems = 16;
|
|
|
| // Default factory for provided file systems. |profile| must not be NULL.
|
| +template <int source = Source_Type::extension>
|
| ProvidedFileSystemInterface* CreateProvidedFileSystem(
|
| Profile* profile,
|
| const ProvidedFileSystemInfo& file_system_info) {
|
| DCHECK(profile);
|
| - return new ThrottledFileSystem(
|
| - make_scoped_ptr(new ProvidedFileSystem(profile, file_system_info)));
|
| + return new ThrottledFileSystem(make_scoped_ptr(
|
| + new ProvidedFileSystem<source>(profile, file_system_info)));
|
| }
|
|
|
| } // namespace
|
| @@ -54,7 +55,8 @@ Service::Service(Profile* profile,
|
| extensions::ExtensionRegistry* extension_registry)
|
| : profile_(profile),
|
| extension_registry_(extension_registry),
|
| - file_system_factory_(base::Bind(&CreateProvidedFileSystem)),
|
| + file_system_factory_(
|
| + base::Bind(&CreateProvidedFileSystem<Source_Type::extension>)),
|
| registry_(new Registry(profile)),
|
| weak_ptr_factory_(this) {
|
| extension_registry_->AddObserver(this);
|
| @@ -71,11 +73,11 @@ Service::~Service() {
|
| while (it != file_system_map_.end()) {
|
| const std::string file_system_id =
|
| it->second->GetFileSystemInfo().file_system_id();
|
| - const std::string extension_id =
|
| - it->second->GetFileSystemInfo().extension_id();
|
| + const std::string source_id =
|
| + it->second->GetFileSystemInfo().source_id();
|
| ++it;
|
| const base::File::Error unmount_result = UnmountFileSystem(
|
| - extension_id, file_system_id, UNMOUNT_REASON_SHUTDOWN);
|
| + source_id, file_system_id, UNMOUNT_REASON_SHUTDOWN);
|
| DCHECK_EQ(base::File::FILE_OK, unmount_result);
|
| }
|
|
|
| @@ -109,20 +111,28 @@ void Service::SetRegistryForTesting(scoped_ptr<RegistryInterface> registry) {
|
| registry_.reset(registry.release());
|
| }
|
|
|
| -base::File::Error Service::MountFileSystem(const std::string& extension_id,
|
| - const MountOptions& options) {
|
| - return MountFileSystemInternal(extension_id, options, MOUNT_CONTEXT_USER);
|
| +base::File::Error Service::MountFileSystem(const std::string& source_id,
|
| + const MountOptions& options,
|
| + Source_Type source_type) {
|
| + switch (source_type) {
|
| + case Source_Type::extension:
|
| + case Source_Type::plugin:
|
| + return MountFileSystemInternal(source_id, options, MOUNT_CONTEXT_USER,
|
| + source_type);
|
| + default:
|
| + return base::File::Error::FILE_ERROR_INVALID_OPERATION;
|
| + }
|
| }
|
|
|
| -base::File::Error Service::MountFileSystemInternal(
|
| - const std::string& extension_id,
|
| - const MountOptions& options,
|
| - MountContext context) {
|
| +base::File::Error Service::MountFileSystemInternal(const std::string& source_id,
|
| + const MountOptions& options,
|
| + MountContext context,
|
| + Source_Type source_type) {
|
| DCHECK(thread_checker_.CalledOnValidThread());
|
|
|
| - // If already exists a file system provided by the same extension with this
|
| + // If already exists a file system provided by the same source with this
|
| // id, then abort.
|
| - if (GetProvidedFileSystem(extension_id, options.file_system_id)) {
|
| + if (GetProvidedFileSystem(source_id, options.file_system_id)) {
|
| FOR_EACH_OBSERVER(
|
| Observer, observers_,
|
| OnProvidedFileSystemMount(ProvidedFileSystemInfo(), context,
|
| @@ -146,7 +156,7 @@ base::File::Error Service::MountFileSystemInternal(
|
| // The mount point path and name are unique per system, since they are system
|
| // wide. This is necessary for copying between profiles.
|
| const base::FilePath& mount_path =
|
| - util::GetMountPath(profile_, extension_id, options.file_system_id);
|
| + util::GetMountPath(profile_, source_id, options.file_system_id);
|
| const std::string mount_point_name = mount_path.BaseName().AsUTF8Unsafe();
|
|
|
| if (!mount_points->RegisterFileSystem(
|
| @@ -169,16 +179,28 @@ base::File::Error Service::MountFileSystemInternal(
|
| // writable = false
|
| // supports_notify_tag = false
|
| // mount_path = /provided/b33f1337-hello_world-5aa5
|
| - ProvidedFileSystemInfo file_system_info(extension_id, options, mount_path);
|
| -
|
| - ProvidedFileSystemInterface* file_system =
|
| - file_system_factory_.Run(profile_, file_system_info);
|
| + ProvidedFileSystemInfo file_system_info(source_id, options, mount_path,
|
| + source_type);
|
| +
|
| + ProvidedFileSystemInterface* file_system = NULL;
|
| + switch (source_type) {
|
| + case Source_Type::extension: // file_system from extension
|
| + file_system = file_system_factory_.Run(profile_, file_system_info);
|
| + break;
|
| + case Source_Type::plugin: // file_system from plugin
|
| + file_system = CreateProvidedFileSystem<Source_Type::plugin>(
|
| + profile_, file_system_info);
|
| + break;
|
| + }
|
| DCHECK(file_system);
|
| - file_system_map_[FileSystemKey(extension_id, options.file_system_id)] =
|
| + file_system_map_[FileSystemKey(source_id, options.file_system_id)] =
|
| file_system;
|
| mount_point_name_to_key_map_[mount_point_name] =
|
| - FileSystemKey(extension_id, options.file_system_id);
|
| - registry_->RememberFileSystem(file_system_info, *file_system->GetWatchers());
|
| + FileSystemKey(source_id, options.file_system_id);
|
| +
|
| + if (source_type == Source_Type::extension)
|
| + registry_->RememberFileSystem(file_system_info,
|
| + *file_system->GetWatchers());
|
|
|
| FOR_EACH_OBSERVER(Observer, observers_,
|
| OnProvidedFileSystemMount(file_system_info, context,
|
| @@ -187,13 +209,13 @@ base::File::Error Service::MountFileSystemInternal(
|
| return base::File::FILE_OK;
|
| }
|
|
|
| -base::File::Error Service::UnmountFileSystem(const std::string& extension_id,
|
| +base::File::Error Service::UnmountFileSystem(const std::string& source_id,
|
| const std::string& file_system_id,
|
| UnmountReason reason) {
|
| DCHECK(thread_checker_.CalledOnValidThread());
|
|
|
| const ProvidedFileSystemMap::iterator file_system_it =
|
| - file_system_map_.find(FileSystemKey(extension_id, file_system_id));
|
| + file_system_map_.find(FileSystemKey(source_id, file_system_id));
|
| if (file_system_it == file_system_map_.end()) {
|
| const ProvidedFileSystemInfo empty_file_system_info;
|
| FOR_EACH_OBSERVER(
|
| @@ -229,8 +251,9 @@ base::File::Error Service::UnmountFileSystem(const std::string& extension_id,
|
|
|
| mount_point_name_to_key_map_.erase(mount_point_name);
|
|
|
| - if (reason == UNMOUNT_REASON_USER) {
|
| - registry_->ForgetFileSystem(file_system_info.extension_id(),
|
| + if (reason == UNMOUNT_REASON_USER &&
|
| + file_system_info.source_type()!=Source_Type::plugin) {
|
| + registry_->ForgetFileSystem(file_system_info.source_id(),
|
| file_system_info.file_system_id());
|
| }
|
|
|
|
|