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