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

Side by Side Diff: components/storage_monitor/storage_monitor_linux.cc

Issue 982883004: Move GetUdevDevicePropertyValue from components/storage_monitor to device/udev_linux and rename to … (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Revert incorrect change in chromeos Created 5 years, 9 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
« no previous file with comments | « no previous file | components/storage_monitor/udev_util_linux.h » ('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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 // StorageMonitorLinux implementation. 5 // StorageMonitorLinux implementation.
6 6
7 #include "components/storage_monitor/storage_monitor_linux.h" 7 #include "components/storage_monitor/storage_monitor_linux.h"
8 8
9 #include <mntent.h> 9 #include <mntent.h>
10 #include <stdio.h> 10 #include <stdio.h>
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 const char kModel[] = "ID_MODEL"; 44 const char kModel[] = "ID_MODEL";
45 const char kModelID[] = "ID_MODEL_ID"; 45 const char kModelID[] = "ID_MODEL_ID";
46 const char kRemovableSysAttr[] = "removable"; 46 const char kRemovableSysAttr[] = "removable";
47 const char kSerialShort[] = "ID_SERIAL_SHORT"; 47 const char kSerialShort[] = "ID_SERIAL_SHORT";
48 const char kSizeSysAttr[] = "size"; 48 const char kSizeSysAttr[] = "size";
49 const char kVendor[] = "ID_VENDOR"; 49 const char kVendor[] = "ID_VENDOR";
50 const char kVendorID[] = "ID_VENDOR_ID"; 50 const char kVendorID[] = "ID_VENDOR_ID";
51 51
52 // Construct a device id using label or manufacturer (vendor and model) details. 52 // Construct a device id using label or manufacturer (vendor and model) details.
53 std::string MakeDeviceUniqueId(struct udev_device* device) { 53 std::string MakeDeviceUniqueId(struct udev_device* device) {
54 std::string uuid = GetUdevDevicePropertyValue(device, kFsUUID); 54 std::string uuid = device::UdevDeviceGetPropertyValue(device, kFsUUID);
55 // Keep track of device uuid, to see how often we receive empty uuid values. 55 // Keep track of device uuid, to see how often we receive empty uuid values.
56 UMA_HISTOGRAM_BOOLEAN( 56 UMA_HISTOGRAM_BOOLEAN(
57 "RemovableDeviceNotificationsLinux.device_file_system_uuid_available", 57 "RemovableDeviceNotificationsLinux.device_file_system_uuid_available",
58 !uuid.empty()); 58 !uuid.empty());
59 59
60 if (!uuid.empty()) 60 if (!uuid.empty())
61 return kFSUniqueIdPrefix + uuid; 61 return kFSUniqueIdPrefix + uuid;
62 62
63 // If one of the vendor, model, serial information is missing, its value 63 // If one of the vendor, model, serial information is missing, its value
64 // in the string is empty. 64 // in the string is empty.
65 // Format: VendorModelSerial:VendorInfo:ModelInfo:SerialShortInfo 65 // Format: VendorModelSerial:VendorInfo:ModelInfo:SerialShortInfo
66 // E.g.: VendorModelSerial:Kn:DataTravel_12.10:8000000000006CB02CDB 66 // E.g.: VendorModelSerial:Kn:DataTravel_12.10:8000000000006CB02CDB
67 std::string vendor = GetUdevDevicePropertyValue(device, kVendorID); 67 std::string vendor = device::UdevDeviceGetPropertyValue(device, kVendorID);
68 std::string model = GetUdevDevicePropertyValue(device, kModelID); 68 std::string model = device::UdevDeviceGetPropertyValue(device, kModelID);
69 std::string serial_short = GetUdevDevicePropertyValue(device, 69 std::string serial_short =
70 kSerialShort); 70 device::UdevDeviceGetPropertyValue(device, kSerialShort);
71 if (vendor.empty() && model.empty() && serial_short.empty()) 71 if (vendor.empty() && model.empty() && serial_short.empty())
72 return std::string(); 72 return std::string();
73 73
74 return kVendorModelSerialPrefix + vendor + ":" + model + ":" + serial_short; 74 return kVendorModelSerialPrefix + vendor + ":" + model + ":" + serial_short;
75 } 75 }
76 76
77 // Records GetDeviceInfo result on destruction, to see how often we fail to get 77 // Records GetDeviceInfo result on destruction, to see how often we fail to get
78 // device details. 78 // device details.
79 class ScopedGetDeviceInfoResultRecorder { 79 class ScopedGetDeviceInfoResultRecorder {
80 public: 80 public:
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 device_type = 'b'; 140 device_type = 'b';
141 else 141 else
142 return storage_info.Pass(); // Not a supported type. 142 return storage_info.Pass(); // Not a supported type.
143 143
144 device::ScopedUdevDevicePtr device( 144 device::ScopedUdevDevicePtr device(
145 device::udev_device_new_from_devnum(udev_obj.get(), device_type, 145 device::udev_device_new_from_devnum(udev_obj.get(), device_type,
146 device_stat.st_rdev)); 146 device_stat.st_rdev));
147 if (!device.get()) 147 if (!device.get())
148 return storage_info.Pass(); 148 return storage_info.Pass();
149 149
150 base::string16 volume_label = 150 base::string16 volume_label = base::UTF8ToUTF16(
151 base::UTF8ToUTF16(GetUdevDevicePropertyValue(device.get(), kLabel)); 151 device::UdevDeviceGetPropertyValue(device.get(), kLabel));
152 base::string16 vendor_name = 152 base::string16 vendor_name = base::UTF8ToUTF16(
153 base::UTF8ToUTF16(GetUdevDevicePropertyValue(device.get(), kVendor)); 153 device::UdevDeviceGetPropertyValue(device.get(), kVendor));
154 base::string16 model_name = 154 base::string16 model_name = base::UTF8ToUTF16(
155 base::UTF8ToUTF16(GetUdevDevicePropertyValue(device.get(), kModel)); 155 device::UdevDeviceGetPropertyValue(device.get(), kModel));
156 156
157 std::string unique_id = MakeDeviceUniqueId(device.get()); 157 std::string unique_id = MakeDeviceUniqueId(device.get());
158 158
159 // Keep track of device info details to see how often we get invalid values. 159 // Keep track of device info details to see how often we get invalid values.
160 MediaStorageUtil::RecordDeviceInfoHistogram(true, unique_id, volume_label); 160 MediaStorageUtil::RecordDeviceInfoHistogram(true, unique_id, volume_label);
161 161
162 const char* value = 162 const char* value =
163 device::udev_device_get_sysattr_value(device.get(), kRemovableSysAttr); 163 device::udev_device_get_sysattr_value(device.get(), kRemovableSysAttr);
164 if (!value) { 164 if (!value) {
165 // |parent_device| is owned by |device| and does not need to be cleaned 165 // |parent_device| is owned by |device| and does not need to be cleaned
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after
500 mount_priority_map_[mount_device][mount_point] = removable; 500 mount_priority_map_[mount_device][mount_point] = removable;
501 receiver()->ProcessAttach(*storage_info); 501 receiver()->ProcessAttach(*storage_info);
502 } 502 }
503 503
504 StorageMonitor* StorageMonitor::CreateInternal() { 504 StorageMonitor* StorageMonitor::CreateInternal() {
505 const base::FilePath kDefaultMtabPath("/etc/mtab"); 505 const base::FilePath kDefaultMtabPath("/etc/mtab");
506 return new StorageMonitorLinux(kDefaultMtabPath); 506 return new StorageMonitorLinux(kDefaultMtabPath);
507 } 507 }
508 508
509 } // namespace storage_monitor 509 } // namespace storage_monitor
OLDNEW
« no previous file with comments | « no previous file | components/storage_monitor/udev_util_linux.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698