| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/chromeos/version_loader.h" | |
| 6 | |
| 7 #include <vector> | |
| 8 | |
| 9 #include "base/files/file_path.h" | |
| 10 #include "base/files/file_util.h" | |
| 11 #include "base/location.h" | |
| 12 #include "base/strings/string_split.h" | |
| 13 #include "base/strings/string_util.h" | |
| 14 #include "base/strings/stringprintf.h" | |
| 15 #include "base/sys_info.h" | |
| 16 #include "base/time/time.h" | |
| 17 | |
| 18 namespace chromeos { | |
| 19 namespace version_loader { | |
| 20 | |
| 21 namespace { | |
| 22 | |
| 23 // Beginning of line we look for that gives full version number. | |
| 24 // Format: x.x.xx.x (Developer|Official build extra info) board info | |
| 25 const char kFullVersionKey[] = "CHROMEOS_RELEASE_DESCRIPTION"; | |
| 26 | |
| 27 // Same but for short version (x.x.xx.x). | |
| 28 const char kVersionKey[] = "CHROMEOS_RELEASE_VERSION"; | |
| 29 | |
| 30 // Beginning of line we look for that gives the firmware version. | |
| 31 const char kFirmwarePrefix[] = "version"; | |
| 32 | |
| 33 // File to look for firmware number in. | |
| 34 const char kPathFirmware[] = "/var/log/bios_info.txt"; | |
| 35 | |
| 36 } // namespace | |
| 37 | |
| 38 std::string GetVersion(VersionFormat format) { | |
| 39 std::string version; | |
| 40 std::string key = (format == VERSION_FULL ? | |
| 41 kFullVersionKey : kVersionKey); | |
| 42 if (!base::SysInfo::GetLsbReleaseValue(key, &version)) { | |
| 43 LOG_IF(ERROR, base::SysInfo::IsRunningOnChromeOS()) | |
| 44 << "No LSB version key: " << key; | |
| 45 version = "0.0.0.0"; | |
| 46 } | |
| 47 if (format == VERSION_SHORT_WITH_DATE) { | |
| 48 base::Time::Exploded ctime; | |
| 49 base::SysInfo::GetLsbReleaseTime().UTCExplode(&ctime); | |
| 50 version += base::StringPrintf("-%02u.%02u.%02u", | |
| 51 ctime.year % 100, | |
| 52 ctime.month, | |
| 53 ctime.day_of_month); | |
| 54 } | |
| 55 | |
| 56 return version; | |
| 57 } | |
| 58 | |
| 59 std::string GetFirmware() { | |
| 60 std::string firmware; | |
| 61 std::string contents; | |
| 62 const base::FilePath file_path(kPathFirmware); | |
| 63 if (base::ReadFileToString(file_path, &contents)) { | |
| 64 firmware = ParseFirmware(contents); | |
| 65 } | |
| 66 return firmware; | |
| 67 } | |
| 68 | |
| 69 std::string ParseFirmware(const std::string& contents) { | |
| 70 // The file contains lines such as: | |
| 71 // vendor | ... | |
| 72 // version | ... | |
| 73 // release_date | ... | |
| 74 // We don't make any assumption that the spaces between "version" and "|" is | |
| 75 // fixed. So we just match kFirmwarePrefix at the start of the line and find | |
| 76 // the first character that is not "|" or space | |
| 77 | |
| 78 std::vector<std::string> lines; | |
| 79 base::SplitString(contents, '\n', &lines); | |
| 80 for (size_t i = 0; i < lines.size(); ++i) { | |
| 81 if (StartsWithASCII(lines[i], kFirmwarePrefix, false)) { | |
| 82 std::string str = lines[i].substr(std::string(kFirmwarePrefix).size()); | |
| 83 size_t found = str.find_first_not_of("| "); | |
| 84 if (found != std::string::npos) | |
| 85 return str.substr(found); | |
| 86 } | |
| 87 } | |
| 88 return std::string(); | |
| 89 } | |
| 90 | |
| 91 } // namespace version_loader | |
| 92 } // namespace chromeos | |
| OLD | NEW |