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

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

Issue 1502503004: Remove kuint64max. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@kint8
Patch Set: rebase Created 5 years 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
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 <stdint.h>
10 #include <stdio.h> 11 #include <stdio.h>
11 12
13 #include <limits>
12 #include <list> 14 #include <list>
13 15
14 #include "base/basictypes.h"
15 #include "base/bind.h" 16 #include "base/bind.h"
16 #include "base/metrics/histogram.h" 17 #include "base/metrics/histogram.h"
17 #include "base/process/kill.h" 18 #include "base/process/kill.h"
18 #include "base/process/launch.h" 19 #include "base/process/launch.h"
19 #include "base/process/process.h" 20 #include "base/process/process.h"
20 #include "base/stl_util.h" 21 #include "base/stl_util.h"
21 #include "base/strings/string_number_conversions.h" 22 #include "base/strings/string_number_conversions.h"
22 #include "base/strings/string_util.h" 23 #include "base/strings/string_util.h"
23 #include "base/strings/utf_string_conversions.h" 24 #include "base/strings/utf_string_conversions.h"
24 #include "components/storage_monitor/media_storage_util.h" 25 #include "components/storage_monitor/media_storage_util.h"
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 } 91 }
91 92
92 private: 93 private:
93 bool result_; 94 bool result_;
94 95
95 DISALLOW_COPY_AND_ASSIGN(ScopedGetDeviceInfoResultRecorder); 96 DISALLOW_COPY_AND_ASSIGN(ScopedGetDeviceInfoResultRecorder);
96 }; 97 };
97 98
98 // Returns the storage partition size of the device specified by |device_path|. 99 // Returns the storage partition size of the device specified by |device_path|.
99 // If the requested information is unavailable, returns 0. 100 // If the requested information is unavailable, returns 0.
100 uint64 GetDeviceStorageSize(const base::FilePath& device_path, 101 uint64_t GetDeviceStorageSize(const base::FilePath& device_path,
101 struct udev_device* device) { 102 struct udev_device* device) {
102 // sysfs provides the device size in units of 512-byte blocks. 103 // sysfs provides the device size in units of 512-byte blocks.
103 const std::string partition_size = 104 const std::string partition_size =
104 device::UdevDeviceGetSysattrValue(device, kSizeSysAttr); 105 device::UdevDeviceGetSysattrValue(device, kSizeSysAttr);
105 106
106 // Keep track of device size, to see how often this information is 107 // Keep track of device size, to see how often this information is
107 // unavailable. 108 // unavailable.
108 UMA_HISTOGRAM_BOOLEAN( 109 UMA_HISTOGRAM_BOOLEAN(
109 "RemovableDeviceNotificationsLinux.device_partition_size_available", 110 "RemovableDeviceNotificationsLinux.device_partition_size_available",
110 !partition_size.empty()); 111 !partition_size.empty());
111 112
112 uint64 total_size_in_bytes = 0; 113 uint64_t total_size_in_bytes = 0;
113 if (!base::StringToUint64(partition_size, &total_size_in_bytes)) 114 if (!base::StringToUint64(partition_size, &total_size_in_bytes))
114 return 0; 115 return 0;
115 return (total_size_in_bytes <= kuint64max / 512) ? 116 return (total_size_in_bytes <= std::numeric_limits<uint64_t>::max() / 512)
116 total_size_in_bytes * 512 : 0; 117 ? total_size_in_bytes * 512
118 : 0;
117 } 119 }
118 120
119 // Gets the device information using udev library. 121 // Gets the device information using udev library.
120 scoped_ptr<StorageInfo> GetDeviceInfo(const base::FilePath& device_path, 122 scoped_ptr<StorageInfo> GetDeviceInfo(const base::FilePath& device_path,
121 const base::FilePath& mount_point) { 123 const base::FilePath& mount_point) {
122 DCHECK_CURRENTLY_ON(BrowserThread::FILE); 124 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
123 DCHECK(!device_path.empty()); 125 DCHECK(!device_path.empty());
124 126
125 scoped_ptr<StorageInfo> storage_info; 127 scoped_ptr<StorageInfo> storage_info;
126 128
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after
500 mount_priority_map_[mount_device][mount_point] = removable; 502 mount_priority_map_[mount_device][mount_point] = removable;
501 receiver()->ProcessAttach(*storage_info); 503 receiver()->ProcessAttach(*storage_info);
502 } 504 }
503 505
504 StorageMonitor* StorageMonitor::CreateInternal() { 506 StorageMonitor* StorageMonitor::CreateInternal() {
505 const base::FilePath kDefaultMtabPath("/etc/mtab"); 507 const base::FilePath kDefaultMtabPath("/etc/mtab");
506 return new StorageMonitorLinux(kDefaultMtabPath); 508 return new StorageMonitorLinux(kDefaultMtabPath);
507 } 509 }
508 510
509 } // namespace storage_monitor 511 } // namespace storage_monitor
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698