Check USB device path access when prompting users to select a device.
[chromium-blink-merge.git] / chrome / browser / media_galleries / media_file_system_registry.h
blob2b38233ad88b746e34bf2ac7dfc8938cbf3625af
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/files/file.h"
18 #include "base/files/file_path.h"
19 #include "base/memory/ref_counted.h"
20 #include "base/memory/scoped_ptr.h"
21 #include "chrome/browser/media_galleries/media_galleries_preferences.h"
22 #include "components/storage_monitor/removable_storage_observer.h"
24 class ExtensionGalleriesHost;
25 class GalleryWatchManager;
26 class MediaFileSystemContext;
27 class MediaGalleriesPreferences;
28 class MediaScanManager;
29 class Profile;
31 namespace content {
32 class RenderViewHost;
35 namespace extensions {
36 class Extension;
39 namespace storage {
40 class IsolatedContext;
43 // Contains information about a particular filesystem being provided to a
44 // client, including metadata like the name and ID, and API handles like the
45 // fsid (filesystem ID) used to hook up the API objects.
46 struct MediaFileSystemInfo {
47 MediaFileSystemInfo(const base::string16& fs_name,
48 const base::FilePath& fs_path,
49 const std::string& filesystem_id,
50 MediaGalleryPrefId pref_id,
51 const std::string& transient_device_id,
52 bool removable,
53 bool media_device);
54 MediaFileSystemInfo();
55 ~MediaFileSystemInfo();
57 base::string16 name;
58 base::FilePath path;
59 std::string fsid;
60 MediaGalleryPrefId pref_id;
61 std::string transient_device_id;
62 bool removable;
63 bool media_device;
66 typedef base::Callback<void(const std::vector<MediaFileSystemInfo>&)>
67 MediaFileSystemsCallback;
69 // Tracks usage of filesystems by extensions.
70 // This object lives on the UI thread.
71 class MediaFileSystemRegistry
72 : public storage_monitor::RemovableStorageObserver,
73 public MediaGalleriesPreferences::GalleryChangeObserver {
74 public:
75 MediaFileSystemRegistry();
76 ~MediaFileSystemRegistry() override;
78 // Passes to |callback| the list of media filesystem IDs and paths for a
79 // given RVH.
80 void GetMediaFileSystemsForExtension(
81 const content::RenderViewHost* rvh,
82 const extensions::Extension* extension,
83 const MediaFileSystemsCallback& callback);
85 // Attempt to register the file system for |pref_id|. If |extension| does not
86 // have permission to |pref_id|, sends |callback| FILE_ERROR_NOT_FOUND.
87 void RegisterMediaFileSystemForExtension(
88 const content::RenderViewHost* rvh,
89 const extensions::Extension* extension,
90 MediaGalleryPrefId pref_id,
91 const base::Callback<void(base::File::Error result)>& callback);
93 // Returns the media galleries preferences for the specified |profile|.
94 // Caller is responsible for ensuring that the preferences are initialized
95 // before use.
96 MediaGalleriesPreferences* GetPreferences(Profile* profile);
98 MediaScanManager* media_scan_manager();
99 GalleryWatchManager* gallery_watch_manager();
101 // RemovableStorageObserver implementation.
102 void OnRemovableStorageDetached(
103 const storage_monitor::StorageInfo& info) override;
105 private:
106 class MediaFileSystemContextImpl;
108 friend class MediaFileSystemContextImpl;
109 friend class MediaFileSystemRegistryTest;
110 friend class TestMediaFileSystemContext;
112 // Map an extension to the ExtensionGalleriesHost.
113 typedef std::map<std::string /*extension_id*/,
114 scoped_refptr<ExtensionGalleriesHost> > ExtensionHostMap;
115 // Map a profile and extension to the ExtensionGalleriesHost.
116 typedef std::map<Profile*, ExtensionHostMap> ExtensionGalleriesHostMap;
118 void OnPermissionRemoved(MediaGalleriesPreferences* pref,
119 const std::string& extension_id,
120 MediaGalleryPrefId pref_id) override;
121 void OnGalleryRemoved(MediaGalleriesPreferences* pref,
122 MediaGalleryPrefId pref_id) override;
124 // Look up or create the extension gallery host.
125 ExtensionGalleriesHost* GetExtensionGalleryHost(
126 Profile* profile,
127 MediaGalleriesPreferences* preferences,
128 const std::string& extension_id);
130 void OnExtensionGalleriesHostEmpty(Profile* profile,
131 const std::string& extension_id);
133 // This map owns all the ExtensionGalleriesHost objects created.
134 ExtensionGalleriesHostMap extension_hosts_map_;
136 scoped_ptr<MediaFileSystemContext> file_system_context_;
138 scoped_ptr<MediaScanManager> media_scan_manager_;
139 scoped_ptr<GalleryWatchManager> gallery_watch_manager_;
141 DISALLOW_COPY_AND_ASSIGN(MediaFileSystemRegistry);
144 #endif // CHROME_BROWSER_MEDIA_GALLERIES_MEDIA_FILE_SYSTEM_REGISTRY_H_