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/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
| 9 #include "base/prefs/scoped_user_pref_update.h" | 9 #include "base/prefs/scoped_user_pref_update.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 153 storage::FileSystemMountOption( | 153 storage::FileSystemMountOption( |
| 154 storage::FlushPolicy::FLUSH_ON_COMPLETION), | 154 storage::FlushPolicy::FLUSH_ON_COMPLETION), |
| 155 mount_path)) { | 155 mount_path)) { |
| 156 FOR_EACH_OBSERVER( | 156 FOR_EACH_OBSERVER( |
| 157 Observer, observers_, | 157 Observer, observers_, |
| 158 OnProvidedFileSystemMount(ProvidedFileSystemInfo(), context, | 158 OnProvidedFileSystemMount(ProvidedFileSystemInfo(), context, |
| 159 base::File::FILE_ERROR_INVALID_OPERATION)); | 159 base::File::FILE_ERROR_INVALID_OPERATION)); |
| 160 return base::File::FILE_ERROR_INVALID_OPERATION; | 160 return base::File::FILE_ERROR_INVALID_OPERATION; |
| 161 } | 161 } |
| 162 | 162 |
| 163 ProvidingExtensionInfo provider_info; | |
| 164 const bool result = GetProvidingExtensionInfo(extension_id, &provider_info); | |
| 165 DCHECK(result); | |
| 163 // Store the file system descriptor. Use the mount point name as the file | 166 // Store the file system descriptor. Use the mount point name as the file |
| 164 // system provider file system id. | 167 // system provider file system id. |
| 165 // Examples: | 168 // Examples: |
| 166 // file_system_id = hello_world | 169 // file_system_id = hello_world |
| 167 // mount_point_name = b33f1337-hello_world-5aa5 | 170 // mount_point_name = b33f1337-hello_world-5aa5 |
| 168 // writable = false | 171 // writable = false |
| 169 // supports_notify_tag = false | 172 // supports_notify_tag = false |
| 170 // mount_path = /provided/b33f1337-hello_world-5aa5 | 173 // mount_path = /provided/b33f1337-hello_world-5aa5 |
| 171 ProvidedFileSystemInfo file_system_info(extension_id, options, mount_path); | 174 // configurable = true |
| 175 // source = SOURCE_FILE | |
| 176 ProvidedFileSystemInfo file_system_info( | |
| 177 extension_id, options, mount_path, | |
| 178 provider_info.capabilities.configurable(), | |
| 179 provider_info.capabilities.source()); | |
| 172 | 180 |
| 173 ProvidedFileSystemInterface* file_system = | 181 ProvidedFileSystemInterface* file_system = |
| 174 file_system_factory_.Run(profile_, file_system_info); | 182 file_system_factory_.Run(profile_, file_system_info); |
| 175 DCHECK(file_system); | 183 DCHECK(file_system); |
| 176 file_system_map_[FileSystemKey(extension_id, options.file_system_id)] = | 184 file_system_map_[FileSystemKey(extension_id, options.file_system_id)] = |
| 177 file_system; | 185 file_system; |
| 178 mount_point_name_to_key_map_[mount_point_name] = | 186 mount_point_name_to_key_map_[mount_point_name] = |
| 179 FileSystemKey(extension_id, options.file_system_id); | 187 FileSystemKey(extension_id, options.file_system_id); |
| 180 registry_->RememberFileSystem(file_system_info, *file_system->GetWatchers()); | 188 registry_->RememberFileSystem(file_system_info, *file_system->GetWatchers()); |
| 181 | 189 |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 303 } | 311 } |
| 304 | 312 |
| 305 std::vector<ProvidingExtensionInfo> Service::GetProvidingExtensionInfoList() | 313 std::vector<ProvidingExtensionInfo> Service::GetProvidingExtensionInfoList() |
| 306 const { | 314 const { |
| 307 extensions::ExtensionRegistry* const registry = | 315 extensions::ExtensionRegistry* const registry = |
| 308 extensions::ExtensionRegistry::Get(profile_); | 316 extensions::ExtensionRegistry::Get(profile_); |
| 309 DCHECK(registry); | 317 DCHECK(registry); |
| 310 | 318 |
| 311 std::vector<ProvidingExtensionInfo> result; | 319 std::vector<ProvidingExtensionInfo> result; |
| 312 for (const auto& extension : registry->enabled_extensions()) { | 320 for (const auto& extension : registry->enabled_extensions()) { |
| 313 if (!extension->permissions_data()->HasAPIPermission( | |
| 314 extensions::APIPermission::kFileSystemProvider)) { | |
| 315 continue; | |
| 316 } | |
| 317 | |
| 318 ProvidingExtensionInfo info; | 321 ProvidingExtensionInfo info; |
| 319 info.extension_id = extension->id(); | 322 if (GetProvidingExtensionInfo(extension->id(), &info)) |
| 320 info.name = extension->name(); | 323 result.push_back(info); |
| 321 const extensions::FileSystemProviderCapabilities* const capabilities = | |
| 322 extensions::FileSystemProviderCapabilities::Get(extension.get()); | |
| 323 DCHECK(capabilities); | |
| 324 info.capabilities = *capabilities; | |
| 325 result.push_back(info); | |
| 326 } | 324 } |
| 327 | 325 |
| 328 return result; | 326 return result; |
| 329 } | 327 } |
| 330 | 328 |
| 329 bool Service::GetProvidingExtensionInfo(const std::string& extension_id, | |
| 330 ProvidingExtensionInfo* result) const { | |
| 331 DCHECK(result); | |
| 332 extensions::ExtensionRegistry* const registry = | |
| 333 extensions::ExtensionRegistry::Get(profile_); | |
| 334 DCHECK(registry); | |
| 335 | |
| 336 const extensions::Extension* const extension = registry->GetExtensionById( | |
| 337 extension_id, extensions::ExtensionRegistry::ENABLED); | |
| 338 if (!extension || | |
| 339 !extension->permissions_data()->HasAPIPermission( | |
| 340 extensions::APIPermission::kFileSystemProvider)) { | |
| 341 return false; | |
| 342 } | |
|
hirono
2015/05/14 10:43:09
Please fix the indent.
mtomasz
2015/05/15 02:03:37
Done.
| |
| 343 | |
| 344 result->extension_id = extension->id(); | |
| 345 result->name = extension->name(); | |
| 346 const extensions::FileSystemProviderCapabilities* const capabilities = | |
| 347 extensions::FileSystemProviderCapabilities::Get(extension); | |
| 348 DCHECK(capabilities); | |
| 349 result->capabilities = *capabilities; | |
| 350 | |
| 351 return true; | |
| 352 } | |
| 353 | |
| 331 void Service::OnExtensionUnloaded( | 354 void Service::OnExtensionUnloaded( |
| 332 content::BrowserContext* browser_context, | 355 content::BrowserContext* browser_context, |
| 333 const extensions::Extension* extension, | 356 const extensions::Extension* extension, |
| 334 extensions::UnloadedExtensionInfo::Reason reason) { | 357 extensions::UnloadedExtensionInfo::Reason reason) { |
| 335 // Unmount all of the provided file systems associated with this extension. | 358 // Unmount all of the provided file systems associated with this extension. |
| 336 ProvidedFileSystemMap::iterator it = file_system_map_.begin(); | 359 ProvidedFileSystemMap::iterator it = file_system_map_.begin(); |
| 337 while (it != file_system_map_.end()) { | 360 while (it != file_system_map_.end()) { |
| 338 const ProvidedFileSystemInfo& file_system_info = | 361 const ProvidedFileSystemInfo& file_system_info = |
| 339 it->second->GetFileSystemInfo(); | 362 it->second->GetFileSystemInfo(); |
| 340 // Advance the iterator beforehand, otherwise it will become invalidated | 363 // Advance the iterator beforehand, otherwise it will become invalidated |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 429 } | 452 } |
| 430 | 453 |
| 431 void Service::OnWatcherListChanged( | 454 void Service::OnWatcherListChanged( |
| 432 const ProvidedFileSystemInfo& file_system_info, | 455 const ProvidedFileSystemInfo& file_system_info, |
| 433 const Watchers& watchers) { | 456 const Watchers& watchers) { |
| 434 registry_->RememberFileSystem(file_system_info, watchers); | 457 registry_->RememberFileSystem(file_system_info, watchers); |
| 435 } | 458 } |
| 436 | 459 |
| 437 } // namespace file_system_provider | 460 } // namespace file_system_provider |
| 438 } // namespace chromeos | 461 } // namespace chromeos |
| OLD | NEW |