Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(162)

Side by Side Diff: chrome/browser/system_monitor/removable_device_notifications_chromeos.cc

Issue 10908277: [Chrome OS] Construct device label and unique id using vendor and product details. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed nit and updated comments in mock_disk_mount_manager.h Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/system_monitor/removable_device_notifications_chromeos_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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::RemovableDeviceNotificationsCros implementation. 5 // chromeos::RemovableDeviceNotificationsCros implementation.
6 6
7 #include "chrome/browser/system_monitor/removable_device_notifications_chromeos. h" 7 #include "chrome/browser/system_monitor/removable_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/stringprintf.h"
14 #include "base/utf_string_conversions.h" 15 #include "base/utf_string_conversions.h"
15 #include "chrome/browser/system_monitor/media_device_notifications_utils.h" 16 #include "chrome/browser/system_monitor/media_device_notifications_utils.h"
16 #include "chrome/browser/system_monitor/media_storage_util.h" 17 #include "chrome/browser/system_monitor/media_storage_util.h"
18 #include "chrome/browser/system_monitor/removable_device_constants.h"
17 #include "content/public/browser/browser_thread.h" 19 #include "content/public/browser/browser_thread.h"
18 20
19 namespace chromeos { 21 namespace chromeos {
20 22
21 namespace { 23 namespace {
22 24
25 // Construct a device name using label or manufacturer (vendor and product) name
26 // details.
27 string16 GetDeviceName(const disks::DiskMountManager::Disk& disk) {
28 std::string device_name = disk.device_label();
29 if (device_name.empty()) {
30 device_name = disk.vendor_name();
31 const std::string& product_name = disk.product_name();
32 if (!product_name.empty()) {
33 if (!device_name.empty())
34 device_name += chrome::kSpaceDelim;
35 device_name += product_name;
36 }
37 }
38 return UTF8ToUTF16(device_name);
39 }
40
41 // Construct a device id using uuid or manufacturer (vendor and product) id
42 // details.
43 std::string MakeDeviceUniqueId(const disks::DiskMountManager::Disk& disk) {
44 std::string uuid = disk.fs_uuid();
45 if (!uuid.empty())
46 return chrome::kFSUniqueIdPrefix + uuid;
47
48 // If one of the vendor or product information is missing, its value in the
49 // string is empty.
50 // Format: VendorModelSerial:VendorInfo:ModelInfo:SerialInfo
51 // TODO(kmadhusu) Extract serial information for the disks and append it to
52 // the device unique id.
53 const std::string& vendor = disk.vendor_id();
54 const std::string& product = disk.product_id();
55 if (vendor.empty() && product.empty())
56 return std::string();
57 return base::StringPrintf("%s%s%s%s%s",
58 chrome::kVendorModelSerialPrefix,
59 vendor.c_str(), chrome::kNonSpaceDelim,
60 product.c_str(), chrome::kNonSpaceDelim);
61 }
62
23 // Returns true if the requested device is valid, else false. On success, fills 63 // Returns true if the requested device is valid, else false. On success, fills
24 // in |unique_id| and |device_label| 64 // in |unique_id| and |device_label|
25 bool GetDeviceInfo(const std::string& source_path, std::string* unique_id, 65 bool GetDeviceInfo(const std::string& source_path, std::string* unique_id,
26 string16* device_label) { 66 string16* device_label) {
27 // Get the media device uuid and label if exists. 67 // Get the media device uuid and label if exists.
28 const disks::DiskMountManager::Disk* disk = 68 const disks::DiskMountManager::Disk* disk =
29 disks::DiskMountManager::GetInstance()->FindDiskBySourcePath(source_path); 69 disks::DiskMountManager::GetInstance()->FindDiskBySourcePath(source_path);
30 if (!disk || disk->device_type() == DEVICE_TYPE_UNKNOWN) 70 if (!disk || disk->device_type() == DEVICE_TYPE_UNKNOWN)
31 return false; 71 return false;
32 72
33 *unique_id = disk->fs_uuid(); 73 if (unique_id)
74 *unique_id = MakeDeviceUniqueId(*disk);
34 75
35 // TODO(kmadhusu): If device label is empty, extract vendor and model details 76 if (device_label)
36 // and use them as device_label. 77 *device_label = GetDeviceName(*disk);
37 *device_label = UTF8ToUTF16(disk->device_label().empty() ?
38 FilePath(source_path).BaseName().value() :
39 disk->device_label());
40 return true; 78 return true;
41 } 79 }
42 80
43 } // namespace 81 } // namespace
44 82
45 using content::BrowserThread; 83 using content::BrowserThread;
46 84
47 RemovableDeviceNotificationsCros::RemovableDeviceNotificationsCros() { 85 RemovableDeviceNotificationsCros::RemovableDeviceNotificationsCros() {
48 DCHECK(disks::DiskMountManager::GetInstance()); 86 DCHECK(disks::DiskMountManager::GetInstance());
49 disks::DiskMountManager::GetInstance()->AddObserver(this); 87 disks::DiskMountManager::GetInstance()->AddObserver(this);
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 182
145 // Get the media device uuid and label if exists. 183 // Get the media device uuid and label if exists.
146 std::string unique_id; 184 std::string unique_id;
147 string16 device_label; 185 string16 device_label;
148 if (!GetDeviceInfo(mount_info.source_path, &unique_id, &device_label)) 186 if (!GetDeviceInfo(mount_info.source_path, &unique_id, &device_label))
149 return; 187 return;
150 188
151 // Keep track of device uuid, to see how often we receive empty uuid values. 189 // Keep track of device uuid, to see how often we receive empty uuid values.
152 UMA_HISTOGRAM_BOOLEAN("MediaDeviceNotification.DeviceUUIDAvailable", 190 UMA_HISTOGRAM_BOOLEAN("MediaDeviceNotification.DeviceUUIDAvailable",
153 !unique_id.empty()); 191 !unique_id.empty());
154 if (unique_id.empty()) 192 UMA_HISTOGRAM_BOOLEAN("MediaDeviceNotification.DeviceNameAvailable",
193 !device_label.empty());
194 if (unique_id.empty() || device_label.empty())
155 return; 195 return;
156 196
157 chrome::MediaStorageUtil::Type type = has_dcim ? 197 chrome::MediaStorageUtil::Type type = has_dcim ?
158 chrome::MediaStorageUtil::REMOVABLE_MASS_STORAGE_WITH_DCIM : 198 chrome::MediaStorageUtil::REMOVABLE_MASS_STORAGE_WITH_DCIM :
159 chrome::MediaStorageUtil::REMOVABLE_MASS_STORAGE_NO_DCIM; 199 chrome::MediaStorageUtil::REMOVABLE_MASS_STORAGE_NO_DCIM;
160 200
161 std::string device_id = chrome::MediaStorageUtil::MakeDeviceId(type, 201 std::string device_id = chrome::MediaStorageUtil::MakeDeviceId(type,
162 unique_id); 202 unique_id);
163 mount_map_.insert(std::make_pair(mount_info.mount_path, device_id)); 203 mount_map_.insert(std::make_pair(mount_info.mount_path, device_id));
164 base::SystemMonitor::Get()->ProcessRemovableStorageAttached( 204 base::SystemMonitor::Get()->ProcessRemovableStorageAttached(
165 device_id, 205 device_id,
166 device_label, 206 device_label,
167 mount_info.mount_path); 207 mount_info.mount_path);
168 } 208 }
169 209
170 } // namespace chrome 210 } // namespace chrome
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/system_monitor/removable_device_notifications_chromeos_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698