[email protected] | ceff840 | 2011-06-12 23:27:12 | [diff] [blame] | 1 | // Copyright (c) 2011 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 | #ifndef CHROME_BROWSER_UPGRADE_DETECTOR_IMPL_H_ |
| 6 | #define CHROME_BROWSER_UPGRADE_DETECTOR_IMPL_H_ |
[email protected] | ceff840 | 2011-06-12 23:27:12 | [diff] [blame] | 7 | |
[email protected] | 6198f798 | 2011-11-17 21:24:37 | [diff] [blame] | 8 | #include "base/memory/weak_ptr.h" |
[email protected] | ceff840 | 2011-06-12 23:27:12 | [diff] [blame] | 9 | #include "base/timer.h" |
[email protected] | daae346 | 2013-04-30 03:45:14 | [diff] [blame] | 10 | #include "chrome/browser/net/network_time_tracker.h" |
[email protected] | ceff840 | 2011-06-12 23:27:12 | [diff] [blame] | 11 | #include "chrome/browser/upgrade_detector.h" |
| 12 | |
| 13 | template <typename T> struct DefaultSingletonTraits; |
| 14 | |
| 15 | class UpgradeDetectorImpl : public UpgradeDetector { |
| 16 | public: |
| 17 | virtual ~UpgradeDetectorImpl(); |
| 18 | |
| 19 | // Returns the singleton instance. |
| 20 | static UpgradeDetectorImpl* GetInstance(); |
| 21 | |
| 22 | private: |
| 23 | friend struct DefaultSingletonTraits<UpgradeDetectorImpl>; |
| 24 | |
| 25 | UpgradeDetectorImpl(); |
| 26 | |
[email protected] | 2a54f2d | 2013-02-15 05:54:36 | [diff] [blame] | 27 | // Start the timer that will call |CheckForUpgrade()|. |
| 28 | void StartTimerForUpgradeCheck(); |
| 29 | |
[email protected] | ceff840 | 2011-06-12 23:27:12 | [diff] [blame] | 30 | // Launches a task on the file thread to check if we have the latest version. |
| 31 | void CheckForUpgrade(); |
| 32 | |
| 33 | // Sends out a notification and starts a one shot timer to wait until |
| 34 | // notifying the user. |
[email protected] | 2a54f2d | 2013-02-15 05:54:36 | [diff] [blame] | 35 | void UpgradeDetected(UpgradeAvailable upgrade_available); |
| 36 | |
| 37 | // Returns true after calling UpgradeDetected if current install is outdated. |
| 38 | bool DetectOutdatedInstall(); |
[email protected] | ceff840 | 2011-06-12 23:27:12 | [diff] [blame] | 39 | |
| 40 | // The function that sends out a notification (after a certain time has |
| 41 | // elapsed) that lets the rest of the UI know we should start notifying the |
| 42 | // user that a new version is available. |
| 43 | void NotifyOnUpgrade(); |
| 44 | |
[email protected] | 2a54f2d | 2013-02-15 05:54:36 | [diff] [blame] | 45 | // Called on the FILE thread to detect an upgrade. Calls back UpgradeDetected |
| 46 | // on the UI thread if so. Although it looks weird, this needs to be a static |
| 47 | // method receiving a WeakPtr<> to this object so that we can interrupt |
| 48 | // the UpgradeDetected callback before it runs. Having this method non-static |
| 49 | // and using |this| directly wouldn't be thread safe. And keeping it as a |
| 50 | // non-class function would prevent it from calling UpgradeDetected. |
| 51 | static void DetectUpgradeTask( |
| 52 | base::WeakPtr<UpgradeDetectorImpl> upgrade_detector); |
| 53 | |
[email protected] | ceff840 | 2011-06-12 23:27:12 | [diff] [blame] | 54 | // We periodically check to see if Chrome has been upgraded. |
| 55 | base::RepeatingTimer<UpgradeDetectorImpl> detect_upgrade_timer_; |
| 56 | |
| 57 | // After we detect an upgrade we start a recurring timer to see if enough time |
| 58 | // has passed and we should start notifying the user. |
| 59 | base::RepeatingTimer<UpgradeDetectorImpl> upgrade_notification_timer_; |
| 60 | |
| 61 | // We use this factory to create callback tasks for UpgradeDetected. We pass |
| 62 | // the task to the actual upgrade detection code, which is in |
| 63 | // DetectUpgradeTask. |
[email protected] | 6198f798 | 2011-11-17 21:24:37 | [diff] [blame] | 64 | base::WeakPtrFactory<UpgradeDetectorImpl> weak_factory_; |
[email protected] | ceff840 | 2011-06-12 23:27:12 | [diff] [blame] | 65 | |
| 66 | // True if this build is a dev or canary channel build. |
| 67 | bool is_unstable_channel_; |
| 68 | |
[email protected] | 2a54f2d | 2013-02-15 05:54:36 | [diff] [blame] | 69 | // The date the binaries were built. |
| 70 | base::Time build_date_; |
| 71 | |
[email protected] | daae346 | 2013-04-30 03:45:14 | [diff] [blame] | 72 | // Tracker for getting network time. |
| 73 | NetworkTimeTracker network_time_tracker_; |
| 74 | |
[email protected] | ceff840 | 2011-06-12 23:27:12 | [diff] [blame] | 75 | DISALLOW_COPY_AND_ASSIGN(UpgradeDetectorImpl); |
| 76 | }; |
| 77 | |
| 78 | |
| 79 | #endif // CHROME_BROWSER_UPGRADE_DETECTOR_IMPL_H_ |