chrome_version_info.cc revision 2a99a7e74a7f215066514fe81d2bfa6639d9eddd
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/threading/thread_restrictions.h"
10#include "base/utf_string_conversions.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"
16
17namespace chrome {
18
19#if defined(OS_WIN) || defined(OS_MACOSX)
20// On Windows and Mac, we get the Chrome version info by querying
21// FileVersionInfo for the current module.
22
23VersionInfo::VersionInfo() {
24  // The current module is already loaded in memory, so this will be cheap.
25  base::ThreadRestrictions::ScopedAllowIO allow_io;
26  version_info_.reset(FileVersionInfo::CreateFileVersionInfoForCurrentModule());
27}
28
29VersionInfo::~VersionInfo() {
30}
31
32bool VersionInfo::is_valid() const {
33  return version_info_.get() != NULL;
34}
35
36std::string VersionInfo::Name() const {
37  if (!is_valid())
38    return std::string();
39  return UTF16ToUTF8(version_info_->product_name());
40}
41
42std::string VersionInfo::Version() const {
43  if (!is_valid())
44    return std::string();
45  return UTF16ToUTF8(version_info_->product_version());
46}
47
48std::string VersionInfo::LastChange() const {
49  if (!is_valid())
50    return std::string();
51  return UTF16ToUTF8(version_info_->last_change());
52}
53
54bool VersionInfo::IsOfficialBuild() const {
55  if (!is_valid())
56    return false;
57  return version_info_->is_official_build();
58}
59
60#elif defined(OS_POSIX)
61// We get chrome version information from chrome_version_info_posix.h,
62// a generated header.
63
64#include "chrome/common/chrome_version_info_posix.h"
65
66VersionInfo::VersionInfo() {
67}
68
69VersionInfo::~VersionInfo() {
70}
71
72bool VersionInfo::is_valid() const {
73  return true;
74}
75
76std::string VersionInfo::Name() const {
77  return PRODUCT_NAME;
78}
79
80std::string VersionInfo::Version() const {
81  return PRODUCT_VERSION;
82}
83
84std::string VersionInfo::LastChange() const {
85  return LAST_CHANGE;
86}
87
88bool VersionInfo::IsOfficialBuild() const {
89  return IS_OFFICIAL_BUILD;
90}
91
92#endif
93
94std::string VersionInfo::CreateVersionString() const {
95  std::string current_version;
96  if (is_valid()) {
97    current_version += Version();
98#if !defined(GOOGLE_CHROME_BUILD)
99    current_version += " (";
100    current_version += l10n_util::GetStringUTF8(IDS_ABOUT_VERSION_UNOFFICIAL);
101    current_version += " ";
102    current_version += LastChange();
103    current_version += " ";
104    current_version += OSType();
105    current_version += ")";
106#endif
107    std::string modifier = GetVersionStringModifier();
108    if (!modifier.empty())
109      current_version += " " + modifier;
110  }
111  return current_version;
112}
113
114std::string VersionInfo::OSType() const {
115#if defined(OS_WIN)
116  return "Windows";
117#elif defined(OS_MACOSX)
118  return "Mac OS X";
119#elif defined(OS_CHROMEOS)
120  #if defined(GOOGLE_CHROME_BUILD)
121    return "Chrome OS";
122  #else
123    return "Chromium OS";
124  #endif
125#elif defined(OS_ANDROID)
126  return "Android";
127#elif defined(OS_LINUX)
128  return "Linux";
129#elif defined(OS_FREEBSD)
130  return "FreeBSD";
131#elif defined(OS_OPENBSD)
132  return "OpenBSD";
133#elif defined(OS_SOLARIS)
134  return "Solaris";
135#else
136  return "Unknown";
137#endif
138}
139
140}  // namespace chrome
141