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