diff options
author | stevenjb@chromium.org <stevenjb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-09-26 21:51:23 +0000 |
---|---|---|
committer | stevenjb@chromium.org <stevenjb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-09-26 21:51:23 +0000 |
commit | a0a1c5a43129c46aec7525f0292ebe17434b77e6 (patch) | |
tree | 089aef99bd9338ad9a30a9ba358f85cbe7ae8e2e /chrome | |
parent | 3d3b931e213b1a972233465055c8aae1f1044f75 (diff) | |
download | chromium_src-a0a1c5a43129c46aec7525f0292ebe17434b77e6.zip chromium_src-a0a1c5a43129c46aec7525f0292ebe17434b77e6.tar.gz chromium_src-a0a1c5a43129c46aec7525f0292ebe17434b77e6.tar.bz2 |
Parse /etc/lsb-release only once on ChromeOS
This moves all parsing and caching of the contents of /etc/lsb-release
to base::SysInfo. This eliminates redundant parsing from:
* LsbReleaseLogSource
* VersionLoader
* StatisticsProvider
BUG=266903
For chrome_main_deleagate.cc (code removal only)
R=brettw@chromium.org, derat@chromium.org, pneubeck@chromium.org, xiyuan@chromium.org
TBR=cpu@chromium.org
Review URL: https://codereview.chromium.org/23588009
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@225581 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
17 files changed, 60 insertions, 392 deletions
diff --git a/chrome/app/chrome_main_delegate.cc b/chrome/app/chrome_main_delegate.cc index 08b9e43..2ab55a5 100644 --- a/chrome/app/chrome_main_delegate.cc +++ b/chrome/app/chrome_main_delegate.cc @@ -744,14 +744,6 @@ void ChromeMainDelegate::PreSandboxStartup() { #endif } #endif - -#if defined(OS_CHROMEOS) - // Read and cache ChromeOS version from file, - // to be used from inside the sandbox. - int32 major_version, minor_version, bugfix_version; - base::SysInfo::OperatingSystemVersionNumbers( - &major_version, &minor_version, &bugfix_version); -#endif } void ChromeMainDelegate::SandboxInitialized(const std::string& process_type) { diff --git a/chrome/browser/chromeos/chrome_browser_main_chromeos.cc b/chrome/browser/chromeos/chrome_browser_main_chromeos.cc index d1a6d86..fd251f28 100644 --- a/chrome/browser/chromeos/chrome_browser_main_chromeos.cc +++ b/chrome/browser/chromeos/chrome_browser_main_chromeos.cc @@ -21,6 +21,7 @@ #include "base/prefs/pref_service.h" #include "base/strings/string_number_conversions.h" #include "base/strings/string_split.h" +#include "base/sys_info.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/browser_process_platform_part_chromeos.h" #include "chrome/browser/chrome_notification_types.h" @@ -388,6 +389,13 @@ void ChromeBrowserMainPartsChromeos::PreEarlyInitialization() { // channel info is read and made available early. system::StatisticsProvider::GetInstance()->Init(); +#if defined(GOOGLE_CHROME_BUILD) + const char kChromeOSReleaseTrack[] = "CHROMEOS_RELEASE_TRACK"; + std::string channel; + if (base::SysInfo::GetLsbReleaseValue(kChromeOSReleaseTrack, &channel)) + chrome::VersionInfo::SetChannel(channel); +#endif + ChromeBrowserMainPartsLinux::PreEarlyInitialization(); } diff --git a/chrome/browser/chromeos/extensions/file_manager/private_api_strings.cc b/chrome/browser/chromeos/extensions/file_manager/private_api_strings.cc index fb1d24e..71fcde5 100644 --- a/chrome/browser/chromeos/extensions/file_manager/private_api_strings.cc +++ b/chrome/browser/chromeos/extensions/file_manager/private_api_strings.cc @@ -4,8 +4,8 @@ #include "chrome/browser/chromeos/extensions/file_manager/private_api_strings.h" +#include "base/sys_info.h" #include "chrome/browser/chromeos/file_manager/open_with_browser.h" -#include "chrome/browser/chromeos/system/statistics_provider.h" #include "chrome/common/extensions/extension_l10n_util.h" #include "grit/app_locale_settings.h" #include "grit/generated_resources.h" @@ -516,14 +516,8 @@ bool FileBrowserPrivateGetStringsFunction::RunImpl() { webui::SetFontAndTextDirection(dict); - std::string board; - chromeos::system::StatisticsProvider* provider = - chromeos::system::StatisticsProvider::GetInstance(); - if (!provider->GetMachineStatistic(chromeos::system::kMachineInfoBoard, - &board)) { - board = "unknown"; - } - dict->SetString(chromeos::system::kMachineInfoBoard, board); + dict->SetString("CHROMEOS_RELEASE_BOARD", + base::SysInfo::GetLsbReleaseBoard()); dict->SetString("UI_LOCALE", extension_l10n_util::CurrentLocaleOrDefault()); diff --git a/chrome/browser/chromeos/extensions/info_private_api.cc b/chrome/browser/chromeos/extensions/info_private_api.cc index 7f31d3b..f7b54fc 100644 --- a/chrome/browser/chromeos/extensions/info_private_api.cc +++ b/chrome/browser/chromeos/extensions/info_private_api.cc @@ -4,6 +4,7 @@ #include "chrome/browser/chromeos/extensions/info_private_api.h" +#include "base/sys_info.h" #include "base/values.h" #include "chrome/browser/chromeos/login/startup_utils.h" #include "chrome/browser/chromeos/login/user_manager.h" @@ -79,11 +80,7 @@ base::Value* ChromeosInfoPrivateGetFunction::GetValue( return new base::StringValue( chromeos::StartupUtils::GetInitialLocale()); } else if (property_name == kPropertyBoard) { - std::string board; - chromeos::system::StatisticsProvider* provider = - chromeos::system::StatisticsProvider::GetInstance(); - provider->GetMachineStatistic(chromeos::system::kMachineInfoBoard, &board); - return new base::StringValue(board); + return new base::StringValue(base::SysInfo::GetLsbReleaseBoard()); } else if (property_name == kPropertyOwner) { return Value::CreateBooleanValue( chromeos::UserManager::Get()->IsCurrentUserOwner()); diff --git a/chrome/browser/chromeos/external_metrics.cc b/chrome/browser/chromeos/external_metrics.cc index b0ae298..55d0d3b 100644 --- a/chrome/browser/chromeos/external_metrics.cc +++ b/chrome/browser/chromeos/external_metrics.cc @@ -97,17 +97,8 @@ void SetupProgressiveScanFieldTrial() { } // Finds out if we're on a 2GB Parrot. -// -// This code reads and parses /etc/lsb-release. There are at least four other -// places that open and parse /etc/lsb-release, and I wish I could fix the -// mess. At least this code is temporary. - bool Is2GBParrot() { - base::FilePath path("/etc/lsb-release"); - std::string contents; - if (!base::ReadFileToString(path, &contents)) - return false; - if (contents.find("CHROMEOS_RELEASE_BOARD=parrot") == std::string::npos) + if (base::SysInfo::GetLsbReleaseBoard() != "parrot") return false; // There are 2GB and 4GB models. return base::SysInfo::AmountOfPhysicalMemory() <= 2LL * 1024 * 1024 * 1024; diff --git a/chrome/browser/chromeos/system/statistics_provider.cc b/chrome/browser/chromeos/system/statistics_provider.cc index 8680f94..6de3b6f 100644 --- a/chrome/browser/chromeos/system/statistics_provider.cc +++ b/chrome/browser/chromeos/system/statistics_provider.cc @@ -20,11 +20,6 @@ #include "chromeos/system/name_value_pairs_parser.h" #include "content/public/browser/browser_thread.h" -#if defined(GOOGLE_CHROME_BUILD) -// TODO(phajdan.jr): Drop that dependency, http://crbug.com/180711 . -#include "chrome/common/chrome_version_info.h" -#endif - using content::BrowserThread; namespace chromeos { @@ -56,11 +51,6 @@ const char kEchoCouponFile[] = "/var/cache/echo/vpd_echo.txt"; const char kEchoCouponEq[] = "="; const char kEchoCouponDelim[] = "\n"; -// File to get machine OS info from, and key/value delimiters of the file. -const char kMachineOSInfoFile[] = "/etc/lsb-release"; -const char kMachineOSInfoEq[] = "="; -const char kMachineOSInfoDelim[] = "\n"; - // File to get VPD info from, and key/value delimiters of the file. const char kVpdFile[] = "/var/log/vpd_2.0.txt"; const char kVpdEq[] = "="; @@ -78,8 +68,6 @@ const CommandLine::CharType kOemManifestFilePath[] = // Key values for GetMachineStatistic()/GetMachineFlag() calls. const char kDevSwitchBootMode[] = "devsw_boot"; const char kHardwareClass[] = "hardware_class"; -const char kMachineInfoBoard[] = - "CHROMEOS_RELEASE_BOARD"; const char kOffersCouponCodeKey[] = "ubind_attribute"; const char kOffersGroupCodeKey[] = "gbind_attribute"; const char kOemCanExitEnterpriseEnrollmentKey[] = @@ -113,13 +101,6 @@ class StatisticsProviderImpl : public StatisticsProvider { typedef std::map<std::string, bool> MachineFlags; friend struct DefaultSingletonTraits<StatisticsProviderImpl>; - // Loads the machine info file, which is necessary to get the Chrome channel. - // Treat MachineOSInfoFile specially, as distribution channel information - // (stable, beta, dev, canary) is required at earlier stage than everything - // else. Rather than posting a delayed task, read and parse the machine OS - // info file immediately. - void LoadMachineOSInfoFile(); - // Loads the machine statistcs by examining the system. void LoadMachineStatistics(); @@ -135,9 +116,6 @@ class StatisticsProviderImpl : public StatisticsProvider { void StatisticsProviderImpl::Init() { DCHECK(!initialized_); initialized_ = true; - - // Load the machine info file immediately to get the channel info. - LoadMachineOSInfoFile(); } bool StatisticsProviderImpl::GetMachineStatistic( @@ -201,21 +179,6 @@ StatisticsProviderImpl::StatisticsProviderImpl() false /* initially_signaled */) { } -void StatisticsProviderImpl::LoadMachineOSInfoFile() { - NameValuePairsParser parser(&machine_info_); - if (parser.GetNameValuePairsFromFile(base::FilePath(kMachineOSInfoFile), - kMachineOSInfoEq, - kMachineOSInfoDelim)) { -#if defined(GOOGLE_CHROME_BUILD) - const char kChromeOSReleaseTrack[] = "CHROMEOS_RELEASE_TRACK"; - NameValuePairsParser::NameValueMap::iterator iter = - machine_info_.find(kChromeOSReleaseTrack); - if (iter != machine_info_.end()) - chrome::VersionInfo::SetChannel(iter->second); -#endif - } -} - void StatisticsProviderImpl::StartLoadingMachineStatistics() { DCHECK(initialized_); DCHECK(!load_statistics_started_); diff --git a/chrome/browser/chromeos/system/statistics_provider.h b/chrome/browser/chromeos/system/statistics_provider.h index 48e7dd8..35ab756 100644 --- a/chrome/browser/chromeos/system/statistics_provider.h +++ b/chrome/browser/chromeos/system/statistics_provider.h @@ -16,9 +16,6 @@ extern const char kDevSwitchBootMode[]; // HWID key. extern const char kHardwareClass[]; -// Machine board key. -extern const char kMachineInfoBoard[]; - // OEM customization flag that permits exiting enterprise enrollment flow in // OOBE when 'oem_enterprise_managed' flag is set. extern const char kOemCanExitEnterpriseEnrollmentKey[]; diff --git a/chrome/browser/chromeos/system_logs/lsb_release_log_source.cc b/chrome/browser/chromeos/system_logs/lsb_release_log_source.cc index d6b0564..789673a 100644 --- a/chrome/browser/chromeos/system_logs/lsb_release_log_source.cc +++ b/chrome/browser/chromeos/system_logs/lsb_release_log_source.cc @@ -4,79 +4,21 @@ #include "chrome/browser/chromeos/system_logs/lsb_release_log_source.h" -#include <string> - -#include "base/bind.h" -#include "base/bind_helpers.h" -#include "base/file_util.h" -#include "base/files/file_path.h" -#include "base/logging.h" -#include "base/strings/string_split.h" -#include "base/strings/string_util.h" -#include "content/public/browser/browser_thread.h" - -using content::BrowserThread; - -const char kInvalidLogEntry[] = "<invalid characters in log entry>"; -const char kEmptyLogEntry[] = "<no value>"; - -namespace { - -typedef std::pair<std::string, std::string> KeyValuePair; - -} // namespace +#include "base/memory/scoped_ptr.h" +#include "base/sys_info.h" namespace chromeos { void LsbReleaseLogSource::Fetch(const SysLogsSourceCallback& callback) { DCHECK(!callback.is_null()); - - SystemLogsResponse* response = new SystemLogsResponse; - BrowserThread::PostBlockingPoolTaskAndReply( - FROM_HERE, - base::Bind(&LsbReleaseLogSource::ReadLSBRelease, response), - base::Bind(callback, - base::Owned(response))); -} - -void LsbReleaseLogSource::ReadLSBRelease(SystemLogsResponse* response) { - DCHECK(response); - - const base::FilePath lsb_release_file("/etc/lsb-release"); - std::string lsb_data; - bool read_success = base::ReadFileToString(lsb_release_file, &lsb_data); - // if we were using an internal temp file, the user does not need the - // logs to stay past the ReadFile call - delete the file - if (!read_success) { - LOG(ERROR) << "Can't access /etc/lsb-release file."; - return; - } - ParseLSBRelease(lsb_data, response); -} - -void LsbReleaseLogSource::ParseLSBRelease(const std::string& lsb_data, - SystemLogsResponse* response) { - std::vector<KeyValuePair> pairs; - base::SplitStringIntoKeyValuePairs(lsb_data, '=', '\n', &pairs); - for (size_t i = 0; i < pairs.size(); ++i) { - std::string key, value; - TrimWhitespaceASCII(pairs[i].first, TRIM_ALL, &key); - TrimWhitespaceASCII(pairs[i].second, TRIM_ALL, &value); - - if (key.empty()) - continue; - if (!IsStringUTF8(value) || !IsStringUTF8(key)) { - LOG(WARNING) << "Invalid characters in system log entry: " << key; - (*response)[key] = kInvalidLogEntry; - continue; - } - - if (value.empty()) - (*response)[key] = kEmptyLogEntry; - else - (*response)[key] = value; + scoped_ptr<SystemLogsResponse> response(new SystemLogsResponse); + const base::SysInfo::LsbReleaseMap& lsb_map = + base::SysInfo::GetLsbReleaseMap(); + for (base::SysInfo::LsbReleaseMap::const_iterator iter = lsb_map.begin(); + iter != lsb_map.end(); ++iter) { + (*response)[iter->first] = iter->second; } + callback.Run(response.get()); } } // namespace chromeos - diff --git a/chrome/browser/chromeos/system_logs/lsb_release_log_source.h b/chrome/browser/chromeos/system_logs/lsb_release_log_source.h index 146c7532..29a071a 100644 --- a/chrome/browser/chromeos/system_logs/lsb_release_log_source.h +++ b/chrome/browser/chromeos/system_logs/lsb_release_log_source.h @@ -17,20 +17,7 @@ class LsbReleaseLogSource : public SystemLogsSource { // SystemLogsSource override. virtual void Fetch(const SysLogsSourceCallback& callback) OVERRIDE; - // For testing. Parses a key=value pairs from a string. There can be only one - // pair per line and the value must confine to a single line. - // Example: - // foo = 1 - // bar = 2 - // Note: it automatically strips whitespaces from the front and back of values - // and keys. - static void ParseLSBRelease(const std::string& lsb_data, - SystemLogsResponse* response); - private: - // Gets the info from the /etc/lsb-release and parses it - static void ReadLSBRelease(SystemLogsResponse* response); - DISALLOW_COPY_AND_ASSIGN(LsbReleaseLogSource); }; diff --git a/chrome/browser/chromeos/system_logs/lsb_release_log_source_unittest.cc b/chrome/browser/chromeos/system_logs/lsb_release_log_source_unittest.cc deleted file mode 100644 index 66c1fed7..0000000 --- a/chrome/browser/chromeos/system_logs/lsb_release_log_source_unittest.cc +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright (c) 2012 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 "chrome/browser/chromeos/system_logs/lsb_release_log_source.h" - -#include "base/basictypes.h" -#include "testing/gtest/include/gtest/gtest.h" - -namespace chromeos { - -TEST(LSBReleaseLogSource, BasicFunctionality) { - std::string data("key=value\nkey2 = value2 "); - SystemLogsResponse response; - LsbReleaseLogSource::ParseLSBRelease(data, &response); - EXPECT_EQ(2U, response.size()); - EXPECT_EQ("value", response["key"]); - - // Make sure extra white space is removed correctly. First from the key and - // then from the value. - EXPECT_EQ(1U, response.count("key2")); - EXPECT_EQ("value2", response["key2"]); -} - -TEST(LSBReleaseLogSource, ValueMissing) { - std::string data("key=value\nkey2=\nkey3"); - SystemLogsResponse response; - LsbReleaseLogSource::ParseLSBRelease(data, &response); - EXPECT_EQ(2U, response.size()); - EXPECT_EQ("value", response["key"]); - EXPECT_EQ("<no value>", response["key2"]); - EXPECT_EQ(0U, response.count("key3")); -} - -TEST(LSBReleaseLogSource, BrokenUTF8) { - std::string data("key=value\nkey2=\nkey3=\xFCts\nkey4=value4\nkey5\xFC=foo"); - SystemLogsResponse response; - LsbReleaseLogSource::ParseLSBRelease(data, &response); - EXPECT_EQ("<invalid characters in log entry>", response["key3"]); - EXPECT_EQ("value4", response["key4"]); - EXPECT_EQ(0U, response.count("key5")); -} - -TEST(LSBReleasLogSource, NoKeyValuePair) { - SystemLogsResponse response; - - std::string contents1("random text without a meaning"); - LsbReleaseLogSource::ParseLSBRelease(contents1, &response); - EXPECT_TRUE(response.empty()); -} - -TEST(LSBReleasLogSource, EmptyInput) { - SystemLogsResponse response; - std::string contents2(""); - LsbReleaseLogSource::ParseLSBRelease(contents2, &response); - EXPECT_TRUE(response.empty()); -} - -} // namespace chromeos diff --git a/chrome/browser/chromeos/version_loader.cc b/chrome/browser/chromeos/version_loader.cc index 5ee7046..c25c9c5a 100644 --- a/chrome/browser/chromeos/version_loader.cc +++ b/chrome/browser/chromeos/version_loader.cc @@ -14,6 +14,7 @@ #include "base/strings/string_split.h" #include "base/strings/string_util.h" #include "base/strings/stringprintf.h" +#include "base/sys_info.h" #include "base/threading/sequenced_worker_pool.h" #include "base/threading/thread.h" #include "base/time/time.h" @@ -24,6 +25,19 @@ using content::BrowserThread; namespace { +// Beginning of line we look for that gives full version number. +// Format: x.x.xx.x (Developer|Official build extra info) board info +const char kFullVersionKey[] = "CHROMEOS_RELEASE_DESCRIPTION"; + +// Same but for short version (x.x.xx.x). +const char kVersionKey[] = "CHROMEOS_RELEASE_VERSION"; + +// Beginning of line we look for that gives the firmware version. +const char kFirmwarePrefix[] = "version"; + +// File to look for firmware number in. +const char kPathFirmware[] = "/var/log/bios_info.txt"; + // Converts const string* to const string&. void VersionLoaderCallbackHelper( base::Callback<void(const std::string&)> callback, @@ -35,29 +49,10 @@ void VersionLoaderCallbackHelper( namespace chromeos { -// File to look for version number in. -static const char kPathVersion[] = "/etc/lsb-release"; - -// File to look for firmware number in. -static const char kPathFirmware[] = "/var/log/bios_info.txt"; - VersionLoader::VersionLoader() : backend_(new Backend()) {} VersionLoader::~VersionLoader() {} -// Beginning of line we look for that gives full version number. -// Format: x.x.xx.x (Developer|Official build extra info) board info -// static -const char VersionLoader::kFullVersionPrefix[] = - "CHROMEOS_RELEASE_DESCRIPTION="; - -// Same but for short version (x.x.xx.x). -// static -const char VersionLoader::kVersionPrefix[] = "CHROMEOS_RELEASE_VERSION="; - -// Beginning of line we look for that gives the firmware version. -const char VersionLoader::kFirmwarePrefix[] = "version"; - CancelableTaskTracker::TaskId VersionLoader::GetVersion( VersionFormat format, const GetVersionCallback& callback, @@ -83,30 +78,6 @@ CancelableTaskTracker::TaskId VersionLoader::GetFirmware( } // static -std::string VersionLoader::ParseVersion(const std::string& contents, - const std::string& prefix) { - // The file contains lines such as: - // XXX=YYY - // AAA=ZZZ - // Split the lines and look for the one that starts with prefix. The version - // file is small, which is why we don't try and be tricky. - std::vector<std::string> lines; - base::SplitString(contents, '\n', &lines); - for (size_t i = 0; i < lines.size(); ++i) { - if (StartsWithASCII(lines[i], prefix, false)) { - std::string version = lines[i].substr(std::string(prefix).size()); - if (version.size() > 1 && version[0] == '"' && - version[version.size() - 1] == '"') { - // Trim trailing and leading quotes. - version = version.substr(1, version.size() - 2); - } - return version; - } - } - return std::string(); -} - -// static std::string VersionLoader::ParseFirmware(const std::string& contents) { // The file contains lines such as: // vendor | ... @@ -133,24 +104,18 @@ void VersionLoader::Backend::GetVersion(VersionFormat format, std::string* version) { DCHECK(BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); - std::string contents; - const base::FilePath file_path(kPathVersion); - if (base::ReadFileToString(file_path, &contents)) { - *version = ParseVersion( - contents, - (format == VERSION_FULL) ? kFullVersionPrefix : kVersionPrefix); + std::string key = (format == VERSION_FULL) ? kFullVersionKey : kVersionKey; + if (!base::SysInfo::GetLsbReleaseValue(key, version)) { + LOG(ERROR) << "No LSB version key: " << key; + *version = "0.0.0.0"; } - if (format == VERSION_SHORT_WITH_DATE) { - base::PlatformFileInfo fileinfo; - if (file_util::GetFileInfo(file_path, &fileinfo)) { - base::Time::Exploded ctime; - fileinfo.creation_time.UTCExplode(&ctime); - *version += base::StringPrintf("-%02u.%02u.%02u", - ctime.year % 100, - ctime.month, - ctime.day_of_month); - } + base::Time::Exploded ctime; + base::SysInfo::GetLsbReleaseTime().UTCExplode(&ctime); + *version += base::StringPrintf("-%02u.%02u.%02u", + ctime.year % 100, + ctime.month, + ctime.day_of_month); } } diff --git a/chrome/browser/chromeos/version_loader.h b/chrome/browser/chromeos/version_loader.h index 66a36cd..6361bcb 100644 --- a/chrome/browser/chromeos/version_loader.h +++ b/chrome/browser/chromeos/version_loader.h @@ -53,13 +53,7 @@ class VersionLoader { CancelableTaskTracker::TaskId GetFirmware(const GetFirmwareCallback& callback, CancelableTaskTracker* tracker); - static const char kFullVersionPrefix[]; - static const char kVersionPrefix[]; - static const char kFirmwarePrefix[]; - private: - FRIEND_TEST_ALL_PREFIXES(VersionLoaderTest, ParseFullVersion); - FRIEND_TEST_ALL_PREFIXES(VersionLoaderTest, ParseVersion); FRIEND_TEST_ALL_PREFIXES(VersionLoaderTest, ParseFirmware); // VersionLoader calls into the Backend in the blocking thread pool to load @@ -68,13 +62,12 @@ class VersionLoader { public: Backend() {} - // Calls ParseVersion to get the version # and notifies request. - // This is invoked in the blocking thread pool. - // If |full_version| is true then extra info is passed in version string. + // Gets the version number from base::SysInfo. This is invoked on the + // blocking thread pool. void GetVersion(VersionFormat format, std::string* version); - // Calls ParseFirmware to get the firmware # and notifies request. - // This is invoked in the blocking thread pool. + // Calls ParseFirmware to get the firmware value. This is invoked on the + // blocking thread pool. void GetFirmware(std::string* firmware); private: @@ -85,11 +78,6 @@ class VersionLoader { DISALLOW_COPY_AND_ASSIGN(Backend); }; - // Extracts the version from the file. - // |prefix| specifies what key defines version data. - static std::string ParseVersion(const std::string& contents, - const std::string& prefix); - // Extracts the firmware from the file. static std::string ParseFirmware(const std::string& contents); diff --git a/chrome/browser/chromeos/version_loader_unittest.cc b/chrome/browser/chromeos/version_loader_unittest.cc index bc2dd6d..7b2ce30 100644 --- a/chrome/browser/chromeos/version_loader_unittest.cc +++ b/chrome/browser/chromeos/version_loader_unittest.cc @@ -12,19 +12,6 @@ namespace chromeos { typedef testing::Test VersionLoaderTest; -static const char kTest1[] = - "DIST_ID=1\nCHROMEOS_RELEASE_DESCRIPTION=0.2.3.3\nFOO=BAR"; -static const char kTest2[] = "DIST_ID=1\nCHROMEOS_RELEASE_DESCRIPTION=0.2.3.3"; -static const char kTest3[] = "CHROMEOS_RELEASE_DESCRIPTION=\"0.2.3.3\""; -static const char kTest4[] = "CHROMEOS_RELEASE_DESCRIPTION=\"\"\""; -static const char kTest5[] = "CHROMEOS_RELEASE_DESCRIPTION=\"\""; - -static const char kTest6[] = - "CHROMEOS_RELEASE_DESCRIPTION=1\nCHROMEOS_RELEASE_VERSION=0.2.3.3\nFOO=BAR"; -static const char kTest7[] = "DIST_ID=1\nCHROMEOS_RELEASE_VERSION=0.2.3.3"; -static const char kTest8[] = "CHROMEOS_RELEASE_VERSION=\"0.2.3.3\""; -static const char kTest9[] = "CHROMEOS_RELEASE_VERSION=\"\""; - static const char kTest10[] = "vendor | FOO"; static const char kTest11[] = "firmware | FOO"; static const char kTest12[] = "firmware | FOO"; @@ -32,46 +19,10 @@ static const char kTest13[] = "version | 0.2.3.3"; static const char kTest14[] = "version | 0.2.3.3"; static const char kTest15[] = "version 0.2.3.3"; -TEST_F(VersionLoaderTest, ParseFullVersion) { - EXPECT_EQ("0.2.3.3", - VersionLoader::ParseVersion(kTest1, - VersionLoader::kFullVersionPrefix)); - EXPECT_EQ("0.2.3.3", - VersionLoader::ParseVersion(kTest2, - VersionLoader::kFullVersionPrefix)); - EXPECT_EQ("0.2.3.3", - VersionLoader::ParseVersion(kTest3, - VersionLoader::kFullVersionPrefix)); - EXPECT_EQ("\"", - VersionLoader::ParseVersion(kTest4, - VersionLoader::kFullVersionPrefix)); - EXPECT_EQ(std::string(), - VersionLoader::ParseVersion(kTest5, - VersionLoader::kFullVersionPrefix)); - EXPECT_EQ(std::string(), - VersionLoader::ParseVersion(std::string(), - VersionLoader::kFullVersionPrefix)); -} - -TEST_F(VersionLoaderTest, ParseVersion) { - EXPECT_EQ("0.2.3.3", - VersionLoader::ParseVersion(kTest6, - VersionLoader::kVersionPrefix)); - EXPECT_EQ("0.2.3.3", - VersionLoader::ParseVersion(kTest7, - VersionLoader::kVersionPrefix)); - EXPECT_EQ("0.2.3.3", - VersionLoader::ParseVersion(kTest8, - VersionLoader::kVersionPrefix)); - EXPECT_EQ(std::string(), - VersionLoader::ParseVersion(kTest9, - VersionLoader::kFullVersionPrefix)); -} - TEST_F(VersionLoaderTest, ParseFirmware) { - EXPECT_EQ(std::string(), VersionLoader::ParseFirmware(kTest10)); - EXPECT_EQ(std::string(), VersionLoader::ParseFirmware(kTest11)); - EXPECT_EQ(std::string(), VersionLoader::ParseFirmware(kTest12)); + EXPECT_EQ("", VersionLoader::ParseFirmware(kTest10)); + EXPECT_EQ("", VersionLoader::ParseFirmware(kTest11)); + EXPECT_EQ("", VersionLoader::ParseFirmware(kTest12)); EXPECT_EQ("0.2.3.3", VersionLoader::ParseFirmware(kTest13)); EXPECT_EQ("0.2.3.3", VersionLoader::ParseFirmware(kTest14)); EXPECT_EQ("0.2.3.3", VersionLoader::ParseFirmware(kTest15)); diff --git a/chrome/browser/policy/cloud/device_management_service.cc b/chrome/browser/policy/cloud/device_management_service.cc index 4e13def..0e784d0 100644 --- a/chrome/browser/policy/cloud/device_management_service.cc +++ b/chrome/browser/policy/cloud/device_management_service.cc @@ -71,7 +71,6 @@ const int kPolicyNotFound = 902; // This error is not sent as HTTP status code. #if defined(OS_CHROMEOS) // Machine info keys. const char kMachineInfoHWClass[] = "hardware_class"; -const char kMachineInfoBoard[] = "CHROMEOS_RELEASE_BOARD"; #endif bool IsProxyError(const net::URLRequestStatus status) { @@ -177,12 +176,9 @@ const std::string& GetPlatformString() { chromeos::system::StatisticsProvider::GetInstance(); std::string hwclass; - std::string board; - if (!provider->GetMachineStatistic(kMachineInfoHWClass, &hwclass) || - !provider->GetMachineStatistic(kMachineInfoBoard, &board)) { + if (!provider->GetMachineStatistic(kMachineInfoHWClass, &hwclass)) LOG(ERROR) << "Failed to get machine information"; - } - os_name += ",CrOS," + board; + os_name += ",CrOS," + base::SysInfo::GetLsbReleaseBoard(); os_hardware += "," + hwclass; #endif diff --git a/chrome/browser/ui/webui/help/help_handler.cc b/chrome/browser/ui/webui/help/help_handler.cc index 6fdc04f..f1891ac 100644 --- a/chrome/browser/ui/webui/help/help_handler.cc +++ b/chrome/browser/ui/webui/help/help_handler.cc @@ -125,11 +125,6 @@ bool CanChangeChannel() { return false; } -// Pointer to a |StringValue| holding the date of the build date to Chromium -// OS. Because this value is obtained by reading a file, it is cached here to -// prevent the need to read from the file system multiple times unnecessarily. -Value* g_build_date_string = NULL; - #endif // defined(OS_CHROMEOS) } // namespace @@ -343,18 +338,10 @@ void HelpHandler::OnPageLoaded(const ListValue* args) { "help.HelpPage.updateEnableReleaseChannel", base::FundamentalValue(CanChangeChannel())); - if (g_build_date_string == NULL) { - // If |g_build_date_string| is |NULL|, the date has not yet been assigned. - // Get the date of the last lsb-release file modification. - base::FileUtilProxy::GetFileInfo( - BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE).get(), - base::SysInfo::GetLsbReleaseFilePath(), - base::Bind(&HelpHandler::ProcessLsbFileInfo, - weak_factory_.GetWeakPtr())); - } else { - web_ui()->CallJavascriptFunction("help.HelpPage.setBuildDate", - *g_build_date_string); - } + base::Time build_time = base::SysInfo::GetLsbReleaseTime(); + string16 build_date = base::TimeFormatFriendlyDate(build_time); + web_ui()->CallJavascriptFunction("help.HelpPage.setBuildDate", + base::StringValue(build_date)); #endif // defined(OS_CHROMEOS) version_updater_->CheckForUpdate( @@ -546,31 +533,4 @@ void HelpHandler::OnTargetChannel(const std::string& channel) { "help.HelpPage.updateTargetChannel", base::StringValue(channel)); } -void HelpHandler::ProcessLsbFileInfo( - base::PlatformFileError error, const base::PlatformFileInfo& file_info) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - - // If |g_build_date_string| is not |NULL|, then the file's information has - // already been retrieved by another tab. - if (g_build_date_string == NULL) { - base::Time time; - if (error == base::PLATFORM_FILE_OK) { - // Retrieves the time at which the Chrome OS build was created. - // Each time a new build is created, /etc/lsb-release is modified with the - // new version numbers of the release. - time = file_info.last_modified; - } else { - // If the time of the build cannot be retrieved, return and do not - // display the "Build Date" section. - return; - } - - // Note that this string will be internationalized. - string16 build_date = base::TimeFormatFriendlyDate(time); - g_build_date_string = Value::CreateStringValue(build_date); - } - - web_ui()->CallJavascriptFunction("help.HelpPage.setBuildDate", - *g_build_date_string); -} #endif // defined(OS_CHROMEOS) diff --git a/chrome/browser/ui/webui/help/help_handler.h b/chrome/browser/ui/webui/help/help_handler.h index 0f25dab..7c657c3 100644 --- a/chrome/browser/ui/webui/help/help_handler.h +++ b/chrome/browser/ui/webui/help/help_handler.h @@ -81,9 +81,6 @@ class HelpHandler : public content::WebUIMessageHandler, void OnOSFirmware(const std::string& firmware); void OnCurrentChannel(const std::string& channel); void OnTargetChannel(const std::string& channel); - - void ProcessLsbFileInfo( - base::PlatformFileError rv, const base::PlatformFileInfo& file_info); #endif // Specialized instance of the VersionUpdater used to update the browser. diff --git a/chrome/chrome_tests_unit.gypi b/chrome/chrome_tests_unit.gypi index cb16621..76b465e 100644 --- a/chrome/chrome_tests_unit.gypi +++ b/chrome/chrome_tests_unit.gypi @@ -716,7 +716,6 @@ 'browser/chromeos/settings/session_manager_operation_unittest.cc', 'browser/chromeos/settings/stub_cros_settings_provider_unittest.cc', 'browser/chromeos/system/automatic_reboot_manager_unittest.cc', - 'browser/chromeos/system_logs/lsb_release_log_source_unittest.cc', 'browser/chromeos/version_loader_unittest.cc', 'browser/command_updater_unittest.cc', 'browser/component_updater/test/component_installers_unittest.cc', |