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 // MediaDeviceNotificationsLinux implementation. | 5 // MediaDeviceNotificationsLinux implementation. |
6 | 6 |
7 #include "chrome/browser/media_gallery/media_device_notifications_linux.h" | 7 #include "chrome/browser/media_gallery/media_device_notifications_linux.h" |
8 | 8 |
9 #include <libudev.h> | |
9 #include <mntent.h> | 10 #include <mntent.h> |
10 #include <stdio.h> | 11 #include <stdio.h> |
11 | 12 |
12 #include <vector> | 13 #include <vector> |
13 | 14 |
14 #include "base/bind.h" | 15 #include "base/bind.h" |
15 #include "base/file_path.h" | 16 #include "base/file_path.h" |
17 #include "base/memory/scoped_generic_obj.h" | |
18 #include "base/metrics/histogram.h" | |
16 #include "base/stl_util.h" | 19 #include "base/stl_util.h" |
17 #include "base/string_number_conversions.h" | 20 #include "base/string_number_conversions.h" |
21 #include "base/string_util.h" | |
18 #include "base/system_monitor/system_monitor.h" | 22 #include "base/system_monitor/system_monitor.h" |
19 #include "base/utf_string_conversions.h" | 23 #include "base/utf_string_conversions.h" |
20 #include "chrome/browser/media_gallery/media_device_notifications_utils.h" | 24 #include "chrome/browser/media_gallery/media_device_notifications_utils.h" |
21 | 25 |
22 namespace { | 26 namespace { |
23 | 27 |
28 using base::SystemMonitor; | |
vandebo (ex-Chrome)
2012/08/13 18:31:18
This is already on line 172.
kmadhusu
2012/08/13 19:36:58
Removed.
| |
29 | |
24 // List of file systems we care about. | 30 // List of file systems we care about. |
25 const char* const kKnownFileSystems[] = { | 31 const char* const kKnownFileSystems[] = { |
26 "ext2", | 32 "ext2", |
27 "ext3", | 33 "ext3", |
28 "ext4", | 34 "ext4", |
29 "fat", | 35 "fat", |
30 "hfsplus", | 36 "hfsplus", |
31 "iso9660", | 37 "iso9660", |
32 "msdos", | 38 "msdos", |
33 "ntfs", | 39 "ntfs", |
34 "udf", | 40 "udf", |
35 "vfat", | 41 "vfat", |
36 }; | 42 }; |
37 | 43 |
44 // Device property constants. | |
vandebo (ex-Chrome)
2012/08/13 18:31:18
nit: udev device property constants.
kmadhusu
2012/08/13 19:36:58
Done.
| |
45 const char kDevName[] = "DEVNAME"; | |
46 const char kFsUUID[] = "ID_FS_UUID"; | |
47 const char kLabel[] = "ID_FS_LABEL"; | |
48 const char kModel[] = "ID_MODEL"; | |
49 const char kModelID[] = "ID_MODEL_ID"; | |
50 const char kSerial[] = "ID_SERIAL"; | |
51 const char kSerialShort[] = "ID_SERIAL_SHORT"; | |
52 const char kVendor[] = "ID_VENDOR"; | |
53 const char kVendorID[] = "ID_VENDOR_ID"; | |
54 | |
55 // Delimiter constants. | |
56 const char kColonDelim[] = ":"; | |
vandebo (ex-Chrome)
2012/08/13 18:31:18
nit: maybe call this kNonSpaceDelim? That way if
kmadhusu
2012/08/13 19:36:58
Done.
| |
57 const char kSpaceDelim[] = " "; | |
58 | |
59 // Unique id prefix constants. | |
60 const char kFSUniqueIdPrefix[] = "UUID:"; | |
61 const char kVendorModelSerialPrefix[] = "VendorModelSerial:"; | |
62 | |
63 // Device mount point details. | |
64 struct MountPointEntryInfo { | |
65 std::string mount_point; | |
66 int entry_pos; | |
67 }; | |
68 | |
69 // ScopedGenericObj functor for UdevObjectRelease(). | |
70 class ScopedReleaseUdevObject { | |
71 public: | |
72 void operator()(struct udev* udev) const { | |
73 udev_unref(udev); | |
74 } | |
75 }; | |
76 | |
77 // ScopedGenericObj functor for UdevDeviceObjectRelease(). | |
78 class ScopedReleaseUdevDeviceObject { | |
79 public: | |
80 void operator()(struct udev_device* device) const { | |
81 udev_device_unref(device); | |
82 } | |
83 }; | |
84 | |
85 // Get the device information using udev library. | |
86 // On success, returns true and fill in |id| and |name|. | |
87 bool GetDeviceInfo(const std::string& device_path, | |
88 std::string* id, | |
89 string16* name) { | |
90 DCHECK(!device_path.empty()); | |
91 | |
92 ScopedGenericObj<struct udev*, ScopedReleaseUdevObject> udev_ptr(udev_new()); | |
vandebo (ex-Chrome)
2012/08/13 18:31:18
nit: we try not to put types into variable names.
kmadhusu
2012/08/13 19:36:58
udev_ptr => udev_obj
| |
93 CHECK(udev_ptr.get()); | |
vandebo (ex-Chrome)
2012/08/13 18:31:18
I'm not sure - should this be fatal, or should it
kmadhusu
2012/08/13 19:36:58
thestig@ preferred CHECK. It is very unlikely to h
| |
94 | |
95 struct stat st; | |
vandebo (ex-Chrome)
2012/08/13 18:31:18
nit: st -> device_stat ?
kmadhusu
2012/08/13 19:36:58
Done.
| |
96 if (stat(device_path.c_str(), &st) < 0) | |
97 return false; | |
98 | |
99 char device_type; | |
100 if (S_ISCHR(st.st_mode)) | |
101 device_type = 'c'; | |
102 else if (S_ISBLK(st.st_mode)) | |
103 device_type = 'b'; | |
104 else | |
105 return false; // Not a supported type. | |
106 | |
107 ScopedGenericObj<struct udev_device*, ScopedReleaseUdevDeviceObject> | |
108 device(udev_device_new_from_devnum(udev_ptr, device_type, st.st_rdev)); | |
109 if (!device.get()) | |
110 return false; | |
111 | |
112 // Construct a device name using label or manufacturer(vendor and model) | |
113 // details. | |
114 std::string device_label; | |
115 const char* device_name = NULL; | |
116 if ((device_name = udev_device_get_property_value(device, kLabel)) || | |
117 (device_name = udev_device_get_property_value(device, kSerial))) { | |
118 device_label = device_name; | |
119 } else { | |
120 // Format: VendorInfo ModelInfo | |
121 // E.g.: KnCompany Model2010 | |
122 const char* vendor_name = NULL; | |
123 if ((vendor_name = udev_device_get_property_value(device, kVendor))) | |
124 device_label = vendor_name; | |
125 | |
126 const char* model_name = NULL; | |
127 if ((model_name = udev_device_get_property_value(device, kModel))) { | |
128 if (!device_label.empty()) | |
129 device_label += kSpaceDelim; | |
130 device_label += model_name; | |
131 } | |
132 } | |
133 | |
134 CHECK(IsStringUTF8(device_label)); | |
135 *name = UTF8ToUTF16(device_label); | |
136 | |
137 const char* uuid = NULL; | |
138 if ((uuid = udev_device_get_property_value(device, kFsUUID))) { | |
139 *id += kFSUniqueIdPrefix; | |
vandebo (ex-Chrome)
2012/08/13 18:31:18
I don't think we want to append to id, we want to
kmadhusu
2012/08/13 19:36:58
I tried this format before. Compiler complains "er
| |
140 *id += uuid; | |
141 } else { | |
142 // If one of the vendor, model, serial information is missing, its value in | |
143 // the string is empty. | |
144 // Format: VendorModelSerial:VendorInfo:ModelInfo:SerialShortInfo | |
145 // E.g. 1: VendorModelSerial:Kn:DataTravel_12.10:8000000000006CB02CDB | |
vandebo (ex-Chrome)
2012/08/13 18:31:18
One example is probably sufficient.
kmadhusu
2012/08/13 19:36:58
Done.
| |
146 // E.g. 2: VendorModelSerial:Kn::80000000000006CB02CDB | |
147 // E.g. 3: VendorModelSerial:::800000000000006CB02CDB | |
148 const char* vendor = udev_device_get_property_value(device, kVendorID); | |
149 const char* model = udev_device_get_property_value(device, kModelID); | |
150 const char* serial_short = udev_device_get_property_value(device, | |
151 kSerialShort); | |
152 if (!vendor && !model && !serial_short) | |
153 return false; | |
154 *id = kVendorModelSerialPrefix; | |
vandebo (ex-Chrome)
2012/08/13 18:31:18
The following might be easier to read, what do you
kmadhusu
2012/08/13 19:36:58
Leaving as it is.
| |
155 if (vendor) | |
156 *id += vendor; | |
157 *id += kColonDelim; | |
158 if (model) | |
159 *id += model; | |
160 *id += kColonDelim; | |
161 if (serial_short) | |
162 *id += serial_short; | |
163 } | |
164 | |
165 return true; | |
166 } | |
167 | |
38 } // namespace | 168 } // namespace |
39 | 169 |
40 namespace chrome { | 170 namespace chrome { |
41 | 171 |
42 using base::SystemMonitor; | 172 using base::SystemMonitor; |
43 using content::BrowserThread; | 173 using content::BrowserThread; |
44 | 174 |
45 MediaDeviceNotificationsLinux::MediaDeviceNotificationsLinux( | 175 MediaDeviceNotificationsLinux::MediaDeviceNotificationsLinux( |
46 const FilePath& path) | 176 const FilePath& path) |
47 : initialized_(false), | 177 : initialized_(false), |
48 mtab_path_(path), | 178 mtab_path_(path), |
49 current_device_id_(0U) { | 179 get_device_info_func_(&GetDeviceInfo) { |
50 CHECK(!path.empty()); | 180 } |
51 | 181 |
52 // Put |kKnownFileSystems| in std::set to get O(log N) access time. | 182 MediaDeviceNotificationsLinux::MediaDeviceNotificationsLinux( |
53 for (size_t i = 0; i < arraysize(kKnownFileSystems); ++i) { | 183 const FilePath& path, |
54 known_file_systems_.insert(kKnownFileSystems[i]); | 184 GetDeviceInfoFunc get_device_info_func) |
55 } | 185 : initialized_(false), |
186 mtab_path_(path), | |
187 get_device_info_func_(get_device_info_func) { | |
56 } | 188 } |
57 | 189 |
58 MediaDeviceNotificationsLinux::~MediaDeviceNotificationsLinux() { | 190 MediaDeviceNotificationsLinux::~MediaDeviceNotificationsLinux() { |
59 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 191 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
60 } | 192 } |
61 | 193 |
62 void MediaDeviceNotificationsLinux::Init() { | 194 void MediaDeviceNotificationsLinux::Init() { |
195 CHECK(!mtab_path_.empty()); | |
196 | |
197 // Put |kKnownFileSystems| in std::set to get O(log N) access time. | |
198 for (size_t i = 0; i < arraysize(kKnownFileSystems); ++i) { | |
vandebo (ex-Chrome)
2012/08/13 18:31:18
nit: remove the {}'s ?
kmadhusu
2012/08/13 19:36:58
Done.
| |
199 known_file_systems_.insert(kKnownFileSystems[i]); | |
200 } | |
63 BrowserThread::PostTask( | 201 BrowserThread::PostTask( |
64 BrowserThread::FILE, FROM_HERE, | 202 BrowserThread::FILE, FROM_HERE, |
65 base::Bind(&MediaDeviceNotificationsLinux::InitOnFileThread, this)); | 203 base::Bind(&MediaDeviceNotificationsLinux::InitOnFileThread, this)); |
66 } | 204 } |
67 | 205 |
68 void MediaDeviceNotificationsLinux::OnFilePathChanged(const FilePath& path, | 206 void MediaDeviceNotificationsLinux::OnFilePathChanged(const FilePath& path, |
69 bool error) { | 207 bool error) { |
70 if (path != mtab_path_) { | 208 if (path != mtab_path_) { |
71 // This cannot happen unless FilePathWatcher is buggy. Just ignore this | 209 // This cannot happen unless FilePathWatcher is buggy. Just ignore this |
72 // notification and do nothing. | 210 // notification and do nothing. |
(...skipping 24 matching lines...) Expand all Loading... | |
97 LOG(ERROR) << "Adding watch for " << mtab_path_.value() << " failed"; | 235 LOG(ERROR) << "Adding watch for " << mtab_path_.value() << " failed"; |
98 return; | 236 return; |
99 } | 237 } |
100 | 238 |
101 UpdateMtab(); | 239 UpdateMtab(); |
102 } | 240 } |
103 | 241 |
104 void MediaDeviceNotificationsLinux::UpdateMtab() { | 242 void MediaDeviceNotificationsLinux::UpdateMtab() { |
105 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 243 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
106 | 244 |
107 MountMap new_mtab; | 245 MountPointDeviceMap new_mtab; |
108 ReadMtab(&new_mtab); | 246 ReadMtab(&new_mtab); |
109 | 247 |
110 // Check existing mtab entries for unaccounted mount points. | 248 // Check existing mtab entries for unaccounted mount points. |
111 // These mount points must have been removed in the new mtab. | 249 // These mount points must have been removed in the new mtab. |
112 std::vector<std::string> mount_points_to_erase; | 250 std::vector<std::string> mount_points_to_erase; |
113 for (MountMap::const_iterator it = mtab_.begin(); it != mtab_.end(); ++it) { | 251 for (MountMap::const_iterator it = mount_info_map_.begin(); |
vandebo (ex-Chrome)
2012/08/13 18:31:18
nit: for consistency, you may want to use old_iter
kmadhusu
2012/08/13 19:36:58
Done.
| |
252 it != mount_info_map_.end(); ++it) { | |
114 const std::string& mount_point = it->first; | 253 const std::string& mount_point = it->first; |
115 // |mount_point| not in |new_mtab|. | 254 const std::string& mount_device = it->second.mount_device; |
116 if (!ContainsKey(new_mtab, mount_point)) { | 255 MountPointDeviceMap::iterator newiter = new_mtab.find(mount_point); |
vandebo (ex-Chrome)
2012/08/13 18:31:18
nit: new_iter
kmadhusu
2012/08/13 19:36:58
Done.
| |
117 const std::string& device_id = it->second.second; | 256 // |mount_point| not in |new_mtab| or |mount_device| is no longer mounted at |
118 RemoveOldDevice(device_id); | 257 // |mount_point|. |
258 if (newiter == new_mtab.end() || (newiter->second != mount_device)) { | |
259 RemoveOldDevice(it->second.device_id); | |
119 mount_points_to_erase.push_back(mount_point); | 260 mount_points_to_erase.push_back(mount_point); |
120 } | 261 } |
121 } | 262 } |
122 // Erase the |mtab_| entries afterwards. Erasing in the loop above using the | 263 // Erase the |mount_info_map_| entries afterwards. Erasing in the loop above |
123 // iterator is slightly more efficient, but more tricky, since calling | 264 // using the iterator is slightly more efficient, but more tricky, since |
124 // std::map::erase() on an iterator invalidates it. | 265 // calling std::map::erase() on an iterator invalidates it. |
125 for (size_t i = 0; i < mount_points_to_erase.size(); ++i) | 266 for (size_t i = 0; i < mount_points_to_erase.size(); ++i) |
126 mtab_.erase(mount_points_to_erase[i]); | 267 mount_info_map_.erase(mount_points_to_erase[i]); |
127 | 268 |
128 // Check new mtab entries against existing ones. | 269 // Check new mtab entries against existing ones. |
129 for (MountMap::iterator newiter = new_mtab.begin(); | 270 for (MountPointDeviceMap::iterator newiter = new_mtab.begin(); |
vandebo (ex-Chrome)
2012/08/13 18:31:18
nit: new_iter
kmadhusu
2012/08/13 19:36:58
Done.
| |
130 newiter != new_mtab.end(); | 271 newiter != new_mtab.end(); |
131 ++newiter) { | 272 ++newiter) { |
132 const std::string& mount_point = newiter->first; | 273 const std::string& mount_point = newiter->first; |
133 const MountDeviceAndId& mount_device_and_id = newiter->second; | 274 const std::string& mount_device = newiter->second; |
134 const std::string& mount_device = mount_device_and_id.first; | 275 MountMap::iterator olditer = mount_info_map_.find(mount_point); |
vandebo (ex-Chrome)
2012/08/13 18:31:18
nit: old_iter
kmadhusu
2012/08/13 19:36:58
Done.
| |
135 std::string& id = newiter->second.second; | 276 if (olditer != mount_info_map_.end() && |
136 MountMap::iterator olditer = mtab_.find(mount_point); | 277 olditer->second.mount_device == mount_device) { |
137 // Check to see if it is a new mount point. | 278 // Existing mount point entry with same device. |
138 if (olditer == mtab_.end()) { | |
139 if (IsMediaDevice(mount_point)) { | |
140 AddNewDevice(mount_device, mount_point, &id); | |
141 mtab_.insert(std::make_pair(mount_point, mount_device_and_id)); | |
142 } | |
143 continue; | 279 continue; |
vandebo (ex-Chrome)
2012/08/13 18:31:18
With the rest of the for body now a single stateme
kmadhusu
2012/08/13 19:36:58
Since you stated this code set in your previous co
| |
144 } | 280 } |
145 | 281 // New mount point found or an existing mount point found with a new device. |
146 // Existing mount point. Check to see if a new device is mounted there. | 282 CheckAndAddMediaDevice(mount_device, mount_point); |
147 const MountDeviceAndId& old_mount_device_and_id = olditer->second; | |
148 if (mount_device == old_mount_device_and_id.first) | |
149 continue; | |
150 | |
151 // New device mounted. | |
152 RemoveOldDevice(old_mount_device_and_id.second); | |
153 if (IsMediaDevice(mount_point)) { | |
154 AddNewDevice(mount_device, mount_point, &id); | |
155 olditer->second = mount_device_and_id; | |
156 } | |
157 } | 283 } |
158 } | 284 } |
159 | 285 |
160 void MediaDeviceNotificationsLinux::ReadMtab(MountMap* mtab) { | 286 void MediaDeviceNotificationsLinux::ReadMtab(MountPointDeviceMap* mtab) { |
161 FILE* fp = setmntent(mtab_path_.value().c_str(), "r"); | 287 FILE* fp = setmntent(mtab_path_.value().c_str(), "r"); |
162 if (!fp) | 288 if (!fp) |
163 return; | 289 return; |
164 | 290 |
165 MountMap& new_mtab = *mtab; | |
166 mntent entry; | 291 mntent entry; |
167 char buf[512]; | 292 char buf[512]; |
168 int mount_position = 0; | 293 |
169 typedef std::pair<std::string, std::string> MountPointAndId; | 294 // Keep track of mount point entry positions in mtab file. |
170 typedef std::map<std::string, MountPointAndId> DeviceMap; | 295 int entry_pos = 0; |
296 | |
297 // Helper map to store the device mount point details. | |
298 // (mount device, MountPointEntryInfo) | |
299 typedef std::map<std::string, MountPointEntryInfo> DeviceMap; | |
171 DeviceMap device_map; | 300 DeviceMap device_map; |
172 while (getmntent_r(fp, &entry, buf, sizeof(buf))) { | 301 while (getmntent_r(fp, &entry, buf, sizeof(buf))) { |
173 // We only care about real file systems. | 302 // We only care about real file systems. |
174 if (!ContainsKey(known_file_systems_, entry.mnt_type)) | 303 if (!ContainsKey(known_file_systems_, entry.mnt_type)) |
175 continue; | 304 continue; |
305 | |
176 // Add entries, but overwrite entries for the same mount device. Keep track | 306 // Add entries, but overwrite entries for the same mount device. Keep track |
177 // of the entry positions in the device id field and use that below to | 307 // of the entry positions in |entry_info| and use that below to resolve |
178 // resolve multiple devices mounted at the same mount point. | 308 // multiple devices mounted at the same mount point. |
179 MountPointAndId mount_point_and_id = | 309 MountPointEntryInfo entry_info; |
180 std::make_pair(entry.mnt_dir, base::IntToString(mount_position++)); | 310 entry_info.mount_point = entry.mnt_dir; |
181 DeviceMap::iterator it = device_map.find(entry.mnt_fsname); | 311 entry_info.entry_pos = entry_pos++; |
182 if (it == device_map.end()) { | 312 device_map[entry.mnt_fsname /* mount device */] = entry_info; |
vandebo (ex-Chrome)
2012/08/13 18:31:18
Generally, we don't use inline comments.
kmadhusu
2012/08/13 19:36:58
Done.
| |
183 device_map.insert(std::make_pair(entry.mnt_fsname, mount_point_and_id)); | |
184 } else { | |
185 it->second = mount_point_and_id; | |
186 } | |
187 } | 313 } |
188 endmntent(fp); | 314 endmntent(fp); |
189 | 315 |
316 // Helper map to store mount point entries. | |
vandebo (ex-Chrome)
2012/08/13 18:31:18
nit: two spaces
kmadhusu
2012/08/13 19:36:58
Done.
| |
317 // (mount point, entry position in mtab file) | |
318 typedef std::map<std::string, int> MountPointsInfoMap; | |
319 MountPointsInfoMap mount_points_info_map; | |
320 MountPointDeviceMap& new_mtab = *mtab; | |
190 for (DeviceMap::const_iterator device_it = device_map.begin(); | 321 for (DeviceMap::const_iterator device_it = device_map.begin(); |
191 device_it != device_map.end(); | 322 device_it != device_map.end(); |
192 ++device_it) { | 323 ++device_it) { |
193 const std::string& device = device_it->first; | 324 // Add entries, but overwrite entries for the same mount point. Keep track |
194 const std::string& mount_point = device_it->second.first; | 325 // of the entry positions and use that information to resolve multiple |
195 const std::string& position = device_it->second.second; | 326 // devices mounted at the same mount point. |
327 const std::string& mount_device = device_it->first; | |
328 const std::string& mount_point = device_it->second.mount_point; | |
329 const int entry_pos = device_it->second.entry_pos; | |
330 MountPointDeviceMap::iterator new_it = new_mtab.find(mount_point); | |
331 MountPointsInfoMap::iterator mount_point_info_map_it = | |
332 mount_points_info_map.find(mount_point); | |
196 | 333 |
197 // No device at |mount_point|, save |device| to it. | 334 // New mount point entry found or there is already a device mounted at |
198 MountMap::iterator mount_it = new_mtab.find(mount_point); | 335 // |mount_point| and the existing mount entry is older than the current one. |
199 if (mount_it == new_mtab.end()) { | 336 if (new_it == new_mtab.end() || |
200 new_mtab.insert(std::make_pair(mount_point, | 337 (mount_point_info_map_it != mount_points_info_map.end() && |
201 std::make_pair(device, position))); | 338 mount_point_info_map_it->second < entry_pos)) { |
202 continue; | 339 new_mtab[mount_point] = mount_device; |
340 mount_points_info_map[mount_point] = entry_pos; | |
203 } | 341 } |
204 | |
205 // There is already a device mounted at |mount_point|. Check to see if | |
206 // the existing mount entry is newer than the current one. | |
207 std::string& existing_device = mount_it->second.first; | |
208 std::string& existing_position = mount_it->second.second; | |
209 if (existing_position > position) | |
210 continue; | |
211 | |
212 // The current entry is newer, update the mount point entry. | |
213 existing_device = device; | |
214 existing_position = position; | |
215 } | 342 } |
216 } | 343 } |
217 | 344 |
218 void MediaDeviceNotificationsLinux::AddNewDevice( | 345 void MediaDeviceNotificationsLinux::CheckAndAddMediaDevice( |
219 const std::string& mount_device, | 346 const std::string& mount_device, |
220 const std::string& mount_point, | 347 const std::string& mount_point) { |
221 std::string* device_id) { | 348 if (!IsMediaDevice(mount_point)) |
222 *device_id = base::IntToString(current_device_id_++); | 349 return; |
350 | |
351 std::string device_id; | |
352 string16 device_name; | |
353 bool result = (*get_device_info_func_)(mount_device, &device_id, | |
354 &device_name); | |
355 | |
356 // Keep track of GetDeviceInfo result, to see how often we fail to get device | |
357 // details. | |
358 UMA_HISTOGRAM_BOOLEAN("MediaDeviceNotification.device_info_available", | |
359 result); | |
360 if (!result) | |
361 return; | |
362 | |
363 // Keep track of device uuid, to see how often we receive empty values. | |
364 UMA_HISTOGRAM_BOOLEAN("MediaDeviceNotification.device_uuid_available", | |
365 !device_id.empty()); | |
366 UMA_HISTOGRAM_BOOLEAN("MediaDeviceNotification.device_name_available", | |
367 !device_name.empty()); | |
368 | |
369 if (device_id.empty() || device_name.empty()) | |
370 return; | |
371 | |
372 MountDeviceAndId mount_device_and_id; | |
373 mount_device_and_id.mount_device = mount_device; | |
374 mount_device_and_id.device_id = device_id; | |
375 mount_info_map_[mount_point] = mount_device_and_id; | |
376 | |
223 base::SystemMonitor* system_monitor = base::SystemMonitor::Get(); | 377 base::SystemMonitor* system_monitor = base::SystemMonitor::Get(); |
224 system_monitor->ProcessMediaDeviceAttached(*device_id, | 378 system_monitor->ProcessMediaDeviceAttached(device_id, |
225 UTF8ToUTF16(mount_device), | 379 device_name, |
226 SystemMonitor::TYPE_PATH, | 380 SystemMonitor::TYPE_PATH, |
227 mount_point); | 381 mount_point); |
228 } | 382 } |
229 | 383 |
230 void MediaDeviceNotificationsLinux::RemoveOldDevice( | 384 void MediaDeviceNotificationsLinux::RemoveOldDevice( |
231 const std::string& device_id) { | 385 const std::string& device_id) { |
232 base::SystemMonitor* system_monitor = base::SystemMonitor::Get(); | 386 base::SystemMonitor* system_monitor = base::SystemMonitor::Get(); |
233 system_monitor->ProcessMediaDeviceDetached(device_id); | 387 system_monitor->ProcessMediaDeviceDetached(device_id); |
234 } | 388 } |
235 | 389 |
236 } // namespace chrome | 390 } // namespace chrome |
OLD | NEW |