| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/chromeos/file_system_provider/service.h" | 5 #include "chrome/browser/chromeos/file_system_provider/service.h" |
| 6 | 6 |
| 7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
| 8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
| 9 #include "chrome/browser/chromeos/file_system_provider/mount_path_util.h" | 9 #include "chrome/browser/chromeos/file_system_provider/mount_path_util.h" |
| 10 #include "chrome/browser/chromeos/file_system_provider/observer.h" | 10 #include "chrome/browser/chromeos/file_system_provider/observer.h" |
| 11 #include "chrome/browser/chromeos/file_system_provider/provided_file_system.h" | 11 #include "chrome/browser/chromeos/file_system_provider/provided_file_system.h" |
| 12 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_info
.h" | 12 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_info
.h" |
| 13 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_inte
rface.h" | 13 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_inte
rface.h" |
| 14 #include "chrome/browser/chromeos/file_system_provider/service_factory.h" | 14 #include "chrome/browser/chromeos/file_system_provider/service_factory.h" |
| 15 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
| 16 #include "extensions/browser/extension_registry.h" |
| 16 #include "extensions/browser/extension_system.h" | 17 #include "extensions/browser/extension_system.h" |
| 18 #include "extensions/common/extension.h" |
| 17 #include "webkit/browser/fileapi/external_mount_points.h" | 19 #include "webkit/browser/fileapi/external_mount_points.h" |
| 18 | 20 |
| 19 namespace chromeos { | 21 namespace chromeos { |
| 20 namespace file_system_provider { | 22 namespace file_system_provider { |
| 21 namespace { | 23 namespace { |
| 22 | 24 |
| 23 // Maximum number of file systems to be mounted in the same time, per profile. | 25 // Maximum number of file systems to be mounted in the same time, per profile. |
| 24 const size_t kMaxFileSystems = 16; | 26 const size_t kMaxFileSystems = 16; |
| 25 | 27 |
| 26 // Default factory for provided file systems. The |event_router| must not be | 28 // Default factory for provided file systems. The |event_router| must not be |
| 27 // NULL. | 29 // NULL. |
| 28 ProvidedFileSystemInterface* CreateProvidedFileSystem( | 30 ProvidedFileSystemInterface* CreateProvidedFileSystem( |
| 29 extensions::EventRouter* event_router, | 31 extensions::EventRouter* event_router, |
| 30 const ProvidedFileSystemInfo& file_system_info) { | 32 const ProvidedFileSystemInfo& file_system_info) { |
| 31 DCHECK(event_router); | 33 DCHECK(event_router); |
| 32 return new ProvidedFileSystem(event_router, file_system_info); | 34 return new ProvidedFileSystem(event_router, file_system_info); |
| 33 } | 35 } |
| 34 | 36 |
| 35 } // namespace | 37 } // namespace |
| 36 | 38 |
| 37 Service::Service(Profile* profile) | 39 Service::Service(Profile* profile, |
| 40 extensions::ExtensionRegistry* extension_registry) |
| 38 : profile_(profile), | 41 : profile_(profile), |
| 42 extension_registry_(extension_registry), |
| 39 file_system_factory_(base::Bind(CreateProvidedFileSystem)), | 43 file_system_factory_(base::Bind(CreateProvidedFileSystem)), |
| 40 next_id_(1), | 44 next_id_(1), |
| 41 weak_ptr_factory_(this) {} | 45 weak_ptr_factory_(this) { |
| 46 extension_registry_->AddObserver(this); |
| 47 } |
| 42 | 48 |
| 43 Service::~Service() { STLDeleteValues(&file_system_map_); } | 49 Service::~Service() { |
| 50 extension_registry_->RemoveObserver(this); |
| 51 STLDeleteValues(&file_system_map_); |
| 52 } |
| 44 | 53 |
| 45 // static | 54 // static |
| 46 Service* Service::Get(content::BrowserContext* context) { | 55 Service* Service::Get(content::BrowserContext* context) { |
| 47 return ServiceFactory::Get(context); | 56 return ServiceFactory::Get(context); |
| 48 } | 57 } |
| 49 | 58 |
| 50 void Service::AddObserver(Observer* observer) { | 59 void Service::AddObserver(Observer* observer) { |
| 51 DCHECK(observer); | 60 DCHECK(observer); |
| 52 observers_.AddObserver(observer); | 61 observers_.AddObserver(observer); |
| 53 } | 62 } |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 file_system_map_.find(file_system_id); | 220 file_system_map_.find(file_system_id); |
| 212 if (file_system_it == file_system_map_.end() || | 221 if (file_system_it == file_system_map_.end() || |
| 213 file_system_it->second->GetFileSystemInfo().extension_id() != | 222 file_system_it->second->GetFileSystemInfo().extension_id() != |
| 214 extension_id) { | 223 extension_id) { |
| 215 return NULL; | 224 return NULL; |
| 216 } | 225 } |
| 217 | 226 |
| 218 return file_system_it->second; | 227 return file_system_it->second; |
| 219 } | 228 } |
| 220 | 229 |
| 221 void Service::Shutdown() {} | 230 void Service::OnExtensionUnloaded(const extensions::Extension* extension) { |
| 231 // Unmount all of the provided file systems associated with this extension. |
| 232 ProvidedFileSystemMap::iterator it = file_system_map_.begin(); |
| 233 while (it != file_system_map_.end()) { |
| 234 const ProvidedFileSystemInfo& file_system_info = |
| 235 it->second->GetFileSystemInfo(); |
| 236 // Advance the iterator beforehand, otherwise it will become invalidated |
| 237 // by the UnmountFileSystem() call. |
| 238 ++it; |
| 239 if (file_system_info.extension_id() == extension->id()) { |
| 240 bool result = UnmountFileSystem(file_system_info.extension_id(), |
| 241 file_system_info.file_system_id()); |
| 242 DCHECK(result); |
| 243 } |
| 244 } |
| 245 } |
| 222 | 246 |
| 223 void Service::OnRequestUnmountStatus( | 247 void Service::OnRequestUnmountStatus( |
| 224 const ProvidedFileSystemInfo& file_system_info, | 248 const ProvidedFileSystemInfo& file_system_info, |
| 225 base::File::Error error) { | 249 base::File::Error error) { |
| 226 // Notify observers about failure in unmounting, since mount() will not be | 250 // Notify observers about failure in unmounting, since mount() will not be |
| 227 // called by the provided file system. In case of success mount() will be | 251 // called by the provided file system. In case of success mount() will be |
| 228 // invoked, and observers notified, so there is no need to call them now. | 252 // invoked, and observers notified, so there is no need to call them now. |
| 229 if (error != base::File::FILE_OK) { | 253 if (error != base::File::FILE_OK) { |
| 230 FOR_EACH_OBSERVER(Observer, | 254 FOR_EACH_OBSERVER(Observer, |
| 231 observers_, | 255 observers_, |
| 232 OnProvidedFileSystemUnmount(file_system_info, error)); | 256 OnProvidedFileSystemUnmount(file_system_info, error)); |
| 233 } | 257 } |
| 234 } | 258 } |
| 235 | 259 |
| 236 } // namespace file_system_provider | 260 } // namespace file_system_provider |
| 237 } // namespace chromeos | 261 } // namespace chromeos |
| OLD | NEW |