| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/common/chrome_version_info.h" | 5 #include "chrome/common/chrome_version_info.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/file_version_info.h" | 8 #include "base/file_version_info.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "base/threading/thread_restrictions.h" | 10 #include "base/threading/thread_restrictions.h" |
| 11 #include "build/build_config.h" | 11 #include "build/build_config.h" |
| 12 #include "chrome/common/chrome_version_info_values.h" |
| 12 #include "chrome/grit/chromium_strings.h" | 13 #include "chrome/grit/chromium_strings.h" |
| 13 #include "chrome/grit/generated_resources.h" | 14 #include "chrome/grit/generated_resources.h" |
| 14 #include "ui/base/l10n/l10n_util.h" | 15 #include "ui/base/l10n/l10n_util.h" |
| 15 | 16 |
| 16 namespace chrome { | 17 namespace chrome { |
| 17 | 18 |
| 18 std::string VersionInfo::ProductNameAndVersionForUserAgent() const { | 19 std::string VersionInfo::ProductNameAndVersionForUserAgent() const { |
| 19 if (!is_valid()) | |
| 20 return std::string(); | |
| 21 return "Chrome/" + Version(); | 20 return "Chrome/" + Version(); |
| 22 } | 21 } |
| 23 | 22 |
| 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 | |
| 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 | |
| 34 VersionInfo::~VersionInfo() { | |
| 35 } | |
| 36 | |
| 37 bool VersionInfo::is_valid() const { | |
| 38 return version_info_.get() != NULL; | |
| 39 } | |
| 40 | |
| 41 std::string VersionInfo::Name() const { | |
| 42 if (!is_valid()) | |
| 43 return std::string(); | |
| 44 return base::UTF16ToUTF8(version_info_->product_name()); | |
| 45 } | |
| 46 | |
| 47 std::string VersionInfo::Version() const { | |
| 48 if (!is_valid()) | |
| 49 return std::string(); | |
| 50 return base::UTF16ToUTF8(version_info_->product_version()); | |
| 51 } | |
| 52 | |
| 53 std::string VersionInfo::LastChange() const { | |
| 54 if (!is_valid()) | |
| 55 return std::string(); | |
| 56 return base::UTF16ToUTF8(version_info_->last_change()); | |
| 57 } | |
| 58 | |
| 59 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 | |
| 71 VersionInfo::VersionInfo() { | 23 VersionInfo::VersionInfo() { |
| 72 } | 24 } |
| 73 | 25 |
| 74 VersionInfo::~VersionInfo() { | 26 VersionInfo::~VersionInfo() { |
| 75 } | 27 } |
| 76 | 28 |
| 77 bool VersionInfo::is_valid() const { | |
| 78 return true; | |
| 79 } | |
| 80 | |
| 81 std::string VersionInfo::Name() const { | 29 std::string VersionInfo::Name() const { |
| 82 return PRODUCT_NAME; | 30 return PRODUCT_NAME; |
| 83 } | 31 } |
| 84 | 32 |
| 85 std::string VersionInfo::Version() const { | 33 std::string VersionInfo::Version() const { |
| 86 return PRODUCT_VERSION; | 34 return PRODUCT_VERSION; |
| 87 } | 35 } |
| 88 | 36 |
| 89 std::string VersionInfo::LastChange() const { | 37 std::string VersionInfo::LastChange() const { |
| 90 return LAST_CHANGE; | 38 return LAST_CHANGE; |
| 91 } | 39 } |
| 92 | 40 |
| 93 bool VersionInfo::IsOfficialBuild() const { | 41 bool VersionInfo::IsOfficialBuild() const { |
| 94 return IS_OFFICIAL_BUILD; | 42 return IS_OFFICIAL_BUILD; |
| 95 } | 43 } |
| 96 | 44 |
| 97 #endif | |
| 98 | |
| 99 std::string VersionInfo::CreateVersionString() const { | 45 std::string VersionInfo::CreateVersionString() const { |
| 100 std::string current_version; | 46 std::string current_version; |
| 101 if (is_valid()) { | 47 current_version += Version(); |
| 102 current_version += Version(); | |
| 103 #if !defined(GOOGLE_CHROME_BUILD) | 48 #if !defined(GOOGLE_CHROME_BUILD) |
| 104 current_version += " ("; | 49 current_version += " ("; |
| 105 current_version += l10n_util::GetStringUTF8(IDS_ABOUT_VERSION_UNOFFICIAL); | 50 current_version += l10n_util::GetStringUTF8(IDS_ABOUT_VERSION_UNOFFICIAL); |
| 106 current_version += " "; | 51 current_version += " "; |
| 107 current_version += LastChange(); | 52 current_version += LastChange(); |
| 108 current_version += " "; | 53 current_version += " "; |
| 109 current_version += OSType(); | 54 current_version += OSType(); |
| 110 current_version += ")"; | 55 current_version += ")"; |
| 111 #endif | 56 #endif |
| 112 std::string modifier = GetVersionStringModifier(); | 57 std::string modifier = GetVersionStringModifier(); |
| 113 if (!modifier.empty()) | 58 if (!modifier.empty()) |
| 114 current_version += " " + modifier; | 59 current_version += " " + modifier; |
| 115 } | |
| 116 return current_version; | 60 return current_version; |
| 117 } | 61 } |
| 118 | 62 |
| 119 std::string VersionInfo::OSType() const { | 63 std::string VersionInfo::OSType() const { |
| 120 #if defined(OS_WIN) | 64 #if defined(OS_WIN) |
| 121 return "Windows"; | 65 return "Windows"; |
| 122 #elif defined(OS_MACOSX) | 66 #elif defined(OS_MACOSX) |
| 123 return "Mac OS X"; | 67 return "Mac OS X"; |
| 124 #elif defined(OS_CHROMEOS) | 68 #elif defined(OS_CHROMEOS) |
| 125 #if defined(GOOGLE_CHROME_BUILD) | 69 #if defined(GOOGLE_CHROME_BUILD) |
| (...skipping 10 matching lines...) Expand all Loading... |
| 136 #elif defined(OS_OPENBSD) | 80 #elif defined(OS_OPENBSD) |
| 137 return "OpenBSD"; | 81 return "OpenBSD"; |
| 138 #elif defined(OS_SOLARIS) | 82 #elif defined(OS_SOLARIS) |
| 139 return "Solaris"; | 83 return "Solaris"; |
| 140 #else | 84 #else |
| 141 return "Unknown"; | 85 return "Unknown"; |
| 142 #endif | 86 #endif |
| 143 } | 87 } |
| 144 | 88 |
| 145 } // namespace chrome | 89 } // namespace chrome |
| OLD | NEW |