Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(127)

Side by Side Diff: base/win/windows_version.cc

Issue 6816024: Revert 80819 due to failed tests (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/win/windows_version.h ('k') | chrome/browser/bug_report_util.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #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 "base/logging.h" 9 #include "base/logging.h"
10 10
11 namespace base { 11 namespace base {
12 namespace win { 12 namespace win {
13 13
14 // static 14 Version GetVersion() {
15 OSInfo* OSInfo::GetInstance() { 15 static bool checked_version = false;
16 return Singleton<OSInfo>::get(); 16 static Version win_version = VERSION_PRE_2000;
17 if (!checked_version) {
18 OSVERSIONINFOEX version_info;
19 version_info.dwOSVersionInfoSize = sizeof version_info;
20 GetVersionEx(reinterpret_cast<OSVERSIONINFO*>(&version_info));
21 if (version_info.dwMajorVersion == 5) {
22 switch (version_info.dwMinorVersion) {
23 case 0:
24 win_version = VERSION_2000;
25 break;
26 case 1:
27 win_version = VERSION_XP;
28 break;
29 case 2:
30 default:
31 win_version = VERSION_SERVER_2003;
32 break;
33 }
34 } else if (version_info.dwMajorVersion == 6) {
35 if (version_info.wProductType != VER_NT_WORKSTATION) {
36 // 2008 is 6.0, and 2008 R2 is 6.1.
37 win_version = VERSION_2008;
38 } else {
39 if (version_info.dwMinorVersion == 0) {
40 win_version = VERSION_VISTA;
41 } else {
42 win_version = VERSION_WIN7;
43 }
44 }
45 } else if (version_info.dwMajorVersion > 6) {
46 win_version = VERSION_WIN7;
47 }
48 checked_version = true;
49 }
50 return win_version;
17 } 51 }
18 52
19 OSInfo::OSInfo() 53 void GetServicePackLevel(int* major, int* minor) {
20 : version_(VERSION_PRE_XP), 54 DCHECK(major && minor);
21 architecture_(OTHER_ARCHITECTURE), 55 static bool checked_version = false;
22 wow64_status_(GetWOW64StatusForProcess(GetCurrentProcess())) { 56 static int service_pack_major = -1;
23 OSVERSIONINFOEX version_info = { sizeof version_info }; 57 static int service_pack_minor = -1;
24 GetVersionEx(reinterpret_cast<OSVERSIONINFO*>(&version_info)); 58 if (!checked_version) {
25 version_number_.major = version_info.dwMajorVersion; 59 OSVERSIONINFOEX version_info = {0};
26 version_number_.minor = version_info.dwMinorVersion; 60 version_info.dwOSVersionInfoSize = sizeof(version_info);
27 version_number_.build = version_info.dwBuildNumber; 61 GetVersionEx(reinterpret_cast<OSVERSIONINFOW*>(&version_info));
28 if ((version_number_.major == 5) && (version_number_.minor > 0)) { 62 service_pack_major = version_info.wServicePackMajor;
29 version_ = (version_number_.minor == 1) ? VERSION_XP : VERSION_SERVER_2003; 63 service_pack_minor = version_info.wServicePackMinor;
30 } else if (version_number_.major == 6) { 64 checked_version = true;
31 if (version_info.wProductType == VER_NT_WORKSTATION)
32 version_ = (version_number_.minor == 0) ? VERSION_VISTA : VERSION_WIN7;
33 else
34 version_ = VERSION_SERVER_2008;
35 } else if (version_number_.major > 6) {
36 version_ = VERSION_WIN7;
37 } 65 }
38 service_pack_.major = version_info.wServicePackMajor;
39 service_pack_.minor = version_info.wServicePackMinor;
40 66
41 SYSTEM_INFO system_info = { 0 }; 67 *major = service_pack_major;
68 *minor = service_pack_minor;
69 }
70
71 WindowsArchitecture GetWindowsArchitecture() {
72 SYSTEM_INFO system_info;
42 GetNativeSystemInfo(&system_info); 73 GetNativeSystemInfo(&system_info);
43 switch (system_info.wProcessorArchitecture) { 74 switch (system_info.wProcessorArchitecture) {
44 case PROCESSOR_ARCHITECTURE_INTEL: architecture_ = X86_ARCHITECTURE; break; 75 case PROCESSOR_ARCHITECTURE_INTEL: return X86_ARCHITECTURE;
45 case PROCESSOR_ARCHITECTURE_AMD64: architecture_ = X64_ARCHITECTURE; break; 76 case PROCESSOR_ARCHITECTURE_AMD64: return X64_ARCHITECTURE;
46 case PROCESSOR_ARCHITECTURE_IA64: architecture_ = IA64_ARCHITECTURE; break; 77 case PROCESSOR_ARCHITECTURE_IA64: return IA64_ARCHITECTURE;
78 default: return OTHER_ARCHITECTURE;
47 } 79 }
48 processors_ = system_info.dwNumberOfProcessors;
49 allocation_granularity_ = system_info.dwAllocationGranularity;
50 } 80 }
51 81
52 OSInfo::~OSInfo() { 82 WOW64Status GetWOW64Status() {
83 static WOW64Status wow64_status =
84 GetWOW64StatusForProcess(GetCurrentProcess());
85 return wow64_status;
53 } 86 }
54 87
55 // static 88 WOW64Status GetWOW64StatusForProcess(HANDLE process_handle) {
56 OSInfo::WOW64Status OSInfo::GetWOW64StatusForProcess(HANDLE process_handle) {
57 typedef BOOL (WINAPI* IsWow64ProcessFunc)(HANDLE, PBOOL); 89 typedef BOOL (WINAPI* IsWow64ProcessFunc)(HANDLE, PBOOL);
58 IsWow64ProcessFunc is_wow64_process = reinterpret_cast<IsWow64ProcessFunc>( 90 IsWow64ProcessFunc is_wow64_process = reinterpret_cast<IsWow64ProcessFunc>(
59 GetProcAddress(GetModuleHandle(L"kernel32.dll"), "IsWow64Process")); 91 GetProcAddress(GetModuleHandle(L"kernel32.dll"), "IsWow64Process"));
60 if (!is_wow64_process) 92 if (!is_wow64_process)
61 return WOW64_DISABLED; 93 return WOW64_DISABLED;
62 BOOL is_wow64 = FALSE; 94 BOOL is_wow64 = FALSE;
63 if (!(*is_wow64_process)(process_handle, &is_wow64)) 95 if (!(*is_wow64_process)(process_handle, &is_wow64))
64 return WOW64_UNKNOWN; 96 return WOW64_UNKNOWN;
65 return is_wow64 ? WOW64_ENABLED : WOW64_DISABLED; 97 return is_wow64 ? WOW64_ENABLED : WOW64_DISABLED;
66 } 98 }
67 99
68 Version GetVersion() {
69 return OSInfo::GetInstance()->version();
70 }
71
72 } // namespace win 100 } // namespace win
73 } // namespace base 101 } // namespace base
OLDNEW
« no previous file with comments | « base/win/windows_version.h ('k') | chrome/browser/bug_report_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698