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

Side by Side Diff: base/sys_info_win.cc

Issue 6713107: Make the windows_version.h functions threadsafe by using a singleton. (Closed) Base URL: svn://chrome-svn/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/sys_info_mac.cc ('k') | base/win/windows_version.h » ('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/sys_info.h" 5 #include "base/sys_info.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 8
9 #include "base/file_path.h" 9 #include "base/file_path.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/stringprintf.h" 12 #include "base/stringprintf.h"
13 #include "base/win/windows_version.h"
13 14
14 namespace base { 15 namespace base {
15 16
16 // static 17 // static
17 int SysInfo::NumberOfProcessors() { 18 int SysInfo::NumberOfProcessors() {
18 SYSTEM_INFO info; 19 return win::OSInfo::GetInstance()->processors();
19 GetSystemInfo(&info);
20 return static_cast<int>(info.dwNumberOfProcessors);
21 } 20 }
22 21
23 // static 22 // static
24 int64 SysInfo::AmountOfPhysicalMemory() { 23 int64 SysInfo::AmountOfPhysicalMemory() {
25 MEMORYSTATUSEX memory_info; 24 MEMORYSTATUSEX memory_info;
26 memory_info.dwLength = sizeof(memory_info); 25 memory_info.dwLength = sizeof(memory_info);
27 if (!GlobalMemoryStatusEx(&memory_info)) { 26 if (!GlobalMemoryStatusEx(&memory_info)) {
28 NOTREACHED(); 27 NOTREACHED();
29 return 0; 28 return 0;
30 } 29 }
(...skipping 16 matching lines...) Expand all
47 return rv; 46 return rv;
48 } 47 }
49 48
50 // static 49 // static
51 std::string SysInfo::OperatingSystemName() { 50 std::string SysInfo::OperatingSystemName() {
52 return "Windows NT"; 51 return "Windows NT";
53 } 52 }
54 53
55 // static 54 // static
56 std::string SysInfo::OperatingSystemVersion() { 55 std::string SysInfo::OperatingSystemVersion() {
57 OSVERSIONINFO info = {0}; 56 win::OSInfo* os_info = win::OSInfo::GetInstance();
58 info.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); 57 win::OSInfo::VersionNumber version_number = os_info->version_number();
59 GetVersionEx(&info); 58 std::string version(StringPrintf("%d.%d", version_number.major,
60 59 version_number.minor));
61 return base::StringPrintf("%lu.%lu", 60 win::OSInfo::ServicePack service_pack = os_info->service_pack();
62 info.dwMajorVersion, info.dwMinorVersion); 61 if (service_pack.major != 0) {
62 version += StringPrintf(" SP%d", service_pack.major);
63 if (service_pack.minor != 0)
64 version += StringPrintf(".%d", service_pack.minor);
65 }
66 return version;
63 } 67 }
64 68
65 // TODO: Implement OperatingSystemVersionComplete, which would include 69 // TODO: Implement OperatingSystemVersionComplete, which would include
66 // patchlevel/service pack number. 70 // patchlevel/service pack number.
67 // See chrome/browser/ui/views/bug_report_view.cc, BugReportView::SetOSVersion. 71 // See chrome/browser/ui/views/bug_report_view.cc, BugReportView::SetOSVersion.
68 72
69 // static 73 // static
70 std::string SysInfo::CPUArchitecture() { 74 std::string SysInfo::CPUArchitecture() {
71 // TODO: Make this vary when we support any other architectures. 75 // TODO: Make this vary when we support any other architectures.
72 return "x86"; 76 return "x86";
73 } 77 }
74 78
75 // static 79 // static
76 void SysInfo::GetPrimaryDisplayDimensions(int* width, int* height) { 80 void SysInfo::GetPrimaryDisplayDimensions(int* width, int* height) {
77 if (width) 81 if (width)
78 *width = GetSystemMetrics(SM_CXSCREEN); 82 *width = GetSystemMetrics(SM_CXSCREEN);
79 83
80 if (height) 84 if (height)
81 *height = GetSystemMetrics(SM_CYSCREEN); 85 *height = GetSystemMetrics(SM_CYSCREEN);
82 } 86 }
83 87
84 // static 88 // static
85 int SysInfo::DisplayCount() { 89 int SysInfo::DisplayCount() {
86 return GetSystemMetrics(SM_CMONITORS); 90 return GetSystemMetrics(SM_CMONITORS);
87 } 91 }
88 92
89 // static 93 // static
90 size_t SysInfo::VMAllocationGranularity() { 94 size_t SysInfo::VMAllocationGranularity() {
91 SYSTEM_INFO sysinfo; 95 return win::OSInfo::GetInstance()->allocation_granularity();
92 GetSystemInfo(&sysinfo);
93
94 return sysinfo.dwAllocationGranularity;
95 } 96 }
96 97
97 // static 98 // static
98 void SysInfo::OperatingSystemVersionNumbers(int32 *major_version, 99 void SysInfo::OperatingSystemVersionNumbers(int32* major_version,
99 int32 *minor_version, 100 int32* minor_version,
100 int32 *bugfix_version) { 101 int32* bugfix_version) {
101 OSVERSIONINFO info = {0}; 102 win::OSInfo* os_info = win::OSInfo::GetInstance();
102 info.dwOSVersionInfoSize = sizeof(info); 103 *major_version = os_info->version_number().major;
103 GetVersionEx(&info); 104 *minor_version = os_info->version_number().minor;
104 *major_version = info.dwMajorVersion;
105 *minor_version = info.dwMinorVersion;
106 *bugfix_version = 0; 105 *bugfix_version = 0;
107 } 106 }
108 107
109 } // namespace base 108 } // namespace base
OLDNEW
« no previous file with comments | « base/sys_info_mac.cc ('k') | base/win/windows_version.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698