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

Side by Side Diff: base/sys_info_chromeos.cc

Issue 105293002: Move more file_util functions to base namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "base/sys_info.h" 5 #include "base/sys_info.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/environment.h" 8 #include "base/environment.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 } 49 }
50 50
51 void Parse() { 51 void Parse() {
52 lsb_release_map_.clear(); 52 lsb_release_map_.clear();
53 major_version_ = 0; 53 major_version_ = 0;
54 minor_version_ = 0; 54 minor_version_ = 0;
55 bugfix_version_ = 0; 55 bugfix_version_ = 0;
56 is_running_on_chromeos_ = false; 56 is_running_on_chromeos_ = false;
57 57
58 std::string lsb_release, lsb_release_time_str; 58 std::string lsb_release, lsb_release_time_str;
59 scoped_ptr<base::Environment> env(base::Environment::Create()); 59 scoped_ptr<Environment> env(Environment::Create());
60 bool parsed_from_env = 60 bool parsed_from_env =
61 env->GetVar(kLsbReleaseKey, &lsb_release) && 61 env->GetVar(kLsbReleaseKey, &lsb_release) &&
62 env->GetVar(kLsbReleaseTimeKey, &lsb_release_time_str); 62 env->GetVar(kLsbReleaseTimeKey, &lsb_release_time_str);
63 if (parsed_from_env) { 63 if (parsed_from_env) {
64 double us = 0; 64 double us = 0;
65 if (StringToDouble(lsb_release_time_str, &us)) 65 if (StringToDouble(lsb_release_time_str, &us))
66 lsb_release_time_ = base::Time::FromDoubleT(us); 66 lsb_release_time_ = Time::FromDoubleT(us);
67 } else { 67 } else {
68 // If the LSB_RELEASE and LSB_RELEASE_TIME environment variables are not 68 // If the LSB_RELEASE and LSB_RELEASE_TIME environment variables are not
69 // set, fall back to a blocking read of the lsb_release file. This should 69 // set, fall back to a blocking read of the lsb_release file. This should
70 // only happen in non Chrome OS environments. 70 // only happen in non Chrome OS environments.
71 ThreadRestrictions::ScopedAllowIO allow_io; 71 ThreadRestrictions::ScopedAllowIO allow_io;
72 FilePath path(kLinuxStandardBaseReleaseFile); 72 FilePath path(kLinuxStandardBaseReleaseFile);
73 ReadFileToString(path, &lsb_release); 73 ReadFileToString(path, &lsb_release);
74 base::PlatformFileInfo fileinfo; 74 PlatformFileInfo fileinfo;
75 if (file_util::GetFileInfo(path, &fileinfo)) 75 if (GetFileInfo(path, &fileinfo))
76 lsb_release_time_ = fileinfo.creation_time; 76 lsb_release_time_ = fileinfo.creation_time;
77 } 77 }
78 ParseLsbRelease(lsb_release); 78 ParseLsbRelease(lsb_release);
79 // For debugging: 79 // For debugging:
80 lsb_release_map_[kLsbReleaseSourceKey] = 80 lsb_release_map_[kLsbReleaseSourceKey] =
81 parsed_from_env ? kLsbReleaseSourceEnv : kLsbReleaseSourceFile; 81 parsed_from_env ? kLsbReleaseSourceEnv : kLsbReleaseSourceFile;
82 } 82 }
83 83
84 bool GetLsbReleaseValue(const std::string& key, std::string* value) { 84 bool GetLsbReleaseValue(const std::string& key, std::string* value) {
85 SysInfo::LsbReleaseMap::const_iterator iter = lsb_release_map_.find(key); 85 SysInfo::LsbReleaseMap::const_iterator iter = lsb_release_map_.find(key);
86 if (iter == lsb_release_map_.end()) 86 if (iter == lsb_release_map_.end())
87 return false; 87 return false;
88 *value = iter->second; 88 *value = iter->second;
89 return true; 89 return true;
90 } 90 }
91 91
92 void GetVersionNumbers(int32* major_version, 92 void GetVersionNumbers(int32* major_version,
93 int32* minor_version, 93 int32* minor_version,
94 int32* bugfix_version) { 94 int32* bugfix_version) {
95 *major_version = major_version_; 95 *major_version = major_version_;
96 *minor_version = minor_version_; 96 *minor_version = minor_version_;
97 *bugfix_version = bugfix_version_; 97 *bugfix_version = bugfix_version_;
98 } 98 }
99 99
100 const base::Time& lsb_release_time() const { return lsb_release_time_; } 100 const Time& lsb_release_time() const { return lsb_release_time_; }
101 const SysInfo::LsbReleaseMap& lsb_release_map() const { 101 const SysInfo::LsbReleaseMap& lsb_release_map() const {
102 return lsb_release_map_; 102 return lsb_release_map_;
103 } 103 }
104 bool is_running_on_chromeos() const { return is_running_on_chromeos_; } 104 bool is_running_on_chromeos() const { return is_running_on_chromeos_; }
105 105
106 private: 106 private:
107 void ParseLsbRelease(const std::string& lsb_release) { 107 void ParseLsbRelease(const std::string& lsb_release) {
108 // Parse and cache lsb_release key pairs. There should only be a handful 108 // Parse and cache lsb_release key pairs. There should only be a handful
109 // of entries so the overhead for this will be small, and it can be 109 // of entries so the overhead for this will be small, and it can be
110 // useful for debugging. 110 // useful for debugging.
111 std::vector<std::pair<std::string, std::string> > pairs; 111 std::vector<std::pair<std::string, std::string> > pairs;
112 base::SplitStringIntoKeyValuePairs(lsb_release, '=', '\n', &pairs); 112 SplitStringIntoKeyValuePairs(lsb_release, '=', '\n', &pairs);
113 for (size_t i = 0; i < pairs.size(); ++i) { 113 for (size_t i = 0; i < pairs.size(); ++i) {
114 std::string key, value; 114 std::string key, value;
115 TrimWhitespaceASCII(pairs[i].first, TRIM_ALL, &key); 115 TrimWhitespaceASCII(pairs[i].first, TRIM_ALL, &key);
116 TrimWhitespaceASCII(pairs[i].second, TRIM_ALL, &value); 116 TrimWhitespaceASCII(pairs[i].second, TRIM_ALL, &value);
117 if (key.empty()) 117 if (key.empty())
118 continue; 118 continue;
119 lsb_release_map_[key] = value; 119 lsb_release_map_[key] = value;
120 } 120 }
121 // Parse the version from the first matching recognized version key. 121 // Parse the version from the first matching recognized version key.
122 std::string version; 122 std::string version;
(...skipping 21 matching lines...) Expand all
144 if (GetLsbReleaseValue(kChromeOsReleaseNameKey, &release_name)) { 144 if (GetLsbReleaseValue(kChromeOsReleaseNameKey, &release_name)) {
145 for (size_t i = 0; i < arraysize(kChromeOsReleaseNames); ++i) { 145 for (size_t i = 0; i < arraysize(kChromeOsReleaseNames); ++i) {
146 if (release_name == kChromeOsReleaseNames[i]) { 146 if (release_name == kChromeOsReleaseNames[i]) {
147 is_running_on_chromeos_ = true; 147 is_running_on_chromeos_ = true;
148 break; 148 break;
149 } 149 }
150 } 150 }
151 } 151 }
152 } 152 }
153 153
154 base::Time lsb_release_time_; 154 Time lsb_release_time_;
155 SysInfo::LsbReleaseMap lsb_release_map_; 155 SysInfo::LsbReleaseMap lsb_release_map_;
156 int32 major_version_; 156 int32 major_version_;
157 int32 minor_version_; 157 int32 minor_version_;
158 int32 bugfix_version_; 158 int32 bugfix_version_;
159 bool is_running_on_chromeos_; 159 bool is_running_on_chromeos_;
160 }; 160 };
161 161
162 static LazyInstance<ChromeOSVersionInfo> 162 static LazyInstance<ChromeOSVersionInfo>
163 g_chrome_os_version_info = LAZY_INSTANCE_INITIALIZER; 163 g_chrome_os_version_info = LAZY_INSTANCE_INITIALIZER;
164 164
(...skipping 24 matching lines...) Expand all
189 // static 189 // static
190 std::string SysInfo::GetLsbReleaseBoard() { 190 std::string SysInfo::GetLsbReleaseBoard() {
191 const char kMachineInfoBoard[] = "CHROMEOS_RELEASE_BOARD"; 191 const char kMachineInfoBoard[] = "CHROMEOS_RELEASE_BOARD";
192 std::string board; 192 std::string board;
193 if (!GetLsbReleaseValue(kMachineInfoBoard, &board)) 193 if (!GetLsbReleaseValue(kMachineInfoBoard, &board))
194 board = "unknown"; 194 board = "unknown";
195 return board; 195 return board;
196 } 196 }
197 197
198 // static 198 // static
199 base::Time SysInfo::GetLsbReleaseTime() { 199 Time SysInfo::GetLsbReleaseTime() {
200 return GetChromeOSVersionInfo().lsb_release_time(); 200 return GetChromeOSVersionInfo().lsb_release_time();
201 } 201 }
202 202
203 // static 203 // static
204 bool SysInfo::IsRunningOnChromeOS() { 204 bool SysInfo::IsRunningOnChromeOS() {
205 return GetChromeOSVersionInfo().is_running_on_chromeos(); 205 return GetChromeOSVersionInfo().is_running_on_chromeos();
206 } 206 }
207 207
208 // static 208 // static
209 void SysInfo::SetChromeOSVersionInfoForTest(const std::string& lsb_release, 209 void SysInfo::SetChromeOSVersionInfoForTest(const std::string& lsb_release,
210 const Time& lsb_release_time) { 210 const Time& lsb_release_time) {
211 scoped_ptr<base::Environment> env(base::Environment::Create()); 211 scoped_ptr<Environment> env(Environment::Create());
212 env->SetVar(kLsbReleaseKey, lsb_release); 212 env->SetVar(kLsbReleaseKey, lsb_release);
213 env->SetVar(kLsbReleaseTimeKey, 213 env->SetVar(kLsbReleaseTimeKey,
214 base::DoubleToString(lsb_release_time.ToDoubleT())); 214 DoubleToString(lsb_release_time.ToDoubleT()));
215 g_chrome_os_version_info.Get().Parse(); 215 g_chrome_os_version_info.Get().Parse();
216 } 216 }
217 217
218 } // namespace base 218 } // namespace base
OLDNEW
« no previous file with comments | « base/nix/mime_util_xdg.cc ('k') | chrome/browser/browsing_data/browsing_data_database_helper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698