summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormark@chromium.org <mark@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-15 20:46:36 +0000
committermark@chromium.org <mark@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-15 20:46:36 +0000
commit2578c8ab913d2f5760c310a9969a4cf77205e59f (patch)
treee11dcb96f8ea9559adbdafc74d3ebc6f33c60b95
parent1f71d58803aa64d574369a85d5b16c1cf8e12b1e (diff)
downloadchromium_src-2578c8ab913d2f5760c310a9969a4cf77205e59f.zip
chromium_src-2578c8ab913d2f5760c310a9969a4cf77205e59f.tar.gz
chromium_src-2578c8ab913d2f5760c310a9969a4cf77205e59f.tar.bz2
Make UpgradeDetector work on the Mac.
This is the backend work only. There's no UI yet. BUG=45147 TEST=manual Review URL: http://codereview.chromium.org/3032001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@52524 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/cocoa/keystone_glue.h19
-rw-r--r--chrome/browser/cocoa/keystone_glue.mm30
-rw-r--r--chrome/browser/upgrade_detector.cc45
-rw-r--r--chrome/chrome_browser.gypi5
-rw-r--r--chrome/chrome_installer_util.gypi15
5 files changed, 87 insertions, 27 deletions
diff --git a/chrome/browser/cocoa/keystone_glue.h b/chrome/browser/cocoa/keystone_glue.h
index eaf84e5..fb16171 100644
--- a/chrome/browser/cocoa/keystone_glue.h
+++ b/chrome/browser/cocoa/keystone_glue.h
@@ -5,9 +5,13 @@
#ifndef CHROME_BROWSER_COCOA_KEYSTONE_GLUE_H_
#define CHROME_BROWSER_COCOA_KEYSTONE_GLUE_H_
+#include "base/string16.h"
+
+#if defined(__OBJC__)
+
#import <Foundation/Foundation.h>
-#import <base/scoped_nsobject.h>
+#import "base/scoped_nsobject.h"
#include "chrome/browser/cocoa/scoped_authorizationref.h"
// Possible outcomes of various operations. A version may accompany some of
@@ -188,4 +192,17 @@ enum BrandFileType {
@end // @interface KeystoneGlue(ExposedForTesting)
+#endif // __OBJC__
+
+// Functions that may be accessed from non-Objective-C C/C++ code.
+namespace keystone_glue {
+
+// True if Keystone is enabled.
+bool KeystoneEnabled();
+
+// The version of the application currently installed on disk.
+string16 CurrentlyInstalledVersion();
+
+} // namespace keystone_glue
+
#endif // CHROME_BROWSER_COCOA_KEYSTONE_GLUE_H_
diff --git a/chrome/browser/cocoa/keystone_glue.mm b/chrome/browser/cocoa/keystone_glue.mm
index a412fc9..a097fd7 100644
--- a/chrome/browser/cocoa/keystone_glue.mm
+++ b/chrome/browser/cocoa/keystone_glue.mm
@@ -12,6 +12,7 @@
#import "app/l10n_util_mac.h"
#include "base/logging.h"
#include "base/mac_util.h"
+#include "base/sys_string_conversions.h"
#import "base/worker_pool_mac.h"
#include "chrome/browser/cocoa/authorization_util.h"
#include "chrome/common/chrome_constants.h"
@@ -126,6 +127,9 @@ NSString* SystemBrandFilePath() {
// center.
- (void)updateStatus:(AutoupdateStatus)status version:(NSString*)version;
+// Returns the version of the currently-installed application on disk.
+- (NSString*)currentlyInstalledVersion;
+
// These three methods are used to determine the version of the application
// currently installed on disk, compare that to the currently-running version,
// decide whether any updates have been installed, and call
@@ -546,6 +550,13 @@ NSString* const kBrandKey = @"KSBrandID";
}
}
+- (NSString*)currentlyInstalledVersion {
+ NSString* appInfoPlistPath = [self appInfoPlistPath];
+ NSDictionary* infoPlist =
+ [NSDictionary dictionaryWithContentsOfFile:appInfoPlistPath];
+ return [infoPlist objectForKey:@"CFBundleShortVersionString"];
+}
+
// Runs on the main thread.
- (void)determineUpdateStatusAsync {
DCHECK([NSThread isMainThread]);
@@ -564,10 +575,7 @@ NSString* const kBrandKey = @"KSBrandID";
- (void)determineUpdateStatus {
DCHECK(![NSThread isMainThread]);
- NSString* appInfoPlistPath = [self appInfoPlistPath];
- NSDictionary* infoPlist =
- [NSDictionary dictionaryWithContentsOfFile:appInfoPlistPath];
- NSString* version = [infoPlist objectForKey:@"CFBundleShortVersionString"];
+ NSString* version = [self currentlyInstalledVersion];
[self performSelectorOnMainThread:@selector(determineUpdateStatusForVersion:)
withObject:version
@@ -898,3 +906,17 @@ NSString* const kBrandKey = @"KSBrandID";
}
@end // @implementation KeystoneGlue
+
+namespace keystone_glue {
+
+bool KeystoneEnabled() {
+ return [KeystoneGlue defaultKeystoneGlue] != nil;
+}
+
+string16 CurrentlyInstalledVersion() {
+ KeystoneGlue* keystoneGlue = [KeystoneGlue defaultKeystoneGlue];
+ NSString* version = [keystoneGlue currentlyInstalledVersion];
+ return base::SysNSStringToUTF16(version);
+}
+
+} // namespace keystone_glue
diff --git a/chrome/browser/upgrade_detector.cc b/chrome/browser/upgrade_detector.cc
index 8825889..192f285 100644
--- a/chrome/browser/upgrade_detector.cc
+++ b/chrome/browser/upgrade_detector.cc
@@ -22,7 +22,9 @@
#if defined(OS_WIN)
#include "chrome/installer/util/install_util.h"
-#elif defined(OS_LINUX)
+#elif defined(OS_MACOSX)
+#include "chrome/browser/cocoa/keystone_glue.h"
+#elif defined(OS_POSIX)
#include "base/process_util.h"
#include "chrome/installer/util/version.h"
#endif
@@ -43,9 +45,10 @@ const int kNotifyUserAfterMs = 0;
// The thread to run the upgrade detection code on. We use FILE for Linux
// because we don't want to block the UI thread while launching a background
-// process and reading its output.
+// process and reading its output; on the Mac, checking for an upgrade
+// requires reading a file.
const ChromeThread::ID kDetectUpgradeTaskID =
-#if defined(OS_LINUX)
+#if defined(OS_POSIX)
ChromeThread::FILE;
#else
ChromeThread::UI;
@@ -71,19 +74,24 @@ class DetectUpgradeTask : public Task {
virtual void Run() {
DCHECK(ChromeThread::CurrentlyOn(kDetectUpgradeTaskID));
-#if defined(OS_WIN) || defined(OS_LINUX)
using installer::Version;
+ scoped_ptr<Version> installed_version;
#if defined(OS_WIN)
// Get the version of the currently *installed* instance of Chrome,
// which might be newer than the *running* instance if we have been
// upgraded in the background.
- scoped_ptr<Version> installed_version(InstallUtil::GetChromeVersion(false));
+ installed_version.reset(InstallUtil::GetChromeVersion(false));
if (!installed_version.get()) {
// User level Chrome is not installed, check system level.
installed_version.reset(InstallUtil::GetChromeVersion(true));
}
-#elif defined(OS_LINUX)
+#elif defined(OS_MACOSX)
+ installed_version.reset(
+ Version::GetVersionFromString(
+ keystone_glue::CurrentlyInstalledVersion()));
+#elif defined(OS_POSIX)
+ // POSIX but not Mac OS X: Linux, etc.
CommandLine command_line(*CommandLine::ForCurrentProcess());
command_line.AppendSwitch(switches::kProductVersion);
std::string reply;
@@ -92,8 +100,7 @@ class DetectUpgradeTask : public Task {
return;
}
- scoped_ptr<Version> installed_version(
- Version::GetVersionFromString(ASCIIToUTF16(reply)));
+ installed_version.reset(Version::GetVersionFromString(ASCIIToUTF16(reply)));
#endif
// Get the version of the currently *running* instance of Chrome.
@@ -119,10 +126,6 @@ class DetectUpgradeTask : public Task {
upgrade_detected_task_);
upgrade_detected_task_ = NULL;
}
-#else // !(defined(OS_WIN) || defined(OS_LINUX))
- DCHECK(kNotifyUserAfterMs >= 0); // Avoid error: var defined but not used.
- NOTIMPLEMENTED();
-#endif
}
private:
@@ -139,12 +142,18 @@ void UpgradeDetector::RegisterPrefs(PrefService* prefs) {
UpgradeDetector::UpgradeDetector()
: ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)),
notify_upgrade_(false) {
- // Upgrade notifications work on Windows (only Google Chrome) and Linux
- // (chromium and Google Chrome).
-#if (defined(OS_WIN) && defined(GOOGLE_CHROME_BUILD)) || defined(OS_LINUX)
- detect_upgrade_timer_.Start(
- base::TimeDelta::FromMilliseconds(kCheckForUpgradeEveryMs),
- this, &UpgradeDetector::CheckForUpgrade);
+ // Windows: only enable upgrade notifications for official builds.
+ // Mac: only enable them if the updater (Keystone) is present.
+ // Linux (and other POSIX): always enable regardless of branding.
+#if (defined(OS_WIN) && defined(GOOGLE_CHROME_BUILD)) || defined(OS_POSIX)
+#if defined(OS_MACOSX)
+ if (keystone_glue::KeystoneEnabled())
+#endif
+ {
+ detect_upgrade_timer_.Start(
+ base::TimeDelta::FromMilliseconds(kCheckForUpgradeEveryMs),
+ this, &UpgradeDetector::CheckForUpgrade);
+ }
#endif
}
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index 18d5d10..c53d6be 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -16,6 +16,7 @@
'chrome_strings',
'chrome_version_info',
'component_extensions',
+ 'installer_util',
'platform_locale_settings',
'profile_import',
'browser/sync/protocol/sync_proto.gyp:sync_proto_cpp',
@@ -3052,10 +3053,6 @@
'<@(xib_files_to_scan)'],
},
],
- }, { # OS != mac
- 'dependencies': [
- 'installer_util',
- ],
}],
['OS=="win"', {
'defines': [
diff --git a/chrome/chrome_installer_util.gypi b/chrome/chrome_installer_util.gypi
index a7dac66..84ae839 100644
--- a/chrome/chrome_installer_util.gypi
+++ b/chrome/chrome_installer_util.gypi
@@ -151,6 +151,21 @@
}
],
}],
+ ['OS=="mac"', {
+ 'targets': [
+ {
+ 'target_name': 'installer_util',
+ 'type': '<(library)',
+ 'dependencies': [
+ '../base/base.gyp:base',
+ ],
+ 'sources': [
+ 'installer/util/version.cc',
+ 'installer/util/version.h',
+ ],
+ }
+ ],
+ }],
],
}