summaryrefslogtreecommitdiffstats
path: root/base/sys_info_chromeos.cc
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 /base/sys_info_chromeos.cc
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
Diffstat (limited to 'base/sys_info_chromeos.cc')
-rw-r--r--base/sys_info_chromeos.cc69
1 files changed, 69 insertions, 0 deletions
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