diff options
author | jeremy@chromium.org <jeremy@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-02-24 15:40:38 +0000 |
---|---|---|
committer | jeremy@chromium.org <jeremy@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-02-24 15:40:38 +0000 |
commit | 4cc015107e2fcc166da1d9d0debfa3e48f30192c (patch) | |
tree | 92866130e7dec74b6b4ed60b143f864ad52147c0 /base | |
parent | 3e9f7fc1bbd90e6e439180e9cedcc48dc7ac9924 (diff) | |
download | chromium_src-4cc015107e2fcc166da1d9d0debfa3e48f30192c.zip chromium_src-4cc015107e2fcc166da1d9d0debfa3e48f30192c.tar.gz chromium_src-4cc015107e2fcc166da1d9d0debfa3e48f30192c.tar.bz2 |
Fix for Sandboxed WebKit on OS X:
* Cache Gestalt's value since it opens files.
* Do a little cleanup in sys_info while I'm there and add a unit test.
* Label some methods as not being threadsafe on OSX/POSIX.
Review URL: http://codereview.chromium.org/27088
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@10259 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r-- | base/base.xcodeproj/project.pbxproj | 4 | ||||
-rw-r--r-- | base/sys_info.h | 11 | ||||
-rw-r--r-- | base/sys_info_mac.cc | 46 | ||||
-rw-r--r-- | base/sys_info_posix.cc | 10 | ||||
-rw-r--r-- | base/sys_info_unittest.cc | 16 | ||||
-rw-r--r-- | base/sys_info_win.cc | 12 |
6 files changed, 89 insertions, 10 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 |