| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/chromeos/version_loader.h" | 5 #include "chrome/browser/chromeos/version_loader.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| 11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
| 12 #include "base/string_split.h" | 12 #include "base/string_split.h" |
| 13 #include "base/string_util.h" | 13 #include "base/string_util.h" |
| 14 #include "base/stringprintf.h" | 14 #include "base/stringprintf.h" |
| 15 #include "base/threading/thread.h" | 15 #include "base/threading/thread.h" |
| 16 #include "base/time.h" | 16 #include "base/time.h" |
| 17 #include "chrome/browser/browser_process.h" | 17 #include "chrome/browser/browser_process.h" |
| 18 #include "content/browser/browser_thread.h" | 18 #include "content/browser/browser_thread.h" |
| 19 | 19 |
| 20 namespace chromeos { | 20 namespace chromeos { |
| 21 | 21 |
| 22 // File to look for version number in. | 22 // File to look for version number in. |
| 23 static const char kPathVersion[] = "/etc/lsb-release"; | 23 static const char kPathVersion[] = "/etc/lsb-release"; |
| 24 | 24 |
| 25 // TODO(rkc): Remove once we change over the Chrome OS version format. | |
| 26 // Done for http://code.google.com/p/chromium-os/issues/detail?id=15789 | |
| 27 static const size_t kTrimVersion = 2; | |
| 28 | |
| 29 // File to look for firmware number in. | 25 // File to look for firmware number in. |
| 30 static const char kPathFirmware[] = "/var/log/bios_info.txt"; | 26 static const char kPathFirmware[] = "/var/log/bios_info.txt"; |
| 31 | 27 |
| 32 VersionLoader::VersionLoader() : backend_(new Backend()) {} | 28 VersionLoader::VersionLoader() : backend_(new Backend()) {} |
| 33 | 29 |
| 34 VersionLoader::~VersionLoader() {} | 30 VersionLoader::~VersionLoader() {} |
| 35 | 31 |
| 36 // Beginning of line we look for that gives full version number. | 32 // Beginning of line we look for that gives full version number. |
| 37 // Format: x.x.xx.x (Developer|Official build extra info) board info | 33 // Format: x.x.xx.x (Developer|Official build extra info) board info |
| 38 // static | 34 // static |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 | 72 |
| 77 scoped_refptr<GetFirmwareRequest> request(new GetFirmwareRequest(callback)); | 73 scoped_refptr<GetFirmwareRequest> request(new GetFirmwareRequest(callback)); |
| 78 AddRequest(request, consumer); | 74 AddRequest(request, consumer); |
| 79 | 75 |
| 80 g_browser_process->file_thread()->message_loop()->PostTask( | 76 g_browser_process->file_thread()->message_loop()->PostTask( |
| 81 FROM_HERE, | 77 FROM_HERE, |
| 82 NewRunnableMethod(backend_.get(), &Backend::GetFirmware, request)); | 78 NewRunnableMethod(backend_.get(), &Backend::GetFirmware, request)); |
| 83 return request->handle(); | 79 return request->handle(); |
| 84 } | 80 } |
| 85 | 81 |
| 86 void VersionLoader::EnablePlatformVersions(bool enable) { | |
| 87 backend_.get()->set_parse_as_platform(enable); | |
| 88 } | |
| 89 | |
| 90 // static | 82 // static |
| 91 std::string VersionLoader::ParseVersion(const std::string& contents, | 83 std::string VersionLoader::ParseVersion(const std::string& contents, |
| 92 const std::string& prefix) { | 84 const std::string& prefix) { |
| 93 // The file contains lines such as: | 85 // The file contains lines such as: |
| 94 // XXX=YYY | 86 // XXX=YYY |
| 95 // AAA=ZZZ | 87 // AAA=ZZZ |
| 96 // Split the lines and look for the one that starts with prefix. The version | 88 // Split the lines and look for the one that starts with prefix. The version |
| 97 // file is small, which is why we don't try and be tricky. | 89 // file is small, which is why we don't try and be tricky. |
| 98 std::vector<std::string> lines; | 90 std::vector<std::string> lines; |
| 99 base::SplitString(contents, '\n', &lines); | 91 base::SplitString(contents, '\n', &lines); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 if (request->canceled()) | 133 if (request->canceled()) |
| 142 return; | 134 return; |
| 143 | 135 |
| 144 std::string version; | 136 std::string version; |
| 145 std::string contents; | 137 std::string contents; |
| 146 const FilePath file_path(kPathVersion); | 138 const FilePath file_path(kPathVersion); |
| 147 if (file_util::ReadFileToString(file_path, &contents)) { | 139 if (file_util::ReadFileToString(file_path, &contents)) { |
| 148 version = ParseVersion( | 140 version = ParseVersion( |
| 149 contents, | 141 contents, |
| 150 (format == VERSION_FULL) ? kFullVersionPrefix : kVersionPrefix); | 142 (format == VERSION_FULL) ? kFullVersionPrefix : kVersionPrefix); |
| 151 | |
| 152 // TODO(rkc): Fix this once we move to xx.yyy version numbers for Chrome OS | |
| 153 // instead of 0.xx.yyy | |
| 154 // Done for http://code.google.com/p/chromium-os/issues/detail?id=15789 | |
| 155 if (parse_as_platform_) { | |
| 156 if (version.size() > kTrimVersion) { | |
| 157 version = version.substr(kTrimVersion); | |
| 158 // Strip the major version. | |
| 159 size_t first_dot = version.find("."); | |
| 160 if (first_dot != std::string::npos) { | |
| 161 version = version.substr(first_dot + 1); | |
| 162 } | |
| 163 } | |
| 164 } | |
| 165 } | 143 } |
| 166 | 144 |
| 167 if (format == VERSION_SHORT_WITH_DATE) { | 145 if (format == VERSION_SHORT_WITH_DATE) { |
| 168 base::PlatformFileInfo fileinfo; | 146 base::PlatformFileInfo fileinfo; |
| 169 if (file_util::GetFileInfo(file_path, &fileinfo)) { | 147 if (file_util::GetFileInfo(file_path, &fileinfo)) { |
| 170 base::Time::Exploded ctime; | 148 base::Time::Exploded ctime; |
| 171 fileinfo.creation_time.UTCExplode(&ctime); | 149 fileinfo.creation_time.UTCExplode(&ctime); |
| 172 version += base::StringPrintf("-%02u.%02u.%02u", | 150 version += base::StringPrintf("-%02u.%02u.%02u", |
| 173 ctime.year % 100, | 151 ctime.year % 100, |
| 174 ctime.month, | 152 ctime.month, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 191 const FilePath file_path(kPathFirmware); | 169 const FilePath file_path(kPathFirmware); |
| 192 if (file_util::ReadFileToString(file_path, &contents)) { | 170 if (file_util::ReadFileToString(file_path, &contents)) { |
| 193 firmware = ParseFirmware(contents); | 171 firmware = ParseFirmware(contents); |
| 194 } | 172 } |
| 195 | 173 |
| 196 request->ForwardResult(GetFirmwareCallback::TupleType(request->handle(), | 174 request->ForwardResult(GetFirmwareCallback::TupleType(request->handle(), |
| 197 firmware)); | 175 firmware)); |
| 198 } | 176 } |
| 199 | 177 |
| 200 } // namespace chromeos | 178 } // namespace chromeos |
| OLD | NEW |