diff options
author | dgozman@chromium.org <dgozman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-05 11:31:42 +0000 |
---|---|---|
committer | dgozman@chromium.org <dgozman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-05 11:31:42 +0000 |
commit | 8c32ac17b38dee072cf187ba2e0cb69d7ed7970c (patch) | |
tree | efda486e4cc28c7edfb5b4df817ab73da6e543c0 /base | |
parent | 83b3cac95df158f25ee2b74096a21ce5d2f22d3a (diff) | |
download | chromium_src-8c32ac17b38dee072cf187ba2e0cb69d7ed7970c.zip chromium_src-8c32ac17b38dee072cf187ba2e0cb69d7ed7970c.tar.gz chromium_src-8c32ac17b38dee072cf187ba2e0cb69d7ed7970c.tar.bz2 |
Read ChromeOS version numbers from file before sandboxing and cache them.
BUG=chromiumos-os:11573
TEST=Check that user agent in javascript contains correct CrOS version.
Review URL: http://codereview.chromium.org/6771012
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@80438 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r-- | base/sys_info_chromeos.cc | 73 |
1 files changed, 54 insertions, 19 deletions
diff --git a/base/sys_info_chromeos.cc b/base/sys_info_chromeos.cc index 5834389..b15d71b 100644 --- a/base/sys_info_chromeos.cc +++ b/base/sys_info_chromeos.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 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. @@ -7,42 +7,70 @@ #include "base/basictypes.h" #include "base/file_path.h" #include "base/file_util.h" +#include "base/lazy_instance.h" #include "base/string_number_conversions.h" #include "base/string_tokenizer.h" #include "base/threading/thread_restrictions.h" +#include <execinfo.h> + namespace base { -#if defined(GOOGLE_CHROME_BUILD) -static const char kLinuxStandardBaseVersionKey[] = "GOOGLE_RELEASE"; -#else -static const char kLinuxStandardBaseVersionKey[] = "DISTRIB_RELEASE"; -#endif +static const char* kLinuxStandardBaseVersionKeys[] = { + "CHROMEOS_RELEASE_VERSION", + "GOOGLE_RELEASE", + "DISTRIB_RELEASE", + NULL +}; const char kLinuxStandardBaseReleaseFile[] = "/etc/lsb-release"; +struct ChromeOSVersionNumbers { + ChromeOSVersionNumbers() + : major_version(0), + minor_version(0), + bugfix_version(0), + parsed(false) { + } + + int32 major_version; + int32 minor_version; + int32 bugfix_version; + bool parsed; +}; + +static base::LazyInstance<ChromeOSVersionNumbers> + g_chrome_os_version_numbers(base::LINKER_INITIALIZED); + // static void SysInfo::OperatingSystemVersionNumbers(int32 *major_version, int32 *minor_version, int32 *bugfix_version) { - // The other implementations of SysInfo don't block on the disk. - // See http://code.google.com/p/chromium/issues/detail?id=60394 - // Perhaps the caller ought to cache this? - // Temporary allowing while we work the bug out. - base::ThreadRestrictions::ScopedAllowIO allow_io; + if (!g_chrome_os_version_numbers.Get().parsed) { + // The other implementations of SysInfo don't block on the disk. + // See http://code.google.com/p/chromium/issues/detail?id=60394 + // Perhaps the caller ought to cache this? + // Temporary allowing while we work the bug out. + base::ThreadRestrictions::ScopedAllowIO allow_io; - // TODO(cmasone): If this gets called a lot, it may kill performance. - // consider using static variables to cache these values? - FilePath path(kLinuxStandardBaseReleaseFile); - std::string contents; - if (file_util::ReadFileToString(path, &contents)) { - ParseLsbRelease(contents, major_version, minor_version, bugfix_version); + FilePath path(kLinuxStandardBaseReleaseFile); + std::string contents; + if (file_util::ReadFileToString(path, &contents)) { + g_chrome_os_version_numbers.Get().parsed = true; + ParseLsbRelease(contents, + &(g_chrome_os_version_numbers.Get().major_version), + &(g_chrome_os_version_numbers.Get().minor_version), + &(g_chrome_os_version_numbers.Get().bugfix_version)); + } } + *major_version = g_chrome_os_version_numbers.Get().major_version; + *minor_version = g_chrome_os_version_numbers.Get().minor_version; + *bugfix_version = g_chrome_os_version_numbers.Get().bugfix_version; } // static std::string SysInfo::GetLinuxStandardBaseVersionKey() { - return std::string(kLinuxStandardBaseVersionKey); + return std::string(kLinuxStandardBaseVersionKeys[0]); } // static @@ -50,10 +78,17 @@ void SysInfo::ParseLsbRelease(const std::string& lsb_release, int32 *major_version, int32 *minor_version, int32 *bugfix_version) { - size_t version_key_index = lsb_release.find(kLinuxStandardBaseVersionKey); + size_t version_key_index = std::string::npos; + for (int i = 0; kLinuxStandardBaseVersionKeys[i] != NULL; ++i) { + version_key_index = lsb_release.find(kLinuxStandardBaseVersionKeys[i]); + if (std::string::npos != version_key_index) { + break; + } + } if (std::string::npos == version_key_index) { return; } + size_t start_index = lsb_release.find_first_of('=', version_key_index); start_index++; // Move past '='. size_t length = lsb_release.find_first_of('\n', start_index) - start_index; |