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

Side by Side Diff: base/sys_info_posix.cc

Issue 10834384: Add AssertIOAllowed check in the SysInfo::AmountOfFreeDiskSpace. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 4 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 | base/sys_info_win.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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #include "base/sys_info.h" 5 #include "base/sys_info.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <string.h> 8 #include <string.h>
9 #include <sys/param.h> 9 #include <sys/param.h>
10 #include <sys/utsname.h> 10 #include <sys/utsname.h>
11 #include <unistd.h> 11 #include <unistd.h>
12 12
13 #include "base/basictypes.h" 13 #include "base/basictypes.h"
14 #include "base/file_util.h" 14 #include "base/file_util.h"
15 #include "base/logging.h" 15 #include "base/logging.h"
16 #include "base/threading/thread_restrictions.h"
16 #include "base/utf_string_conversions.h" 17 #include "base/utf_string_conversions.h"
17 18
18 #if defined(OS_ANDROID) 19 #if defined(OS_ANDROID)
19 #include <sys/vfs.h> 20 #include <sys/vfs.h>
20 #define statvfs statfs // Android uses a statvfs-like statfs struct and call. 21 #define statvfs statfs // Android uses a statvfs-like statfs struct and call.
21 #else 22 #else
22 #include <sys/statvfs.h> 23 #include <sys/statvfs.h>
23 #endif 24 #endif
24 25
25 namespace base { 26 namespace base {
26 27
27 #if !defined(OS_OPENBSD) 28 #if !defined(OS_OPENBSD)
28 int SysInfo::NumberOfProcessors() { 29 int SysInfo::NumberOfProcessors() {
29 // It seems that sysconf returns the number of "logical" processors on both 30 // It seems that sysconf returns the number of "logical" processors on both
30 // Mac and Linux. So we get the number of "online logical" processors. 31 // Mac and Linux. So we get the number of "online logical" processors.
31 long res = sysconf(_SC_NPROCESSORS_ONLN); 32 long res = sysconf(_SC_NPROCESSORS_ONLN);
32 if (res == -1) { 33 if (res == -1) {
33 NOTREACHED(); 34 NOTREACHED();
34 return 1; 35 return 1;
35 } 36 }
36 37
37 return static_cast<int>(res); 38 return static_cast<int>(res);
38 } 39 }
39 #endif 40 #endif
40 41
41 // static 42 // static
42 int64 SysInfo::AmountOfFreeDiskSpace(const FilePath& path) { 43 int64 SysInfo::AmountOfFreeDiskSpace(const FilePath& path) {
44 base::ThreadRestrictions::AssertIOAllowed();
45
43 struct statvfs stats; 46 struct statvfs stats;
44 if (statvfs(path.value().c_str(), &stats) != 0) { 47 if (statvfs(path.value().c_str(), &stats) != 0) {
45 return -1; 48 return -1;
46 } 49 }
47 return static_cast<int64>(stats.f_bavail) * stats.f_frsize; 50 return static_cast<int64>(stats.f_bavail) * stats.f_frsize;
48 } 51 }
49 52
50 #if !defined(OS_MACOSX) 53 #if !defined(OS_MACOSX)
51 // static 54 // static
52 std::string SysInfo::OperatingSystemName() { 55 std::string SysInfo::OperatingSystemName() {
(...skipping 25 matching lines...) Expand all
78 } 81 }
79 return std::string(info.machine); 82 return std::string(info.machine);
80 } 83 }
81 84
82 // static 85 // static
83 size_t SysInfo::VMAllocationGranularity() { 86 size_t SysInfo::VMAllocationGranularity() {
84 return getpagesize(); 87 return getpagesize();
85 } 88 }
86 89
87 } // namespace base 90 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | base/sys_info_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698