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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/memory/ptr_util.h" |
10 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
11 #include "base/values.h" | 12 #include "base/values.h" |
12 #include "chrome/browser/chromeos/file_system_provider/mount_path_util.h" | 13 #include "chrome/browser/chromeos/file_system_provider/mount_path_util.h" |
13 #include "chrome/browser/chromeos/file_system_provider/observer.h" | 14 #include "chrome/browser/chromeos/file_system_provider/observer.h" |
14 #include "chrome/browser/chromeos/file_system_provider/provided_file_system.h" | 15 #include "chrome/browser/chromeos/file_system_provider/provided_file_system.h" |
15 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_info
.h" | 16 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_info
.h" |
16 #include "chrome/browser/chromeos/file_system_provider/registry.h" | 17 #include "chrome/browser/chromeos/file_system_provider/registry.h" |
17 #include "chrome/browser/chromeos/file_system_provider/registry_interface.h" | 18 #include "chrome/browser/chromeos/file_system_provider/registry_interface.h" |
18 #include "chrome/browser/chromeos/file_system_provider/service_factory.h" | 19 #include "chrome/browser/chromeos/file_system_provider/service_factory.h" |
19 #include "chrome/browser/chromeos/file_system_provider/throttled_file_system.h" | 20 #include "chrome/browser/chromeos/file_system_provider/throttled_file_system.h" |
(...skipping 13 matching lines...) Expand all Loading... |
33 | 34 |
34 // Maximum number of file systems to be mounted in the same time, per profile. | 35 // Maximum number of file systems to be mounted in the same time, per profile. |
35 const size_t kMaxFileSystems = 16; | 36 const size_t kMaxFileSystems = 16; |
36 | 37 |
37 // Default factory for provided file systems. |profile| must not be NULL. | 38 // Default factory for provided file systems. |profile| must not be NULL. |
38 ProvidedFileSystemInterface* CreateProvidedFileSystem( | 39 ProvidedFileSystemInterface* CreateProvidedFileSystem( |
39 Profile* profile, | 40 Profile* profile, |
40 const ProvidedFileSystemInfo& file_system_info) { | 41 const ProvidedFileSystemInfo& file_system_info) { |
41 DCHECK(profile); | 42 DCHECK(profile); |
42 return new ThrottledFileSystem( | 43 return new ThrottledFileSystem( |
43 make_scoped_ptr(new ProvidedFileSystem(profile, file_system_info))); | 44 base::WrapUnique(new ProvidedFileSystem(profile, file_system_info))); |
44 } | 45 } |
45 | 46 |
46 } // namespace | 47 } // namespace |
47 | 48 |
48 ProvidingExtensionInfo::ProvidingExtensionInfo() { | 49 ProvidingExtensionInfo::ProvidingExtensionInfo() { |
49 } | 50 } |
50 | 51 |
51 ProvidingExtensionInfo::~ProvidingExtensionInfo() { | 52 ProvidingExtensionInfo::~ProvidingExtensionInfo() { |
52 } | 53 } |
53 | 54 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 DCHECK(observer); | 99 DCHECK(observer); |
99 observers_.RemoveObserver(observer); | 100 observers_.RemoveObserver(observer); |
100 } | 101 } |
101 | 102 |
102 void Service::SetFileSystemFactoryForTesting( | 103 void Service::SetFileSystemFactoryForTesting( |
103 const FileSystemFactoryCallback& factory_callback) { | 104 const FileSystemFactoryCallback& factory_callback) { |
104 DCHECK(!factory_callback.is_null()); | 105 DCHECK(!factory_callback.is_null()); |
105 file_system_factory_ = factory_callback; | 106 file_system_factory_ = factory_callback; |
106 } | 107 } |
107 | 108 |
108 void Service::SetRegistryForTesting(scoped_ptr<RegistryInterface> registry) { | 109 void Service::SetRegistryForTesting( |
| 110 std::unique_ptr<RegistryInterface> registry) { |
109 DCHECK(registry); | 111 DCHECK(registry); |
110 registry_.reset(registry.release()); | 112 registry_.reset(registry.release()); |
111 } | 113 } |
112 | 114 |
113 base::File::Error Service::MountFileSystem(const std::string& extension_id, | 115 base::File::Error Service::MountFileSystem(const std::string& extension_id, |
114 const MountOptions& options) { | 116 const MountOptions& options) { |
115 return MountFileSystemInternal(extension_id, options, MOUNT_CONTEXT_USER); | 117 return MountFileSystemInternal(extension_id, options, MOUNT_CONTEXT_USER); |
116 } | 118 } |
117 | 119 |
118 base::File::Error Service::MountFileSystemInternal( | 120 base::File::Error Service::MountFileSystemInternal( |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 DCHECK(event_router); | 277 DCHECK(event_router); |
276 | 278 |
277 if (!event_router->ExtensionHasEventListener( | 279 if (!event_router->ExtensionHasEventListener( |
278 extension_id, extensions::api::file_system_provider:: | 280 extension_id, extensions::api::file_system_provider:: |
279 OnMountRequested::kEventName)) { | 281 OnMountRequested::kEventName)) { |
280 return false; | 282 return false; |
281 } | 283 } |
282 | 284 |
283 event_router->DispatchEventToExtension( | 285 event_router->DispatchEventToExtension( |
284 extension_id, | 286 extension_id, |
285 make_scoped_ptr(new extensions::Event( | 287 base::WrapUnique(new extensions::Event( |
286 extensions::events::FILE_SYSTEM_PROVIDER_ON_MOUNT_REQUESTED, | 288 extensions::events::FILE_SYSTEM_PROVIDER_ON_MOUNT_REQUESTED, |
287 extensions::api::file_system_provider::OnMountRequested::kEventName, | 289 extensions::api::file_system_provider::OnMountRequested::kEventName, |
288 scoped_ptr<base::ListValue>(new base::ListValue())))); | 290 std::unique_ptr<base::ListValue>(new base::ListValue())))); |
289 | 291 |
290 return true; | 292 return true; |
291 } | 293 } |
292 | 294 |
293 std::vector<ProvidedFileSystemInfo> Service::GetProvidedFileSystemInfoList() { | 295 std::vector<ProvidedFileSystemInfo> Service::GetProvidedFileSystemInfoList() { |
294 DCHECK(thread_checker_.CalledOnValidThread()); | 296 DCHECK(thread_checker_.CalledOnValidThread()); |
295 | 297 |
296 std::vector<ProvidedFileSystemInfo> result; | 298 std::vector<ProvidedFileSystemInfo> result; |
297 for (ProvidedFileSystemMap::const_iterator it = file_system_map_.begin(); | 299 for (ProvidedFileSystemMap::const_iterator it = file_system_map_.begin(); |
298 it != file_system_map_.end(); | 300 it != file_system_map_.end(); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
374 reason == extensions::UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN | 376 reason == extensions::UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN |
375 ? UNMOUNT_REASON_SHUTDOWN | 377 ? UNMOUNT_REASON_SHUTDOWN |
376 : UNMOUNT_REASON_USER); | 378 : UNMOUNT_REASON_USER); |
377 DCHECK_EQ(base::File::FILE_OK, unmount_result); | 379 DCHECK_EQ(base::File::FILE_OK, unmount_result); |
378 } | 380 } |
379 } | 381 } |
380 } | 382 } |
381 | 383 |
382 void Service::OnExtensionLoaded(content::BrowserContext* browser_context, | 384 void Service::OnExtensionLoaded(content::BrowserContext* browser_context, |
383 const extensions::Extension* extension) { | 385 const extensions::Extension* extension) { |
384 scoped_ptr<RegistryInterface::RestoredFileSystems> restored_file_systems = | 386 std::unique_ptr<RegistryInterface::RestoredFileSystems> |
385 registry_->RestoreFileSystems(extension->id()); | 387 restored_file_systems = registry_->RestoreFileSystems(extension->id()); |
386 | 388 |
387 for (const auto& restored_file_system : *restored_file_systems) { | 389 for (const auto& restored_file_system : *restored_file_systems) { |
388 const base::File::Error result = MountFileSystemInternal( | 390 const base::File::Error result = MountFileSystemInternal( |
389 restored_file_system.extension_id, restored_file_system.options, | 391 restored_file_system.extension_id, restored_file_system.options, |
390 MOUNT_CONTEXT_RESTORE); | 392 MOUNT_CONTEXT_RESTORE); |
391 if (result != base::File::FILE_OK) { | 393 if (result != base::File::FILE_OK) { |
392 LOG(ERROR) << "Failed to restore a provided file system from " | 394 LOG(ERROR) << "Failed to restore a provided file system from " |
393 << "registry: " << restored_file_system.extension_id << ", " | 395 << "registry: " << restored_file_system.extension_id << ", " |
394 << restored_file_system.options.file_system_id << ", " | 396 << restored_file_system.options.file_system_id << ", " |
395 << restored_file_system.options.display_name << "."; | 397 << restored_file_system.options.display_name << "."; |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
457 } | 459 } |
458 | 460 |
459 void Service::OnWatcherListChanged( | 461 void Service::OnWatcherListChanged( |
460 const ProvidedFileSystemInfo& file_system_info, | 462 const ProvidedFileSystemInfo& file_system_info, |
461 const Watchers& watchers) { | 463 const Watchers& watchers) { |
462 registry_->RememberFileSystem(file_system_info, watchers); | 464 registry_->RememberFileSystem(file_system_info, watchers); |
463 } | 465 } |
464 | 466 |
465 } // namespace file_system_provider | 467 } // namespace file_system_provider |
466 } // namespace chromeos | 468 } // namespace chromeos |
OLD | NEW |