Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(356)

Unified Diff: chrome/browser/chromeos/version_loader.cc

Issue 6883142: Show ChromeOS bios firmware in about dialog. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/chromeos/version_loader.h ('k') | chrome/browser/chromeos/version_loader_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/chromeos/version_loader.cc
===================================================================
--- chrome/browser/chromeos/version_loader.cc (revision 82505)
+++ chrome/browser/chromeos/version_loader.cc (working copy)
@@ -19,8 +19,11 @@
namespace chromeos {
// File to look for version number in.
-static const char kPath[] = "/etc/lsb-release";
+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()) {
}
@@ -34,6 +37,9 @@
// static
const char VersionLoader::kVersionPrefix[] = "CHROMEOS_RELEASE_VERSION=";
+// Beginning of line we look for that gives the firmware version.
+const char VersionLoader::kFirmwarePrefix[] = "version";
+
VersionLoader::Handle VersionLoader::GetVersion(
CancelableRequestConsumerBase* consumer,
VersionLoader::GetVersionCallback* callback,
@@ -53,6 +59,24 @@
return request->handle();
}
+VersionLoader::Handle VersionLoader::GetFirmware(
+ CancelableRequestConsumerBase* consumer,
+ VersionLoader::GetFirmwareCallback* callback) {
+ if (!g_browser_process->file_thread()) {
+ // This should only happen if Chrome is shutting down, so we don't do
+ // anything.
+ return 0;
+ }
+
+ scoped_refptr<GetFirmwareRequest> request(new GetFirmwareRequest(callback));
+ AddRequest(request, consumer);
+
+ g_browser_process->file_thread()->message_loop()->PostTask(
+ FROM_HERE,
+ NewRunnableMethod(backend_.get(), &Backend::GetFirmware, request));
+ return request->handle();
+}
+
// static
std::string VersionLoader::ParseVersion(const std::string& contents,
const std::string& prefix) {
@@ -77,6 +101,29 @@
return std::string();
}
+// static
+std::string VersionLoader::ParseFirmware(const std::string& contents) {
+ // The file contains lines such as:
+ // vendor | ...
+ // version | ...
+ // release_date | ...
+ // We don't make any assumption that the spaces between "version" and "|" is
+ // fixed. So we just match kFirmwarePrefix at the start of the line and find
+ // the first character that is not "|" or space
+
+ std::vector<std::string> lines;
+ base::SplitString(contents, '\n', &lines);
+ for (size_t i = 0; i < lines.size(); ++i) {
+ if (StartsWithASCII(lines[i], kFirmwarePrefix, false)) {
+ std::string str = lines[i].substr(std::string(kFirmwarePrefix).size());
+ size_t found = str.find_first_not_of("| ");
+ if (found != std::string::npos)
+ return str.substr(found);
+ }
+ }
+ return std::string();
+}
+
void VersionLoader::Backend::GetVersion(
scoped_refptr<GetVersionRequest> request,
VersionFormat format) {
@@ -86,7 +133,7 @@
std::string version;
std::string contents;
- const FilePath file_path(kPath);
+ const FilePath file_path(kPathVersion);
if (file_util::ReadFileToString(file_path, &contents)) {
version = ParseVersion(
contents,
@@ -109,4 +156,21 @@
version));
}
+void VersionLoader::Backend::GetFirmware(
+ scoped_refptr<GetFirmwareRequest> request) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
+ if (request->canceled())
+ return;
+
+ std::string firmware;
+ std::string contents;
+ const FilePath file_path(kPathFirmware);
+ if (file_util::ReadFileToString(file_path, &contents)) {
+ firmware = ParseFirmware(contents);
+ }
+
+ request->ForwardResult(GetFirmwareCallback::TupleType(request->handle(),
+ firmware));
+}
+
} // namespace chromeos
« no previous file with comments | « chrome/browser/chromeos/version_loader.h ('k') | chrome/browser/chromeos/version_loader_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698