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

Unified Diff: base/sys_info_chromeos.cc

Issue 23904025: Move IsRunningOnChromeOS to SysInfo (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge fix Created 7 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/sys_info.h ('k') | base/sys_info_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/sys_info_chromeos.cc
diff --git a/base/sys_info_chromeos.cc b/base/sys_info_chromeos.cc
index 9d7505e25682f8c33b1f82fb4f8c7cbd06e03c66..e0f8b4f07b46e013a30808642d16b0709628ccd2 100644
--- a/base/sys_info_chromeos.cc
+++ b/base/sys_info_chromeos.cc
@@ -25,8 +25,13 @@ const char* kLinuxStandardBaseVersionKeys[] = {
"GOOGLE_RELEASE",
"DISTRIB_RELEASE",
};
-const size_t kLinuxStandardBaseVersionKeysLength =
- arraysize(kLinuxStandardBaseVersionKeys);
+
+const char kChromeOsReleaseNameKey[] = "CHROMEOS_RELEASE_NAME";
+
+const char* const kChromeOsReleaseNames[] = {
+ "Chrome OS",
+ "Chromium OS",
+};
const char kLinuxStandardBaseReleaseFile[] = "/etc/lsb-release";
@@ -48,6 +53,7 @@ class ChromeOSVersionInfo {
major_version_ = 0;
minor_version_ = 0;
bugfix_version_ = 0;
+ is_running_on_chromeos_ = false;
std::string lsb_release, lsb_release_time_str;
scoped_ptr<base::Environment> env(base::Environment::Create());
@@ -95,6 +101,7 @@ class ChromeOSVersionInfo {
const SysInfo::LsbReleaseMap& lsb_release_map() const {
return lsb_release_map_;
}
+ bool is_running_on_chromeos() const { return is_running_on_chromeos_; }
private:
void ParseLsbRelease(const std::string& lsb_release) {
@@ -113,7 +120,7 @@ class ChromeOSVersionInfo {
}
// Parse the version from the first matching recognized version key.
std::string version;
- for (size_t i = 0; i < kLinuxStandardBaseVersionKeysLength; ++i) {
+ for (size_t i = 0; i < arraysize(kLinuxStandardBaseVersionKeys); ++i) {
std::string key = kLinuxStandardBaseVersionKeys[i];
if (GetLsbReleaseValue(key, &version) && !version.empty())
break;
@@ -131,6 +138,17 @@ class ChromeOSVersionInfo {
StringToInt(StringPiece(tokenizer.token_begin(), tokenizer.token_end()),
&bugfix_version_);
}
+
+ // Check release name for Chrome OS.
+ std::string release_name;
+ if (GetLsbReleaseValue(kChromeOsReleaseNameKey, &release_name)) {
+ for (size_t i = 0; i < arraysize(kChromeOsReleaseNames); ++i) {
+ if (release_name == kChromeOsReleaseNames[i]) {
+ is_running_on_chromeos_ = true;
+ break;
+ }
+ }
+ }
}
base::Time lsb_release_time_;
@@ -138,6 +156,7 @@ class ChromeOSVersionInfo {
int32 major_version_;
int32 minor_version_;
int32 bugfix_version_;
+ bool is_running_on_chromeos_;
};
static LazyInstance<ChromeOSVersionInfo>
@@ -182,6 +201,11 @@ base::Time SysInfo::GetLsbReleaseTime() {
}
// static
+bool SysInfo::IsRunningOnChromeOS() {
+ return GetChromeOSVersionInfo().is_running_on_chromeos();
+}
+
+// static
void SysInfo::SetChromeOSVersionInfoForTest(const std::string& lsb_release,
const Time& lsb_release_time) {
scoped_ptr<base::Environment> env(base::Environment::Create());
« no previous file with comments | « base/sys_info.h ('k') | base/sys_info_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698