OLD | NEW |
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 <stdint.h> | 10 #include <stdint.h> |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 | 113 |
114 uint64_t total_size_in_bytes = 0; | 114 uint64_t total_size_in_bytes = 0; |
115 if (!base::StringToUint64(partition_size, &total_size_in_bytes)) | 115 if (!base::StringToUint64(partition_size, &total_size_in_bytes)) |
116 return 0; | 116 return 0; |
117 return (total_size_in_bytes <= std::numeric_limits<uint64_t>::max() / 512) | 117 return (total_size_in_bytes <= std::numeric_limits<uint64_t>::max() / 512) |
118 ? total_size_in_bytes * 512 | 118 ? total_size_in_bytes * 512 |
119 : 0; | 119 : 0; |
120 } | 120 } |
121 | 121 |
122 // Gets the device information using udev library. | 122 // Gets the device information using udev library. |
123 scoped_ptr<StorageInfo> GetDeviceInfo(const base::FilePath& device_path, | 123 std::unique_ptr<StorageInfo> GetDeviceInfo(const base::FilePath& device_path, |
124 const base::FilePath& mount_point) { | 124 const base::FilePath& mount_point) { |
125 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 125 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
126 DCHECK(!device_path.empty()); | 126 DCHECK(!device_path.empty()); |
127 | 127 |
128 scoped_ptr<StorageInfo> storage_info; | 128 std::unique_ptr<StorageInfo> storage_info; |
129 | 129 |
130 ScopedGetDeviceInfoResultRecorder results_recorder; | 130 ScopedGetDeviceInfoResultRecorder results_recorder; |
131 | 131 |
132 device::ScopedUdevPtr udev_obj(device::udev_new()); | 132 device::ScopedUdevPtr udev_obj(device::udev_new()); |
133 if (!udev_obj.get()) | 133 if (!udev_obj.get()) |
134 return storage_info; | 134 return storage_info; |
135 | 135 |
136 struct stat device_stat; | 136 struct stat device_stat; |
137 if (stat(device_path.value().c_str(), &device_stat) < 0) | 137 if (stat(device_path.value().c_str(), &device_stat) < 0) |
138 return storage_info; | 138 return storage_info; |
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
477 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 477 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
478 | 478 |
479 MountPriorityMap::iterator priority = mount_priority_map_.find(mount_device); | 479 MountPriorityMap::iterator priority = mount_priority_map_.find(mount_device); |
480 DCHECK(priority != mount_priority_map_.end()); | 480 DCHECK(priority != mount_priority_map_.end()); |
481 const base::FilePath& other_mount_point = priority->second.begin()->first; | 481 const base::FilePath& other_mount_point = priority->second.begin()->first; |
482 priority->second[mount_point] = false; | 482 priority->second[mount_point] = false; |
483 mount_info_map_[mount_point] = | 483 mount_info_map_[mount_point] = |
484 mount_info_map_.find(other_mount_point)->second; | 484 mount_info_map_.find(other_mount_point)->second; |
485 } | 485 } |
486 | 486 |
487 void StorageMonitorLinux::AddNewMount(const base::FilePath& mount_device, | 487 void StorageMonitorLinux::AddNewMount( |
488 scoped_ptr<StorageInfo> storage_info) { | 488 const base::FilePath& mount_device, |
| 489 std::unique_ptr<StorageInfo> storage_info) { |
489 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 490 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
490 | 491 |
491 if (!storage_info) | 492 if (!storage_info) |
492 return; | 493 return; |
493 | 494 |
494 DCHECK(!storage_info->device_id().empty()); | 495 DCHECK(!storage_info->device_id().empty()); |
495 | 496 |
496 bool removable = StorageInfo::IsRemovableDevice(storage_info->device_id()); | 497 bool removable = StorageInfo::IsRemovableDevice(storage_info->device_id()); |
497 const base::FilePath mount_point(storage_info->location()); | 498 const base::FilePath mount_point(storage_info->location()); |
498 | 499 |
499 MountPointInfo mount_point_info; | 500 MountPointInfo mount_point_info; |
500 mount_point_info.mount_device = mount_device; | 501 mount_point_info.mount_device = mount_device; |
501 mount_point_info.storage_info = *storage_info; | 502 mount_point_info.storage_info = *storage_info; |
502 mount_info_map_[mount_point] = mount_point_info; | 503 mount_info_map_[mount_point] = mount_point_info; |
503 mount_priority_map_[mount_device][mount_point] = removable; | 504 mount_priority_map_[mount_device][mount_point] = removable; |
504 receiver()->ProcessAttach(*storage_info); | 505 receiver()->ProcessAttach(*storage_info); |
505 } | 506 } |
506 | 507 |
507 StorageMonitor* StorageMonitor::CreateInternal() { | 508 StorageMonitor* StorageMonitor::CreateInternal() { |
508 const base::FilePath kDefaultMtabPath("/etc/mtab"); | 509 const base::FilePath kDefaultMtabPath("/etc/mtab"); |
509 return new StorageMonitorLinux(kDefaultMtabPath); | 510 return new StorageMonitorLinux(kDefaultMtabPath); |
510 } | 511 } |
511 | 512 |
512 } // namespace storage_monitor | 513 } // namespace storage_monitor |
OLD | NEW |