summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorevan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-22 00:35:18 +0000
committerevan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-22 00:35:18 +0000
commit61b8ad79a502d0b3666305307e3cba9208a6c2e9 (patch)
tree8a0653f9909ee9b54d7f2982d75f10ae7aec4bd1
parent87fc168b364ef36033f72e545a4894bd7ce9354f (diff)
downloadchromium_src-61b8ad79a502d0b3666305307e3cba9208a6c2e9.zip
chromium_src-61b8ad79a502d0b3666305307e3cba9208a6c2e9.tar.gz
chromium_src-61b8ad79a502d0b3666305307e3cba9208a6c2e9.tar.bz2
Creating a unique user-agent string for ChromeOS builds, so that metrics can be aggregated separately from standard Chrome on Linux
Review URL: http://codereview.chromium.org/155101 Patch from Chris Masone <cmasone@google.com>. git-svn-id: svn://svn.chromium.org/chrome/trunk/src@21247 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--base/base.gyp13
-rw-r--r--base/sys_info.h13
-rw-r--r--base/sys_info_chromeos.cc69
-rw-r--r--base/sys_info_unittest.cc55
-rw-r--r--webkit/glue/webkit_glue.cc11
5 files changed, 152 insertions, 9 deletions
diff --git a/base/base.gyp b/base/base.gyp
index 0937786..25d9e32 100644
--- a/base/base.gyp
+++ b/base/base.gyp
@@ -285,6 +285,7 @@
'string_util_icu.cc',
'string_util_win.h',
'sys_info.h',
+ 'sys_info_chromeos.cc',
'sys_info_mac.cc',
'sys_info_posix.cc',
'sys_info_win.cc',
@@ -415,7 +416,7 @@
'include_dirs': [
'<(SHARED_INTERMEDIATE_DIR)',
],
- 'sources/': [ ['exclude', '_(mac|win)\\.cc$'],
+ 'sources/': [ ['exclude', '_(mac|win|chromeos)\\.cc$'],
['exclude', '\\.mm?$' ] ],
'sources!': [
# Linux has an implementation of idle_timer that depends
@@ -423,6 +424,12 @@
# so use idle_timer_none.cc instead.
'idle_timer.cc',
],
+ 'conditions': [
+ [ 'chromeos==1', {
+ 'sources/': [ ['include', '_chromeos\\.cc$'] ]
+ },
+ ],
+ ],
'dependencies': [
'../build/util/build_util.gyp:lastchange',
'../build/linux/system.gyp:gtk',
@@ -471,7 +478,7 @@
},
],
[ 'OS == "mac"', {
- 'sources/': [ ['exclude', '_(linux|win)\\.cc$'] ],
+ 'sources/': [ ['exclude', '_(linux|win|chromeos)\\.cc$'] ],
'sources!': [
],
'link_settings': {
@@ -492,7 +499,7 @@
}
],
[ 'OS == "win"', {
- 'sources/': [ ['exclude', '_(linux|mac|posix)\\.cc$'],
+ 'sources/': [ ['exclude', '_(linux|mac|posix|chromeos)\\.cc$'],
['exclude', '\\.mm?$' ] ],
'sources!': [
'data_pack.cc',
diff --git a/base/sys_info.h b/base/sys_info.h
index d083377..581720d 100644
--- a/base/sys_info.h
+++ b/base/sys_info.h
@@ -64,6 +64,19 @@ class SysInfo {
// Return the smallest amount of memory (in bytes) which the VM system will
// allocate.
static size_t VMAllocationGranularity();
+
+#if defined(OS_CHROMEOS)
+ // Returns the name of the version entry we wish to look up in the
+ // Linux Standard Base release information file.
+ static std::string GetLinuxStandardBaseVersionKey();
+
+ // Parses /etc/lsb-release to get version information for Google Chrome OS.
+ // Declared here so it can be exposed for unit testing.
+ static void ParseLsbRelease(const std::string& lsb_release,
+ int32 *major_version,
+ int32 *minor_version,
+ int32 *bugfix_version);
+#endif
};
} // namespace base
diff --git a/base/sys_info_chromeos.cc b/base/sys_info_chromeos.cc
new file mode 100644
index 0000000..08827b0
--- /dev/null
+++ b/base/sys_info_chromeos.cc
@@ -0,0 +1,69 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/sys_info.h"
+
+#include "base/basictypes.h"
+#include "base/file_path.h"
+#include "base/file_util.h"
+#include "base/string_tokenizer.h"
+#include "base/string_util.h"
+
+namespace base {
+
+#if defined(OFFICIAL_BUILD)
+static const char kLinuxStandardBaseVersionKey[] = "GOOGLE_RELEASE";
+#else
+static const char kLinuxStandardBaseVersionKey[] = "DISTRIB_RELEASE";
+#endif
+
+const char kLinuxStandardBaseReleaseFile[] = "/etc/lsb-release";
+
+// static
+void SysInfo::OperatingSystemVersionNumbers(int32 *major_version,
+ int32 *minor_version,
+ int32 *bugfix_version) {
+ // TODO(cmasone): If this gets called a lot, it may kill performance.
+ // consider using static variables to cache these values?
+ FilePath path(kLinuxStandardBaseReleaseFile);
+ std::string contents;
+ if (file_util::ReadFileToString(path, &contents)) {
+ ParseLsbRelease(contents, major_version, minor_version, bugfix_version);
+ }
+}
+
+// static
+std::string SysInfo::GetLinuxStandardBaseVersionKey() {
+ return std::string(kLinuxStandardBaseVersionKey);
+}
+
+// static
+void SysInfo::ParseLsbRelease(const std::string& lsb_release,
+ int32 *major_version,
+ int32 *minor_version,
+ int32 *bugfix_version) {
+ size_t version_key_index =
+ lsb_release.find(kLinuxStandardBaseVersionKey,
+ arraysize(kLinuxStandardBaseVersionKey) - 1);
+ if (std::string::npos == version_key_index) {
+ return;
+ }
+ size_t start_index = lsb_release.find_first_of('=', version_key_index);
+ start_index++; // Move past '='.
+ size_t length = lsb_release.find_first_of('\n', start_index) - start_index;
+ std::string version = lsb_release.substr(start_index, length);
+ StringTokenizer tokenizer(version, ".");
+ for (int i = 0; i < 3 && tokenizer.GetNext(); i++) {
+ if (0 == i) {
+ *major_version = StringToInt(tokenizer.token());
+ *minor_version = *bugfix_version = 0;
+ } else if (1 == i) {
+ *minor_version = StringToInt(tokenizer.token());
+ } else { // 2 == i
+ *bugfix_version = StringToInt(tokenizer.token());
+ }
+ }
+}
+
+} // namespace base
diff --git a/base/sys_info_unittest.cc b/base/sys_info_unittest.cc
index 64fcacf..8c5391f 100644
--- a/base/sys_info_unittest.cc
+++ b/base/sys_info_unittest.cc
@@ -37,9 +37,7 @@ TEST_F(SysInfoTest, HasEnvVar) {
EXPECT_TRUE(base::SysInfo::HasEnvVar(L"PATH"));
}
-// TODO(port): If and when there's a LINUX version of this method, enable this
-// unit test.
-#if defined(OS_WIN) || defined(OS_MACOSX)
+#if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_CHROMEOS)
TEST_F(SysInfoTest, OperatingSystemVersionNumbers) {
int32 os_major_version = -1;
int32 os_minor_version = -1;
@@ -51,4 +49,53 @@ TEST_F(SysInfoTest, OperatingSystemVersionNumbers) {
EXPECT_GT(os_minor_version, -1);
EXPECT_GT(os_bugfix_version, -1);
}
-#endif // OS_WIN || OS_MACOSX
+#endif
+
+#if defined(OS_CHROMEOS)
+TEST_F(SysInfoTest, GoogleChromeOSVersionNumbers) {
+ int32 os_major_version = -1;
+ int32 os_minor_version = -1;
+ int32 os_bugfix_version = -1;
+ std::string lsb_release("FOO=1234123.34.5\n");
+ lsb_release.append(base::SysInfo::GetLinuxStandardBaseVersionKey());
+ lsb_release.append("=1.2.3.4\n");
+ base::SysInfo::ParseLsbRelease(lsb_release,
+ &os_major_version,
+ &os_minor_version,
+ &os_bugfix_version);
+ EXPECT_EQ(os_major_version, 1);
+ EXPECT_EQ(os_minor_version, 2);
+ EXPECT_EQ(os_bugfix_version, 3);
+}
+
+TEST_F(SysInfoTest, GoogleChromeOSVersionNumbersFirst) {
+ int32 os_major_version = -1;
+ int32 os_minor_version = -1;
+ int32 os_bugfix_version = -1;
+ std::string lsb_release(base::SysInfo::GetLinuxStandardBaseVersionKey());
+ lsb_release.append("=1.2.3.4\n");
+ lsb_release.append("FOO=1234123.34.5\n");
+ base::SysInfo::ParseLsbRelease(lsb_release,
+ &os_major_version,
+ &os_minor_version,
+ &os_bugfix_version);
+ EXPECT_EQ(os_major_version, 1);
+ EXPECT_EQ(os_minor_version, 2);
+ EXPECT_EQ(os_bugfix_version, 3);
+}
+
+TEST_F(SysInfoTest, GoogleChromeOSNoVersionNumbers) {
+ int32 os_major_version = -1;
+ int32 os_minor_version = -1;
+ int32 os_bugfix_version = -1;
+ std::string lsb_release("FOO=1234123.34.5\n");
+ base::SysInfo::ParseLsbRelease(lsb_release,
+ &os_major_version,
+ &os_minor_version,
+ &os_bugfix_version);
+ EXPECT_EQ(os_major_version, -1);
+ EXPECT_EQ(os_minor_version, -1);
+ EXPECT_EQ(os_bugfix_version, -1);
+}
+
+#endif // OS_CHROMEOS
diff --git a/webkit/glue/webkit_glue.cc b/webkit/glue/webkit_glue.cc
index 8ffb59f..2c8d032 100644
--- a/webkit/glue/webkit_glue.cc
+++ b/webkit/glue/webkit_glue.cc
@@ -294,14 +294,15 @@ Singleton<UserAgentState> g_user_agent;
std::string BuildOSCpuInfo() {
std::string os_cpu;
-#if defined(OS_WIN) || defined(OS_MACOSX)
+#if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_CHROMEOS)
int32 os_major_version = 0;
int32 os_minor_version = 0;
int32 os_bugfix_version = 0;
base::SysInfo::OperatingSystemVersionNumbers(&os_major_version,
&os_minor_version,
&os_bugfix_version);
-#else
+#endif
+#if !defined(OS_WIN) && !defined(OS_MACOSX)
// Should work on any Posix system.
struct utsname unixinfo;
uname(&unixinfo);
@@ -327,6 +328,12 @@ std::string BuildOSCpuInfo() {
os_major_version,
os_minor_version,
os_bugfix_version
+#elif defined(OS_CHROMEOS)
+ "CrOS %s %d.%d.%d",
+ cputype.c_str(), // e.g. i686
+ os_major_version,
+ os_minor_version,
+ os_bugfix_version
#else
"%s %s",
unixinfo.sysname, // e.g. Linux