[email protected] | 2a758d61 | 2008-09-17 10:09:39 | [diff] [blame] | 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 | |
[email protected] | d632798e | 2008-09-17 13:10:45 | [diff] [blame] | 8 | #include "base/basictypes.h" |
| 9 | |
[email protected] | 0e91dd2 | 2008-09-18 12:34:24 | [diff] [blame] | 10 | #include <string> |
| 11 | |
[email protected] | 2a758d61 | 2008-09-17 10:09:39 | [diff] [blame] | 12 | namespace base { |
| 13 | |
| 14 | class SysInfo { |
| 15 | public: |
| 16 | // Return the number of logical processors/cores on the current machine. |
[email protected] | 71aa16c | 2009-02-24 16:37:13 | [diff] [blame^] | 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. |
[email protected] | 2a758d61 | 2008-09-17 10:09:39 | [diff] [blame] | 19 | static int NumberOfProcessors(); |
[email protected] | 5965842 | 2009-02-11 02:01:51 | [diff] [blame] | 20 | |
[email protected] | d632798e | 2008-09-17 13:10:45 | [diff] [blame] | 21 | // Return the number of bytes of physical memory on the current machine. |
| 22 | static int64 AmountOfPhysicalMemory(); |
[email protected] | fadf97f | 2008-09-18 12:18:14 | [diff] [blame] | 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 | } |
[email protected] | 0e91dd2 | 2008-09-18 12:34:24 | [diff] [blame] | 28 | |
[email protected] | 02ee34a | 2008-09-20 01:16:23 | [diff] [blame] | 29 | // Return the available disk space in bytes on the volume containing |path|, |
| 30 | // or -1 on failure. |
[email protected] | 0e91dd2 | 2008-09-18 12:34:24 | [diff] [blame] | 31 | static int64 AmountOfFreeDiskSpace(const std::wstring& path); |
| 32 | |
[email protected] | 05f9b68 | 2008-09-29 22:18:01 | [diff] [blame] | 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 | |
[email protected] | 71aa16c | 2009-02-24 16:37:13 | [diff] [blame^] | 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 *major_version, |
| 54 | int32 *minor_version, |
| 55 | int32 *bugfix_version); |
| 56 | |
[email protected] | 05f9b68 | 2008-09-29 22:18:01 | [diff] [blame] | 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(); |
[email protected] | 037fce0 | 2009-01-22 01:42:15 | [diff] [blame] | 67 | |
| 68 | // Return the smallest amount of memory (in bytes) which the VM system will |
| 69 | // allocate. |
| 70 | static size_t VMAllocationGranularity(); |
[email protected] | 5965842 | 2009-02-11 02:01:51 | [diff] [blame] | 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 |
[email protected] | 2a758d61 | 2008-09-17 10:09:39 | [diff] [blame] | 79 | }; |
| 80 | |
| 81 | } // namespace base |
| 82 | |
| 83 | #endif // BASE_SYS_INFO_H_ |