Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / chrome / common / chrome_version_info.cc
blobe197bd0a8253a38b359ed4447220a7dc4b2773a1
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
3 // found in the LICENSE file.
5 #include "chrome/common/chrome_version_info.h"
7 #include "base/basictypes.h"
8 #include "base/file_version_info.h"
9 #include "base/strings/utf_string_conversions.h"
10 #include "base/threading/thread_restrictions.h"
11 #include "build/build_config.h"
12 #include "chrome/grit/chromium_strings.h"
13 #include "chrome/grit/generated_resources.h"
14 #include "ui/base/l10n/l10n_util.h"
16 namespace chrome {
18 std::string VersionInfo::ProductNameAndVersionForUserAgent() const {
19 if (!is_valid())
20 return std::string();
21 return "Chrome/" + Version();
24 #if defined(OS_WIN) || defined(OS_MACOSX)
25 // On Windows and Mac, we get the Chrome version info by querying
26 // FileVersionInfo for the current module.
28 VersionInfo::VersionInfo() {
29 // The current module is already loaded in memory, so this will be cheap.
30 base::ThreadRestrictions::ScopedAllowIO allow_io;
31 version_info_.reset(FileVersionInfo::CreateFileVersionInfoForCurrentModule());
34 VersionInfo::~VersionInfo() {
37 bool VersionInfo::is_valid() const {
38 return version_info_.get() != NULL;
41 std::string VersionInfo::Name() const {
42 if (!is_valid())
43 return std::string();
44 return base::UTF16ToUTF8(version_info_->product_name());
47 std::string VersionInfo::Version() const {
48 if (!is_valid())
49 return std::string();
50 return base::UTF16ToUTF8(version_info_->product_version());
53 std::string VersionInfo::LastChange() const {
54 if (!is_valid())
55 return std::string();
56 return base::UTF16ToUTF8(version_info_->last_change());
59 bool VersionInfo::IsOfficialBuild() const {
60 if (!is_valid())
61 return false;
62 return version_info_->is_official_build();
65 #elif defined(OS_POSIX)
66 // We get chrome version information from chrome_version_info_posix.h,
67 // a generated header.
69 #include "chrome/common/chrome_version_info_posix.h"
71 VersionInfo::VersionInfo() {
74 VersionInfo::~VersionInfo() {
77 bool VersionInfo::is_valid() const {
78 return true;
81 std::string VersionInfo::Name() const {
82 return PRODUCT_NAME;
85 std::string VersionInfo::Version() const {
86 return PRODUCT_VERSION;
89 std::string VersionInfo::LastChange() const {
90 return LAST_CHANGE;
93 bool VersionInfo::IsOfficialBuild() const {
94 return IS_OFFICIAL_BUILD;
97 #endif
99 std::string VersionInfo::CreateVersionString() const {
100 std::string current_version;
101 if (is_valid()) {
102 current_version += Version();
103 #if !defined(GOOGLE_CHROME_BUILD)
104 current_version += " (";
105 current_version += l10n_util::GetStringUTF8(IDS_ABOUT_VERSION_UNOFFICIAL);
106 current_version += " ";
107 current_version += LastChange();
108 current_version += " ";
109 current_version += OSType();
110 current_version += ")";
111 #endif
112 std::string modifier = GetVersionStringModifier();
113 if (!modifier.empty())
114 current_version += " " + modifier;
116 return current_version;
119 std::string VersionInfo::OSType() const {
120 #if defined(OS_WIN)
121 return "Windows";
122 #elif defined(OS_MACOSX)
123 return "Mac OS X";
124 #elif defined(OS_CHROMEOS)
125 #if defined(GOOGLE_CHROME_BUILD)
126 return "Chrome OS";
127 #else
128 return "Chromium OS";
129 #endif
130 #elif defined(OS_ANDROID)
131 return "Android";
132 #elif defined(OS_LINUX)
133 return "Linux";
134 #elif defined(OS_FREEBSD)
135 return "FreeBSD";
136 #elif defined(OS_OPENBSD)
137 return "OpenBSD";
138 #elif defined(OS_SOLARIS)
139 return "Solaris";
140 #else
141 return "Unknown";
142 #endif
145 } // namespace chrome