OLD | NEW |
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 #ifndef BASE_WIN_WINDOWS_VERSION_H_ | 5 #ifndef BASE_WIN_WINDOWS_VERSION_H_ |
6 #define BASE_WIN_WINDOWS_VERSION_H_ | 6 #define BASE_WIN_WINDOWS_VERSION_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/base_api.h" | 9 #include "base/base_api.h" |
| 10 #include "base/memory/singleton.h" |
10 | 11 |
11 typedef void* HANDLE; | 12 typedef void* HANDLE; |
12 | 13 |
13 namespace base { | 14 namespace base { |
14 namespace win { | 15 namespace win { |
15 | 16 |
| 17 // The running version of Windows. This is declared outside OSInfo for |
| 18 // syntactic sugar reasons; see the declaration of GetVersion() below. |
16 // NOTE: Keep these in order so callers can do things like | 19 // NOTE: Keep these in order so callers can do things like |
17 // "if (GetWinVersion() > WINVERSION_2000) ...". It's OK to change the values, | 20 // "if (base::win::GetVersion() >= base::win::VERSION_VISTA) ...". |
18 // though. | |
19 enum Version { | 21 enum Version { |
20 VERSION_PRE_2000 = 0, // Not supported | 22 VERSION_PRE_XP = 0, // Not supported. |
21 VERSION_2000 = 1, // Not supported | 23 VERSION_XP, |
22 VERSION_XP = 2, | 24 VERSION_SERVER_2003, // Also includes Windows XP Professional x64. |
23 VERSION_SERVER_2003 = 3, // Also includes Windows XP Professional x64 edition | 25 VERSION_VISTA, |
24 VERSION_VISTA = 4, | 26 VERSION_SERVER_2008, |
25 VERSION_2008 = 5, | 27 VERSION_WIN7, |
26 VERSION_WIN7 = 6, | |
27 }; | 28 }; |
28 | 29 |
29 // Returns the running version of Windows. | 30 // A Singleton that can be used to query various pieces of information about the |
30 BASE_API Version GetVersion(); | 31 // OS and process state. |
| 32 class BASE_API OSInfo { |
| 33 public: |
| 34 struct VersionNumber { |
| 35 int major; |
| 36 int minor; |
| 37 int build; |
| 38 }; |
31 | 39 |
32 // Returns the major and minor version of the service pack installed. | 40 struct ServicePack { |
33 BASE_API void GetServicePackLevel(int* major, int* minor); | 41 int major; |
| 42 int minor; |
| 43 }; |
34 | 44 |
35 enum WindowsArchitecture { | 45 // The processor architecture this copy of Windows natively uses. For |
36 X86_ARCHITECTURE, | 46 // example, given an x64-capable processor, we have three possibilities: |
37 X64_ARCHITECTURE, | 47 // 32-bit Chrome running on 32-bit Windows: X86_ARCHITECTURE |
38 IA64_ARCHITECTURE, | 48 // 32-bit Chrome running on 64-bit Windows via WOW64: X64_ARCHITECTURE |
39 OTHER_ARCHITECTURE, | 49 // 64-bit Chrome running on 64-bit Windows: X64_ARCHITECTURE |
| 50 enum WindowsArchitecture { |
| 51 X86_ARCHITECTURE, |
| 52 X64_ARCHITECTURE, |
| 53 IA64_ARCHITECTURE, |
| 54 OTHER_ARCHITECTURE, |
| 55 }; |
| 56 |
| 57 // Whether a process is running under WOW64 (the wrapper that allows 32-bit |
| 58 // processes to run on 64-bit versions of Windows). This will return |
| 59 // WOW64_DISABLED for both "32-bit Chrome on 32-bit Windows" and "64-bit |
| 60 // Chrome on 64-bit Windows". WOW64_UNKNOWN means "an error occurred", e.g. |
| 61 // the process does not have sufficient access rights to determine this. |
| 62 enum WOW64Status { |
| 63 WOW64_DISABLED, |
| 64 WOW64_ENABLED, |
| 65 WOW64_UNKNOWN, |
| 66 }; |
| 67 |
| 68 static OSInfo* GetInstance(); |
| 69 |
| 70 Version version() const { return version_; } |
| 71 // The next two functions return arrays of values, [major, minor(, build)]. |
| 72 VersionNumber version_number() const { return version_number_; } |
| 73 ServicePack service_pack() const { return service_pack_; } |
| 74 WindowsArchitecture architecture() const { return architecture_; } |
| 75 int processors() const { return processors_; } |
| 76 size_t allocation_granularity() const { return allocation_granularity_; } |
| 77 WOW64Status wow64_status() const { return wow64_status_; } |
| 78 |
| 79 // Like wow64_status(), but for the supplied handle instead of the current |
| 80 // process. This doesn't touch member state, so you can bypass the singleton. |
| 81 static WOW64Status GetWOW64StatusForProcess(HANDLE process_handle); |
| 82 |
| 83 private: |
| 84 OSInfo(); |
| 85 ~OSInfo(); |
| 86 |
| 87 Version version_; |
| 88 VersionNumber version_number_; |
| 89 ServicePack service_pack_; |
| 90 WindowsArchitecture architecture_; |
| 91 int processors_; |
| 92 size_t allocation_granularity_; |
| 93 WOW64Status wow64_status_; |
| 94 |
| 95 friend struct DefaultSingletonTraits<OSInfo>; |
| 96 DISALLOW_COPY_AND_ASSIGN(OSInfo); |
40 }; | 97 }; |
41 | 98 |
42 // Returns the processor architecture this copy of Windows natively uses. | 99 // Because this is by far the most commonly-requested value from the above |
43 // For example, given an x64-capable processor, we have three possibilities: | 100 // singleton, we add a global-scope accessor here as syntactic sugar. |
44 // 32-bit Chrome running on 32-bit Windows: X86_ARCHITECTURE | 101 BASE_API Version GetVersion(); |
45 // 32-bit Chrome running on 64-bit Windows via WOW64: X64_ARCHITECTURE | |
46 // 64-bit Chrome running on 64-bit Windows: X64_ARCHITECTURE | |
47 BASE_API WindowsArchitecture GetWindowsArchitecture(); | |
48 | |
49 enum WOW64Status { | |
50 WOW64_DISABLED, | |
51 WOW64_ENABLED, | |
52 WOW64_UNKNOWN, | |
53 }; | |
54 | |
55 // Returns whether this process is running under WOW64 (the wrapper that allows | |
56 // 32-bit processes to run on 64-bit versions of Windows). This will return | |
57 // WOW64_DISABLED for both "32-bit Chrome on 32-bit Windows" and "64-bit Chrome | |
58 // on 64-bit Windows". WOW64_UNKNOWN means "an error occurred", e.g. the | |
59 // process does not have sufficient access rights to determine this. | |
60 BASE_API WOW64Status GetWOW64Status(); | |
61 | |
62 // Like GetWOW64Status(), but for the supplied handle instead of the current | |
63 // process. | |
64 BASE_API WOW64Status GetWOW64StatusForProcess(HANDLE process_handle); | |
65 | 102 |
66 } // namespace win | 103 } // namespace win |
67 } // namespace base | 104 } // namespace base |
68 | 105 |
69 #endif // BASE_WIN_WINDOWS_VERSION_H_ | 106 #endif // BASE_WIN_WINDOWS_VERSION_H_ |
OLD | NEW |