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

Side by Side Diff: chrome/browser/chromeos/version_loader.cc

Issue 8068028: Remove version hacks for platform version. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Test fix + Nit fix. Created 9 years, 2 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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
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
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
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/version_loader.h ('k') | chrome/browser/ui/webui/options/chromeos/about_page_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698