OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/upgrade_detector.h" |
| 6 |
| 7 #include "base/file_version_info.h" |
| 8 #include "base/scoped_ptr.h" |
| 9 #include "base/time.h" |
| 10 #include "base/version.h" |
| 11 #include "chrome/app/chrome_version_info.h" |
| 12 #include "chrome/common/notification_service.h" |
| 13 #include "chrome/common/notification_type.h" |
| 14 #include "chrome/installer/util/browser_distribution.h" |
| 15 |
| 16 #if defined(OS_WIN) |
| 17 #include "chrome/installer/util/install_util.h" |
| 18 #endif |
| 19 |
| 20 // TODO(finnur): For the stable channel we want to check daily and notify |
| 21 // the user if more than 2 weeks have passed since the upgrade happened |
| 22 // (without a reboot). For the dev channel however, I want quicker feedback |
| 23 // on how the feature works so I'm checking every hour and notifying the |
| 24 // user immediately. |
| 25 |
| 26 // How often to check for an upgrade. |
| 27 static int kCheckForUpgradeEveryMs = 60 * 60 * 1000; // 1 hour. |
| 28 |
| 29 // How long to wait before notifying the user about the upgrade. |
| 30 static int kNotifyUserAfterMs = 0; |
| 31 |
| 32 UpgradeDetector::UpgradeDetector() : upgrade_detected_(false) { |
| 33 #if !defined(OS_WIN) |
| 34 return; |
| 35 #endif |
| 36 |
| 37 detect_upgrade_timer_.Start( |
| 38 base::TimeDelta::FromMilliseconds(kCheckForUpgradeEveryMs), |
| 39 this, &UpgradeDetector::CheckForUpgrade); |
| 40 } |
| 41 |
| 42 UpgradeDetector::~UpgradeDetector() { |
| 43 } |
| 44 |
| 45 void UpgradeDetector::CheckForUpgrade() { |
| 46 #if defined(OS_WIN) |
| 47 using installer::Version; |
| 48 |
| 49 // Get the version of the currently *installed* instance of Chrome, |
| 50 // which might be newer than the *running* instance if we have been |
| 51 // upgraded in the background. |
| 52 Version* installed_version = InstallUtil::GetChromeVersion(false); |
| 53 if (!installed_version) { |
| 54 // User level Chrome is not installed, check system level. |
| 55 installed_version = InstallUtil::GetChromeVersion(true); |
| 56 } |
| 57 |
| 58 // Get the version of the currently *running* instance of Chrome. |
| 59 scoped_ptr<FileVersionInfo> version(chrome_app::GetChromeVersionInfo()); |
| 60 if (version.get() == NULL) { |
| 61 NOTREACHED() << L"Failed to get current file version"; |
| 62 return; |
| 63 } |
| 64 scoped_ptr<Version> running_version(Version::GetVersionFromString( |
| 65 version->file_version())); |
| 66 |
| 67 if (installed_version->IsHigherThan(running_version.get())) { |
| 68 // Stop the recurring timer (that is checking for changes). |
| 69 detect_upgrade_timer_.Stop(); |
| 70 |
| 71 upgrade_detected_ = true; |
| 72 |
| 73 NotificationService::current()->Notify( |
| 74 NotificationType::UPGRADE_DETECTED, |
| 75 Source<UpgradeDetector>(this), |
| 76 NotificationService::NoDetails()); |
| 77 |
| 78 // Start the OneShot timer for notifying the user after a certain period. |
| 79 upgrade_notification_timer_.Start( |
| 80 base::TimeDelta::FromMilliseconds(kNotifyUserAfterMs), |
| 81 this, &UpgradeDetector::NotifyOnUpgrade); |
| 82 } |
| 83 #else |
| 84 DCHECK(kNotifyUserAfterMs > 0); // Avoid error: var defined but not used. |
| 85 NOTIMPLEMENTED(); |
| 86 #endif |
| 87 } |
| 88 |
| 89 void UpgradeDetector::NotifyOnUpgrade() { |
| 90 notify_upgrade_ = true; |
| 91 |
| 92 NotificationService::current()->Notify( |
| 93 NotificationType::UPGRADE_RECOMMENDED, |
| 94 Source<UpgradeDetector>(this), |
| 95 NotificationService::NoDetails()); |
| 96 } |
OLD | NEW |