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.
5 #ifndef CHROME_BROWSER_UPGRADE_DETECTOR_IMPL_H_
6 #define CHROME_BROWSER_UPGRADE_DETECTOR_IMPL_H_
8 #include "base/memory/weak_ptr.h"
9 #include "base/timer/timer.h"
10 #include "base/version.h"
11 #include "chrome/browser/upgrade_detector.h"
12 #include "components/variations/service/variations_service.h"
14 template <typename T
> struct DefaultSingletonTraits
;
16 class UpgradeDetectorImpl
: public UpgradeDetector
,
17 public variations::VariationsService::Observer
{
19 ~UpgradeDetectorImpl() override
;
21 // Returns the currently installed Chrome version, which may be newer than the
22 // one currently running. Not supported on Android, iOS or ChromeOS. Must be
23 // run on a thread where I/O operations are allowed (e.g. FILE thread).
24 static base::Version
GetCurrentlyInstalledVersion();
26 // Returns the singleton instance.
27 static UpgradeDetectorImpl
* GetInstance();
30 UpgradeDetectorImpl();
32 // variations::VariationsService::Observer:
33 void OnExperimentChangesDetected(Severity severity
) override
;
35 // Trigger an "on upgrade" notification based on the specified |time_passed|
36 // interval. Exposed as protected for testing.
37 void NotifyOnUpgradeWithTimePassed(base::TimeDelta time_passed
);
40 friend struct DefaultSingletonTraits
<UpgradeDetectorImpl
>;
42 // Start the timer that will call |CheckForUpgrade()|.
43 void StartTimerForUpgradeCheck();
45 // Launches a task on the file thread to check if we have the latest version.
46 void CheckForUpgrade();
48 // Starts the upgrade notification timer that will check periodically whether
49 // enough time has elapsed to update the severity (which maps to visual
50 // badging) of the notification.
51 void StartUpgradeNotificationTimer();
53 // Sends out a notification and starts a one shot timer to wait until
54 // notifying the user.
55 void UpgradeDetected(UpgradeAvailable upgrade_available
);
57 // Returns true after calling UpgradeDetected if current install is outdated.
58 bool DetectOutdatedInstall();
60 // The function that sends out a notification (after a certain time has
61 // elapsed) that lets the rest of the UI know we should start notifying the
62 // user that a new version is available.
63 void NotifyOnUpgrade();
65 // Called on the FILE thread to detect an upgrade. Calls back UpgradeDetected
66 // on the UI thread if so. Although it looks weird, this needs to be a static
67 // method receiving a WeakPtr<> to this object so that we can interrupt
68 // the UpgradeDetected callback before it runs. Having this method non-static
69 // and using |this| directly wouldn't be thread safe. And keeping it as a
70 // non-class function would prevent it from calling UpgradeDetected.
71 static void DetectUpgradeTask(
72 base::WeakPtr
<UpgradeDetectorImpl
> upgrade_detector
);
74 // We periodically check to see if Chrome has been upgraded.
75 base::RepeatingTimer
<UpgradeDetectorImpl
> detect_upgrade_timer_
;
77 // After we detect an upgrade we start a recurring timer to see if enough time
78 // has passed and we should start notifying the user.
79 base::RepeatingTimer
<UpgradeDetectorImpl
> upgrade_notification_timer_
;
81 // True if this build is a dev or canary channel build.
82 bool is_unstable_channel_
;
84 // True if auto update is turned on.
85 bool is_auto_update_enabled_
;
87 // When the upgrade was detected - either a software update or a variations
88 // update, whichever happened first.
89 base::TimeTicks upgrade_detected_time_
;
91 // The date the binaries were built.
92 base::Time build_date_
;
94 // We use this factory to create callback tasks for UpgradeDetected. We pass
95 // the task to the actual upgrade detection code, which is in
97 base::WeakPtrFactory
<UpgradeDetectorImpl
> weak_factory_
;
99 DISALLOW_COPY_AND_ASSIGN(UpgradeDetectorImpl
);
103 #endif // CHROME_BROWSER_UPGRADE_DETECTOR_IMPL_H_