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 // StorageMonitorLinux implementation. | 5 // StorageMonitorLinux implementation. |
6 | 6 |
7 #include "chrome/browser/storage_monitor/storage_monitor_linux.h" | 7 #include "chrome/browser/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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 "RemovableDeviceNotificationsLinux.device_partition_size_available", | 104 "RemovableDeviceNotificationsLinux.device_partition_size_available", |
105 !partition_size.empty()); | 105 !partition_size.empty()); |
106 | 106 |
107 uint64 total_size_in_bytes = 0; | 107 uint64 total_size_in_bytes = 0; |
108 if (!base::StringToUint64(partition_size, &total_size_in_bytes)) | 108 if (!base::StringToUint64(partition_size, &total_size_in_bytes)) |
109 return 0; | 109 return 0; |
110 return (total_size_in_bytes <= kuint64max / 512) ? | 110 return (total_size_in_bytes <= kuint64max / 512) ? |
111 total_size_in_bytes * 512 : 0; | 111 total_size_in_bytes * 512 : 0; |
112 } | 112 } |
113 | 113 |
114 // Constructs the device name from the device properties. If the device details | |
115 // are unavailable, returns an empty string. | |
116 void GetDeviceName(struct udev_device* device, | |
117 string16* out_volume_label, | |
118 string16* out_vendor_name, | |
119 string16* out_model_name) { | |
120 std::string device_label = GetUdevDevicePropertyValue(device, kLabel); | |
121 std::string vendor_name = GetUdevDevicePropertyValue(device, kVendor); | |
122 std::string model_name = GetUdevDevicePropertyValue(device, kModel); | |
123 if (out_volume_label) | |
124 *out_volume_label = UTF8ToUTF16(device_label); | |
125 if (out_vendor_name) | |
126 *out_vendor_name = UTF8ToUTF16(vendor_name); | |
127 if (out_model_name) | |
128 *out_model_name = UTF8ToUTF16(model_name); | |
129 } | |
130 | |
131 // Gets the device information using udev library. | 114 // Gets the device information using udev library. |
132 scoped_ptr<StorageInfo> GetDeviceInfo(const base::FilePath& device_path, | 115 scoped_ptr<StorageInfo> GetDeviceInfo(const base::FilePath& device_path, |
133 const base::FilePath& mount_point) { | 116 const base::FilePath& mount_point) { |
134 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 117 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
135 DCHECK(!device_path.empty()); | 118 DCHECK(!device_path.empty()); |
136 | 119 |
137 scoped_ptr<StorageInfo> storage_info; | 120 scoped_ptr<StorageInfo> storage_info; |
138 | 121 |
139 ScopedGetDeviceInfoResultRecorder results_recorder; | 122 ScopedGetDeviceInfoResultRecorder results_recorder; |
140 | 123 |
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
510 mount_point_info.storage_info = *storage_info; | 493 mount_point_info.storage_info = *storage_info; |
511 mount_info_map_[mount_point] = mount_point_info; | 494 mount_info_map_[mount_point] = mount_point_info; |
512 mount_priority_map_[mount_device][mount_point] = removable; | 495 mount_priority_map_[mount_device][mount_point] = removable; |
513 receiver()->ProcessAttach(*storage_info); | 496 receiver()->ProcessAttach(*storage_info); |
514 } | 497 } |
515 | 498 |
516 StorageMonitor* StorageMonitor::Create() { | 499 StorageMonitor* StorageMonitor::Create() { |
517 const base::FilePath kDefaultMtabPath("/etc/mtab"); | 500 const base::FilePath kDefaultMtabPath("/etc/mtab"); |
518 return new StorageMonitorLinux(kDefaultMtabPath); | 501 return new StorageMonitorLinux(kDefaultMtabPath); |
519 } | 502 } |
OLD | NEW |