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

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

Issue 10829228: [LINUX] Extract the name and id of the device and send it along the device attach message. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed review comments 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 // MediaDeviceNotificationsLinux listens for mount point changes and notifies 5 // MediaDeviceNotificationsLinux listens for mount point changes and notifies
6 // the SystemMonitor about the addition and deletion of media devices. 6 // the SystemMonitor about the addition and deletion of media devices.
7 7
8 #ifndef CHROME_BROWSER_MEDIA_GALLERY_MEDIA_DEVICE_NOTIFICATIONS_LINUX_H_ 8 #ifndef CHROME_BROWSER_MEDIA_GALLERY_MEDIA_DEVICE_NOTIFICATIONS_LINUX_H_
9 #define CHROME_BROWSER_MEDIA_GALLERY_MEDIA_DEVICE_NOTIFICATIONS_LINUX_H_ 9 #define CHROME_BROWSER_MEDIA_GALLERY_MEDIA_DEVICE_NOTIFICATIONS_LINUX_H_
10 10
11 #if defined(OS_CHROMEOS) 11 #if defined(OS_CHROMEOS)
12 #error "Use the ChromeOS-specific implementation instead." 12 #error "Use the ChromeOS-specific implementation instead."
13 #endif 13 #endif
14 14
15 #include <map> 15 #include <map>
16 #include <set> 16 #include <set>
17 #include <string> 17 #include <string>
18 #include <utility> 18 #include <utility>
19 19
20 #include "base/basictypes.h" 20 #include "base/basictypes.h"
21 #include "base/compiler_specific.h" 21 #include "base/compiler_specific.h"
22 #include "base/files/file_path_watcher.h" 22 #include "base/files/file_path_watcher.h"
23 #include "base/memory/ref_counted.h" 23 #include "base/memory/ref_counted.h"
24 #include "base/system_monitor/system_monitor.h"
24 #include "content/public/browser/browser_thread.h" 25 #include "content/public/browser/browser_thread.h"
25 26
26 class FilePath; 27 class FilePath;
27 28
29 typedef bool (*GetDeviceInfoFunc)(
30 const std::string& device_path,
31 base::SystemMonitor::MediaDeviceType media_device_type,
32 std::string* device_name,
33 string16* device_id);
34
28 namespace chrome { 35 namespace chrome {
29 36
30 class MediaDeviceNotificationsLinux 37 class MediaDeviceNotificationsLinux
31 : public base::RefCountedThreadSafe<MediaDeviceNotificationsLinux, 38 : public base::RefCountedThreadSafe<MediaDeviceNotificationsLinux,
32 content::BrowserThread::DeleteOnFileThread> { 39 content::BrowserThread::DeleteOnFileThread> {
33 public: 40 public:
34 explicit MediaDeviceNotificationsLinux(const FilePath& path); 41 explicit MediaDeviceNotificationsLinux(const FilePath& path);
35 42
43 // Only for use in unit tests.
44 MediaDeviceNotificationsLinux(const FilePath& path,
Lei Zhang 2012/08/10 10:26:33 protected?
kmadhusu 2012/08/10 19:41:01 Done.
45 GetDeviceInfoFunc getDeviceInfo);
46
36 // Must be called for MediaDeviceNotificationsLinux to work. 47 // Must be called for MediaDeviceNotificationsLinux to work.
37 void Init(); 48 void Init();
38 49
39 protected: 50 protected:
40 // Avoids code deleting the object while there are references to it. 51 // Avoids code deleting the object while there are references to it.
41 // Aside from the base::RefCountedThreadSafe friend class, and derived 52 // Aside from the base::RefCountedThreadSafe friend class, and derived
42 // classes, any attempts to call this dtor will result in a compile-time 53 // classes, any attempts to call this dtor will result in a compile-time
43 // error. 54 // error.
44 virtual ~MediaDeviceNotificationsLinux(); 55 virtual ~MediaDeviceNotificationsLinux();
45 56
46 virtual void OnFilePathChanged(const FilePath& path, bool error); 57 virtual void OnFilePathChanged(const FilePath& path, bool error);
47 58
48 private: 59 private:
49 friend class base::RefCountedThreadSafe<MediaDeviceNotificationsLinux>; 60 friend class base::RefCountedThreadSafe<MediaDeviceNotificationsLinux>;
50 friend class base::DeleteHelper<MediaDeviceNotificationsLinux>; 61 friend class base::DeleteHelper<MediaDeviceNotificationsLinux>;
51 friend struct content::BrowserThread::DeleteOnThread< 62 friend struct content::BrowserThread::DeleteOnThread<
52 content::BrowserThread::FILE>; 63 content::BrowserThread::FILE>;
53 64
54 // (mount device, device id) 65 struct MountDeviceAndId {
55 typedef std::pair<std::string, std::string> MountDeviceAndId; 66 MountDeviceAndId(const std::string& mount_device, const std::string& id)
67 : mount_device(mount_device),
Lei Zhang 2012/08/10 10:26:33 nit: name the parameter can just be "device" so th
kmadhusu 2012/08/10 19:41:01 Done.
68 device_unique_id(id) {
69 }
70
71 // Mounted device path.
72 std::string mount_device;
73
74 // Device unique id.
75 std::string device_unique_id;
vandebo (ex-Chrome) 2012/08/10 00:32:58 nit: device_id is probably sufficient
kmadhusu 2012/08/10 19:41:01 Done.
76 };
77
56 // Mapping of mount points to MountDeviceAndId. 78 // Mapping of mount points to MountDeviceAndId.
57 typedef std::map<std::string, MountDeviceAndId> MountMap; 79 typedef std::map<std::string, MountDeviceAndId> MountMap;
58 80
81 // (mount point, mount device)
82 // Helper map to get new entries from mtab file.
83 typedef std::map<std::string, std::string> MountPointDeviceMap;
84
85 // Update |known_file_systems_| based on known file system information.
86 void PopulateKnownFileSystemsInfo();
87
59 void InitOnFileThread(); 88 void InitOnFileThread();
60 89
61 // Parse the mtab file and find all changes. 90 // Parse the mtab file and find all changes.
62 void UpdateMtab(); 91 void UpdateMtab();
63 92
64 // Read the mtab file entries into |mtab|. 93 // Read the mtab file entries into |mtab|.
65 void ReadMtab(MountMap* mtab); 94 void ReadMtab(MountPointDeviceMap* mtab);
66 95
67 // Add a media device with a given device and mount device. Assign it a device 96 // Check and add |mount_device| as media device given the |mount_point|.
68 // id as well. 97 void CheckAndAddMediaDevice(const std::string& mount_device,
69 void AddNewDevice(const std::string& mount_device, 98 const std::string& mount_point);
70 const std::string& mount_point,
71 std::string* device_id);
72 99
73 // Remove a media device with a given device id. 100 // Remove a media device with a given device id.
74 void RemoveOldDevice(const std::string& device_id); 101 void RemoveOldDevice(const std::string& device_id);
75 102
76 // Whether Init() has been called or not. 103 // Whether Init() has been called or not.
77 bool initialized_; 104 bool initialized_;
78 105
79 // Mtab file that lists the mount points. 106 // Mtab file that lists the mount points.
80 const FilePath mtab_path_; 107 const FilePath mtab_path_;
81 108
82 // Watcher for |mtab_path_|. 109 // Watcher for |mtab_path_|.
83 base::files::FilePathWatcher file_watcher_; 110 base::files::FilePathWatcher file_watcher_;
84 111
85 // Mapping of relevant mount points and their corresponding mount devices. 112 // Mapping of relevant mount points and their corresponding mount devices.
86 // Keep in mind on Linux, a device can be mounted at multiple mount points, 113 // Keep in mind on Linux, a device can be mounted at multiple mount points,
87 // and multiple devices can be mounted at a mount point. 114 // and multiple devices can be mounted at a mount point.
88 MountMap mtab_; 115 MountMap mount_info_map_;
89
90 // The lowest available device id number.
91 // TODO(thestig) Remove this and use a real per-device unique id instead.
92 int current_device_id_;
93 116
94 // Set of known file systems that we care about. 117 // Set of known file systems that we care about.
95 std::set<std::string> known_file_systems_; 118 std::set<std::string> known_file_systems_;
96 119
120 GetDeviceInfoFunc get_device_info_func_;
121
97 DISALLOW_COPY_AND_ASSIGN(MediaDeviceNotificationsLinux); 122 DISALLOW_COPY_AND_ASSIGN(MediaDeviceNotificationsLinux);
98 }; 123 };
99 124
100 } // namespace chrome 125 } // namespace chrome
101 126
102 #endif // CHROME_BROWSER_MEDIA_GALLERY_MEDIA_DEVICE_NOTIFICATIONS_LINUX_H_ 127 #endif // CHROME_BROWSER_MEDIA_GALLERY_MEDIA_DEVICE_NOTIFICATIONS_LINUX_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698