|
1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. |
|
2 // Use of this source code is governed by a BSD-style license that can be |
|
3 // found in the LICENSE file. |
|
4 |
|
5 #ifndef BASE_SYS_INFO_H_ |
|
6 #define BASE_SYS_INFO_H_ |
|
7 |
|
8 #include "base/basictypes.h" |
|
9 |
|
10 #include <string> |
|
11 |
|
12 namespace base { |
|
13 |
|
14 class SysInfo { |
|
15 public: |
|
16 // Return the number of logical processors/cores on the current machine. |
|
17 // WARNING: On POSIX, this method uses static variables and is not threadsafe |
|
18 // until it's been initialized by being called once without a race. |
|
19 static int NumberOfProcessors(); |
|
20 |
|
21 // Return the number of bytes of physical memory on the current machine. |
|
22 static int64_t AmountOfPhysicalMemory(); |
|
23 |
|
24 // Return the number of megabytes of physical memory on the current machine. |
|
25 static int AmountOfPhysicalMemoryMB() { |
|
26 return static_cast<int>(AmountOfPhysicalMemory() / 1024 / 1024); |
|
27 } |
|
28 |
|
29 // Return the available disk space in bytes on the volume containing |path|, |
|
30 // or -1 on failure. |
|
31 static int64_t AmountOfFreeDiskSpace(const std::wstring& path); |
|
32 |
|
33 // Return true if the given environment variable is defined. |
|
34 // TODO: find a better place for HasEnvVar. |
|
35 static bool HasEnvVar(const wchar_t* var); |
|
36 |
|
37 // Return the value of the given environment variable |
|
38 // or an empty string if not defined. |
|
39 // TODO: find a better place for GetEnvVar. |
|
40 static std::wstring GetEnvVar(const wchar_t* var); |
|
41 |
|
42 // Returns the name of the host operating system. |
|
43 static std::string OperatingSystemName(); |
|
44 |
|
45 // Returns the version of the host operating system. |
|
46 static std::string OperatingSystemVersion(); |
|
47 |
|
48 // Retrieves detailed numeric values for the OS version. |
|
49 // WARNING: On OS X, this method uses static variables and is not threadsafe |
|
50 // until it's been initialized by being called once without a race. |
|
51 // TODO(port): Implement a Linux version of this method and enable the |
|
52 // corresponding unit test. |
|
53 static void OperatingSystemVersionNumbers(int32_t *major_version, |
|
54 int32_t *minor_version, |
|
55 int32_t *bugfix_version); |
|
56 |
|
57 // Returns the CPU architecture of the system. Exact return value may differ |
|
58 // across platforms. |
|
59 static std::string CPUArchitecture(); |
|
60 |
|
61 // Returns the pixel dimensions of the primary display via the |
|
62 // width and height parameters. |
|
63 static void GetPrimaryDisplayDimensions(int* width, int* height); |
|
64 |
|
65 // Return the number of displays. |
|
66 static int DisplayCount(); |
|
67 |
|
68 // Return the smallest amount of memory (in bytes) which the VM system will |
|
69 // allocate. |
|
70 static size_t VMAllocationGranularity(); |
|
71 |
|
72 #if defined(OS_MACOSX) |
|
73 // Under the OS X Sandbox, our access to the system is limited, this call |
|
74 // caches the system info on startup before we turn the Sandbox on. |
|
75 // The above functions are all wired up to return the cached value so the rest |
|
76 // of the code can call them in the Sandbox without worrying. |
|
77 static void CacheSysInfo(); |
|
78 #endif |
|
79 }; |
|
80 |
|
81 } // namespace base |
|
82 |
|
83 #endif // BASE_SYS_INFO_H_ |