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

Side by Side Diff: chrome/browser/media_gallery/media_file_system_registry.h

Issue 11358243: Redesigned and refactored ScopedMTPDeviceMapEntry, MTPDeviceMapService & MTPDeviceDelegate classes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: '' Created 8 years, 1 month 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 | Annotate | Revision Log
OLDNEW
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_GALLERY_MEDIA_FILE_SYSTEM_REGISTRY_H_ 8 #ifndef CHROME_BROWSER_MEDIA_GALLERY_MEDIA_FILE_SYSTEM_REGISTRY_H_
9 #define CHROME_BROWSER_MEDIA_GALLERY_MEDIA_FILE_SYSTEM_REGISTRY_H_ 9 #define CHROME_BROWSER_MEDIA_GALLERY_MEDIA_FILE_SYSTEM_REGISTRY_H_
10 10
11 #include <map> 11 #include <map>
12 #include <set>
12 #include <string> 13 #include <string>
13 #include <utility> 14 #include <utility>
14 #include <vector> 15 #include <vector>
15 16
16 #include "base/basictypes.h" 17 #include "base/basictypes.h"
17 #include "base/lazy_instance.h" 18 #include "base/lazy_instance.h"
18 #include "base/file_path.h" 19 #include "base/file_path.h"
19 #include "base/memory/ref_counted.h" 20 #include "base/memory/ref_counted.h"
20 #include "base/memory/weak_ptr.h"
21 #include "base/prefs/public/pref_change_registrar.h" 21 #include "base/prefs/public/pref_change_registrar.h"
22 #include "base/prefs/public/pref_observer.h" 22 #include "base/prefs/public/pref_observer.h"
23 #include "base/system_monitor/system_monitor.h" 23 #include "base/system_monitor/system_monitor.h"
24 #include "webkit/fileapi/media/mtp_device_file_system_config.h" 24 #include "webkit/fileapi/media/mtp_device_file_system_config.h"
25 25
26 class Profile; 26 class Profile;
27 27
28 namespace content { 28 namespace content {
29 class RenderViewHost; 29 class RenderViewHost;
30 } 30 }
(...skipping 26 matching lines...) Expand all
57 class MediaFileSystemContext { 57 class MediaFileSystemContext {
58 public: 58 public:
59 virtual ~MediaFileSystemContext() {} 59 virtual ~MediaFileSystemContext() {}
60 60
61 // Register a media file system (filtered to media files) for |path| and 61 // Register a media file system (filtered to media files) for |path| and
62 // return the new file system id. 62 // return the new file system id.
63 virtual std::string RegisterFileSystemForMassStorage( 63 virtual std::string RegisterFileSystemForMassStorage(
64 const std::string& device_id, const FilePath& path) = 0; 64 const std::string& device_id, const FilePath& path) = 0;
65 65
66 #if defined(SUPPORT_MTP_DEVICE_FILESYSTEM) 66 #if defined(SUPPORT_MTP_DEVICE_FILESYSTEM)
67 // Registers and returns the file system id for the MTP or PTP device 67 // For the given |galleries_host|, this function returns the file system id
68 // specified by |device_id| and |path|. Updates |entry| with the corresponding 68 // of the registered MTP or PTP device specified by |device_id| and |path|.
69 // ScopedMTPDeviceMapEntry object.
70 virtual std::string RegisterFileSystemForMTPDevice( 69 virtual std::string RegisterFileSystemForMTPDevice(
71 const std::string& device_id, const FilePath& path, 70 const std::string& device_id, const FilePath& path,
72 scoped_refptr<ScopedMTPDeviceMapEntry>* entry) = 0; 71 const ExtensionGalleriesHost* galleries_host) = 0;
72
73 // Removes the MTP or PTP device reference for the given |galleries_host|.
74 virtual void RemoveMTPDeviceReferenceForHost(
75 const FilePath::StringType& device_location,
76 const ExtensionGalleriesHost* galleries_host) = 0;
73 #endif 77 #endif
74 78
75 // Revoke the passed |fsid|. 79 // Revoke the passed |fsid|.
76 virtual void RevokeFileSystem(const std::string& fsid) = 0; 80 virtual void RevokeFileSystem(const std::string& fsid) = 0;
77 }; 81 };
78 82
79 typedef base::Callback<void(const std::vector<MediaFileSystemInfo>&)> 83 typedef base::Callback<void(const std::vector<MediaFileSystemInfo>&)>
80 MediaFileSystemsCallback; 84 MediaFileSystemsCallback;
81 85
82 class MediaFileSystemRegistry 86 class MediaFileSystemRegistry
(...skipping 30 matching lines...) Expand all
113 117
114 // Map an extension to the ExtensionGalleriesHost. 118 // Map an extension to the ExtensionGalleriesHost.
115 typedef std::map<std::string /*extension_id*/, 119 typedef std::map<std::string /*extension_id*/,
116 scoped_refptr<ExtensionGalleriesHost> > ExtensionHostMap; 120 scoped_refptr<ExtensionGalleriesHost> > ExtensionHostMap;
117 // Map a profile and extension to the ExtensionGalleriesHost. 121 // Map a profile and extension to the ExtensionGalleriesHost.
118 typedef std::map<Profile*, ExtensionHostMap> ExtensionGalleriesHostMap; 122 typedef std::map<Profile*, ExtensionHostMap> ExtensionGalleriesHostMap;
119 // Map a profile to a PrefChangeRegistrar. 123 // Map a profile to a PrefChangeRegistrar.
120 typedef std::map<Profile*, PrefChangeRegistrar*> PrefChangeRegistrarMap; 124 typedef std::map<Profile*, PrefChangeRegistrar*> PrefChangeRegistrarMap;
121 125
122 #if defined(SUPPORT_MTP_DEVICE_FILESYSTEM) 126 #if defined(SUPPORT_MTP_DEVICE_FILESYSTEM)
123 // Map a MTP or PTP device location to the weak pointer of 127 // Map a MTP or PTP device location to the ScopedMTPDeviceMapEntry.
124 // ScopedMTPDeviceMapEntry. 128 // This map owns ScopedMTPDeviceMapEntry.
125 typedef std::map<const FilePath::StringType, 129 typedef std::map<const FilePath::StringType, ScopedMTPDeviceMapEntry*>
126 base::WeakPtr<ScopedMTPDeviceMapEntry> >
127 MTPDeviceDelegateMap; 130 MTPDeviceDelegateMap;
131
132 // Set of extension galleries host.
133 typedef std::set<const ExtensionGalleriesHost*> ExtensionGalleriesHostSet;
134
135 // Map a device location to a set of extension galleries host.
136 // This map keeps track of extension galleries that currently registered
137 // the MTP device gallery as a file system.
138 typedef std::map<const FilePath::StringType, ExtensionGalleriesHostSet>
139 MTPDeviceReferencesMap;
128 #endif 140 #endif
129 141
130 // Obtain an instance of this class via GetInstance(). 142 // Obtain an instance of this class via GetInstance().
131 MediaFileSystemRegistry(); 143 MediaFileSystemRegistry();
132 virtual ~MediaFileSystemRegistry(); 144 virtual ~MediaFileSystemRegistry();
133 145
134 // PrefObserver implementation. 146 // PrefObserver implementation.
135 virtual void OnPreferenceChanged(PrefServiceBase* service, 147 virtual void OnPreferenceChanged(PrefServiceBase* service,
136 const std::string& pref_name) OVERRIDE; 148 const std::string& pref_name) OVERRIDE;
137 149
138 #if defined(SUPPORT_MTP_DEVICE_FILESYSTEM) 150 #if defined(SUPPORT_MTP_DEVICE_FILESYSTEM)
139 // Returns ScopedMTPDeviceMapEntry object for the given |device_location|. 151 // Adds the |galleries_host| reference for the MTP device specified by the
140 ScopedMTPDeviceMapEntry* GetOrCreateScopedMTPDeviceMapEntry( 152 // |device_location|.
141 const FilePath::StringType& device_location); 153 void AddGalleriesHostReferenceForMTPDevice(
154 const FilePath::StringType& device_location,
155 const ExtensionGalleriesHost* galleries_host);
142 156
143 // Removes the ScopedMTPDeviceMapEntry associated with the given 157 // Removes the |galleries_host| reference for the MTP device specified by the
144 // |device_location|. 158 // |device_location|.
145 void RemoveScopedMTPDeviceMapEntry( 159 void RemoveGalleriesHostReferenceForMTPDevice(
146 const FilePath::StringType& device_location); 160 const FilePath::StringType& device_location,
161 const ExtensionGalleriesHost* galleries_host);
147 #endif 162 #endif
148 163
149 void OnExtensionGalleriesHostEmpty(Profile* profile, 164 void OnExtensionGalleriesHostEmpty(Profile* profile,
150 const std::string& extension_id); 165 const std::string& extension_id);
151 166
152 // Only accessed on the UI thread. This map owns all the 167 // Only accessed on the UI thread. This map owns all the
153 // ExtensionGalleriesHost objects created. 168 // ExtensionGalleriesHost objects created.
154 ExtensionGalleriesHostMap extension_hosts_map_; 169 ExtensionGalleriesHostMap extension_hosts_map_;
155 170
156 PrefChangeRegistrarMap pref_change_registrar_map_; 171 PrefChangeRegistrarMap pref_change_registrar_map_;
157 172
158 #if defined(SUPPORT_MTP_DEVICE_FILESYSTEM) 173 #if defined(SUPPORT_MTP_DEVICE_FILESYSTEM)
159 // Only accessed on the UI thread. 174 // Only accessed on the UI thread.
160 MTPDeviceDelegateMap mtp_delegate_map_; 175 MTPDeviceDelegateMap mtp_device_delegate_map_;
176 MTPDeviceReferencesMap mtp_device_references_map_;
161 #endif 177 #endif
162 178
163 scoped_ptr<MediaFileSystemContext> file_system_context_; 179 scoped_ptr<MediaFileSystemContext> file_system_context_;
164 180
165 DISALLOW_COPY_AND_ASSIGN(MediaFileSystemRegistry); 181 DISALLOW_COPY_AND_ASSIGN(MediaFileSystemRegistry);
166 }; 182 };
167 183
168 } // namespace chrome 184 } // namespace chrome
169 185
170 #endif // CHROME_BROWSER_MEDIA_GALLERY_MEDIA_FILE_SYSTEM_REGISTRY_H_ 186 #endif // CHROME_BROWSER_MEDIA_GALLERY_MEDIA_FILE_SYSTEM_REGISTRY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698