blob: 16b86903920274a177c531b8dfc146e309236e0a [file] [log] [blame]
[email protected]2a758d612008-09-17 10:09:391// 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]d632798e2008-09-17 13:10:458#include "base/basictypes.h"
9
[email protected]0e91dd22008-09-18 12:34:2410#include <string>
11
[email protected]2a758d612008-09-17 10:09:3912namespace base {
13
14class SysInfo {
15 public:
16 // Return the number of logical processors/cores on the current machine.
[email protected]71aa16c2009-02-24 16:37:1317 // 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]2a758d612008-09-17 10:09:3919 static int NumberOfProcessors();
[email protected]59658422009-02-11 02:01:5120
[email protected]d632798e2008-09-17 13:10:4521 // Return the number of bytes of physical memory on the current machine.
22 static int64 AmountOfPhysicalMemory();
[email protected]fadf97f2008-09-18 12:18:1423
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]0e91dd22008-09-18 12:34:2428
[email protected]02ee34a2008-09-20 01:16:2329 // Return the available disk space in bytes on the volume containing |path|,
30 // or -1 on failure.
[email protected]0e91dd22008-09-18 12:34:2431 static int64 AmountOfFreeDiskSpace(const std::wstring& path);
32
[email protected]05f9b682008-09-29 22:18:0133 // 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]71aa16c2009-02-24 16:37:1348 // 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]05f9b682008-09-29 22:18:0157 // 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]037fce02009-01-22 01:42:1567
68 // Return the smallest amount of memory (in bytes) which the VM system will
69 // allocate.
70 static size_t VMAllocationGranularity();
[email protected]59658422009-02-11 02:01:5171
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]2a758d612008-09-17 10:09:3979};
80
81} // namespace base
82
83#endif // BASE_SYS_INFO_H_