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

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 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 <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/lazy_instance.h" 17 #include "base/lazy_instance.h"
18 #include "base/file_path.h" 18 #include "base/file_path.h"
19 #include "base/memory/ref_counted.h" 19 #include "base/memory/ref_counted.h"
20 #include "base/memory/weak_ptr.h"
21 #include "base/prefs/public/pref_change_registrar.h" 20 #include "base/prefs/public/pref_change_registrar.h"
22 #include "base/system_monitor/system_monitor.h" 21 #include "base/system_monitor/system_monitor.h"
23 #include "webkit/fileapi/media/mtp_device_file_system_config.h" 22 #include "webkit/fileapi/media/mtp_device_file_system_config.h"
24 23
25 #if defined(SUPPORT_MTP_DEVICE_FILESYSTEM) 24 #if defined(SUPPORT_MTP_DEVICE_FILESYSTEM)
26 #include "chrome/browser/media_gallery/mtp_device_delegate_impl.h" 25 #include "chrome/browser/media_gallery/mtp_device_delegate_impl.h"
27 #endif 26 #endif
28 27
29 class Profile; 28 class Profile;
30 29
(...skipping 19 matching lines...) Expand all
50 const FilePath& fs_path, 49 const FilePath& fs_path,
51 const std::string& filesystem_id); 50 const std::string& filesystem_id);
52 MediaFileSystemInfo(); 51 MediaFileSystemInfo();
53 52
54 std::string name; // JSON string, must not contain slashes. 53 std::string name; // JSON string, must not contain slashes.
55 FilePath path; 54 FilePath path;
56 std::string fsid; 55 std::string fsid;
57 }; 56 };
58 57
59 #if defined(SUPPORT_MTP_DEVICE_FILESYSTEM) 58 #if defined(SUPPORT_MTP_DEVICE_FILESYSTEM)
60 // Class to manage MTPDeviceDelegateImpl object for the attached MTP device. 59 // Class to manage the lifetime of MTPDeviceDelegateImpl object for the
61 // Refcounted to reuse the same MTP device delegate entry across extensions. 60 // attached media transfer protocol (MTP) device. This object is constructed
62 // This class supports WeakPtr (extends SupportsWeakPtr) to expose itself as 61 // for each MTP device. Refcounted to reuse the same MTP device delegate entry
63 // a weak pointer to MediaFileSystemRegistry. 62 // across extensions.
64 class ScopedMTPDeviceMapEntry 63 class ScopedMTPDeviceMapEntry
65 : public base::RefCounted<ScopedMTPDeviceMapEntry>, 64 : public base::RefCounted<ScopedMTPDeviceMapEntry> {
66 public base::SupportsWeakPtr<ScopedMTPDeviceMapEntry> {
67 public: 65 public:
68 // |no_references_callback| is called when the last ScopedMTPDeviceMapEntry 66 // |no_references_callback| is called when the last ScopedMTPDeviceMapEntry
69 // reference goes away. 67 // reference goes away.
70 ScopedMTPDeviceMapEntry(const FilePath::StringType& device_location, 68 ScopedMTPDeviceMapEntry(const FilePath::StringType& device_location,
71 const base::Closure& no_references_callback); 69 const base::Closure& no_references_callback);
72 70
73 private: 71 private:
74 // Friend declaration for ref counted implementation. 72 // Friend declaration for ref counted implementation.
75 friend class base::RefCounted<ScopedMTPDeviceMapEntry>; 73 friend class base::RefCounted<ScopedMTPDeviceMapEntry>;
76 74
77 // Private because this class is ref-counted. 75 // Private because this class is ref-counted. Destructed when the last user of
76 // this MTP device is destroyed or when the MTP device is detached from the
77 // system or when the browser is in shutdown mode or when the last extension
78 // revokes the MTP device gallery permissions.
78 ~ScopedMTPDeviceMapEntry(); 79 ~ScopedMTPDeviceMapEntry();
79 80
80 // Store the MTP or PTP device location. 81 // The MTP or PTP device location.
81 const FilePath::StringType device_location_; 82 const FilePath::StringType device_location_;
82 83
83 // Store a raw pointer of MTPDeviceDelegateImpl object.
84 // MTPDeviceDelegateImpl is ref-counted and owned by MTPDeviceMapService.
85 // This class tells MTPDeviceMapService to dispose of it when the last
86 // reference to |this| goes away.
87 MTPDeviceDelegateImpl* delegate_;
88
89 // A callback to call when the last reference of this object goes away. 84 // A callback to call when the last reference of this object goes away.
90 base::Closure no_references_callback_; 85 base::Closure no_references_callback_;
91 86
92 DISALLOW_COPY_AND_ASSIGN(ScopedMTPDeviceMapEntry); 87 DISALLOW_COPY_AND_ASSIGN(ScopedMTPDeviceMapEntry);
93 }; 88 };
94 #endif 89 #endif
95 90
96 class MediaFileSystemContext { 91 class MediaFileSystemContext {
97 public: 92 public:
98 virtual ~MediaFileSystemContext() {} 93 virtual ~MediaFileSystemContext() {}
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 149
155 // Map an extension to the ExtensionGalleriesHost. 150 // Map an extension to the ExtensionGalleriesHost.
156 typedef std::map<std::string /*extension_id*/, 151 typedef std::map<std::string /*extension_id*/,
157 scoped_refptr<ExtensionGalleriesHost> > ExtensionHostMap; 152 scoped_refptr<ExtensionGalleriesHost> > ExtensionHostMap;
158 // Map a profile and extension to the ExtensionGalleriesHost. 153 // Map a profile and extension to the ExtensionGalleriesHost.
159 typedef std::map<Profile*, ExtensionHostMap> ExtensionGalleriesHostMap; 154 typedef std::map<Profile*, ExtensionHostMap> ExtensionGalleriesHostMap;
160 // Map a profile to a PrefChangeRegistrar. 155 // Map a profile to a PrefChangeRegistrar.
161 typedef std::map<Profile*, PrefChangeRegistrar*> PrefChangeRegistrarMap; 156 typedef std::map<Profile*, PrefChangeRegistrar*> PrefChangeRegistrarMap;
162 157
163 #if defined(SUPPORT_MTP_DEVICE_FILESYSTEM) 158 #if defined(SUPPORT_MTP_DEVICE_FILESYSTEM)
164 // Map a MTP or PTP device location to the weak pointer of 159 // Map a MTP or PTP device location to the raw pointer of
165 // ScopedMTPDeviceMapEntry. 160 // ScopedMTPDeviceMapEntry. It is safe to store a raw pointer in this
166 typedef std::map<const FilePath::StringType, 161 // map.
167 base::WeakPtr<ScopedMTPDeviceMapEntry> > 162 typedef std::map<const FilePath::StringType, ScopedMTPDeviceMapEntry*>
168 MTPDeviceDelegateMap; 163 MTPDeviceDelegateMap;
169 #endif 164 #endif
170 165
171 // Obtain an instance of this class via GetInstance(). 166 // Obtain an instance of this class via GetInstance().
172 MediaFileSystemRegistry(); 167 MediaFileSystemRegistry();
173 virtual ~MediaFileSystemRegistry(); 168 virtual ~MediaFileSystemRegistry();
174 169
175 void OnMediaGalleriesRememberedGalleriesChanged(PrefServiceBase* service); 170 void OnMediaGalleriesRememberedGalleriesChanged(PrefServiceBase* service);
176 171
177 #if defined(SUPPORT_MTP_DEVICE_FILESYSTEM) 172 #if defined(SUPPORT_MTP_DEVICE_FILESYSTEM)
(...skipping 11 matching lines...) Expand all
189 const std::string& extension_id); 184 const std::string& extension_id);
190 185
191 // Only accessed on the UI thread. This map owns all the 186 // Only accessed on the UI thread. This map owns all the
192 // ExtensionGalleriesHost objects created. 187 // ExtensionGalleriesHost objects created.
193 ExtensionGalleriesHostMap extension_hosts_map_; 188 ExtensionGalleriesHostMap extension_hosts_map_;
194 189
195 PrefChangeRegistrarMap pref_change_registrar_map_; 190 PrefChangeRegistrarMap pref_change_registrar_map_;
196 191
197 #if defined(SUPPORT_MTP_DEVICE_FILESYSTEM) 192 #if defined(SUPPORT_MTP_DEVICE_FILESYSTEM)
198 // Only accessed on the UI thread. 193 // Only accessed on the UI thread.
199 MTPDeviceDelegateMap mtp_delegate_map_; 194 MTPDeviceDelegateMap mtp_device_delegate_map_;
200 #endif 195 #endif
201 196
202 scoped_ptr<MediaFileSystemContext> file_system_context_; 197 scoped_ptr<MediaFileSystemContext> file_system_context_;
203 198
204 DISALLOW_COPY_AND_ASSIGN(MediaFileSystemRegistry); 199 DISALLOW_COPY_AND_ASSIGN(MediaFileSystemRegistry);
205 }; 200 };
206 201
207 } // namespace chrome 202 } // namespace chrome
208 203
209 #endif // CHROME_BROWSER_MEDIA_GALLERY_MEDIA_FILE_SYSTEM_REGISTRY_H_ 204 #endif // CHROME_BROWSER_MEDIA_GALLERY_MEDIA_FILE_SYSTEM_REGISTRY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698