summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--base/base.xcodeproj/project.pbxproj4
-rw-r--r--base/sys_info.h11
-rw-r--r--base/sys_info_mac.cc46
-rw-r--r--base/sys_info_posix.cc10
-rw-r--r--base/sys_info_unittest.cc16
-rw-r--r--base/sys_info_win.cc12
-rw-r--r--webkit/glue/webkit_glue.cc18
7 files changed, 93 insertions, 24 deletions
diff --git a/base/base.xcodeproj/project.pbxproj b/base/base.xcodeproj/project.pbxproj
index fb82a52..7df077c 100644
--- a/base/base.xcodeproj/project.pbxproj
+++ b/base/base.xcodeproj/project.pbxproj
@@ -180,6 +180,7 @@
B52C916C0E9428F500208D01 /* clipboard_unittest.cc in Sources */ = {isa = PBXBuildFile; fileRef = B52C916B0E9428F500208D01 /* clipboard_unittest.cc */; };
B53C85280E9C298C000F70AB /* idle_timer.cc in Sources */ = {isa = PBXBuildFile; fileRef = 820EB4EB0E3A60FE009668FC /* idle_timer.cc */; };
B5637CB20EF2D79A004EF692 /* process_util_unittest.cc in Sources */ = {isa = PBXBuildFile; fileRef = 7BD8F4A00E65AA2400034DE9 /* process_util_unittest.cc */; };
+ B57008B60F5426B900932CCC /* sys_info_mac.cc in Sources */ = {isa = PBXBuildFile; fileRef = B57008B50F5426B900932CCC /* sys_info_mac.cc */; };
B57E4D780E9C26340090055D /* idletimer_unittest.cc in Sources */ = {isa = PBXBuildFile; fileRef = B57E4D770E9C26340090055D /* idletimer_unittest.cc */; };
B5A8618E0EC1257900B332C2 /* clipboard.cc in Sources */ = {isa = PBXBuildFile; fileRef = B5A8618D0EC1257900B332C2 /* clipboard.cc */; };
B5C4B9C90F44C2AD003F59F9 /* debug_util_mac.cc in Sources */ = {isa = PBXBuildFile; fileRef = B5C4B9C80F44C2AD003F59F9 /* debug_util_mac.cc */; };
@@ -658,6 +659,7 @@
AE11B49026857EAED66B50E5 /* version.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = version.h; sourceTree = "<group>"; };
B290BFCBD30E45A63758BFC7 /* waitable_event_posix.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = waitable_event_posix.cc; sourceTree = "<group>"; };
B52C916B0E9428F500208D01 /* clipboard_unittest.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = clipboard_unittest.cc; sourceTree = "<group>"; };
+ B57008B50F5426B900932CCC /* sys_info_mac.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = sys_info_mac.cc; sourceTree = "<group>"; };
B57D788E0F26983200685566 /* scoped_file.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = scoped_file.h; sourceTree = "<group>"; };
B57E4D770E9C26340090055D /* idletimer_unittest.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = idletimer_unittest.cc; sourceTree = "<group>"; };
B5A8618D0EC1257900B332C2 /* clipboard.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = clipboard.cc; sourceTree = "<group>"; };
@@ -1065,6 +1067,7 @@
7BAF50A90E50BACB00CA8A07 /* string_util_posix.h */,
7BAF50B10E50BAE700CA8A07 /* string_util_unittest.cc */,
7B6AF6310E80211700F9F9CF /* sys_info.h */,
+ B57008B50F5426B900932CCC /* sys_info_mac.cc */,
7B6AF6320E80211700F9F9CF /* sys_info_posix.cc */,
7B6AF6330E80211700F9F9CF /* sys_info_unittest.cc */,
7B4C5F470E4B6BF900679E8F /* sys_string_conversions.h */,
@@ -1488,6 +1491,7 @@
820EB4F70E3A613F009668FC /* string_piece.cc in Sources */,
829E36460DC0F6AC00819EBF /* string_util.cc in Sources */,
820EB4FA0E3A6178009668FC /* string_util_icu.cc in Sources */,
+ B57008B60F5426B900932CCC /* sys_info_mac.cc in Sources */,
7B6AF6340E80211C00F9F9CF /* sys_info_posix.cc in Sources */,
7B4C5F4A0E4B6BF900679E8F /* sys_string_conversions_mac.mm in Sources */,
E4CE9D7A0E8C1FD400D5378C /* system_monitor.cc in Sources */,
diff --git a/base/sys_info.h b/base/sys_info.h
index 35d371b..16b8690 100644
--- a/base/sys_info.h
+++ b/base/sys_info.h
@@ -14,6 +14,8 @@ namespace base {
class SysInfo {
public:
// Return the number of logical processors/cores on the current machine.
+ // WARNING: On POSIX, this method uses static variables and is not threadsafe
+ // until it's been initialized by being called once without a race.
static int NumberOfProcessors();
// Return the number of bytes of physical memory on the current machine.
@@ -43,6 +45,15 @@ class SysInfo {
// Returns the version of the host operating system.
static std::string OperatingSystemVersion();
+ // Retrieves detailed numeric values for the OS version.
+ // WARNING: On OS X, this method uses static variables and is not threadsafe
+ // until it's been initialized by being called once without a race.
+ // TODO(port): Implement a Linux version of this method and enable the
+ // corresponding unit test.
+ static void OperatingSystemVersionNumbers(int32 *major_version,
+ int32 *minor_version,
+ int32 *bugfix_version);
+
// Returns the CPU architecture of the system. Exact return value may differ
// across platforms.
static std::string CPUArchitecture();
diff --git a/base/sys_info_mac.cc b/base/sys_info_mac.cc
new file mode 100644
index 0000000..cd93ce9
--- /dev/null
+++ b/base/sys_info_mac.cc
@@ -0,0 +1,46 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/sys_info.h"
+
+#include <CoreServices/CoreServices.h>
+
+namespace base {
+
+// static
+void SysInfo::OperatingSystemVersionNumbers(int32 *major_version,
+ int32 *minor_version,
+ int32 *bugfix_version) {
+ static bool is_initialized = false;
+ static int32 major_version_cached = 0;
+ static int32 minor_version_cached = 0;
+ static int32 bugfix_version_cached = 0;
+
+ if (!is_initialized) {
+ // Gestalt can't be called in the sandbox, so we cache its return value.
+ Gestalt(gestaltSystemVersionMajor,
+ reinterpret_cast<SInt32*>(&major_version_cached));
+ Gestalt(gestaltSystemVersionMinor,
+ reinterpret_cast<SInt32*>(&minor_version_cached));
+ Gestalt(gestaltSystemVersionBugFix,
+ reinterpret_cast<SInt32*>(&bugfix_version_cached));
+ is_initialized = true;
+ }
+
+ *major_version = major_version_cached;
+ *minor_version = minor_version_cached;
+ *bugfix_version = bugfix_version_cached;
+}
+
+// static
+void SysInfo::CacheSysInfo() {
+ // Due to startup time concerns [premature optimization?] we only cache values
+ // from functions we know to be called in the renderer & fail when the sandbox
+ // is enabled.
+ NumberOfProcessors();
+ int32 dummy;
+ OperatingSystemVersionNumbers(&dummy, &dummy, &dummy);
+}
+
+} // namespace base
diff --git a/base/sys_info_posix.cc b/base/sys_info_posix.cc
index 61c527a..1d218ce 100644
--- a/base/sys_info_posix.cc
+++ b/base/sys_info_posix.cc
@@ -134,14 +134,4 @@ size_t SysInfo::VMAllocationGranularity() {
return getpagesize();
}
-#if defined(OS_MACOSX)
-// static
-void SysInfo::CacheSysInfo() {
- // Due to startup time concerns [premature optimization?] we only cache values
- // from functions we know to be called in the renderer & fail when the sandbox
- // is enabled.
- NumberOfProcessors();
-}
-#endif
-
} // namespace base
diff --git a/base/sys_info_unittest.cc b/base/sys_info_unittest.cc
index ec43c05..ae86821 100644
--- a/base/sys_info_unittest.cc
+++ b/base/sys_info_unittest.cc
@@ -36,3 +36,19 @@ TEST_F(SysInfoTest, HasEnvVar) {
// Every setup should have PATH...
EXPECT_TRUE(base::SysInfo::HasEnvVar(L"PATH"));
}
+
+// TODO(port): If and when there's a LINUX version of this method, enable this
+// unit test.
+#if defined(OS_WIN) || defined(OS_MACOSX)
+TEST_F(SysInfoTest, OperatingSystemVersionNumbers) {
+ int32 os_major_version = -1;
+ int32 os_minor_version = -1;
+ int32 os_bugfix_version = -1;
+ base::SysInfo::OperatingSystemVersionNumbers(&os_major_version,
+ &os_minor_version,
+ &os_bugfix_version);
+ EXPECT_GT(os_major_version, 0);
+ EXPECT_GT(os_minor_version, 0);
+ EXPECT_GT(os_bugfix_version, 0);
+}
+#endif // OS_WIN || OS_MACOSX
diff --git a/base/sys_info_win.cc b/base/sys_info_win.cc
index a195204..1c10156 100644
--- a/base/sys_info_win.cc
+++ b/base/sys_info_win.cc
@@ -108,4 +108,16 @@ size_t SysInfo::VMAllocationGranularity() {
return sysinfo.dwAllocationGranularity;
}
+// static
+void OperatingSystemVersionNumbers(int32 *major_version,
+ int32 *minor_version,
+ int32 *bugfix_version) {
+ OSVERSIONINFO info = {0};
+ info.dwOSVersionInfoSize = sizeof(info);
+ GetVersionEx(&info);
+ *major_version = info.dwMajorVersion;
+ *minor_version = info.dwMinorVersion;
+ *bugfix_version = 0;
+}
+
} // namespace base
diff --git a/webkit/glue/webkit_glue.cc b/webkit/glue/webkit_glue.cc
index c98c987..cd099b3 100644
--- a/webkit/glue/webkit_glue.cc
+++ b/webkit/glue/webkit_glue.cc
@@ -37,6 +37,7 @@ MSVC_POP_WARNING();
#include "base/file_version_info.h"
#include "base/singleton.h"
#include "base/string_util.h"
+#include "base/sys_info.h"
#include "skia/include/SkBitmap.h"
#include "webkit/glue/event_conversion.h"
#include "webkit/glue/glue_util.h"
@@ -336,20 +337,9 @@ void BuildUserAgent(bool mimic_safari, std::string* result) {
int32 os_major_version = 0;
int32 os_minor_version = 0;
int32 os_bugfix_version = 0;
-#if defined(OS_WIN)
- OSVERSIONINFO info = {0};
- info.dwOSVersionInfoSize = sizeof(info);
- GetVersionEx(&info);
- os_major_version = info.dwMajorVersion;
- os_minor_version = info.dwMinorVersion;
-#elif defined(OS_MACOSX)
- Gestalt(gestaltSystemVersionMajor,
- reinterpret_cast<SInt32*>(&os_major_version));
- Gestalt(gestaltSystemVersionMinor,
- reinterpret_cast<SInt32*>(&os_minor_version));
- Gestalt(gestaltSystemVersionBugFix,
- reinterpret_cast<SInt32*>(&os_bugfix_version));
-#endif
+ base::SysInfo::OperatingSystemVersionNumbers(&os_major_version,
+ &os_minor_version,
+ &os_bugfix_version);
// Get the product name and version, and replace Safari's Version/X string
// with it. This is done to expose our product name in a manner that is