Index: chrome/browser/chromeos/version_loader.cc |
diff --git a/chrome/browser/chromeos/version_loader.cc b/chrome/browser/chromeos/version_loader.cc |
index 5ee7046e32f1e5d7c5fc38a2879ca5666b3af952..c25c9c5a35d3160e72c8adfe5376aa64fe2ad28a 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); |
} |
} |