Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "base/win/windows_version.h" | 5 #include "base/win/windows_version.h" |
| 6 | 6 |
| 7 #include <windows.h> | 7 #include <windows.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 76 LOWORD(file_version_info->fixed_file_info()->dwFileVersionMS); | 76 LOWORD(file_version_info->fixed_file_info()->dwFileVersionMS); |
| 77 const int build = | 77 const int build = |
| 78 HIWORD(file_version_info->fixed_file_info()->dwFileVersionLS); | 78 HIWORD(file_version_info->fixed_file_info()->dwFileVersionLS); |
| 79 return MajorMinorBuildToVersion(major, minor, build); | 79 return MajorMinorBuildToVersion(major, minor, build); |
| 80 } | 80 } |
| 81 | 81 |
| 82 NOTREACHED(); | 82 NOTREACHED(); |
| 83 return VERSION_WIN_LAST; | 83 return VERSION_WIN_LAST; |
| 84 } | 84 } |
| 85 | 85 |
| 86 // Returns the the "UBR" value from the registry. Introduced in Windows 10, | |
| 87 // this undocumented value appears to be similar to a patch number. | |
| 88 // Returns 0 if the value does not exist or it could not be read. | |
| 89 int GetUBR() { | |
| 90 // The values under the CurrentVersion registry hive are mirrored under | |
| 91 // the corresponding Wow6432 hive. | |
| 92 constexpr wchar_t kRegKeyWindowsNTCurrentVersion[] = | |
|
grt (UTC plus 2)
2016/11/15 20:59:09
"static constexpr ..." so that the string isn't pu
Sorin Jianu
2016/11/15 23:03:29
Done.
This had a massive impact, which I admit I
| |
| 93 L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion"; | |
| 94 constexpr wchar_t kRegValUBR[] = L"UBR"; | |
| 95 | |
| 96 base::win::RegKey key; | |
| 97 if (key.Open(HKEY_LOCAL_MACHINE, kRegKeyWindowsNTCurrentVersion, | |
| 98 KEY_QUERY_VALUE) != ERROR_SUCCESS) { | |
| 99 return 0; | |
| 100 } | |
| 101 | |
| 102 DWORD ubr = 0; | |
| 103 key.ReadValueDW(kRegValUBR, &ubr); | |
|
grt (UTC plus 2)
2016/11/15 20:59:09
nit: i would use L"UBR" directly here since using
Sorin Jianu
2016/11/15 23:03:29
Done.
| |
| 104 | |
| 105 return static_cast<int>(ubr); | |
| 106 } | |
| 107 | |
| 86 } // namespace | 108 } // namespace |
| 87 | 109 |
| 88 // static | 110 // static |
| 89 OSInfo* OSInfo::GetInstance() { | 111 OSInfo* OSInfo::GetInstance() { |
| 90 // Note: we don't use the Singleton class because it depends on AtExitManager, | 112 // Note: we don't use the Singleton class because it depends on AtExitManager, |
| 91 // and it's convenient for other modules to use this classs without it. This | 113 // and it's convenient for other modules to use this classs without it. This |
| 92 // pattern is copied from gurl.cc. | 114 // pattern is copied from gurl.cc. |
| 93 static OSInfo* info; | 115 static OSInfo* info; |
| 94 if (!info) { | 116 if (!info) { |
| 95 OSInfo* new_info = new OSInfo(); | 117 OSInfo* new_info = new OSInfo(); |
| 96 if (InterlockedCompareExchangePointer( | 118 if (InterlockedCompareExchangePointer( |
| 97 reinterpret_cast<PVOID*>(&info), new_info, NULL)) { | 119 reinterpret_cast<PVOID*>(&info), new_info, NULL)) { |
| 98 delete new_info; | 120 delete new_info; |
| 99 } | 121 } |
| 100 } | 122 } |
| 101 return info; | 123 return info; |
| 102 } | 124 } |
| 103 | 125 |
| 104 OSInfo::OSInfo() | 126 OSInfo::OSInfo() |
| 105 : version_(VERSION_PRE_XP), | 127 : version_(VERSION_PRE_XP), |
| 106 kernel32_version_(VERSION_PRE_XP), | 128 kernel32_version_(VERSION_PRE_XP), |
| 107 got_kernel32_version_(false), | 129 got_kernel32_version_(false), |
| 108 architecture_(OTHER_ARCHITECTURE), | 130 architecture_(OTHER_ARCHITECTURE), |
| 109 wow64_status_(GetWOW64StatusForProcess(GetCurrentProcess())) { | 131 wow64_status_(GetWOW64StatusForProcess(GetCurrentProcess())) { |
| 110 OSVERSIONINFOEX version_info = { sizeof version_info }; | 132 OSVERSIONINFOEX version_info = { sizeof version_info }; |
| 111 ::GetVersionEx(reinterpret_cast<OSVERSIONINFO*>(&version_info)); | 133 ::GetVersionEx(reinterpret_cast<OSVERSIONINFO*>(&version_info)); |
| 112 version_number_.major = version_info.dwMajorVersion; | 134 version_number_.major = version_info.dwMajorVersion; |
| 113 version_number_.minor = version_info.dwMinorVersion; | 135 version_number_.minor = version_info.dwMinorVersion; |
| 114 version_number_.build = version_info.dwBuildNumber; | 136 version_number_.build = version_info.dwBuildNumber; |
| 137 version_number_.patch = GetUBR(); | |
| 115 version_ = MajorMinorBuildToVersion( | 138 version_ = MajorMinorBuildToVersion( |
| 116 version_number_.major, version_number_.minor, version_number_.build); | 139 version_number_.major, version_number_.minor, version_number_.build); |
| 117 service_pack_.major = version_info.wServicePackMajor; | 140 service_pack_.major = version_info.wServicePackMajor; |
| 118 service_pack_.minor = version_info.wServicePackMinor; | 141 service_pack_.minor = version_info.wServicePackMinor; |
| 119 service_pack_str_ = base::WideToUTF8(version_info.szCSDVersion); | 142 service_pack_str_ = base::WideToUTF8(version_info.szCSDVersion); |
| 120 | 143 |
| 121 SYSTEM_INFO system_info = {}; | 144 SYSTEM_INFO system_info = {}; |
| 122 ::GetNativeSystemInfo(&system_info); | 145 ::GetNativeSystemInfo(&system_info); |
| 123 switch (system_info.wProcessorArchitecture) { | 146 switch (system_info.wProcessorArchitecture) { |
| 124 case PROCESSOR_ARCHITECTURE_INTEL: architecture_ = X86_ARCHITECTURE; break; | 147 case PROCESSOR_ARCHITECTURE_INTEL: architecture_ = X86_ARCHITECTURE; break; |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 222 return WOW64_UNKNOWN; | 245 return WOW64_UNKNOWN; |
| 223 return is_wow64 ? WOW64_ENABLED : WOW64_DISABLED; | 246 return is_wow64 ? WOW64_ENABLED : WOW64_DISABLED; |
| 224 } | 247 } |
| 225 | 248 |
| 226 Version GetVersion() { | 249 Version GetVersion() { |
| 227 return OSInfo::GetInstance()->version(); | 250 return OSInfo::GetInstance()->version(); |
| 228 } | 251 } |
| 229 | 252 |
| 230 } // namespace win | 253 } // namespace win |
| 231 } // namespace base | 254 } // namespace base |
| OLD | NEW |