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 bool GetDeviceInfo(const std::string& source_path, std::string* device_id, | 22 bool GetDeviceInfo(const std::string& source_path, std::string* device_id, |
23 string16* device_label) { | 23 string16* device_label) { |
24 // Get the media device uuid and label if exists. | 24 // Get the media device uuid and label if exists. |
25 const disks::DiskMountManager::DiskMap& disks = | 25 const disks::DiskMountManager::Disk* disk = |
26 disks::DiskMountManager::GetInstance()->disks(); | 26 disks::DiskMountManager::GetInstance()->FindDiskBySourcePath(source_path); |
27 disks::DiskMountManager::DiskMap::const_iterator it = disks.find(source_path); | 27 if (!disk) |
28 if (it == disks.end()) | |
29 return false; | 28 return false; |
30 | 29 |
31 const disks::DiskMountManager::Disk& disk = *(it->second); | 30 *device_id = disk->fs_uuid(); |
32 *device_id = disk.fs_uuid(); | |
33 | 31 |
34 // TODO(kmadhusu): If device label is empty, extract vendor and model details | 32 // TODO(kmadhusu): If device label is empty, extract vendor and model details |
35 // and use them as device_label. | 33 // and use them as device_label. |
36 *device_label = UTF8ToUTF16(disk.device_label().empty() ? | 34 *device_label = UTF8ToUTF16(disk->device_label().empty() ? |
37 FilePath(source_path).BaseName().value() : | 35 FilePath(source_path).BaseName().value() : |
38 disk.device_label()); | 36 disk->device_label()); |
39 return true; | 37 return true; |
40 } | 38 } |
41 | 39 |
42 } // namespace | 40 } // namespace |
43 | 41 |
44 using content::BrowserThread; | 42 using content::BrowserThread; |
45 | 43 |
46 MediaDeviceNotifications::MediaDeviceNotifications() { | 44 MediaDeviceNotifications::MediaDeviceNotifications() { |
47 DCHECK(disks::DiskMountManager::GetInstance()); | 45 DCHECK(disks::DiskMountManager::GetInstance()); |
48 disks::DiskMountManager::GetInstance()->AddObserver(this); | 46 disks::DiskMountManager::GetInstance()->AddObserver(this); |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 | 152 |
155 mount_map_.insert(std::make_pair(mount_info.mount_path, device_id)); | 153 mount_map_.insert(std::make_pair(mount_info.mount_path, device_id)); |
156 base::SystemMonitor::Get()->ProcessMediaDeviceAttached( | 154 base::SystemMonitor::Get()->ProcessMediaDeviceAttached( |
157 device_id, | 155 device_id, |
158 device_label, | 156 device_label, |
159 base::SystemMonitor::TYPE_PATH, | 157 base::SystemMonitor::TYPE_PATH, |
160 mount_info.mount_path); | 158 mount_info.mount_path); |
161 } | 159 } |
162 | 160 |
163 } // namespace chrome | 161 } // namespace chrome |
OLD | NEW |