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 // chromeos::MediaDeviceNotifications implementation. | 5 // chromeos::MediaDeviceNotifications implementation. |
6 | 6 |
7 #include "chrome/browser/media_gallery/media_device_notifications_chromeos.h" | 7 #include "chrome/browser/media_gallery/media_device_notifications_chromeos.h" |
8 | 8 |
9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
12 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
13 #include "base/string_number_conversions.h" | 13 #include "base/string_number_conversions.h" |
14 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
15 #include "chrome/browser/media_gallery/media_device_notifications_utils.h" | 15 #include "chrome/browser/media_gallery/media_device_notifications_utils.h" |
16 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
17 | 17 |
18 namespace chromeos { | 18 namespace chromeos { |
19 | 19 |
20 namespace { | 20 namespace { |
21 | 21 |
22 std::string GetDeviceUuid(const std::string& source_path) { | 22 void GetDeviceInfo(const std::string& source_path, std::string* device_id_str, |
Lei Zhang
2012/08/03 05:45:25
|device_id_str| -> |device_id| here and below.
kmadhusu
2012/08/03 06:07:11
Done.
| |
23 // Get the media device uuid if exists. | 23 string16* device_label) { |
24 // Get the media device uuid and label if exists. | |
24 const disks::DiskMountManager::DiskMap& disks = | 25 const disks::DiskMountManager::DiskMap& disks = |
25 disks::DiskMountManager::GetInstance()->disks(); | 26 disks::DiskMountManager::GetInstance()->disks(); |
26 disks::DiskMountManager::DiskMap::const_iterator it = disks.find(source_path); | 27 disks::DiskMountManager::DiskMap::const_iterator it = disks.find(source_path); |
27 return it == disks.end() ? std::string() : it->second->fs_uuid(); | 28 if (it == disks.end()) |
29 return; | |
Lei Zhang
2012/08/03 05:45:25
May want to return bool, so the caller knows |devi
kmadhusu
2012/08/03 06:07:11
Done.
| |
30 | |
31 const disks::DiskMountManager::Disk& disk = *(it->second); | |
32 *device_id_str = disk.fs_uuid(); | |
33 | |
34 // TODO(kmadhusu): If device label is empty, extract vendor and model details | |
35 // and use them as device_label. | |
36 *device_label = disk.device_label().empty() ? | |
Lei Zhang
2012/08/03 05:45:25
Would UTF8ToUTF16(foo ? bar : qux) be better?
kmadhusu
2012/08/03 06:07:11
Done.
| |
37 UTF8ToUTF16(FilePath(source_path).BaseName().value()) : | |
38 UTF8ToUTF16(disk.device_label()); | |
28 } | 39 } |
29 | 40 |
30 } // namespace | 41 } // namespace |
31 | 42 |
32 using content::BrowserThread; | 43 using content::BrowserThread; |
33 | 44 |
34 MediaDeviceNotifications::MediaDeviceNotifications() { | 45 MediaDeviceNotifications::MediaDeviceNotifications() { |
35 DCHECK(disks::DiskMountManager::GetInstance()); | 46 DCHECK(disks::DiskMountManager::GetInstance()); |
36 disks::DiskMountManager::GetInstance()->AddObserver(this); | 47 disks::DiskMountManager::GetInstance()->AddObserver(this); |
37 } | 48 } |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
107 | 118 |
108 void MediaDeviceNotifications::AddMountedPathOnUIThread( | 119 void MediaDeviceNotifications::AddMountedPathOnUIThread( |
109 const disks::DiskMountManager::MountPointInfo& mount_info) { | 120 const disks::DiskMountManager::MountPointInfo& mount_info) { |
110 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 121 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
111 | 122 |
112 if (ContainsKey(mount_map_, mount_info.mount_path)) { | 123 if (ContainsKey(mount_map_, mount_info.mount_path)) { |
113 NOTREACHED(); | 124 NOTREACHED(); |
114 return; | 125 return; |
115 } | 126 } |
116 | 127 |
117 // Get the media device uuid if exists. | 128 // Get the media device uuid and label if exists. |
118 std::string device_id_str = GetDeviceUuid(mount_info.source_path); | 129 std::string device_id_str; |
130 string16 device_label; | |
131 GetDeviceInfo(mount_info.source_path, &device_id_str, &device_label); | |
119 | 132 |
120 // Keep track of device uuid, to see how often we receive empty uuid values. | 133 // Keep track of device uuid, to see how often we receive empty uuid values. |
121 UMA_HISTOGRAM_BOOLEAN("MediaDeviceNotification.device_uuid_available", | 134 UMA_HISTOGRAM_BOOLEAN("MediaDeviceNotification.device_uuid_available", |
122 !device_id_str.empty()); | 135 !device_id_str.empty()); |
123 if (device_id_str.empty()) | 136 if (device_id_str.empty()) |
124 return; | 137 return; |
125 | 138 |
126 mount_map_.insert(std::make_pair(mount_info.mount_path, device_id_str)); | 139 mount_map_.insert(std::make_pair(mount_info.mount_path, device_id_str)); |
127 base::SystemMonitor::Get()->ProcessMediaDeviceAttached( | 140 base::SystemMonitor::Get()->ProcessMediaDeviceAttached( |
128 device_id_str, | 141 device_id_str, |
129 UTF8ToUTF16(FilePath(mount_info.source_path).BaseName().value()), | 142 device_label, |
130 base::SystemMonitor::TYPE_PATH, | 143 base::SystemMonitor::TYPE_PATH, |
131 mount_info.mount_path); | 144 mount_info.mount_path); |
132 } | 145 } |
133 | 146 |
134 } // namespace chrome | 147 } // namespace chrome |
OLD | NEW |