summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordmaclach@chromium.org <dmaclach@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-18 00:40:17 +0000
committerdmaclach@chromium.org <dmaclach@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-18 00:40:17 +0000
commit30c918084bac874b6cfaabb93f0bb2545c5354e2 (patch)
tree45bd81ec93407433426c0a6d1421bc189a96c2c4
parentd9cb161850584e5d277b141aadb68abec0af28bb (diff)
downloadchromium_src-30c918084bac874b6cfaabb93f0bb2545c5354e2.zip
chromium_src-30c918084bac874b6cfaabb93f0bb2545c5354e2.tar.gz
chromium_src-30c918084bac874b6cfaabb93f0bb2545c5354e2.tar.bz2
Revert 69592 - file_version_info was not finding Mac values correctly.
Changed file_version_info to find Mac values, and changed version_info to fail if values can't be found. BUG=NONE TEST=BUILD Review URL: http://codereview.chromium.org/5815001 TBR=dmaclach@chromium.org Review URL: http://codereview.chromium.org/6017003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@69601 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--base/file_version_info.h5
-rw-r--r--base/file_version_info_mac.h15
-rw-r--r--base/file_version_info_mac.mm68
-rw-r--r--chrome/browser/bug_report_util.cc12
-rw-r--r--chrome/browser/diagnostics/recon_diagnostics.cc4
-rw-r--r--chrome/browser/dom_ui/gpu_internals_ui.cc30
-rw-r--r--chrome/browser/dom_ui/net_internals_ui.cc30
-rw-r--r--chrome/browser/dom_ui/options/about_page_handler.cc1
-rw-r--r--chrome/browser/extensions/extension_updater.cc6
-rw-r--r--chrome/browser/memory_details_mac.cc9
-rw-r--r--chrome/browser/memory_details_win.cc3
-rw-r--r--chrome/browser/metrics/metrics_log.cc5
-rw-r--r--chrome/browser/safe_browsing/protocol_manager.cc2
-rw-r--r--chrome/browser/sync/glue/sync_backend_host.cc5
-rw-r--r--chrome/browser/ui/views/about_chrome_view.cc5
-rw-r--r--chrome/browser/upgrade_detector.cc4
-rw-r--r--chrome/common/chrome_version_info.cc25
-rw-r--r--chrome/common/chrome_version_info.h6
-rw-r--r--chrome/common/extensions/extension.cc5
-rw-r--r--chrome/common/service_process_util.cc11
-rw-r--r--chrome/common/service_process_util_unittest.cc1
-rw-r--r--chrome/renderer/renderer_glue.cc3
-rw-r--r--chrome/service/net/service_url_request_context.cc3
-rw-r--r--chrome/test/automation/automation_proxy.cc1
-rw-r--r--chrome_frame/metrics_service.cc20
-rw-r--r--chrome_frame/renderer_glue.cc11
26 files changed, 199 insertions, 91 deletions
diff --git a/base/file_version_info.h b/base/file_version_info.h
index 41a97fa..19407d2 100644
--- a/base/file_version_info.h
+++ b/base/file_version_info.h
@@ -24,13 +24,10 @@ class FileVersionInfo {
// goes wrong (typically the file does not exit or cannot be opened). The
// returned object should be deleted when you are done with it.
static FileVersionInfo* CreateFileVersionInfo(const FilePath& file_path);
-#endif // OS_WIN || OS_MACOSX
-
-#if defined(OS_WIN)
// This version, taking a wstring, is deprecated and only kept around
// until we can fix all callers.
static FileVersionInfo* CreateFileVersionInfo(const std::wstring& file_path);
-#endif // OS_WIN
+#endif
// Creates a FileVersionInfo for the current module. Returns NULL in case
// of error. The returned object should be deleted when you are done with it.
diff --git a/base/file_version_info_mac.h b/base/file_version_info_mac.h
index 36cb538..d66c4e6 100644
--- a/base/file_version_info_mac.h
+++ b/base/file_version_info_mac.h
@@ -8,8 +8,9 @@
#include <string>
+#include "base/basictypes.h"
#include "base/file_version_info.h"
-#include "base/scoped_nsobject.h"
+#include "base/scoped_ptr.h"
#ifdef __OBJC__
@class NSBundle;
@@ -24,6 +25,7 @@ class NSBundle;
class FileVersionInfoMac : public FileVersionInfo {
public:
explicit FileVersionInfoMac(NSBundle *bundle);
+ ~FileVersionInfoMac();
// Accessors to the different version properties.
// Returns an empty string if the property is not found.
@@ -45,13 +47,14 @@ class FileVersionInfoMac : public FileVersionInfo {
virtual bool is_official_build();
private:
+ // Lets you access other properties not covered above.
+ bool GetValue(const wchar_t* name, std::wstring* value);
+ // Similar to GetValue but returns a wstring (empty string if the property
+ // does not exist).
+ std::wstring GetStringValue(const wchar_t* name);
- // Returns a wstring value for a property name.
- // Returns the empty string if the property does not exist.
- std::wstring GetWStringValue(CFStringRef name);
-
- scoped_nsobject<NSBundle> bundle_;
+ NSBundle *bundle_;
DISALLOW_COPY_AND_ASSIGN(FileVersionInfoMac);
};
diff --git a/base/file_version_info_mac.mm b/base/file_version_info_mac.mm
index 7b1ac54..57be79a 100644
--- a/base/file_version_info_mac.mm
+++ b/base/file_version_info_mac.mm
@@ -4,33 +4,43 @@
#include "base/file_version_info_mac.h"
-#import <Foundation/Foundation.h>
+#import <Cocoa/Cocoa.h>
+#include "base/basictypes.h"
#include "base/file_path.h"
-#include "base/logging.h"
-#include "base/sys_string_conversions.h"
-#include "base/mac_util.h"
+#include "base/string_util.h"
+#include "base/utf_string_conversions.h"
FileVersionInfoMac::FileVersionInfoMac(NSBundle *bundle) : bundle_(bundle) {
+ [bundle_ retain];
+}
+
+FileVersionInfoMac::~FileVersionInfoMac() {
+ [bundle_ release];
}
// static
FileVersionInfo* FileVersionInfo::CreateFileVersionInfoForCurrentModule() {
- return CreateFileVersionInfo(mac_util::MainAppBundlePath());
+ // TODO(erikkay): this should really use bundleForClass, but we don't have
+ // a class to hang onto yet.
+ NSBundle* bundle = [NSBundle mainBundle];
+ return new FileVersionInfoMac(bundle);
+}
+
+// static
+FileVersionInfo* FileVersionInfo::CreateFileVersionInfo(
+ const std::wstring& file_path) {
+ NSString* path = [NSString stringWithCString:
+ reinterpret_cast<const char*>(file_path.c_str())
+ encoding:NSUTF32StringEncoding];
+ return new FileVersionInfoMac([NSBundle bundleWithPath:path]);
}
// static
FileVersionInfo* FileVersionInfo::CreateFileVersionInfo(
const FilePath& file_path) {
- NSString* path = base::SysUTF8ToNSString(file_path.value());
- NSBundle *bundle = [NSBundle bundleWithPath:path];
- NSString *identifier = [bundle bundleIdentifier];
- if (!identifier) {
- NOTREACHED() << "Unable to create file version for " << file_path.value();
- return NULL;
- } else {
- return new FileVersionInfoMac(bundle);
- }
+ NSString* path = [NSString stringWithUTF8String:file_path.value().c_str()];
+ return new FileVersionInfoMac([NSBundle bundleWithPath:path]);
}
std::wstring FileVersionInfoMac::company_name() {
@@ -46,11 +56,11 @@ std::wstring FileVersionInfoMac::internal_name() {
}
std::wstring FileVersionInfoMac::product_name() {
- return GetWStringValue(kCFBundleNameKey);
+ return GetStringValue(L"CFBundleName");
}
std::wstring FileVersionInfoMac::product_short_name() {
- return GetWStringValue(kCFBundleNameKey);
+ return GetStringValue(L"CFBundleName");
}
std::wstring FileVersionInfoMac::comments() {
@@ -58,11 +68,11 @@ std::wstring FileVersionInfoMac::comments() {
}
std::wstring FileVersionInfoMac::legal_copyright() {
- return GetWStringValue(CFSTR("CFBundleGetInfoString"));
+ return GetStringValue(L"CFBundleGetInfoString");
}
std::wstring FileVersionInfoMac::product_version() {
- return GetWStringValue(CFSTR("CFBundleShortVersionString"));
+ return GetStringValue(L"CFBundleShortVersionString");
}
std::wstring FileVersionInfoMac::file_description() {
@@ -82,7 +92,7 @@ std::wstring FileVersionInfoMac::file_version() {
}
std::wstring FileVersionInfoMac::original_filename() {
- return GetWStringValue(kCFBundleNameKey);
+ return GetStringValue(L"CFBundleName");
}
std::wstring FileVersionInfoMac::special_build() {
@@ -90,7 +100,7 @@ std::wstring FileVersionInfoMac::special_build() {
}
std::wstring FileVersionInfoMac::last_change() {
- return GetWStringValue(CFSTR("SVNRevision"));
+ return GetStringValue(L"SVNRevision");
}
bool FileVersionInfoMac::is_official_build() {
@@ -101,13 +111,23 @@ bool FileVersionInfoMac::is_official_build() {
#endif
}
-std::wstring FileVersionInfoMac::GetWStringValue(CFStringRef name) {
+bool FileVersionInfoMac::GetValue(const wchar_t* name,
+ std::wstring* value_str) {
if (bundle_) {
- NSString *ns_name = mac_util::CFToNSCast(name);
- NSString* value = [bundle_ objectForInfoDictionaryKey:ns_name];
+ NSString* value = [bundle_ objectForInfoDictionaryKey:
+ [NSString stringWithUTF8String:WideToUTF8(name).c_str()]];
if (value) {
- return base::SysNSStringToWide(value);
+ *value_str = reinterpret_cast<const wchar_t*>(
+ [value cStringUsingEncoding:NSUTF32StringEncoding]);
+ return true;
}
}
+ return false;
+}
+
+std::wstring FileVersionInfoMac::GetStringValue(const wchar_t* name) {
+ std::wstring str;
+ if (GetValue(name, &str))
+ return str;
return std::wstring();
}
diff --git a/chrome/browser/bug_report_util.cc b/chrome/browser/bug_report_util.cc
index b89d742..28cc685 100644
--- a/chrome/browser/bug_report_util.cc
+++ b/chrome/browser/bug_report_util.cc
@@ -309,11 +309,13 @@ void BugReportUtil::SendReport(Profile* profile,
// Add the Chrome version
chrome::VersionInfo version_info;
- std::string chrome_version = version_info.Name() + " - " +
- version_info.Version() +
- " (" + version_info.LastChange() + ")";
- AddFeedbackData(&feedback_data, std::string(kChromeVersionTag),
- chrome_version);
+ if (version_info.is_valid()) {
+ std::string chrome_version = version_info.Name() + " - " +
+ version_info.Version() +
+ " (" + version_info.LastChange() + ")";
+ AddFeedbackData(&feedback_data, std::string(kChromeVersionTag),
+ chrome_version);
+ }
// Add OS version (eg, for WinXP SP2: "5.1.2600 Service Pack 2").
std::string os_version = "";
diff --git a/chrome/browser/diagnostics/recon_diagnostics.cc b/chrome/browser/diagnostics/recon_diagnostics.cc
index 0a572f3..f657fef 100644
--- a/chrome/browser/diagnostics/recon_diagnostics.cc
+++ b/chrome/browser/diagnostics/recon_diagnostics.cc
@@ -117,6 +117,10 @@ class VersionTest : public DiagnosticTest {
virtual bool ExecuteImpl(DiagnosticsModel::Observer* observer) {
chrome::VersionInfo version_info;
+ if (!version_info.is_valid()) {
+ RecordFailure(ASCIIToUTF16("No Version"));
+ return true;
+ }
std::string current_version = version_info.Version();
if (current_version.empty()) {
RecordFailure(ASCIIToUTF16("Empty Version"));
diff --git a/chrome/browser/dom_ui/gpu_internals_ui.cc b/chrome/browser/dom_ui/gpu_internals_ui.cc
index 9b2b58f..9b93bfb 100644
--- a/chrome/browser/dom_ui/gpu_internals_ui.cc
+++ b/chrome/browser/dom_ui/gpu_internals_ui.cc
@@ -206,19 +206,23 @@ Value* GpuMessageHandler::OnRequestClientInfo(const ListValue* list) {
chrome::VersionInfo version_info;
- // We have everything we need to send the right values.
- dict->SetString("version", version_info.Version());
- dict->SetString("cl", version_info.LastChange());
- dict->SetString("version_mod",
- platform_util::GetVersionStringModifier());
- dict->SetString("official",
- l10n_util::GetStringUTF16(
- version_info.IsOfficialBuild() ?
- IDS_ABOUT_VERSION_OFFICIAL
- : IDS_ABOUT_VERSION_UNOFFICIAL));
-
- dict->SetString("command_line",
- CommandLine::ForCurrentProcess()->command_line_string());
+ if (!version_info.is_valid()) {
+ DLOG(ERROR) << "Unable to create chrome::VersionInfo";
+ } else {
+ // We have everything we need to send the right values.
+ dict->SetString("version", version_info.Version());
+ dict->SetString("cl", version_info.LastChange());
+ dict->SetString("version_mod",
+ platform_util::GetVersionStringModifier());
+ dict->SetString("official",
+ l10n_util::GetStringUTF16(
+ version_info.IsOfficialBuild() ?
+ IDS_ABOUT_VERSION_OFFICIAL
+ : IDS_ABOUT_VERSION_UNOFFICIAL));
+
+ dict->SetString("command_line",
+ CommandLine::ForCurrentProcess()->command_line_string());
+ }
return dict;
}
diff --git a/chrome/browser/dom_ui/net_internals_ui.cc b/chrome/browser/dom_ui/net_internals_ui.cc
index 1f81022..f44ac9e 100644
--- a/chrome/browser/dom_ui/net_internals_ui.cc
+++ b/chrome/browser/dom_ui/net_internals_ui.cc
@@ -537,19 +537,23 @@ void NetInternalsMessageHandler::IOThreadImpl::OnRendererReady(
chrome::VersionInfo version_info;
- // We have everything we need to send the right values.
- dict->SetString("version", version_info.Version());
- dict->SetString("cl", version_info.LastChange());
- dict->SetString("version_mod",
- platform_util::GetVersionStringModifier());
- dict->SetString("official",
- l10n_util::GetStringUTF16(
- version_info.IsOfficialBuild() ?
- IDS_ABOUT_VERSION_OFFICIAL
- : IDS_ABOUT_VERSION_UNOFFICIAL));
-
- dict->SetString("command_line",
- CommandLine::ForCurrentProcess()->command_line_string());
+ if (!version_info.is_valid()) {
+ DLOG(ERROR) << "Unable to create chrome::VersionInfo";
+ } else {
+ // We have everything we need to send the right values.
+ dict->SetString("version", version_info.Version());
+ dict->SetString("cl", version_info.LastChange());
+ dict->SetString("version_mod",
+ platform_util::GetVersionStringModifier());
+ dict->SetString("official",
+ l10n_util::GetStringUTF16(
+ version_info.IsOfficialBuild() ?
+ IDS_ABOUT_VERSION_OFFICIAL
+ : IDS_ABOUT_VERSION_UNOFFICIAL));
+
+ dict->SetString("command_line",
+ CommandLine::ForCurrentProcess()->command_line_string());
+ }
CallJavascriptFunction(L"g_browser.receivedClientInfo",
dict);
diff --git a/chrome/browser/dom_ui/options/about_page_handler.cc b/chrome/browser/dom_ui/options/about_page_handler.cc
index 66420be..71f994f7 100644
--- a/chrome/browser/dom_ui/options/about_page_handler.cc
+++ b/chrome/browser/dom_ui/options/about_page_handler.cc
@@ -143,6 +143,7 @@ void AboutPageHandler::GetLocalizedValues(DictionaryValue* localized_strings) {
// browser version
chrome::VersionInfo version_info;
+ DCHECK(version_info.is_valid());
std::string browser_version = version_info.Version();
std::string version_modifier = platform_util::GetVersionStringModifier();
diff --git a/chrome/browser/extensions/extension_updater.cc b/chrome/browser/extensions/extension_updater.cc
index 1ebf65b..d143052 100644
--- a/chrome/browser/extensions/extension_updater.cc
+++ b/chrome/browser/extensions/extension_updater.cc
@@ -827,8 +827,10 @@ std::vector<int> ExtensionUpdater::DetermineUpdates(
// First determine the browser version if we haven't already.
if (!browser_version.get()) {
chrome::VersionInfo version_info;
- browser_version.reset(Version::GetVersionFromString(
- version_info.Version()));
+ if (version_info.is_valid()) {
+ browser_version.reset(Version::GetVersionFromString(
+ version_info.Version()));
+ }
}
scoped_ptr<Version> browser_min_version(
Version::GetVersionFromString(update->browser_min_version));
diff --git a/chrome/browser/memory_details_mac.cc b/chrome/browser/memory_details_mac.cc
index 08fced1..b17d25f 100644
--- a/chrome/browser/memory_details_mac.cc
+++ b/chrome/browser/memory_details_mac.cc
@@ -201,8 +201,13 @@ void MemoryDetails::CollectProcessDataChrome(
info.type = ChildProcessInfo::UNKNOWN_PROCESS;
chrome::VersionInfo version_info;
- info.product_name = ASCIIToWide(version_info.Name());
- info.version = ASCIIToWide(version_info.Version());
+ if (version_info.is_valid()) {
+ info.product_name = ASCIIToWide(version_info.Name());
+ info.version = ASCIIToWide(version_info.Version());
+ } else {
+ info.product_name = process_data_[CHROME_BROWSER].name;
+ info.version = L"";
+ }
// Check if this is one of the child processes whose data we collected
// on the IO thread, and if so copy over that data.
diff --git a/chrome/browser/memory_details_win.cc b/chrome/browser/memory_details_win.cc
index a3ea337..959cebd 100644
--- a/chrome/browser/memory_details_win.cc
+++ b/chrome/browser/memory_details_win.cc
@@ -121,7 +121,8 @@ void MemoryDetails::CollectProcessData(
TCHAR name[MAX_PATH];
if (index2 == CHROME_BROWSER || index2 == CHROME_NACL_PROCESS) {
chrome::VersionInfo version_info;
- info.version = ASCIIToWide(version_info.Version());
+ if (version_info.is_valid())
+ info.version = ASCIIToWide(version_info.Version());
// Check if this is one of the child processes whose data we collected
// on the IO thread, and if so copy over that data.
for (size_t child = 0; child < child_info.size(); child++) {
diff --git a/chrome/browser/metrics/metrics_log.cc b/chrome/browser/metrics/metrics_log.cc
index 14f6ba9..d0a1f01 100644
--- a/chrome/browser/metrics/metrics_log.cc
+++ b/chrome/browser/metrics/metrics_log.cc
@@ -71,6 +71,11 @@ std::string MetricsLog::GetInstallDate() const {
// static
std::string MetricsLog::GetVersionString() {
chrome::VersionInfo version_info;
+ if (!version_info.is_valid()) {
+ NOTREACHED() << "Unable to retrieve version info.";
+ return std::string();
+ }
+
std::string version = version_info.Version();
if (!version_extension_.empty())
version += version_extension_;
diff --git a/chrome/browser/safe_browsing/protocol_manager.cc b/chrome/browser/safe_browsing/protocol_manager.cc
index e620c11..8e29489 100644
--- a/chrome/browser/safe_browsing/protocol_manager.cc
+++ b/chrome/browser/safe_browsing/protocol_manager.cc
@@ -119,7 +119,7 @@ SafeBrowsingProtocolManager::SafeBrowsingProtocolManager(
next_update_sec_ = base::RandInt(60, kSbTimerStartIntervalSec);
chrome::VersionInfo version_info;
- if (version_info.Version().empty())
+ if (!version_info.is_valid() || version_info.Version().empty())
version_ = "0.1";
else
version_ = version_info.Version();
diff --git a/chrome/browser/sync/glue/sync_backend_host.cc b/chrome/browser/sync/glue/sync_backend_host.cc
index b34943b33..4dafe24 100644
--- a/chrome/browser/sync/glue/sync_backend_host.cc
+++ b/chrome/browser/sync/glue/sync_backend_host.cc
@@ -547,6 +547,11 @@ std::string MakeUserAgentForSyncapi() {
user_agent += "MAC ";
#endif
chrome::VersionInfo version_info;
+ if (!version_info.is_valid()) {
+ DLOG(ERROR) << "Unable to create chrome::VersionInfo object";
+ return user_agent;
+ }
+
user_agent += version_info.Version();
user_agent += " (" + version_info.LastChange() + ")";
if (!version_info.IsOfficialBuild())
diff --git a/chrome/browser/ui/views/about_chrome_view.cc b/chrome/browser/ui/views/about_chrome_view.cc
index 7d53af6..9e58f04 100644
--- a/chrome/browser/ui/views/about_chrome_view.cc
+++ b/chrome/browser/ui/views/about_chrome_view.cc
@@ -151,6 +151,11 @@ void AboutChromeView::Init() {
ResourceBundle& rb = ResourceBundle::GetSharedInstance();
chrome::VersionInfo version_info;
+ if (!version_info.is_valid()) {
+ NOTREACHED() << L"Failed to initialize about window";
+ return;
+ }
+
current_version_ = ASCIIToWide(version_info.Version());
std::string version_modifier = platform_util::GetVersionStringModifier();
diff --git a/chrome/browser/upgrade_detector.cc b/chrome/browser/upgrade_detector.cc
index 2e0eeed..7f3161d 100644
--- a/chrome/browser/upgrade_detector.cc
+++ b/chrome/browser/upgrade_detector.cc
@@ -113,6 +113,10 @@ class DetectUpgradeTask : public Task {
// Get the version of the currently *running* instance of Chrome.
chrome::VersionInfo version_info;
+ if (!version_info.is_valid()) {
+ NOTREACHED() << "Failed to get current file version";
+ return;
+ }
scoped_ptr<Version> running_version(
Version::GetVersionFromString(version_info.Version()));
if (running_version.get() == NULL) {
diff --git a/chrome/common/chrome_version_info.cc b/chrome/common/chrome_version_info.cc
index 70e8cb24..5157c4a 100644
--- a/chrome/common/chrome_version_info.cc
+++ b/chrome/common/chrome_version_info.cc
@@ -9,38 +9,47 @@
#include "base/string_util.h"
#include "base/thread_restrictions.h"
#include "build/build_config.h"
-#include "chrome/common/chrome_constants.h"
namespace chrome {
#if defined(OS_WIN) || defined(OS_MACOSX)
-// On Windows and Mac we get the Chrome version info by querying FileVersionInfo
-// for the current module.
+// On Windows and Mac, we get the Chrome version info by querying
+// FileVersionInfo for the current module.
VersionInfo::VersionInfo() {
// The current module is already loaded in memory, so this will be cheap.
base::ThreadRestrictions::ScopedAllowIO allow_io;
version_info_.reset(FileVersionInfo::CreateFileVersionInfoForCurrentModule());
- DCHECK(version_info_.get());
}
VersionInfo::~VersionInfo() {
}
+bool VersionInfo::is_valid() const {
+ return version_info_.get() != NULL;
+}
+
std::string VersionInfo::Name() const {
- std::wstring name = version_info_->product_name();
- return WideToASCII(name);
+ 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();
}
@@ -56,6 +65,10 @@ VersionInfo::VersionInfo() {
VersionInfo::~VersionInfo() {
}
+bool VersionInfo::is_valid() const {
+ return true;
+}
+
std::string VersionInfo::Name() const {
return PRODUCT_NAME;
}
diff --git a/chrome/common/chrome_version_info.h b/chrome/common/chrome_version_info.h
index b785249..0ec911e 100644
--- a/chrome/common/chrome_version_info.h
+++ b/chrome/common/chrome_version_info.h
@@ -22,6 +22,12 @@ class VersionInfo {
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;
diff --git a/chrome/common/extensions/extension.cc b/chrome/common/extensions/extension.cc
index 3cbe44d..56e0683 100644
--- a/chrome/common/extensions/extension.cc
+++ b/chrome/common/extensions/extension.cc
@@ -1343,6 +1343,11 @@ bool Extension::InitFromValue(const DictionaryValue& source, bool require_key,
}
chrome::VersionInfo current_version_info;
+ if (!current_version_info.is_valid()) {
+ NOTREACHED();
+ return false;
+ }
+
scoped_ptr<Version> current_version(
Version::GetVersionFromString(current_version_info.Version()));
if (!current_version.get()) {
diff --git a/chrome/common/service_process_util.cc b/chrome/common/service_process_util.cc
index 4c22fda..bcbac69 100644
--- a/chrome/common/service_process_util.cc
+++ b/chrome/common/service_process_util.cc
@@ -82,6 +82,12 @@ ServiceProcessRunningState GetServiceProcessRunningState(
// Get the version of the currently *running* instance of Chrome.
chrome::VersionInfo version_info;
+ if (!version_info.is_valid()) {
+ NOTREACHED() << "Failed to get current file version";
+ // Our own version is invalid. This is an error case. Pretend that we
+ // are out of date.
+ return SERVICE_NEWER_VERSION_RUNNING;
+ }
scoped_ptr<Version> running_version(Version::GetVersionFromString(
version_info.Version()));
if (!running_version.get()) {
@@ -124,6 +130,7 @@ std::string GetServiceProcessScopedVersionedName(
const std::string& append_str) {
std::string versioned_str;
chrome::VersionInfo version_info;
+ DCHECK(version_info.is_valid());
versioned_str.append(version_info.Version());
versioned_str.append(append_str);
return GetServiceProcessScopedName(versioned_str);
@@ -191,6 +198,10 @@ bool ServiceProcessState::HandleOtherVersion() {
bool ServiceProcessState::CreateSharedData() {
chrome::VersionInfo version_info;
+ if (!version_info.is_valid()) {
+ NOTREACHED() << "Failed to get current file version";
+ return false;
+ }
if (version_info.Version().length() >= kMaxVersionStringLength) {
NOTREACHED() << "Version string length is << " <<
version_info.Version().length() << "which is longer than" <<
diff --git a/chrome/common/service_process_util_unittest.cc b/chrome/common/service_process_util_unittest.cc
index 34b855a..58b68e1 100644
--- a/chrome/common/service_process_util_unittest.cc
+++ b/chrome/common/service_process_util_unittest.cc
@@ -14,6 +14,7 @@ TEST(ServiceProcessUtilTest, ScopedVersionedName) {
std::string test_str = "test";
std::string scoped_name = GetServiceProcessScopedVersionedName(test_str);
chrome::VersionInfo version_info;
+ DCHECK(version_info.is_valid());
EXPECT_TRUE(EndsWith(scoped_name, test_str, true));
EXPECT_NE(std::string::npos, scoped_name.find(version_info.Version()));
}
diff --git a/chrome/renderer/renderer_glue.cc b/chrome/renderer/renderer_glue.cc
index 6b29531..5cae2a9 100644
--- a/chrome/renderer/renderer_glue.cc
+++ b/chrome/renderer/renderer_glue.cc
@@ -261,7 +261,8 @@ void ClearCache() {
std::string GetProductVersion() {
chrome::VersionInfo version_info;
std::string product("Chrome/");
- product += version_info.Version();
+ product += version_info.is_valid() ? version_info.Version()
+ : "0.0.0.0";
return product;
}
diff --git a/chrome/service/net/service_url_request_context.cc b/chrome/service/net/service_url_request_context.cc
index cd94482..7f589e0 100644
--- a/chrome/service/net/service_url_request_context.cc
+++ b/chrome/service/net/service_url_request_context.cc
@@ -86,6 +86,9 @@ std::string BuildOSCpuInfo() {
std::string MakeUserAgentForServiceProcess() {
std::string user_agent;
chrome::VersionInfo version_info;
+ if (!version_info.is_valid()) {
+ DLOG(ERROR) << "Unable to create chrome::VersionInfo object";
+ }
std::string extra_version_info;
if (!version_info.IsOfficialBuild())
extra_version_info = "-devel";
diff --git a/chrome/test/automation/automation_proxy.cc b/chrome/test/automation/automation_proxy.cc
index 62b003e..4da271b 100644
--- a/chrome/test/automation/automation_proxy.cc
+++ b/chrome/test/automation/automation_proxy.cc
@@ -174,6 +174,7 @@ AutomationLaunchResult AutomationProxy::WaitForAppLaunch() {
// Obtain our own version number and compare it to what the automation
// provider sent.
chrome::VersionInfo version_info;
+ DCHECK(version_info.is_valid());
// Note that we use a simple string comparison since we expect the version
// to be a punctuated numeric string. Consider using base/Version if we
diff --git a/chrome_frame/metrics_service.cc b/chrome_frame/metrics_service.cc
index 1ca8caa..d82e16b 100644
--- a/chrome_frame/metrics_service.cc
+++ b/chrome_frame/metrics_service.cc
@@ -608,11 +608,17 @@ bool MetricsService::UploadData() {
// static
std::string MetricsService::GetVersionString() {
chrome::VersionInfo version_info;
- std::string version = version_info.Version();
- // Add the -F extensions to ensure that UMA data uploaded by ChromeFrame
- // lands in the ChromeFrame bucket.
- version += "-F";
- if (!version_info.IsOfficialBuild())
- version.append("-devel");
- return version;
+ if (version_info.is_valid()) {
+ std::string version = version_info.Version();
+ // Add the -F extensions to ensure that UMA data uploaded by ChromeFrame
+ // lands in the ChromeFrame bucket.
+ version += "-F";
+ if (!version_info.IsOfficialBuild())
+ version.append("-devel");
+ return version;
+ } else {
+ NOTREACHED() << "Unable to retrieve version string.";
+ }
+
+ return std::string();
}
diff --git a/chrome_frame/renderer_glue.cc b/chrome_frame/renderer_glue.cc
index 3e973bc..8980e97 100644
--- a/chrome_frame/renderer_glue.cc
+++ b/chrome_frame/renderer_glue.cc
@@ -2,9 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "base/file_version_info.h"
-#include "base/scoped_ptr.h"
-#include "base/string_util.h"
+#include "chrome/common/chrome_version_info.h"
namespace webkit_glue {
@@ -12,11 +10,12 @@ namespace webkit_glue {
// here instead of pulling in the whole renderer lib where this function
// is implemented for Chrome.
std::string GetProductVersion() {
- scoped_ptr<FileVersionInfo> info(
- FileVersionInfo::CreateFileVersionInfoForCurrentModule());
+ chrome::VersionInfo version_info;
std::string product("Chrome/");
- product += info.get() ? WideToASCII(info->product_version()) : "0.0.0.0";
+ product += version_info.is_valid() ? version_info.Version()
+ : "0.0.0.0";
return product;
}
} // end namespace webkit_glue
+