Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(93)

Side by Side Diff: chrome/browser/chromeos/file_system_provider/service.cc

Issue 1089193002: Add chrome.fileManagerPrivate.getProvidingExtensions(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased. Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
11 #include "base/values.h" 11 #include "base/values.h"
12 #include "chrome/browser/chromeos/file_system_provider/mount_path_util.h" 12 #include "chrome/browser/chromeos/file_system_provider/mount_path_util.h"
13 #include "chrome/browser/chromeos/file_system_provider/observer.h" 13 #include "chrome/browser/chromeos/file_system_provider/observer.h"
14 #include "chrome/browser/chromeos/file_system_provider/provided_file_system.h" 14 #include "chrome/browser/chromeos/file_system_provider/provided_file_system.h"
15 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_info .h" 15 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_info .h"
16 #include "chrome/browser/chromeos/file_system_provider/registry.h" 16 #include "chrome/browser/chromeos/file_system_provider/registry.h"
17 #include "chrome/browser/chromeos/file_system_provider/registry_interface.h" 17 #include "chrome/browser/chromeos/file_system_provider/registry_interface.h"
18 #include "chrome/browser/chromeos/file_system_provider/service_factory.h" 18 #include "chrome/browser/chromeos/file_system_provider/service_factory.h"
19 #include "chrome/browser/chromeos/file_system_provider/throttled_file_system.h" 19 #include "chrome/browser/chromeos/file_system_provider/throttled_file_system.h"
20 #include "extensions/browser/event_router.h" 20 #include "extensions/browser/event_router.h"
21 #include "extensions/browser/extension_registry.h" 21 #include "extensions/browser/extension_registry.h"
22 #include "extensions/browser/extension_system.h" 22 #include "extensions/browser/extension_system.h"
23 #include "extensions/common/permissions/api_permission.h"
24 #include "extensions/common/permissions/permissions_data.h"
23 #include "storage/browser/fileapi/external_mount_points.h" 25 #include "storage/browser/fileapi/external_mount_points.h"
24 #include "storage/common/fileapi/file_system_mount_option.h" 26 #include "storage/common/fileapi/file_system_mount_option.h"
25 27
26 namespace chromeos { 28 namespace chromeos {
27 namespace file_system_provider { 29 namespace file_system_provider {
28 namespace { 30 namespace {
29 31
30 // Maximum number of file systems to be mounted in the same time, per profile. 32 // Maximum number of file systems to be mounted in the same time, per profile.
31 const size_t kMaxFileSystems = 16; 33 const size_t kMaxFileSystems = 16;
32 34
33 // Default factory for provided file systems. |profile| must not be NULL. 35 // Default factory for provided file systems. |profile| must not be NULL.
34 ProvidedFileSystemInterface* CreateProvidedFileSystem( 36 ProvidedFileSystemInterface* CreateProvidedFileSystem(
35 Profile* profile, 37 Profile* profile,
36 const ProvidedFileSystemInfo& file_system_info) { 38 const ProvidedFileSystemInfo& file_system_info) {
37 DCHECK(profile); 39 DCHECK(profile);
38 return new ThrottledFileSystem( 40 return new ThrottledFileSystem(
39 make_scoped_ptr(new ProvidedFileSystem(profile, file_system_info))); 41 make_scoped_ptr(new ProvidedFileSystem(profile, file_system_info)));
40 } 42 }
41 43
42 } // namespace 44 } // namespace
43 45
46 ProvidingExtensionInfo::ProvidingExtensionInfo()
47 : can_configure(false), can_add(false) {
48 }
49
50 ProvidingExtensionInfo::~ProvidingExtensionInfo() {
51 }
52
44 Service::Service(Profile* profile, 53 Service::Service(Profile* profile,
45 extensions::ExtensionRegistry* extension_registry) 54 extensions::ExtensionRegistry* extension_registry)
46 : profile_(profile), 55 : profile_(profile),
47 extension_registry_(extension_registry), 56 extension_registry_(extension_registry),
48 file_system_factory_(base::Bind(&CreateProvidedFileSystem)), 57 file_system_factory_(base::Bind(&CreateProvidedFileSystem)),
49 registry_(new Registry(profile)), 58 registry_(new Registry(profile)),
50 weak_ptr_factory_(this) { 59 weak_ptr_factory_(this) {
51 extension_registry_->AddObserver(this); 60 extension_registry_->AddObserver(this);
52 } 61 }
53 62
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 DCHECK(thread_checker_.CalledOnValidThread()); 296 DCHECK(thread_checker_.CalledOnValidThread());
288 297
289 const ProvidedFileSystemMap::const_iterator file_system_it = 298 const ProvidedFileSystemMap::const_iterator file_system_it =
290 file_system_map_.find(FileSystemKey(extension_id, file_system_id)); 299 file_system_map_.find(FileSystemKey(extension_id, file_system_id));
291 if (file_system_it == file_system_map_.end()) 300 if (file_system_it == file_system_map_.end())
292 return NULL; 301 return NULL;
293 302
294 return file_system_it->second; 303 return file_system_it->second;
295 } 304 }
296 305
306 std::vector<ProvidingExtensionInfo> Service::GetProvidingExtensionInfoList()
307 const {
308 extensions::ExtensionRegistry* const registry =
309 extensions::ExtensionRegistry::Get(profile_);
310 DCHECK(registry);
311
312 extensions::EventRouter* const router =
313 extensions::EventRouter::Get(profile_);
314 DCHECK(router);
315
316 std::vector<ProvidingExtensionInfo> result;
317 for (const auto& extension : registry->enabled_extensions()) {
318 if (!extension->permissions_data()->HasAPIPermission(
319 extensions::APIPermission::kFileSystemProvider)) {
320 continue;
321 }
322
323 ProvidingExtensionInfo info;
324 info.extension_id = extension->id();
325 info.name = extension->name();
326 info.can_configure = router->ExtensionHasEventListener(
327 extension->id(), extensions::api::file_system_provider::
328 OnConfigureRequested::kEventName);
329 info.can_add = router->ExtensionHasEventListener(
330 extension->id(),
331 extensions::api::file_system_provider::OnMountRequested::kEventName);
332
333 result.push_back(info);
334 }
335
336 return result;
337 }
338
297 void Service::OnExtensionUnloaded( 339 void Service::OnExtensionUnloaded(
298 content::BrowserContext* browser_context, 340 content::BrowserContext* browser_context,
299 const extensions::Extension* extension, 341 const extensions::Extension* extension,
300 extensions::UnloadedExtensionInfo::Reason reason) { 342 extensions::UnloadedExtensionInfo::Reason reason) {
301 // Unmount all of the provided file systems associated with this extension. 343 // Unmount all of the provided file systems associated with this extension.
302 ProvidedFileSystemMap::iterator it = file_system_map_.begin(); 344 ProvidedFileSystemMap::iterator it = file_system_map_.begin();
303 while (it != file_system_map_.end()) { 345 while (it != file_system_map_.end()) {
304 const ProvidedFileSystemInfo& file_system_info = 346 const ProvidedFileSystemInfo& file_system_info =
305 it->second->GetFileSystemInfo(); 347 it->second->GetFileSystemInfo();
306 // Advance the iterator beforehand, otherwise it will become invalidated 348 // Advance the iterator beforehand, otherwise it will become invalidated
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 } 437 }
396 438
397 void Service::OnWatcherListChanged( 439 void Service::OnWatcherListChanged(
398 const ProvidedFileSystemInfo& file_system_info, 440 const ProvidedFileSystemInfo& file_system_info,
399 const Watchers& watchers) { 441 const Watchers& watchers) {
400 registry_->RememberFileSystem(file_system_info, watchers); 442 registry_->RememberFileSystem(file_system_info, watchers);
401 } 443 }
402 444
403 } // namespace file_system_provider 445 } // namespace file_system_provider
404 } // namespace chromeos 446 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/file_system_provider/service.h ('k') | chrome/common/extensions/api/file_manager_private.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698