Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / browser / media_galleries / media_file_system_registry.h
blobced36ad98a59ddcc32b3336b9026ce176e1e9aa3
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 // MediaFileSystemRegistry registers pictures directories and media devices as
6 // File API filesystems and keeps track of the path to filesystem ID mappings.
8 #ifndef CHROME_BROWSER_MEDIA_GALLERIES_MEDIA_FILE_SYSTEM_REGISTRY_H_
9 #define CHROME_BROWSER_MEDIA_GALLERIES_MEDIA_FILE_SYSTEM_REGISTRY_H_
11 #include <map>
12 #include <string>
13 #include <utility>
14 #include <vector>
16 #include "base/basictypes.h"
17 #include "base/containers/scoped_ptr_map.h"
18 #include "base/files/file.h"
19 #include "base/files/file_path.h"
20 #include "base/memory/ref_counted.h"
21 #include "base/memory/scoped_ptr.h"
22 #include "chrome/browser/media_galleries/media_galleries_preferences.h"
23 #include "components/keyed_service/core/keyed_service_shutdown_notifier.h"
24 #include "components/storage_monitor/removable_storage_observer.h"
26 class ExtensionGalleriesHost;
27 class GalleryWatchManager;
28 class MediaFileSystemContext;
29 class MediaGalleriesPreferences;
30 class MediaScanManager;
31 class Profile;
33 namespace content {
34 class WebContents;
37 namespace extensions {
38 class Extension;
41 namespace storage {
42 class IsolatedContext;
45 // Contains information about a particular filesystem being provided to a
46 // client, including metadata like the name and ID, and API handles like the
47 // fsid (filesystem ID) used to hook up the API objects.
48 struct MediaFileSystemInfo {
49 MediaFileSystemInfo(const base::string16& fs_name,
50 const base::FilePath& fs_path,
51 const std::string& filesystem_id,
52 MediaGalleryPrefId pref_id,
53 const std::string& transient_device_id,
54 bool removable,
55 bool media_device);
56 MediaFileSystemInfo();
57 ~MediaFileSystemInfo();
59 base::string16 name;
60 base::FilePath path;
61 std::string fsid;
62 MediaGalleryPrefId pref_id;
63 std::string transient_device_id;
64 bool removable;
65 bool media_device;
68 typedef base::Callback<void(const std::vector<MediaFileSystemInfo>&)>
69 MediaFileSystemsCallback;
71 // Tracks usage of filesystems by extensions.
72 // This object lives on the UI thread.
73 class MediaFileSystemRegistry
74 : public storage_monitor::RemovableStorageObserver,
75 public MediaGalleriesPreferences::GalleryChangeObserver {
76 public:
77 MediaFileSystemRegistry();
78 ~MediaFileSystemRegistry() override;
80 // Passes to |callback| the list of media filesystem IDs and paths for a
81 // given WebContents.
82 void GetMediaFileSystemsForExtension(
83 content::WebContents* contents,
84 const extensions::Extension* extension,
85 const MediaFileSystemsCallback& callback);
87 // Attempt to register the file system for |pref_id|. If |extension| does not
88 // have permission to |pref_id|, sends |callback| FILE_ERROR_NOT_FOUND.
89 void RegisterMediaFileSystemForExtension(
90 content::WebContents* contents,
91 const extensions::Extension* extension,
92 MediaGalleryPrefId pref_id,
93 const base::Callback<void(base::File::Error result)>& callback);
95 // Returns the media galleries preferences for the specified |profile|.
96 // Caller is responsible for ensuring that the preferences are initialized
97 // before use.
98 MediaGalleriesPreferences* GetPreferences(Profile* profile);
100 MediaScanManager* media_scan_manager();
101 GalleryWatchManager* gallery_watch_manager();
103 // RemovableStorageObserver implementation.
104 void OnRemovableStorageDetached(
105 const storage_monitor::StorageInfo& info) override;
107 private:
108 class MediaFileSystemContextImpl;
110 friend class MediaFileSystemContextImpl;
111 friend class MediaFileSystemRegistryTest;
112 friend class TestMediaFileSystemContext;
114 // Map an extension to the ExtensionGalleriesHost.
115 typedef std::map<std::string /*extension_id*/,
116 scoped_refptr<ExtensionGalleriesHost>> ExtensionHostMap;
117 // Map a profile and extension to the ExtensionGalleriesHost.
118 typedef std::map<Profile*, ExtensionHostMap> ExtensionGalleriesHostMap;
119 // Map a profile to a shutdown notification subscription.
120 typedef base::ScopedPtrMap<
121 Profile*,
122 scoped_ptr<KeyedServiceShutdownNotifier::Subscription>>
123 ProfileSubscriptionMap;
125 void OnPermissionRemoved(MediaGalleriesPreferences* pref,
126 const std::string& extension_id,
127 MediaGalleryPrefId pref_id) override;
128 void OnGalleryRemoved(MediaGalleriesPreferences* pref,
129 MediaGalleryPrefId pref_id) override;
131 // Look up or create the extension gallery host.
132 ExtensionGalleriesHost* GetExtensionGalleryHost(
133 Profile* profile,
134 MediaGalleriesPreferences* preferences,
135 const std::string& extension_id);
137 void OnExtensionGalleriesHostEmpty(Profile* profile,
138 const std::string& extension_id);
140 void OnProfileShutdown(Profile* profile);
142 // This map owns all the ExtensionGalleriesHost objects created.
143 ExtensionGalleriesHostMap extension_hosts_map_;
145 // The above map uses raw Profile pointers as keys. This map removes those
146 // entries when the Profile is destroyed.
147 ProfileSubscriptionMap profile_subscription_map_;
149 scoped_ptr<MediaFileSystemContext> file_system_context_;
151 scoped_ptr<MediaScanManager> media_scan_manager_;
152 scoped_ptr<GalleryWatchManager> gallery_watch_manager_;
154 DISALLOW_COPY_AND_ASSIGN(MediaFileSystemRegistry);
157 #endif // CHROME_BROWSER_MEDIA_GALLERIES_MEDIA_FILE_SYSTEM_REGISTRY_H_