diff options
author | finnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-26 20:11:54 +0000 |
---|---|---|
committer | finnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-26 20:11:54 +0000 |
commit | b1b7394fa3880dab9f9bd0cfc40ea8c614f0b49e (patch) | |
tree | d6e9f57d10714b67c4c7fbed0e874d4e337f406e /chrome/browser/upgrade_detector.cc | |
parent | a8e4a8fa39604cd309e1e3d62cf9c552dcfe541d (diff) | |
download | chromium_src-b1b7394fa3880dab9f9bd0cfc40ea8c614f0b49e.zip chromium_src-b1b7394fa3880dab9f9bd0cfc40ea8c614f0b49e.tar.gz chromium_src-b1b7394fa3880dab9f9bd0cfc40ea8c614f0b49e.tar.bz2 |
Implement upgrade notifications.
When we detect that the installed version is newer than the version you are
running we show a little throbbing orange dot over the wrench menu.
If you open the wrench menu and close it again, the throbbing will stop.
However, if you look at the contents of the wrench menu you'll notice that
the About box menu item has been removed and in its place is a menu item
"Update Chrome Now" with a bright orange icon to draw your attention to it.
Clicking on the icon shows a dialog box asking whether you want to restart
Chrome. If you do, the browser restarts with your session restored
(even if you have Session Restore turned off).
Known issues:
- Currently this is Windows only. We'll have to port this to Linux and do
something differnet for Mac (which doesn't have the wrench menu).
- Showing an icon in front of Update Chrome causes the checkbox for the
bookmark bar menu to go away. Given that we will soon redesign the menus I'm
not going to spend much time trying to fix it.
BUG=27941
TEST=Wait for Chrome to be upgraded in the background, an orange dot should
appear over the wrench menu and if you select Update Chrome your session should
be retained.
Review URL: http://codereview.chromium.org/2225003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@48318 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/upgrade_detector.cc')
-rw-r--r-- | chrome/browser/upgrade_detector.cc | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/chrome/browser/upgrade_detector.cc b/chrome/browser/upgrade_detector.cc new file mode 100644 index 0000000..3aedb9a --- /dev/null +++ b/chrome/browser/upgrade_detector.cc @@ -0,0 +1,96 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/upgrade_detector.h" + +#include "base/file_version_info.h" +#include "base/scoped_ptr.h" +#include "base/time.h" +#include "base/version.h" +#include "chrome/app/chrome_version_info.h" +#include "chrome/common/notification_service.h" +#include "chrome/common/notification_type.h" +#include "chrome/installer/util/browser_distribution.h" + +#if defined(OS_WIN) +#include "chrome/installer/util/install_util.h" +#endif + +// TODO(finnur): For the stable channel we want to check daily and notify +// the user if more than 2 weeks have passed since the upgrade happened +// (without a reboot). For the dev channel however, I want quicker feedback +// on how the feature works so I'm checking every hour and notifying the +// user immediately. + +// How often to check for an upgrade. +static int kCheckForUpgradeEveryMs = 60 * 60 * 1000; // 1 hour. + +// How long to wait before notifying the user about the upgrade. +static int kNotifyUserAfterMs = 0; + +UpgradeDetector::UpgradeDetector() : upgrade_detected_(false) { +#if !defined(OS_WIN) + return; +#endif + + detect_upgrade_timer_.Start( + base::TimeDelta::FromMilliseconds(kCheckForUpgradeEveryMs), + this, &UpgradeDetector::CheckForUpgrade); +} + +UpgradeDetector::~UpgradeDetector() { +} + +void UpgradeDetector::CheckForUpgrade() { +#if defined(OS_WIN) + using installer::Version; + + // 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. + Version* installed_version = InstallUtil::GetChromeVersion(false); + if (!installed_version) { + // User level Chrome is not installed, check system level. + installed_version = InstallUtil::GetChromeVersion(true); + } + + // Get the version of the currently *running* instance of Chrome. + scoped_ptr<FileVersionInfo> version(chrome_app::GetChromeVersionInfo()); + if (version.get() == NULL) { + NOTREACHED() << L"Failed to get current file version"; + return; + } + scoped_ptr<Version> running_version(Version::GetVersionFromString( + version->file_version())); + + if (installed_version->IsHigherThan(running_version.get())) { + // Stop the recurring timer (that is checking for changes). + detect_upgrade_timer_.Stop(); + + upgrade_detected_ = true; + + NotificationService::current()->Notify( + NotificationType::UPGRADE_DETECTED, + Source<UpgradeDetector>(this), + NotificationService::NoDetails()); + + // Start the OneShot timer for notifying the user after a certain period. + upgrade_notification_timer_.Start( + base::TimeDelta::FromMilliseconds(kNotifyUserAfterMs), + this, &UpgradeDetector::NotifyOnUpgrade); + } +#else + DCHECK(kNotifyUserAfterMs > 0); // Avoid error: var defined but not used. + NOTIMPLEMENTED(); +#endif +} + +void UpgradeDetector::NotifyOnUpgrade() { + notify_upgrade_ = true; + + NotificationService::current()->Notify( + NotificationType::UPGRADE_RECOMMENDED, + Source<UpgradeDetector>(this), + NotificationService::NoDetails()); +} |