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

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

Issue 341044: Move chromeos code to namespace chromeos. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 1 month 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
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/chromeos_version_loader.h" 5 #include "chrome/browser/chromeos/version_loader.h"
6
7 #include <vector>
6 8
7 #include "base/file_path.h" 9 #include "base/file_path.h"
8 #include "base/file_util.h" 10 #include "base/file_util.h"
9 #include "base/message_loop.h" 11 #include "base/message_loop.h"
10 #include "base/string_util.h" 12 #include "base/string_util.h"
11 #include "base/thread.h" 13 #include "base/thread.h"
12 #include "chrome/browser/browser_process.h" 14 #include "chrome/browser/browser_process.h"
13 15
16 namespace chromeos {
17
14 // Beginning of line we look for that gives version number. 18 // Beginning of line we look for that gives version number.
15 static const char kPrefix[] = "CHROMEOS_RELEASE_DESCRIPTION="; 19 static const char kPrefix[] = "CHROMEOS_RELEASE_DESCRIPTION=";
16 20
17 // File to look for version number in. 21 // File to look for version number in.
18 static const char kPath[] = "/etc/lsb-release"; 22 static const char kPath[] = "/etc/lsb-release";
19 23
20 ChromeOSVersionLoader::ChromeOSVersionLoader() : backend_(new Backend()) { 24 VersionLoader::VersionLoader() : backend_(new Backend()) {
21 } 25 }
22 26
23 ChromeOSVersionLoader::Handle ChromeOSVersionLoader::GetVersion( 27 VersionLoader::Handle VersionLoader::GetVersion(
24 CancelableRequestConsumerBase* consumer, 28 CancelableRequestConsumerBase* consumer,
25 ChromeOSVersionLoader::GetVersionCallback* callback) { 29 VersionLoader::GetVersionCallback* callback) {
26 if (!g_browser_process->file_thread()) { 30 if (!g_browser_process->file_thread()) {
27 // This should only happen if Chrome is shutting down, so we don't do 31 // This should only happen if Chrome is shutting down, so we don't do
28 // anything. 32 // anything.
29 return 0; 33 return 0;
30 } 34 }
31 35
32 scoped_refptr<CancelableRequest<GetVersionCallback> > request( 36 scoped_refptr<CancelableRequest<GetVersionCallback> > request(
33 new CancelableRequest<GetVersionCallback>(callback)); 37 new CancelableRequest<GetVersionCallback>(callback));
34 AddRequest(request, consumer); 38 AddRequest(request, consumer);
35 39
36 g_browser_process->file_thread()->message_loop()->PostTask( 40 g_browser_process->file_thread()->message_loop()->PostTask(
37 FROM_HERE, 41 FROM_HERE,
38 NewRunnableMethod(backend_.get(), &Backend::GetVersion, request)); 42 NewRunnableMethod(backend_.get(), &Backend::GetVersion, request));
39 return request->handle(); 43 return request->handle();
40 } 44 }
41 45
42 // static 46 // static
43 std::string ChromeOSVersionLoader::ParseVersion(const std::string& contents) { 47 std::string VersionLoader::ParseVersion(const std::string& contents) {
44 // The file contains lines such as: 48 // The file contains lines such as:
45 // XXX=YYY 49 // XXX=YYY
46 // AAA=ZZZ 50 // AAA=ZZZ
47 // Split the lines and look for the one that starts with kPrefix. The version 51 // Split the lines and look for the one that starts with kPrefix. The version
48 // file is small, which is why we don't try and be tricky. 52 // file is small, which is why we don't try and be tricky.
49 std::vector<std::string> lines; 53 std::vector<std::string> lines;
50 SplitString(contents, '\n', &lines); 54 SplitString(contents, '\n', &lines);
51 for (size_t i = 0; i < lines.size(); ++i) { 55 for (size_t i = 0; i < lines.size(); ++i) {
52 if (StartsWithASCII(lines[i], kPrefix, false)) { 56 if (StartsWithASCII(lines[i], kPrefix, false)) {
53 std::string version = lines[i].substr(std::string(kPrefix).size()); 57 std::string version = lines[i].substr(std::string(kPrefix).size());
54 if (version.size() > 1 && version[0] == '"' && 58 if (version.size() > 1 && version[0] == '"' &&
55 version[version.size() - 1] == '"') { 59 version[version.size() - 1] == '"') {
56 // Trim trailing and leading quotes. 60 // Trim trailing and leading quotes.
57 version = version.substr(1, version.size() - 2); 61 version = version.substr(1, version.size() - 2);
58 } 62 }
59 return version; 63 return version;
60 } 64 }
61 } 65 }
62 return std::string(); 66 return std::string();
63 } 67 }
64 68
65 void ChromeOSVersionLoader::Backend::GetVersion( 69 void VersionLoader::Backend::GetVersion(
66 scoped_refptr<GetVersionRequest> request) { 70 scoped_refptr<GetVersionRequest> request) {
67 if (request->canceled()) 71 if (request->canceled())
68 return; 72 return;
69 73
70 std::string version; 74 std::string version;
71 std::string contents; 75 std::string contents;
72 if (file_util::ReadFileToString(FilePath(kPath), &contents)) 76 if (file_util::ReadFileToString(FilePath(kPath), &contents))
73 version = ParseVersion(contents); 77 version = ParseVersion(contents);
74 request->ForwardResult(GetVersionCallback::TupleType(request->handle(), 78 request->ForwardResult(GetVersionCallback::TupleType(request->handle(),
75 version)); 79 version));
76 } 80 }
81
82 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698