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/stl_util.h" | 12 #include "base/stl_util.h" |
12 #include "base/string_number_conversions.h" | 13 #include "base/string_number_conversions.h" |
13 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
14 #include "chrome/browser/media_gallery/media_device_notifications_utils.h" | 15 #include "chrome/browser/media_gallery/media_device_notifications_utils.h" |
15 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
16 | 17 |
17 namespace chromeos { | 18 namespace chromeos { |
18 | 19 |
20 namespace { | |
21 | |
22 std::string GetDeviceUuid(const std::string& source_path) { | |
23 // Get the media device uuid if exists. | |
24 const disks::DiskMountManager::DiskMap& disks = | |
25 disks::DiskMountManager::GetInstance()->disks(); | |
26 disks::DiskMountManager::DiskMap::const_iterator it = disks.find(source_path); | |
27 std::string device_id; | |
Lei Zhang
2012/07/26 18:34:31
you can further simplify lines 27-32 to:
return
kmadhusu
2012/07/26 18:44:50
Done.
| |
28 if (it != disks.end()) { | |
29 const disks::DiskMountManager::Disk& disk = *it->second; | |
30 device_id = disk.fs_uuid(); | |
Ben Chan
2012/07/26 17:56:03
this may be simpler:
if (it != disks.end())
dev
kmadhusu
2012/07/26 18:44:50
done.
| |
31 } | |
32 return device_id; | |
33 } | |
34 | |
35 } // namespace | |
36 | |
19 using content::BrowserThread; | 37 using content::BrowserThread; |
20 | 38 |
21 MediaDeviceNotifications::MediaDeviceNotifications() | 39 MediaDeviceNotifications::MediaDeviceNotifications() { |
22 : current_device_id_(0) { | |
23 DCHECK(disks::DiskMountManager::GetInstance()); | 40 DCHECK(disks::DiskMountManager::GetInstance()); |
24 disks::DiskMountManager::GetInstance()->AddObserver(this); | 41 disks::DiskMountManager::GetInstance()->AddObserver(this); |
25 } | 42 } |
26 | 43 |
27 MediaDeviceNotifications::~MediaDeviceNotifications() { | 44 MediaDeviceNotifications::~MediaDeviceNotifications() { |
28 disks::DiskMountManager* manager = disks::DiskMountManager::GetInstance(); | 45 disks::DiskMountManager* manager = disks::DiskMountManager::GetInstance(); |
29 if (manager) { | 46 if (manager) { |
30 manager->RemoveObserver(this); | 47 manager->RemoveObserver(this); |
31 } | 48 } |
32 } | 49 } |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
94 } | 111 } |
95 | 112 |
96 void MediaDeviceNotifications::AddMountedPathOnUIThread( | 113 void MediaDeviceNotifications::AddMountedPathOnUIThread( |
97 const disks::DiskMountManager::MountPointInfo& mount_info) { | 114 const disks::DiskMountManager::MountPointInfo& mount_info) { |
98 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 115 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
99 | 116 |
100 if (ContainsKey(mount_map_, mount_info.mount_path)) { | 117 if (ContainsKey(mount_map_, mount_info.mount_path)) { |
101 NOTREACHED(); | 118 NOTREACHED(); |
102 return; | 119 return; |
103 } | 120 } |
104 const std::string device_id_str = base::IntToString(current_device_id_++); | 121 |
122 // Get the media device uuid if exists. | |
123 std::string device_id_str = GetDeviceUuid(mount_info.source_path); | |
124 | |
125 // Keep track of device uuid, to see how often we receive empty uuid values. | |
126 static base::Histogram* media_device_uuid_available(NULL); | |
Lei Zhang
2012/07/26 18:34:31
I see some Histogram code that uses a static Histo
| |
127 if (!media_device_uuid_available) { | |
128 media_device_uuid_available = base::BooleanHistogram::FactoryGet( | |
129 "MediaDeviceNotification.device_uuid_available", | |
130 base::Histogram::kUmaTargetedHistogramFlag); | |
131 } | |
132 media_device_uuid_available->AddBoolean(!device_id_str.empty()); | |
133 if (device_id_str.empty()) | |
134 return; | |
135 | |
105 mount_map_.insert(std::make_pair(mount_info.mount_path, device_id_str)); | 136 mount_map_.insert(std::make_pair(mount_info.mount_path, device_id_str)); |
106 base::SystemMonitor::Get()->ProcessMediaDeviceAttached( | 137 base::SystemMonitor::Get()->ProcessMediaDeviceAttached( |
107 device_id_str, | 138 device_id_str, |
108 UTF8ToUTF16(FilePath(mount_info.source_path).BaseName().value()), | 139 UTF8ToUTF16(FilePath(mount_info.source_path).BaseName().value()), |
109 base::SystemMonitor::TYPE_PATH, | 140 base::SystemMonitor::TYPE_PATH, |
110 mount_info.mount_path); | 141 mount_info.mount_path); |
111 } | 142 } |
112 | 143 |
113 } // namespace chrome | 144 } // namespace chrome |
OLD | NEW |