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