Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
michael@0 | 2 | // Use of this source code is governed by a BSD-style license that can be |
michael@0 | 3 | // found in the LICENSE file. |
michael@0 | 4 | |
michael@0 | 5 | #ifndef BASE_WIN_WINDOWS_VERSION_H_ |
michael@0 | 6 | #define BASE_WIN_WINDOWS_VERSION_H_ |
michael@0 | 7 | |
michael@0 | 8 | #include <string> |
michael@0 | 9 | |
michael@0 | 10 | #include "base/base_export.h" |
michael@0 | 11 | #include "base/basictypes.h" |
michael@0 | 12 | |
michael@0 | 13 | typedef void* HANDLE; |
michael@0 | 14 | |
michael@0 | 15 | namespace base { |
michael@0 | 16 | namespace win { |
michael@0 | 17 | |
michael@0 | 18 | // The running version of Windows. This is declared outside OSInfo for |
michael@0 | 19 | // syntactic sugar reasons; see the declaration of GetVersion() below. |
michael@0 | 20 | // NOTE: Keep these in order so callers can do things like |
michael@0 | 21 | // "if (base::win::GetVersion() >= base::win::VERSION_VISTA) ...". |
michael@0 | 22 | enum Version { |
michael@0 | 23 | VERSION_PRE_XP = 0, // Not supported. |
michael@0 | 24 | VERSION_XP, |
michael@0 | 25 | VERSION_SERVER_2003, // Also includes XP Pro x64 and Server 2003 R2. |
michael@0 | 26 | VERSION_VISTA, // Also includes Windows Server 2008. |
michael@0 | 27 | VERSION_WIN7, // Also includes Windows Server 2008 R2. |
michael@0 | 28 | VERSION_WIN8, // Also includes Windows Server 2012. |
michael@0 | 29 | VERSION_WIN8_1, // Code named Windows Blue |
michael@0 | 30 | VERSION_WIN_LAST, // Indicates error condition. |
michael@0 | 31 | }; |
michael@0 | 32 | |
michael@0 | 33 | // A singleton that can be used to query various pieces of information about the |
michael@0 | 34 | // OS and process state. Note that this doesn't use the base Singleton class, so |
michael@0 | 35 | // it can be used without an AtExitManager. |
michael@0 | 36 | class BASE_EXPORT OSInfo { |
michael@0 | 37 | public: |
michael@0 | 38 | struct VersionNumber { |
michael@0 | 39 | int major; |
michael@0 | 40 | int minor; |
michael@0 | 41 | int build; |
michael@0 | 42 | }; |
michael@0 | 43 | |
michael@0 | 44 | struct ServicePack { |
michael@0 | 45 | int major; |
michael@0 | 46 | int minor; |
michael@0 | 47 | }; |
michael@0 | 48 | |
michael@0 | 49 | // The processor architecture this copy of Windows natively uses. For |
michael@0 | 50 | // example, given an x64-capable processor, we have three possibilities: |
michael@0 | 51 | // 32-bit Chrome running on 32-bit Windows: X86_ARCHITECTURE |
michael@0 | 52 | // 32-bit Chrome running on 64-bit Windows via WOW64: X64_ARCHITECTURE |
michael@0 | 53 | // 64-bit Chrome running on 64-bit Windows: X64_ARCHITECTURE |
michael@0 | 54 | enum WindowsArchitecture { |
michael@0 | 55 | X86_ARCHITECTURE, |
michael@0 | 56 | X64_ARCHITECTURE, |
michael@0 | 57 | IA64_ARCHITECTURE, |
michael@0 | 58 | OTHER_ARCHITECTURE, |
michael@0 | 59 | }; |
michael@0 | 60 | |
michael@0 | 61 | // Whether a process is running under WOW64 (the wrapper that allows 32-bit |
michael@0 | 62 | // processes to run on 64-bit versions of Windows). This will return |
michael@0 | 63 | // WOW64_DISABLED for both "32-bit Chrome on 32-bit Windows" and "64-bit |
michael@0 | 64 | // Chrome on 64-bit Windows". WOW64_UNKNOWN means "an error occurred", e.g. |
michael@0 | 65 | // the process does not have sufficient access rights to determine this. |
michael@0 | 66 | enum WOW64Status { |
michael@0 | 67 | WOW64_DISABLED, |
michael@0 | 68 | WOW64_ENABLED, |
michael@0 | 69 | WOW64_UNKNOWN, |
michael@0 | 70 | }; |
michael@0 | 71 | |
michael@0 | 72 | static OSInfo* GetInstance(); |
michael@0 | 73 | |
michael@0 | 74 | Version version() const { return version_; } |
michael@0 | 75 | // The next two functions return arrays of values, [major, minor(, build)]. |
michael@0 | 76 | VersionNumber version_number() const { return version_number_; } |
michael@0 | 77 | ServicePack service_pack() const { return service_pack_; } |
michael@0 | 78 | WindowsArchitecture architecture() const { return architecture_; } |
michael@0 | 79 | int processors() const { return processors_; } |
michael@0 | 80 | size_t allocation_granularity() const { return allocation_granularity_; } |
michael@0 | 81 | WOW64Status wow64_status() const { return wow64_status_; } |
michael@0 | 82 | std::string processor_model_name(); |
michael@0 | 83 | |
michael@0 | 84 | // Like wow64_status(), but for the supplied handle instead of the current |
michael@0 | 85 | // process. This doesn't touch member state, so you can bypass the singleton. |
michael@0 | 86 | static WOW64Status GetWOW64StatusForProcess(HANDLE process_handle); |
michael@0 | 87 | |
michael@0 | 88 | private: |
michael@0 | 89 | OSInfo(); |
michael@0 | 90 | ~OSInfo(); |
michael@0 | 91 | |
michael@0 | 92 | Version version_; |
michael@0 | 93 | VersionNumber version_number_; |
michael@0 | 94 | ServicePack service_pack_; |
michael@0 | 95 | WindowsArchitecture architecture_; |
michael@0 | 96 | int processors_; |
michael@0 | 97 | size_t allocation_granularity_; |
michael@0 | 98 | WOW64Status wow64_status_; |
michael@0 | 99 | std::string processor_model_name_; |
michael@0 | 100 | |
michael@0 | 101 | DISALLOW_COPY_AND_ASSIGN(OSInfo); |
michael@0 | 102 | }; |
michael@0 | 103 | |
michael@0 | 104 | // Because this is by far the most commonly-requested value from the above |
michael@0 | 105 | // singleton, we add a global-scope accessor here as syntactic sugar. |
michael@0 | 106 | BASE_EXPORT Version GetVersion(); |
michael@0 | 107 | |
michael@0 | 108 | } // namespace win |
michael@0 | 109 | } // namespace base |
michael@0 | 110 | |
michael@0 | 111 | #endif // BASE_WIN_WINDOWS_VERSION_H_ |