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 "grit/chromium_strings.h"
13 #include "grit/generated_resources.h"
14 #include "ui/base/l10n/l10n_util.h"
15 #include "ui/base/resource/resource_bundle.h"
19 std::string
VersionInfo::ProductNameAndVersionForUserAgent() const {
22 return "Chrome/" + Version();
25 #if defined(OS_WIN) || defined(OS_MACOSX)
26 // On Windows and Mac, we get the Chrome version info by querying
27 // FileVersionInfo for the current module.
29 VersionInfo::VersionInfo() {
30 // The current module is already loaded in memory, so this will be cheap.
31 base::ThreadRestrictions::ScopedAllowIO allow_io
;
32 version_info_
.reset(FileVersionInfo::CreateFileVersionInfoForCurrentModule());
35 VersionInfo::~VersionInfo() {
38 bool VersionInfo::is_valid() const {
39 return version_info_
.get() != NULL
;
42 std::string
VersionInfo::Name() const {
45 return base::UTF16ToUTF8(version_info_
->product_name());
48 std::string
VersionInfo::Version() const {
51 return base::UTF16ToUTF8(version_info_
->product_version());
54 std::string
VersionInfo::LastChange() const {
57 return base::UTF16ToUTF8(version_info_
->last_change());
60 bool VersionInfo::IsOfficialBuild() const {
63 return version_info_
->is_official_build();
66 #elif defined(OS_POSIX)
67 // We get chrome version information from chrome_version_info_posix.h,
68 // a generated header.
70 #include "chrome/common/chrome_version_info_posix.h"
72 VersionInfo::VersionInfo() {
75 VersionInfo::~VersionInfo() {
78 bool VersionInfo::is_valid() const {
82 std::string
VersionInfo::Name() const {
86 std::string
VersionInfo::Version() const {
87 return PRODUCT_VERSION
;
90 std::string
VersionInfo::LastChange() const {
94 bool VersionInfo::IsOfficialBuild() const {
95 return IS_OFFICIAL_BUILD
;
100 std::string
VersionInfo::CreateVersionString() const {
101 std::string current_version
;
103 current_version
+= Version();
104 #if !defined(GOOGLE_CHROME_BUILD)
105 current_version
+= " (";
106 current_version
+= l10n_util::GetStringUTF8(IDS_ABOUT_VERSION_UNOFFICIAL
);
107 current_version
+= " ";
108 current_version
+= LastChange();
109 current_version
+= " ";
110 current_version
+= OSType();
111 current_version
+= ")";
113 std::string modifier
= GetVersionStringModifier();
114 if (!modifier
.empty())
115 current_version
+= " " + modifier
;
117 return current_version
;
120 std::string
VersionInfo::OSType() const {
123 #elif defined(OS_MACOSX)
125 #elif defined(OS_CHROMEOS)
126 #if defined(GOOGLE_CHROME_BUILD)
129 return "Chromium OS";
131 #elif defined(OS_ANDROID)
133 #elif defined(OS_LINUX)
135 #elif defined(OS_FREEBSD)
137 #elif defined(OS_OPENBSD)
139 #elif defined(OS_SOLARIS)
146 } // namespace chrome