OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 | |
28 // File to look for firmware number in. | 24 // File to look for firmware number in. |
29 static const char kPathFirmware[] = "/var/log/bios_info.txt"; | 25 static const char kPathFirmware[] = "/var/log/bios_info.txt"; |
30 | 26 |
31 VersionLoader::VersionLoader() : backend_(new Backend()) {} | 27 VersionLoader::VersionLoader() : backend_(new Backend()) {} |
32 | 28 |
33 VersionLoader::~VersionLoader() {} | 29 VersionLoader::~VersionLoader() {} |
34 | 30 |
35 // Beginning of line we look for that gives full version number. | 31 // Beginning of line we look for that gives full version number. |
36 // Format: x.x.xx.x (Developer|Official build extra info) board info | 32 // Format: x.x.xx.x (Developer|Official build extra info) board info |
37 // static | 33 // static |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 | 71 |
76 scoped_refptr<GetFirmwareRequest> request(new GetFirmwareRequest(callback)); | 72 scoped_refptr<GetFirmwareRequest> request(new GetFirmwareRequest(callback)); |
77 AddRequest(request, consumer); | 73 AddRequest(request, consumer); |
78 | 74 |
79 g_browser_process->file_thread()->message_loop()->PostTask( | 75 g_browser_process->file_thread()->message_loop()->PostTask( |
80 FROM_HERE, | 76 FROM_HERE, |
81 NewRunnableMethod(backend_.get(), &Backend::GetFirmware, request)); | 77 NewRunnableMethod(backend_.get(), &Backend::GetFirmware, request)); |
82 return request->handle(); | 78 return request->handle(); |
83 } | 79 } |
84 | 80 |
85 void VersionLoader::EnablePlatformVersions(bool enable) { | |
86 backend_.get()->set_parse_as_platform(enable); | |
87 } | |
88 | |
89 // static | 81 // static |
90 std::string VersionLoader::ParseVersion(const std::string& contents, | 82 std::string VersionLoader::ParseVersion(const std::string& contents, |
91 const std::string& prefix) { | 83 const std::string& prefix) { |
92 // The file contains lines such as: | 84 // The file contains lines such as: |
93 // XXX=YYY | 85 // XXX=YYY |
94 // AAA=ZZZ | 86 // AAA=ZZZ |
95 // Split the lines and look for the one that starts with prefix. The version | 87 // Split the lines and look for the one that starts with prefix. The version |
96 // file is small, which is why we don't try and be tricky. | 88 // file is small, which is why we don't try and be tricky. |
97 std::vector<std::string> lines; | 89 std::vector<std::string> lines; |
98 base::SplitString(contents, '\n', &lines); | 90 base::SplitString(contents, '\n', &lines); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 if (request->canceled()) | 132 if (request->canceled()) |
141 return; | 133 return; |
142 | 134 |
143 std::string version; | 135 std::string version; |
144 std::string contents; | 136 std::string contents; |
145 const FilePath file_path(kPathVersion); | 137 const FilePath file_path(kPathVersion); |
146 if (file_util::ReadFileToString(file_path, &contents)) { | 138 if (file_util::ReadFileToString(file_path, &contents)) { |
147 version = ParseVersion( | 139 version = ParseVersion( |
148 contents, | 140 contents, |
149 (format == VERSION_FULL) ? kFullVersionPrefix : kVersionPrefix); | 141 (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 } | |
164 } | 142 } |
165 | 143 |
166 if (format == VERSION_SHORT_WITH_DATE) { | 144 if (format == VERSION_SHORT_WITH_DATE) { |
167 base::PlatformFileInfo fileinfo; | 145 base::PlatformFileInfo fileinfo; |
168 if (file_util::GetFileInfo(file_path, &fileinfo)) { | 146 if (file_util::GetFileInfo(file_path, &fileinfo)) { |
169 base::Time::Exploded ctime; | 147 base::Time::Exploded ctime; |
170 fileinfo.creation_time.UTCExplode(&ctime); | 148 fileinfo.creation_time.UTCExplode(&ctime); |
171 version += StringPrintf("-%02u.%02u.%02u", | 149 version += StringPrintf("-%02u.%02u.%02u", |
172 ctime.year % 100, | 150 ctime.year % 100, |
173 ctime.month, | 151 ctime.month, |
(...skipping 16 matching lines...) Expand all Loading... |
190 const FilePath file_path(kPathFirmware); | 168 const FilePath file_path(kPathFirmware); |
191 if (file_util::ReadFileToString(file_path, &contents)) { | 169 if (file_util::ReadFileToString(file_path, &contents)) { |
192 firmware = ParseFirmware(contents); | 170 firmware = ParseFirmware(contents); |
193 } | 171 } |
194 | 172 |
195 request->ForwardResult(GetFirmwareCallback::TupleType(request->handle(), | 173 request->ForwardResult(GetFirmwareCallback::TupleType(request->handle(), |
196 firmware)); | 174 firmware)); |
197 } | 175 } |
198 | 176 |
199 } // namespace chromeos | 177 } // namespace chromeos |
OLD | NEW |