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