• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #include "chrome/common/chrome_version_info.h"
6 
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"
15 
16 namespace chrome {
17 
ProductNameAndVersionForUserAgent() const18 std::string VersionInfo::ProductNameAndVersionForUserAgent() const {
19   if (!is_valid())
20     return std::string();
21   return "Chrome/" + Version();
22 }
23 
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.
27 
VersionInfo()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());
32 }
33 
~VersionInfo()34 VersionInfo::~VersionInfo() {
35 }
36 
is_valid() const37 bool VersionInfo::is_valid() const {
38   return version_info_.get() != NULL;
39 }
40 
Name() const41 std::string VersionInfo::Name() const {
42   if (!is_valid())
43     return std::string();
44   return base::UTF16ToUTF8(version_info_->product_name());
45 }
46 
Version() const47 std::string VersionInfo::Version() const {
48   if (!is_valid())
49     return std::string();
50   return base::UTF16ToUTF8(version_info_->product_version());
51 }
52 
LastChange() const53 std::string VersionInfo::LastChange() const {
54   if (!is_valid())
55     return std::string();
56   return base::UTF16ToUTF8(version_info_->last_change());
57 }
58 
IsOfficialBuild() const59 bool VersionInfo::IsOfficialBuild() const {
60   if (!is_valid())
61     return false;
62   return version_info_->is_official_build();
63 }
64 
65 #elif defined(OS_POSIX)
66 // We get chrome version information from chrome_version_info_posix.h,
67 // a generated header.
68 
69 #include "chrome/common/chrome_version_info_posix.h"
70 
VersionInfo()71 VersionInfo::VersionInfo() {
72 }
73 
~VersionInfo()74 VersionInfo::~VersionInfo() {
75 }
76 
is_valid() const77 bool VersionInfo::is_valid() const {
78   return true;
79 }
80 
Name() const81 std::string VersionInfo::Name() const {
82   return PRODUCT_NAME;
83 }
84 
Version() const85 std::string VersionInfo::Version() const {
86   return PRODUCT_VERSION;
87 }
88 
LastChange() const89 std::string VersionInfo::LastChange() const {
90   return LAST_CHANGE;
91 }
92 
IsOfficialBuild() const93 bool VersionInfo::IsOfficialBuild() const {
94   return IS_OFFICIAL_BUILD;
95 }
96 
97 #endif
98 
CreateVersionString() const99 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;
115   }
116   return current_version;
117 }
118 
OSType() const119 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
143 }
144 
145 }  // namespace chrome
146