| 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/event_router.h" | 16 #include "extensions/browser/event_router.h" |
| 17 #include "extensions/browser/extension_registry.h" |
| 18 #include "extensions/browser/extension_system.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 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 file_system_map_.find(file_system_id); | 219 file_system_map_.find(file_system_id); |
| 211 if (file_system_it == file_system_map_.end() || | 220 if (file_system_it == file_system_map_.end() || |
| 212 file_system_it->second->GetFileSystemInfo().extension_id() != | 221 file_system_it->second->GetFileSystemInfo().extension_id() != |
| 213 extension_id) { | 222 extension_id) { |
| 214 return NULL; | 223 return NULL; |
| 215 } | 224 } |
| 216 | 225 |
| 217 return file_system_it->second; | 226 return file_system_it->second; |
| 218 } | 227 } |
| 219 | 228 |
| 220 void Service::Shutdown() {} | 229 void Service::OnExtensionUnloaded( |
| 230 content::BrowserContext* browser_context, |
| 231 const extensions::Extension* extension, |
| 232 extensions::UnloadedExtensionInfo::Reason reason) { |
| 233 // Unmount all of the provided file systems associated with this extension. |
| 234 ProvidedFileSystemMap::iterator it = file_system_map_.begin(); |
| 235 while (it != file_system_map_.end()) { |
| 236 const ProvidedFileSystemInfo& file_system_info = |
| 237 it->second->GetFileSystemInfo(); |
| 238 // Advance the iterator beforehand, otherwise it will become invalidated |
| 239 // by the UnmountFileSystem() call. |
| 240 ++it; |
| 241 if (file_system_info.extension_id() == extension->id()) { |
| 242 bool result = UnmountFileSystem(file_system_info.extension_id(), |
| 243 file_system_info.file_system_id()); |
| 244 DCHECK(result); |
| 245 } |
| 246 } |
| 247 } |
| 221 | 248 |
| 222 void Service::OnRequestUnmountStatus( | 249 void Service::OnRequestUnmountStatus( |
| 223 const ProvidedFileSystemInfo& file_system_info, | 250 const ProvidedFileSystemInfo& file_system_info, |
| 224 base::File::Error error) { | 251 base::File::Error error) { |
| 225 // Notify observers about failure in unmounting, since mount() will not be | 252 // Notify observers about failure in unmounting, since mount() will not be |
| 226 // called by the provided file system. In case of success mount() will be | 253 // called by the provided file system. In case of success mount() will be |
| 227 // invoked, and observers notified, so there is no need to call them now. | 254 // invoked, and observers notified, so there is no need to call them now. |
| 228 if (error != base::File::FILE_OK) { | 255 if (error != base::File::FILE_OK) { |
| 229 FOR_EACH_OBSERVER(Observer, | 256 FOR_EACH_OBSERVER(Observer, |
| 230 observers_, | 257 observers_, |
| 231 OnProvidedFileSystemUnmount(file_system_info, error)); | 258 OnProvidedFileSystemUnmount(file_system_info, error)); |
| 232 } | 259 } |
| 233 } | 260 } |
| 234 | 261 |
| 235 } // namespace file_system_provider | 262 } // namespace file_system_provider |
| 236 } // namespace chromeos | 263 } // namespace chromeos |
| OLD | NEW |