OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 // MediaFileSystemRegistry registers pictures directories and media devices as | 5 // MediaFileSystemRegistry registers pictures directories and media devices as |
6 // File API filesystems and keeps track of the path to filesystem ID mappings. | 6 // File API filesystems and keeps track of the path to filesystem ID mappings. |
7 | 7 |
8 #ifndef CHROME_BROWSER_MEDIA_GALLERIES_MEDIA_FILE_SYSTEM_REGISTRY_H_ | 8 #ifndef CHROME_BROWSER_MEDIA_GALLERIES_MEDIA_FILE_SYSTEM_REGISTRY_H_ |
9 #define CHROME_BROWSER_MEDIA_GALLERIES_MEDIA_FILE_SYSTEM_REGISTRY_H_ | 9 #define CHROME_BROWSER_MEDIA_GALLERIES_MEDIA_FILE_SYSTEM_REGISTRY_H_ |
10 | 10 |
11 #include <map> | 11 #include <map> |
12 #include <string> | 12 #include <string> |
13 #include <utility> | 13 #include <utility> |
14 #include <vector> | 14 #include <vector> |
15 | 15 |
16 #include "base/basictypes.h" | 16 #include "base/basictypes.h" |
17 #include "base/files/file_path.h" | 17 #include "base/files/file_path.h" |
18 #include "base/memory/ref_counted.h" | 18 #include "base/memory/ref_counted.h" |
| 19 #include "base/memory/weak_ptr.h" |
19 #include "base/prefs/pref_change_registrar.h" | 20 #include "base/prefs/pref_change_registrar.h" |
20 #include "chrome/browser/media_galleries/media_galleries_preferences.h" | 21 #include "chrome/browser/media_galleries/media_galleries_preferences.h" |
21 #include "chrome/browser/media_galleries/mtp_device_delegate_impl.h" | 22 #include "chrome/browser/media_galleries/mtp_device_delegate_impl.h" |
22 #include "chrome/browser/storage_monitor/removable_storage_observer.h" | 23 #include "chrome/browser/storage_monitor/removable_storage_observer.h" |
23 | 24 |
24 class Profile; | 25 class Profile; |
25 | 26 |
26 namespace content { | 27 namespace content { |
27 class RenderViewHost; | 28 class RenderViewHost; |
28 } | 29 } |
(...skipping 29 matching lines...) Expand all Loading... |
58 std::string fsid; | 59 std::string fsid; |
59 MediaGalleryPrefId pref_id; | 60 MediaGalleryPrefId pref_id; |
60 std::string transient_device_id; | 61 std::string transient_device_id; |
61 bool removable; | 62 bool removable; |
62 bool media_device; | 63 bool media_device; |
63 }; | 64 }; |
64 | 65 |
65 typedef base::Callback<void(const std::vector<MediaFileSystemInfo>&)> | 66 typedef base::Callback<void(const std::vector<MediaFileSystemInfo>&)> |
66 MediaFileSystemsCallback; | 67 MediaFileSystemsCallback; |
67 | 68 |
68 class MediaFileSystemRegistry : public RemovableStorageObserver { | 69 class MediaFileSystemRegistry : public RemovableStorageObserver, |
| 70 public MediaGalleriesPreferences::Vendor { |
69 public: | 71 public: |
70 MediaFileSystemRegistry(); | 72 MediaFileSystemRegistry(); |
71 virtual ~MediaFileSystemRegistry(); | 73 virtual ~MediaFileSystemRegistry(); |
72 | 74 |
73 // Passes to |callback| the list of media filesystem IDs and paths for a | 75 // Passes to |callback| the list of media filesystem IDs and paths for a |
74 // given RVH. Called on the UI thread. | 76 // given RVH. Called on the UI thread. |
75 void GetMediaFileSystemsForExtension( | 77 void GetMediaFileSystemsForExtension( |
76 const content::RenderViewHost* rvh, | 78 content::RenderViewHost* rvh, |
77 const extensions::Extension* extension, | 79 const extensions::Extension* extension, |
78 const MediaFileSystemsCallback& callback); | 80 const MediaFileSystemsCallback& callback); |
79 | 81 |
80 // Returns the initialized media galleries preferences for the specified | 82 // Call the given callback with preferences. This is asynchronous so that |
81 // |profile|. This method should be used instead of calling | 83 // StorageMonitor may be initialized lazily in order to set up the returned |
| 84 // preferences vendor. |
| 85 // This method should be used instead of calling |
82 // MediaGalleriesPreferences directly because this method also ensures that | 86 // MediaGalleriesPreferences directly because this method also ensures that |
83 // currently attached removable devices are added to the preferences. | 87 // currently attached removable devices are added to the preferences. |
84 // Called on the UI thread. | 88 // Called on the UI thread. |
85 MediaGalleriesPreferences* GetPreferences(Profile* profile); | 89 void GetPreferencesAsync( |
| 90 base::Callback<void(MediaGalleriesPreferences::Vendor*)> callback); |
86 | 91 |
87 // RemovableStorageObserver implementation. | 92 // RemovableStorageObserver implementation. |
88 virtual void OnRemovableStorageDetached(const StorageInfo& info) OVERRIDE; | 93 virtual void OnRemovableStorageDetached(const StorageInfo& info) OVERRIDE; |
89 | 94 |
90 size_t GetExtensionGalleriesHostCountForTests() const; | 95 size_t GetExtensionGalleriesHostCountForTests() const; |
91 | 96 |
92 // See TransientDeviceIds::GetTransientIdForDeviceId(). | 97 // See TransientDeviceIds::GetTransientIdForDeviceId(). |
93 uint64 GetTransientIdForDeviceId(const std::string& device_id); | 98 uint64 GetTransientIdForDeviceId(const std::string& device_id); |
94 | 99 |
| 100 // MediaGalleriesPreferences::Vendor |
| 101 virtual MediaGalleriesPreferences* GetPreferences(Profile* profile) OVERRIDE; |
| 102 |
95 private: | 103 private: |
96 friend class TestMediaFileSystemContext; | 104 friend class TestMediaFileSystemContext; |
97 class MediaFileSystemContextImpl; | 105 class MediaFileSystemContextImpl; |
98 | 106 |
| 107 // Bottom half of |GetMediaFileSystemsForExtensions|, called after the |
| 108 // StorageMonitor is initialized. |
| 109 void GetMediaFileSystemsWithPreferences( |
| 110 const content::RenderViewHost* rvh, |
| 111 const extensions::Extension* extension, |
| 112 const MediaFileSystemsCallback& callback, |
| 113 MediaGalleriesPreferences::Vendor* vendor); |
| 114 |
| 115 // Notify the registry when the storage monitor has been initialized. |
| 116 void OnStorageMonitorInitialized( |
| 117 base::Callback<void(MediaGalleriesPreferences::Vendor*)> callback); |
| 118 |
99 // Map an extension to the ExtensionGalleriesHost. | 119 // Map an extension to the ExtensionGalleriesHost. |
100 typedef std::map<std::string /*extension_id*/, | 120 typedef std::map<std::string /*extension_id*/, |
101 scoped_refptr<ExtensionGalleriesHost> > ExtensionHostMap; | 121 scoped_refptr<ExtensionGalleriesHost> > ExtensionHostMap; |
102 // Map a profile and extension to the ExtensionGalleriesHost. | 122 // Map a profile and extension to the ExtensionGalleriesHost. |
103 typedef std::map<Profile*, ExtensionHostMap> ExtensionGalleriesHostMap; | 123 typedef std::map<Profile*, ExtensionHostMap> ExtensionGalleriesHostMap; |
104 // Map a profile to a PrefChangeRegistrar. | 124 // Map a profile to a PrefChangeRegistrar. |
105 typedef std::map<Profile*, PrefChangeRegistrar*> PrefChangeRegistrarMap; | 125 typedef std::map<Profile*, PrefChangeRegistrar*> PrefChangeRegistrarMap; |
106 | 126 |
107 // Map a MTP or PTP device location to the raw pointer of | 127 // Map a MTP or PTP device location to the raw pointer of |
108 // ScopedMTPDeviceMapEntry. It is safe to store a raw pointer in this | 128 // ScopedMTPDeviceMapEntry. It is safe to store a raw pointer in this |
(...skipping 19 matching lines...) Expand all Loading... |
128 // ExtensionGalleriesHost objects created. | 148 // ExtensionGalleriesHost objects created. |
129 ExtensionGalleriesHostMap extension_hosts_map_; | 149 ExtensionGalleriesHostMap extension_hosts_map_; |
130 | 150 |
131 PrefChangeRegistrarMap pref_change_registrar_map_; | 151 PrefChangeRegistrarMap pref_change_registrar_map_; |
132 | 152 |
133 // Only accessed on the UI thread. | 153 // Only accessed on the UI thread. |
134 MTPDeviceDelegateMap mtp_device_delegate_map_; | 154 MTPDeviceDelegateMap mtp_device_delegate_map_; |
135 | 155 |
136 scoped_ptr<MediaFileSystemContext> file_system_context_; | 156 scoped_ptr<MediaFileSystemContext> file_system_context_; |
137 | 157 |
| 158 base::WeakPtrFactory<MediaFileSystemRegistry> weak_ptr_factory_; |
| 159 |
138 DISALLOW_COPY_AND_ASSIGN(MediaFileSystemRegistry); | 160 DISALLOW_COPY_AND_ASSIGN(MediaFileSystemRegistry); |
139 }; | 161 }; |
140 | 162 |
141 } // namespace chrome | 163 } // namespace chrome |
142 | 164 |
143 #endif // CHROME_BROWSER_MEDIA_GALLERIES_MEDIA_FILE_SYSTEM_REGISTRY_H_ | 165 #endif // CHROME_BROWSER_MEDIA_GALLERIES_MEDIA_FILE_SYSTEM_REGISTRY_H_ |
OLD | NEW |