diff options
author | evan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-27 20:28:42 +0000 |
---|---|---|
committer | evan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-27 20:28:42 +0000 |
commit | 0211f57eabdc1a3e34aee1e1629c26e93b803ded (patch) | |
tree | 3bcbab3506e5f3dbcbc99825529cc803d223b017 /chrome/common | |
parent | 1f8322043d302eb0f6a050a21d2f0f9a8c1df71e (diff) | |
download | chromium_src-0211f57eabdc1a3e34aee1e1629c26e93b803ded.zip chromium_src-0211f57eabdc1a3e34aee1e1629c26e93b803ded.tar.gz chromium_src-0211f57eabdc1a3e34aee1e1629c26e93b803ded.tar.bz2 |
Refactor version-getting info into a chrome::VersionInfo object.
I was trying to replace wstring usage in base::FileVersionInfo, but
that class is rather Windows-specific with strange fields like
"private_build()" where the value and encoding aren't clear. 95%
of the users of FileVersionInfo actually just care about the current
Chrome version, so we can provide a much simpler interface for them.
We still use FileVersionInfo for retrieving information from e.g.
plugin DLLs, but in those cases the usage is clearer.
Review URL: http://codereview.chromium.org/3135028
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@57725 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common')
-rw-r--r-- | chrome/common/chrome_version_info.cc | 105 | ||||
-rw-r--r-- | chrome/common/chrome_version_info.h | 42 | ||||
-rw-r--r-- | chrome/common/chrome_version_info_posix.h.version | 19 | ||||
-rw-r--r-- | chrome/common/extensions/extension.cc | 10 |
4 files changed, 116 insertions, 60 deletions
diff --git a/chrome/common/chrome_version_info.cc b/chrome/common/chrome_version_info.cc index 1b1d479..a26f81f 100644 --- a/chrome/common/chrome_version_info.cc +++ b/chrome/common/chrome_version_info.cc @@ -6,47 +6,82 @@ #include "base/basictypes.h" #include "base/file_version_info.h" +#include "base/string_util.h" #include "build/build_config.h" -#if defined(OS_POSIX) && !defined(OS_MACOSX) -#include "chrome/common/chrome_version_info_posix.h" - -// Posix files don't have per-file version information, so we get chrome -// version information from chrome_version_info_posix.h, a generated header. -class ChromeVersionInfoPosix : public FileVersionInfo { - public: - ChromeVersionInfoPosix() {} - - virtual std::wstring company_name() { return COMPANY_NAME; } - virtual std::wstring company_short_name() { return COMPANY_SHORT_NAME; } - virtual std::wstring product_name() { return PRODUCT_NAME; } - virtual std::wstring product_short_name() { return PRODUCT_SHORT_NAME; } - virtual std::wstring internal_name() { return INTERNAL_NAME; } - virtual std::wstring product_version() { return PRODUCT_VERSION; } - virtual std::wstring private_build() { return PRIVATE_BUILD; } - virtual std::wstring special_build() { return SPECIAL_BUILD; } - virtual std::wstring comments() { return COMMENTS; } - virtual std::wstring original_filename() { return ORIGINAL_FILENAME; } - virtual std::wstring file_description() { return FILE_DESCRIPTION; } - virtual std::wstring file_version() { return FILE_VERSION; } - virtual std::wstring legal_copyright() { return LEGAL_COPYRIGHT; } - virtual std::wstring legal_trademarks() { return LEGAL_TRADEMARKS; } - virtual std::wstring last_change() { return LAST_CHANGE; } - virtual bool is_official_build() { return OFFICIAL_BUILD; } - - private: - DISALLOW_COPY_AND_ASSIGN(ChromeVersionInfoPosix); -}; -#endif - namespace chrome { -FileVersionInfo* GetChromeVersionInfo() { #if defined(OS_WIN) || defined(OS_MACOSX) - return FileVersionInfo::CreateFileVersionInfoForCurrentModule(); +// On Windows and Mac, we get the Chrome version info by querying +// FileVersionInfo for the current module. + +VersionInfo::VersionInfo() { + version_info_.reset(FileVersionInfo::CreateFileVersionInfoForCurrentModule()); +} + +VersionInfo::~VersionInfo() { +} + +bool VersionInfo::is_valid() const { + return version_info_.get() != NULL; +} + +std::string VersionInfo::Name() const { + if (!is_valid()) + return std::string(); + return WideToASCII(version_info_->product_name()); +} + +std::string VersionInfo::Version() const { + if (!is_valid()) + return std::string(); + return WideToASCII(version_info_->product_version()); +} + +std::string VersionInfo::LastChange() const { + if (!is_valid()) + return std::string(); + return WideToASCII(version_info_->last_change()); +} + +bool VersionInfo::IsOfficialBuild() const { + if (!is_valid()) + return false; + return version_info_->is_official_build(); +} + #elif defined(OS_POSIX) - return new ChromeVersionInfoPosix(); -#endif +// We get chrome version information from chrome_version_info_posix.h, +// a generated header. + +#include "chrome/common/chrome_version_info_posix.h" + +VersionInfo::VersionInfo() { +} + +VersionInfo::~VersionInfo() { +} + +bool VersionInfo::is_valid() const { + return true; +} + +std::string VersionInfo::Name() const { + return PRODUCT_NAME; +} + +std::string VersionInfo::Version() const { + return PRODUCT_VERSION; +} + +std::string VersionInfo::LastChange() const { + return LAST_CHANGE; } +bool VersionInfo::IsOfficialBuild() const { + return OFFICIAL_BUILD; +} + +#endif + } // namespace chrome diff --git a/chrome/common/chrome_version_info.h b/chrome/common/chrome_version_info.h index a539130..0ec911e 100644 --- a/chrome/common/chrome_version_info.h +++ b/chrome/common/chrome_version_info.h @@ -6,13 +6,49 @@ #define CHROME_COMMON_CHROME_VERSION_INFO_H_ #pragma once +#include <string> + +#include "base/basictypes.h" +#include "base/scoped_ptr.h" + class FileVersionInfo; namespace chrome { -// Creates a FileVersionInfo for the app, Chrome. Returns NULL in case of -// error. The returned object should be deleted when you are done with it. -FileVersionInfo* GetChromeVersionInfo(); +// An instance of chrome::VersionInfo has information about the +// current running build of Chrome. +class VersionInfo { + public: + VersionInfo(); + ~VersionInfo(); + + // In the rare case where we fail to get the version info, + // is_valid() will return false. The other functions will return + // the empty string in this case, so it's not harmful if you don't + // check is_valid(). + bool is_valid() const; + + // E.g. "Chromium" or "Google Chrome". + std::string Name() const; + + // Version number, e.g. "6.0.490.1". + std::string Version() const; + + // The SVN revision of this release. E.g. "55800". + std::string LastChange() const; + + // Whether this is an "official" release of the current Version(): + // whether knowing Version() is enough to completely determine what + // LastChange() is. + bool IsOfficialBuild() const; + + private: +#if defined(OS_WIN) || defined(OS_MACOSX) + scoped_ptr<FileVersionInfo> version_info_; +#endif + + DISALLOW_COPY_AND_ASSIGN(VersionInfo); +}; } // namespace chrome diff --git a/chrome/common/chrome_version_info_posix.h.version b/chrome/common/chrome_version_info_posix.h.version index 56a8fea..670dc8c 100644 --- a/chrome/common/chrome_version_info_posix.h.version +++ b/chrome/common/chrome_version_info_posix.h.version @@ -5,22 +5,9 @@ #ifndef CHROME_COMMON_CHROME_VERSION_INFO_POSIX_H_ #define CHROME_COMMON_CHROME_VERSION_INFO_POSIX_H_ -#define COMPANY_NAME L"@COMPANY_FULLNAME@" -#define FILE_DESCRIPTION L"@PRODUCT_FULLNAME@" -#define FILE_VERSION L"@MAJOR@.@MINOR@.@BUILD@.@PATCH@" -#define LEGAL_COPYRIGHT L"@COPYRIGHT@" -#define PRODUCT_NAME L"@PRODUCT_FULLNAME@" -#define PRODUCT_VERSION L"@MAJOR@.@MINOR@.@BUILD@.@PATCH@" -#define COMPANY_SHORT_NAME L"@COMPANY_SHORTNAME@" -#define PRODUCT_SHORT_NAME L"@PRODUCT_SHORTNAME@" -#define LAST_CHANGE L"@LASTCHANGE@" +#define PRODUCT_NAME "@PRODUCT_FULLNAME@" +#define PRODUCT_VERSION "@MAJOR@.@MINOR@.@BUILD@.@PATCH@" +#define LAST_CHANGE "@LASTCHANGE@" #define OFFICIAL_BUILD @OFFICIAL_BUILD@ -// TODO(mmoss) Do these have values for Linux? -#define INTERNAL_NAME L"" -#define ORIGINAL_FILENAME L"" -#define PRIVATE_BUILD L"" -#define SPECIAL_BUILD L"" -#define COMMENTS L"" -#define LEGAL_TRADEMARKS L"" #endif // CHROME_COMMON_CHROME_VERSION_INFO_POSIX_H_ diff --git a/chrome/common/extensions/extension.cc b/chrome/common/extensions/extension.cc index 4dfe74c..728006c 100644 --- a/chrome/common/extensions/extension.cc +++ b/chrome/common/extensions/extension.cc @@ -12,7 +12,6 @@ #include "base/command_line.h" #include "base/file_path.h" #include "base/file_util.h" -#include "base/file_version_info.h" #include "base/i18n/rtl.h" #include "base/logging.h" #include "base/stl_util-inl.h" @@ -1059,15 +1058,14 @@ bool Extension::InitFromValue(const DictionaryValue& source, bool require_key, return false; } - scoped_ptr<FileVersionInfo> current_version_info( - chrome::GetChromeVersionInfo()); - if (!current_version_info.get()) { - DCHECK(false); + chrome::VersionInfo current_version_info; + if (!current_version_info.is_valid()) { + NOTREACHED(); return false; } scoped_ptr<Version> current_version( - Version::GetVersionFromString(current_version_info->file_version())); + Version::GetVersionFromString(current_version_info.Version())); if (!current_version.get()) { DCHECK(false); return false; |