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

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

Issue 10871049: Connect MediaFileSystemRegistry with MediaGalleriesPreferences (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 months 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/system_monitor/system_monitor.h" 18 #include "base/system_monitor/system_monitor.h"
19 #include "content/public/browser/notification_observer.h" 19 #include "content/public/browser/notification_observer.h"
Lei Zhang 2012/08/24 04:39:04 You can remove these guys if you are removing Noti
vandebo (ex-Chrome) 2012/09/04 21:02:20 Done.
20 #include "content/public/browser/notification_registrar.h" 20 #include "content/public/browser/notification_registrar.h"
21 21
22 class FilePath; 22 class FilePath;
23 23
24 namespace content { 24 namespace content {
25 class RenderProcessHost; 25 class RenderViewHost;
26 } 26 }
27 27
28 namespace extensions { 28 namespace extensions {
29 class Extension; 29 class Extension;
30 } 30 }
31 31
32 namespace fileapi { 32 namespace fileapi {
33 class IsolatedContext; 33 class IsolatedContext;
34 } 34 }
35 35
36 namespace chrome { 36 namespace chrome {
37 37
38 class ExtensionGalleriesHost
39
38 class MediaFileSystemRegistry 40 class MediaFileSystemRegistry
39 : public base::SystemMonitor::DevicesChangedObserver, 41 : public base::SystemMonitor::DevicesChangedObserver {
40 public content::NotificationObserver {
41 public: 42 public:
42 struct MediaFSInfo { 43 struct MediaFSInfo {
43 std::string name; 44 std::string name;
44 std::string fsid; 45 std::string fsid;
45 FilePath path; 46 FilePath path;
46 }; 47 };
47 48
48 // The instance is lazily created per browser process. 49 // The instance is lazily created per browser process.
49 static MediaFileSystemRegistry* GetInstance(); 50 static MediaFileSystemRegistry* GetInstance();
50 51
51 // Returns the list of media filesystem IDs and paths for a given RPH. 52 // Returns the list of media filesystem IDs and paths for a given RVH.
52 // Called on the UI thread. 53 // Called on the UI thread.
53 std::vector<MediaFSInfo> GetMediaFileSystemsForExtension( 54 std::vector<MediaFSInfo> GetMediaFileSystemsForExtension(
54 const content::RenderProcessHost* rph, 55 const content::RenderViewHost* rph,
55 const extensions::Extension& extension); 56 const extensions::Extension* extension);
56 57
57 // base::SystemMonitor::DevicesChangedObserver implementation. 58 // base::SystemMonitor::DevicesChangedObserver implementation.
58 virtual void OnMediaDeviceDetached(const std::string& id) OVERRIDE; 59 virtual void OnMediaDeviceDetached(const std::string& id) OVERRIDE;
59 60
60 // content::NotificationObserver implementation.
61 virtual void Observe(int type,
62 const content::NotificationSource& source,
63 const content::NotificationDetails& details) OVERRIDE;
64
65 std::string GetDeviceIdFromPath(const FilePath& path) const; 61 std::string GetDeviceIdFromPath(const FilePath& path) const;
66 62
67 private: 63 private:
68 friend struct base::DefaultLazyInstanceTraits<MediaFileSystemRegistry>; 64 friend struct base::DefaultLazyInstanceTraits<MediaFileSystemRegistry>;
69 65
70 // Mapping of media directories to filesystem IDs. 66 // Map an extension to the ExtensionGalleriesHost.
71 typedef std::map<FilePath, std::string> MediaPathToFSIDMap; 67 typedef std::map<const extensions::Extension*,
72 68 scoped_ptr<ExtensionGalleriesHost> > ExtensionHostMap;
73 // Mapping of RPH to MediaPathToFSIDMaps. 69 // Map a profile and extension to the ExtensionGallerisHost.
74 typedef std::map<const content::RenderProcessHost*, 70 typedef std::map<const Profile*, ExtensionHostMap>
75 MediaPathToFSIDMap> ChildIdToMediaFSMap; 71 ExtensionGalleriesHostMap;
76
77 // Mapping of device id to media device info.
78 typedef std::map<std::string, base::SystemMonitor::MediaDeviceInfo>
79 DeviceIdToInfoMap;
80 72
81 // Obtain an instance of this class via GetInstance(). 73 // Obtain an instance of this class via GetInstance().
82 MediaFileSystemRegistry(); 74 MediaFileSystemRegistry();
83 virtual ~MediaFileSystemRegistry(); 75 virtual ~MediaFileSystemRegistry();
84 76
85 // Helper functions to register / unregister listening for renderer process 77 void OnExtensionGalleriesHostEmpty(const Profile* profile,
86 // closed / terminiated notifications. 78 const extensions::Extension* extension);
87 void RegisterForRPHGoneNotifications(const content::RenderProcessHost* rph);
88 void UnregisterForRPHGoneNotifications(const content::RenderProcessHost* rph);
89 79
90 // Registers a path as a media file system and return the filesystem id. 80 // Only accessed on the UI thread. This map owns all the
91 std::string RegisterPathAsFileSystem(const FilePath& path); 81 // ExtensionGalleriesHost objects created.
92 82 ExtensionGalleriesHostMap extension_host_map_;
93 // Revoke a media file system with a given |path|.
94 void RevokeMediaFileSystem(const FilePath& path);
95
96 // Only accessed on the UI thread.
97 ChildIdToMediaFSMap media_fs_map_;
98
99 // Only accessed on the UI thread.
100 DeviceIdToInfoMap device_id_map_;
101
102 // Is only used on the UI thread.
103 content::NotificationRegistrar registrar_;
104 83
105 DISALLOW_COPY_AND_ASSIGN(MediaFileSystemRegistry); 84 DISALLOW_COPY_AND_ASSIGN(MediaFileSystemRegistry);
106 }; 85 };
107 86
108 } // namespace chrome 87 } // namespace chrome
109 88
110 #endif // CHROME_BROWSER_MEDIA_GALLERY_MEDIA_FILE_SYSTEM_REGISTRY_H_ 89 #endif // CHROME_BROWSER_MEDIA_GALLERY_MEDIA_FILE_SYSTEM_REGISTRY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698