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

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

Issue 11027051: MediaFileSystemRegistry unit tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase 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 <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" 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/system_monitor/system_monitor.h" 22 #include "base/system_monitor/system_monitor.h"
23 #include "webkit/fileapi/media/mtp_device_file_system_config.h" 23 #include "webkit/fileapi/media/mtp_device_file_system_config.h"
24 24
25 #if defined(SUPPORT_MTP_DEVICE_FILESYSTEM)
26 #include "chrome/browser/media_gallery/mtp_device_delegate_impl.h"
27 #endif
28
25 class Profile; 29 class Profile;
26 30
27 namespace content { 31 namespace content {
28 class RenderViewHost; 32 class RenderViewHost;
29 } 33 }
30 34
31 namespace extensions { 35 namespace extensions {
32 class Extension; 36 class Extension;
33 } 37 }
34 38
35 namespace fileapi { 39 namespace fileapi {
36 class IsolatedContext; 40 class IsolatedContext;
37 } 41 }
38 42
39 namespace chrome { 43 namespace chrome {
40 44
41 class ExtensionGalleriesHost; 45 class ExtensionGalleriesHost;
42 class MediaGalleriesPreferences; 46 class MediaGalleriesPreferences;
43 class ScopedMTPDeviceMapEntry;
44 47
45 struct MediaFileSystemInfo { 48 struct MediaFileSystemInfo {
46 MediaFileSystemInfo(const std::string& fs_name, 49 MediaFileSystemInfo(const std::string& fs_name,
47 const FilePath& fs_path, 50 const FilePath& fs_path,
48 const std::string& filesystem_id); 51 const std::string& filesystem_id);
49 MediaFileSystemInfo(); 52 MediaFileSystemInfo();
50 53
51 std::string name; // JSON string, must not contain slashes. 54 std::string name; // JSON string, must not contain slashes.
52 FilePath path; 55 FilePath path;
53 std::string fsid; 56 std::string fsid;
54 }; 57 };
55 58
59 #if defined(SUPPORT_MTP_DEVICE_FILESYSTEM)
60 // Class to manage MTPDeviceDelegateImpl object for the attached MTP device.
61 // Refcounted to reuse the same MTP device delegate entry across extensions.
62 // This class supports WeakPtr (extends SupportsWeakPtr) to expose itself as
63 // a weak pointer to MediaFileSystemRegistry.
64 class ScopedMTPDeviceMapEntry
65 : public base::RefCounted<ScopedMTPDeviceMapEntry>,
66 public base::SupportsWeakPtr<ScopedMTPDeviceMapEntry> {
67 public:
68 // |no_references_callback| is called when the last ScopedMTPDeviceMapEntry
69 // reference goes away.
70 ScopedMTPDeviceMapEntry(const FilePath::StringType& device_location,
71 const base::Closure& no_references_callback);
72
73 private:
74 // Friend declaration for ref counted implementation.
75 friend class base::RefCounted<ScopedMTPDeviceMapEntry>;
76
77 // Private because this class is ref-counted.
78 ~ScopedMTPDeviceMapEntry();
79
80 // Store the MTP or PTP device location.
81 const FilePath::StringType device_location_;
82
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.
90 base::Closure no_references_callback_;
91
92 DISALLOW_COPY_AND_ASSIGN(ScopedMTPDeviceMapEntry);
93 };
94 #endif
95
56 class MediaFileSystemContext { 96 class MediaFileSystemContext {
57 public: 97 public:
58 virtual ~MediaFileSystemContext() {} 98 virtual ~MediaFileSystemContext() {}
59 99
60 // Register a media file system (filtered to media files) for |path| and 100 // Register a media file system (filtered to media files) for |path| and
61 // return the new file system id. 101 // return the new file system id.
62 virtual std::string RegisterFileSystemForMassStorage( 102 virtual std::string RegisterFileSystemForMassStorage(
63 const std::string& device_id, const FilePath& path) = 0; 103 const std::string& device_id, const FilePath& path) = 0;
64 104
65 #if defined(SUPPORT_MTP_DEVICE_FILESYSTEM) 105 #if defined(SUPPORT_MTP_DEVICE_FILESYSTEM)
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 // Called on the UI thread. 138 // Called on the UI thread.
99 MediaGalleriesPreferences* GetPreferences(Profile* profile); 139 MediaGalleriesPreferences* GetPreferences(Profile* profile);
100 140
101 // base::SystemMonitor::DevicesChangedObserver implementation. 141 // base::SystemMonitor::DevicesChangedObserver implementation.
102 virtual void OnRemovableStorageAttached( 142 virtual void OnRemovableStorageAttached(
103 const std::string& id, 143 const std::string& id,
104 const string16& name, 144 const string16& name,
105 const FilePath::StringType& location) OVERRIDE; 145 const FilePath::StringType& location) OVERRIDE;
106 virtual void OnRemovableStorageDetached(const std::string& id) OVERRIDE; 146 virtual void OnRemovableStorageDetached(const std::string& id) OVERRIDE;
107 147
148 size_t GetExtensionHostCountForTests() const;
149
108 private: 150 private:
151 friend class TestMediaFileSystemContext;
109 friend struct base::DefaultLazyInstanceTraits<MediaFileSystemRegistry>; 152 friend struct base::DefaultLazyInstanceTraits<MediaFileSystemRegistry>;
110 class MediaFileSystemContextImpl; 153 class MediaFileSystemContextImpl;
111 154
112 // Map an extension to the ExtensionGalleriesHost. 155 // Map an extension to the ExtensionGalleriesHost.
113 typedef std::map<std::string /*extension_id*/, 156 typedef std::map<std::string /*extension_id*/,
114 scoped_refptr<ExtensionGalleriesHost> > ExtensionHostMap; 157 scoped_refptr<ExtensionGalleriesHost> > ExtensionHostMap;
115 // Map a profile and extension to the ExtensionGalleriesHost. 158 // Map a profile and extension to the ExtensionGalleriesHost.
116 typedef std::map<Profile*, ExtensionHostMap> ExtensionGalleriesHostMap; 159 typedef std::map<Profile*, ExtensionHostMap> ExtensionGalleriesHostMap;
117 // Map a profile to a PrefChangeRegistrar. 160 // Map a profile to a PrefChangeRegistrar.
118 typedef std::map<Profile*, PrefChangeRegistrar*> PrefChangeRegistrarMap; 161 typedef std::map<Profile*, PrefChangeRegistrar*> PrefChangeRegistrarMap;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 #endif 200 #endif
158 201
159 scoped_ptr<MediaFileSystemContext> file_system_context_; 202 scoped_ptr<MediaFileSystemContext> file_system_context_;
160 203
161 DISALLOW_COPY_AND_ASSIGN(MediaFileSystemRegistry); 204 DISALLOW_COPY_AND_ASSIGN(MediaFileSystemRegistry);
162 }; 205 };
163 206
164 } // namespace chrome 207 } // namespace chrome
165 208
166 #endif // CHROME_BROWSER_MEDIA_GALLERY_MEDIA_FILE_SYSTEM_REGISTRY_H_ 209 #endif // CHROME_BROWSER_MEDIA_GALLERY_MEDIA_FILE_SYSTEM_REGISTRY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698