Chromium Code Reviews| 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 "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.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 "chrome/browser/chromeos/login/user.h" | 15 #include "chrome/browser/chromeos/login/user.h" |
| 16 #include "chrome/browser/chromeos/login/user_manager.h" | 16 #include "chrome/browser/chromeos/login/user_manager.h" |
| 17 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
| 18 #include "extensions/browser/event_router.h" | 18 #include "extensions/browser/event_router.h" |
| 19 #include "extensions/browser/extension_registry.h" | |
| 19 #include "extensions/browser/extension_system.h" | 20 #include "extensions/browser/extension_system.h" |
| 21 #include "extensions/common/extension.h" | |
| 20 #include "webkit/browser/fileapi/external_mount_points.h" | 22 #include "webkit/browser/fileapi/external_mount_points.h" |
| 21 | 23 |
| 22 namespace chromeos { | 24 namespace chromeos { |
| 23 namespace file_system_provider { | 25 namespace file_system_provider { |
| 24 namespace { | 26 namespace { |
| 25 | 27 |
| 26 // Root mount path for all of the provided file systems. | 28 // Root mount path for all of the provided file systems. |
| 27 const base::FilePath::CharType kProvidedMountPointRoot[] = | 29 const base::FilePath::CharType kProvidedMountPointRoot[] = |
| 28 FILE_PATH_LITERAL("/provided"); | 30 FILE_PATH_LITERAL("/provided"); |
| 29 | 31 |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 40 ? chromeos::UserManager::Get()->GetUserByProfile( | 42 ? chromeos::UserManager::Get()->GetUserByProfile( |
| 41 profile->GetOriginalProfile()) | 43 profile->GetOriginalProfile()) |
| 42 : NULL; | 44 : NULL; |
| 43 const std::string user_suffix = user ? "-" + user->username_hash() : ""; | 45 const std::string user_suffix = user ? "-" + user->username_hash() : ""; |
| 44 return base::FilePath(kProvidedMountPointRoot).AppendASCII( | 46 return base::FilePath(kProvidedMountPointRoot).AppendASCII( |
| 45 extension_id + "-" + base::IntToString(file_system_id) + user_suffix); | 47 extension_id + "-" + base::IntToString(file_system_id) + user_suffix); |
| 46 } | 48 } |
| 47 | 49 |
| 48 } // namespace | 50 } // namespace |
| 49 | 51 |
| 50 Service::Service(Profile* profile) | 52 Service::Service(Profile* profile, |
| 51 : profile_(profile), next_id_(1), weak_ptr_factory_(this) { | 53 extensions::ExtensionRegistry* extension_registry) |
| 54 : profile_(profile), | |
| 55 extension_registry_(extension_registry), | |
| 56 next_id_(1), | |
| 57 weak_ptr_factory_(this) { | |
| 52 AddObserver(&request_manager_); | 58 AddObserver(&request_manager_); |
| 59 extension_registry_->AddObserver(this); | |
| 53 } | 60 } |
| 54 | 61 |
| 55 Service::~Service() { STLDeleteValues(&file_system_map_); } | 62 Service::~Service() { STLDeleteValues(&file_system_map_); } |
| 56 | 63 |
| 57 // static | 64 // static |
| 58 Service* Service::Get(content::BrowserContext* context) { | 65 Service* Service::Get(content::BrowserContext* context) { |
| 59 return ServiceFactory::Get(context); | 66 return ServiceFactory::Get(context); |
| 60 } | 67 } |
| 61 | 68 |
| 62 void Service::AddObserver(Observer* observer) { | 69 void Service::AddObserver(Observer* observer) { |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 219 file_system_map_.find(file_system_id); | 226 file_system_map_.find(file_system_id); |
| 220 if (file_system_it == file_system_map_.end() || | 227 if (file_system_it == file_system_map_.end() || |
| 221 file_system_it->second->GetFileSystemInfo().extension_id() != | 228 file_system_it->second->GetFileSystemInfo().extension_id() != |
| 222 extension_id) { | 229 extension_id) { |
| 223 return NULL; | 230 return NULL; |
| 224 } | 231 } |
| 225 | 232 |
| 226 return file_system_it->second; | 233 return file_system_it->second; |
| 227 } | 234 } |
| 228 | 235 |
| 229 void Service::Shutdown() { RemoveObserver(&request_manager_); } | 236 void Service::Shutdown() { |
| 237 RemoveObserver(&request_manager_); | |
| 238 extension_registry_->RemoveObserver(this); | |
| 239 } | |
| 240 | |
| 241 void Service::OnExtensionUnloaded(const extensions::Extension* extension) { | |
| 242 // Unmount all of the provided file systems associated with this extension. | |
| 243 ProvidedFileSystemMap::iterator it = file_system_map_.begin(); | |
| 244 while (it != file_system_map_.end()) { | |
| 245 const ProvidedFileSystemInfo& file_system_info = | |
| 246 it->second->GetFileSystemInfo(); | |
| 247 LOG(ERROR) << extension->id() << " vs. " << file_system_info.extension_id(); | |
|
hashimoto
2014/03/27 09:18:49
No need to corrupt the feedback log with this info
mtomasz
2014/03/28 06:01:10
Done.
| |
| 248 if (file_system_info.extension_id() == extension->id()) { | |
| 249 // Advance the iterator beforehand, otherwise it will become invalidated | |
| 250 // by the UnmountFileSystem() call. | |
| 251 ++it; | |
| 252 bool result = UnmountFileSystem(file_system_info.extension_id(), | |
| 253 file_system_info.file_system_id()); | |
| 254 DCHECK(result); | |
| 255 } else { | |
| 256 ++it; | |
|
hashimoto
2014/03/27 09:18:49
nit: How about moving this ++it to above the if-st
mtomasz
2014/03/28 06:01:10
Good idea. Done.
| |
| 257 } | |
| 258 } | |
| 259 } | |
| 230 | 260 |
| 231 void Service::OnRequestUnmountStatus( | 261 void Service::OnRequestUnmountStatus( |
| 232 const ProvidedFileSystemInfo& file_system_info, | 262 const ProvidedFileSystemInfo& file_system_info, |
| 233 base::File::Error error) { | 263 base::File::Error error) { |
| 234 // Notify observers about failure in unmounting, since mount() will not be | 264 // Notify observers about failure in unmounting, since mount() will not be |
| 235 // called by the provided file system. In case of success mount() will be | 265 // called by the provided file system. In case of success mount() will be |
| 236 // invoked, and observers notified, so there is no need to call them now. | 266 // invoked, and observers notified, so there is no need to call them now. |
| 237 if (error != base::File::FILE_OK) { | 267 if (error != base::File::FILE_OK) { |
| 238 FOR_EACH_OBSERVER(Observer, | 268 FOR_EACH_OBSERVER(Observer, |
| 239 observers_, | 269 observers_, |
| 240 OnProvidedFileSystemUnmount(file_system_info, error)); | 270 OnProvidedFileSystemUnmount(file_system_info, error)); |
| 241 } | 271 } |
| 242 } | 272 } |
| 243 | 273 |
| 244 } // namespace file_system_provider | 274 } // namespace file_system_provider |
| 245 } // namespace chromeos | 275 } // namespace chromeos |
| OLD | NEW |