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" | |
| 19 #include "base/memory/ref_counted.h" | |
| 18 #include "base/system_monitor/system_monitor.h" | 20 #include "base/system_monitor/system_monitor.h" |
| 19 #include "content/public/browser/notification_observer.h" | |
| 20 #include "content/public/browser/notification_registrar.h" | |
| 21 | 21 |
| 22 class FilePath; | 22 class FilePath; |
|
Lei Zhang
2012/09/04 23:38:51
nit: you don't need this since you're adding file_
vandebo (ex-Chrome)
2012/09/05 00:58:12
Done.
| |
| 23 class Profile; | |
| 23 | 24 |
| 24 namespace content { | 25 namespace content { |
| 25 class RenderProcessHost; | 26 class RenderViewHost; |
| 26 } | 27 } |
| 27 | 28 |
| 28 namespace extensions { | 29 namespace extensions { |
| 29 class Extension; | 30 class Extension; |
| 30 } | 31 } |
| 31 | 32 |
| 32 namespace fileapi { | 33 namespace fileapi { |
| 33 class IsolatedContext; | 34 class IsolatedContext; |
| 34 } | 35 } |
| 35 | 36 |
| 36 namespace chrome { | 37 namespace chrome { |
| 37 | 38 |
| 39 class ExtensionGalleriesHost; | |
| 40 | |
| 38 class MediaFileSystemRegistry | 41 class MediaFileSystemRegistry |
| 39 : public base::SystemMonitor::DevicesChangedObserver, | 42 : public base::SystemMonitor::DevicesChangedObserver { |
| 40 public content::NotificationObserver { | |
| 41 public: | 43 public: |
| 42 struct MediaFSInfo { | 44 struct MediaFSInfo { |
| 43 std::string name; | 45 string16 name; |
| 44 std::string fsid; | 46 std::string fsid; |
| 45 FilePath path; | 47 FilePath path; |
| 46 }; | 48 }; |
| 47 | 49 |
| 48 // The instance is lazily created per browser process. | 50 // The instance is lazily created per browser process. |
| 49 static MediaFileSystemRegistry* GetInstance(); | 51 static MediaFileSystemRegistry* GetInstance(); |
| 50 | 52 |
| 51 // Returns the list of media filesystem IDs and paths for a given RPH. | 53 // Returns the list of media filesystem IDs and paths for a given RVH. |
| 52 // Called on the UI thread. | 54 // Called on the UI thread. |
| 53 std::vector<MediaFSInfo> GetMediaFileSystemsForExtension( | 55 std::vector<MediaFSInfo> GetMediaFileSystemsForExtension( |
| 54 const content::RenderProcessHost* rph, | 56 const content::RenderViewHost* rvh, |
| 55 const extensions::Extension& extension); | 57 const extensions::Extension* extension); |
| 56 | 58 |
| 57 // base::SystemMonitor::DevicesChangedObserver implementation. | 59 // base::SystemMonitor::DevicesChangedObserver implementation. |
| 58 virtual void OnRemovableStorageDetached(const std::string& id) OVERRIDE; | 60 virtual void OnRemovableStorageDetached(const std::string& id) OVERRIDE; |
| 59 | 61 |
| 60 // content::NotificationObserver implementation. | |
| 61 virtual void Observe(int type, | |
| 62 const content::NotificationSource& source, | |
| 63 const content::NotificationDetails& details) OVERRIDE; | |
| 64 | |
| 65 private: | 62 private: |
| 66 friend struct base::DefaultLazyInstanceTraits<MediaFileSystemRegistry>; | 63 friend struct base::DefaultLazyInstanceTraits<MediaFileSystemRegistry>; |
| 67 | 64 |
| 68 // Mapping of media directories to filesystem IDs. | 65 // Map an extension to the ExtensionGalleriesHost. |
| 69 typedef std::map<FilePath, std::string> MediaPathToFSIDMap; | 66 typedef std::map<std::string /*extension_id*/, |
| 70 | 67 scoped_refptr<ExtensionGalleriesHost> > ExtensionHostMap; |
| 71 // Mapping of RPH to MediaPathToFSIDMaps. | 68 // Map a profile and extension to the ExtensionGallerisHost. |
|
Lei Zhang
2012/09/04 23:38:51
nit: typo
vandebo (ex-Chrome)
2012/09/05 00:58:12
Done.
| |
| 72 typedef std::map<const content::RenderProcessHost*, | 69 typedef std::map<Profile*, ExtensionHostMap> |
|
Lei Zhang
2012/09/04 23:38:51
You can probably use const Profile* here and on li
vandebo (ex-Chrome)
2012/09/05 00:58:12
I had that originally, but removed it because Medi
| |
| 73 MediaPathToFSIDMap> ChildIdToMediaFSMap; | 70 ExtensionGalleriesHostMap; |
|
Lei Zhang
2012/09/04 23:38:51
nit: fits on previous line.
vandebo (ex-Chrome)
2012/09/05 00:58:12
Done.
| |
| 74 | |
| 75 // Mapping of device id to media device info. | |
| 76 typedef std::map<std::string, base::SystemMonitor::RemovableStorageInfo> | |
| 77 DeviceIdToInfoMap; | |
| 78 | 71 |
| 79 // Obtain an instance of this class via GetInstance(). | 72 // Obtain an instance of this class via GetInstance(). |
| 80 MediaFileSystemRegistry(); | 73 MediaFileSystemRegistry(); |
| 81 virtual ~MediaFileSystemRegistry(); | 74 virtual ~MediaFileSystemRegistry(); |
| 82 | 75 |
| 83 // Helper functions to register / unregister listening for renderer process | 76 void OnExtensionGalleriesHostEmpty(Profile* profile, |
| 84 // closed / terminiated notifications. | 77 const std::string& extension_id); |
| 85 void RegisterForRPHGoneNotifications(const content::RenderProcessHost* rph); | |
| 86 void UnregisterForRPHGoneNotifications(const content::RenderProcessHost* rph); | |
| 87 | 78 |
| 88 // Registers a path as a media file system and return the filesystem id. | 79 // Only accessed on the UI thread. This map owns all the |
| 89 std::string RegisterPathAsFileSystem(const FilePath& path); | 80 // ExtensionGalleriesHost objects created. |
| 90 | 81 ExtensionGalleriesHostMap extension_hosts_map_; |
| 91 // Revoke a media file system with a given |path|. | |
| 92 void RevokeMediaFileSystem(const FilePath& path); | |
| 93 | |
| 94 // Only accessed on the UI thread. | |
| 95 ChildIdToMediaFSMap media_fs_map_; | |
| 96 | |
| 97 // Only accessed on the UI thread. | |
| 98 DeviceIdToInfoMap device_id_map_; | |
| 99 | |
| 100 // Is only used on the UI thread. | |
| 101 content::NotificationRegistrar registrar_; | |
| 102 | 82 |
| 103 DISALLOW_COPY_AND_ASSIGN(MediaFileSystemRegistry); | 83 DISALLOW_COPY_AND_ASSIGN(MediaFileSystemRegistry); |
| 104 }; | 84 }; |
| 105 | 85 |
| 106 } // namespace chrome | 86 } // namespace chrome |
| 107 | 87 |
| 108 #endif // CHROME_BROWSER_MEDIA_GALLERY_MEDIA_FILE_SYSTEM_REGISTRY_H_ | 88 #endif // CHROME_BROWSER_MEDIA_GALLERY_MEDIA_FILE_SYSTEM_REGISTRY_H_ |
| OLD | NEW |