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 <libudev.h> |
10 #include <mntent.h> | 10 #include <mntent.h> |
11 #include <stdio.h> | 11 #include <stdio.h> |
12 | 12 |
13 #include <vector> | 13 #include <vector> |
14 | 14 |
15 #include "base/bind.h" | 15 #include "base/bind.h" |
16 #include "base/file_path.h" | 16 #include "base/file_path.h" |
17 #include "base/memory/scoped_generic_obj.h" | 17 #include "base/memory/scoped_generic_obj.h" |
18 #include "base/metrics/histogram.h" | 18 #include "base/metrics/histogram.h" |
19 #include "base/stl_util.h" | 19 #include "base/stl_util.h" |
20 #include "base/string_number_conversions.h" | 20 #include "base/string_number_conversions.h" |
21 #include "base/string_util.h" | 21 #include "base/string_util.h" |
22 #include "base/system_monitor/system_monitor.h" | 22 #include "base/system_monitor/system_monitor.h" |
23 #include "base/utf_string_conversions.h" | 23 #include "base/utf_string_conversions.h" |
24 #include "chrome/browser/media_gallery/media_device_notifications_utils.h" | 24 #include "chrome/browser/media_gallery/media_device_notifications_utils.h" |
25 #include "chrome/browser/media_gallery/media_storage_util.h" | |
25 | 26 |
26 namespace { | 27 namespace { |
27 | 28 |
28 // List of file systems we care about. | 29 // List of file systems we care about. |
29 const char* const kKnownFileSystems[] = { | 30 const char* const kKnownFileSystems[] = { |
30 "ext2", | 31 "ext2", |
31 "ext3", | 32 "ext3", |
32 "ext4", | 33 "ext4", |
33 "fat", | 34 "fat", |
34 "hfsplus", | 35 "hfsplus", |
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
332 } | 333 } |
333 } | 334 } |
334 } | 335 } |
335 | 336 |
336 void MediaDeviceNotificationsLinux::CheckAndAddMediaDevice( | 337 void MediaDeviceNotificationsLinux::CheckAndAddMediaDevice( |
337 const std::string& mount_device, | 338 const std::string& mount_device, |
338 const std::string& mount_point) { | 339 const std::string& mount_point) { |
339 if (!IsMediaDevice(mount_point)) | 340 if (!IsMediaDevice(mount_point)) |
340 return; | 341 return; |
341 | 342 |
342 std::string device_id; | 343 std::string unique_id; |
343 string16 device_name; | 344 string16 device_name; |
344 bool result = (*get_device_info_func_)(mount_device, &device_id, | 345 bool result = (*get_device_info_func_)(mount_device, &unique_id, |
345 &device_name); | 346 &device_name); |
346 | 347 |
347 // Keep track of GetDeviceInfo result, to see how often we fail to get device | 348 // Keep track of GetDeviceInfo result, to see how often we fail to get device |
348 // details. | 349 // details. |
349 UMA_HISTOGRAM_BOOLEAN("MediaDeviceNotification.device_info_available", | 350 UMA_HISTOGRAM_BOOLEAN("MediaDeviceNotification.device_info_available", |
350 result); | 351 result); |
351 if (!result) | 352 if (!result) |
352 return; | 353 return; |
353 | 354 |
354 // Keep track of device uuid, to see how often we receive empty values. | 355 // Keep track of device uuid, to see how often we receive empty values. |
355 UMA_HISTOGRAM_BOOLEAN("MediaDeviceNotification.device_uuid_available", | 356 UMA_HISTOGRAM_BOOLEAN("MediaDeviceNotification.device_uuid_available", |
356 !device_id.empty()); | 357 !unique_id.empty()); |
357 UMA_HISTOGRAM_BOOLEAN("MediaDeviceNotification.device_name_available", | 358 UMA_HISTOGRAM_BOOLEAN("MediaDeviceNotification.device_name_available", |
358 !device_name.empty()); | 359 !device_name.empty()); |
359 | 360 |
360 if (device_id.empty() || device_name.empty()) | 361 if (unique_id.empty() || device_name.empty()) |
361 return; | 362 return; |
362 | 363 |
363 MountDeviceAndId mount_device_and_id; | 364 MountDeviceAndId mount_device_and_id; |
364 mount_device_and_id.mount_device = mount_device; | 365 mount_device_and_id.mount_device = mount_device; |
365 mount_device_and_id.device_id = device_id; | 366 mount_device_and_id.device_id = MediaStorageUtil::MakeDeviceId( |
367 MediaStorageUtil::USB_MASS_STORAGE_WITH_DCIM, unique_id); | |
kmadhusu
2012/08/17 18:53:35
Can we construct the DeviceId in get_device_info_f
vandebo (ex-Chrome)
2012/08/17 22:55:51
SGTM. Done.
| |
366 mount_info_map_[mount_point] = mount_device_and_id; | 368 mount_info_map_[mount_point] = mount_device_and_id; |
367 | 369 |
368 base::SystemMonitor* system_monitor = base::SystemMonitor::Get(); | 370 base::SystemMonitor* system_monitor = base::SystemMonitor::Get(); |
369 system_monitor->ProcessMediaDeviceAttached(device_id, | 371 system_monitor->ProcessMediaDeviceAttached(mount_device_and_id.device_id, |
370 device_name, | 372 device_name, |
371 SystemMonitor::TYPE_PATH, | |
372 mount_point); | 373 mount_point); |
373 } | 374 } |
374 | 375 |
375 void MediaDeviceNotificationsLinux::RemoveOldDevice( | 376 void MediaDeviceNotificationsLinux::RemoveOldDevice( |
376 const std::string& device_id) { | 377 const std::string& device_id) { |
377 base::SystemMonitor* system_monitor = base::SystemMonitor::Get(); | 378 base::SystemMonitor* system_monitor = base::SystemMonitor::Get(); |
378 system_monitor->ProcessMediaDeviceDetached(device_id); | 379 system_monitor->ProcessMediaDeviceDetached(device_id); |
379 } | 380 } |
380 | 381 |
381 } // namespace chrome | 382 } // namespace chrome |
OLD | NEW |