Move AppMenuTest from ChromeShellTest to ChromePublicTest
[chromium-blink-merge.git] / chrome / browser / upgrade_detector_impl.h
blobaeba643e5533be724362e642b7bb0ea2fd73ee1c
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/metrics/variations/variations_service.h"
12 #include "chrome/browser/upgrade_detector.h"
14 template <typename T> struct DefaultSingletonTraits;
16 class UpgradeDetectorImpl :
17 public UpgradeDetector,
18 public chrome_variations::VariationsService::Observer {
19 public:
20 ~UpgradeDetectorImpl() override;
22 // Returns the currently installed Chrome version, which may be newer than the
23 // one currently running. Not supported on Android, iOS or ChromeOS. Must be
24 // run on a thread where I/O operations are allowed (e.g. FILE thread).
25 static base::Version GetCurrentlyInstalledVersion();
27 // Returns the singleton instance.
28 static UpgradeDetectorImpl* GetInstance();
30 protected:
31 UpgradeDetectorImpl();
33 // chrome_variations::VariationsService::Observer:
34 void OnExperimentChangesDetected(Severity severity) override;
36 // Trigger an "on upgrade" notification based on the specified |time_passed|
37 // interval. Exposed as protected for testing.
38 void NotifyOnUpgradeWithTimePassed(base::TimeDelta time_passed);
40 private:
41 friend struct DefaultSingletonTraits<UpgradeDetectorImpl>;
43 // Start the timer that will call |CheckForUpgrade()|.
44 void StartTimerForUpgradeCheck();
46 // Launches a task on the file thread to check if we have the latest version.
47 void CheckForUpgrade();
49 // Starts the upgrade notification timer that will check periodically whether
50 // enough time has elapsed to update the severity (which maps to visual
51 // badging) of the notification.
52 void StartUpgradeNotificationTimer();
54 // Sends out a notification and starts a one shot timer to wait until
55 // notifying the user.
56 void UpgradeDetected(UpgradeAvailable upgrade_available);
58 // Returns true after calling UpgradeDetected if current install is outdated.
59 bool DetectOutdatedInstall();
61 // The function that sends out a notification (after a certain time has
62 // elapsed) that lets the rest of the UI know we should start notifying the
63 // user that a new version is available.
64 void NotifyOnUpgrade();
66 // Called on the FILE thread to detect an upgrade. Calls back UpgradeDetected
67 // on the UI thread if so. Although it looks weird, this needs to be a static
68 // method receiving a WeakPtr<> to this object so that we can interrupt
69 // the UpgradeDetected callback before it runs. Having this method non-static
70 // and using |this| directly wouldn't be thread safe. And keeping it as a
71 // non-class function would prevent it from calling UpgradeDetected.
72 static void DetectUpgradeTask(
73 base::WeakPtr<UpgradeDetectorImpl> upgrade_detector);
75 // We periodically check to see if Chrome has been upgraded.
76 base::RepeatingTimer<UpgradeDetectorImpl> detect_upgrade_timer_;
78 // After we detect an upgrade we start a recurring timer to see if enough time
79 // has passed and we should start notifying the user.
80 base::RepeatingTimer<UpgradeDetectorImpl> upgrade_notification_timer_;
82 // True if this build is a dev or canary channel build.
83 bool is_unstable_channel_;
85 // True if auto update is turned on.
86 bool is_auto_update_enabled_;
88 // When the upgrade was detected - either a software update or a variations
89 // update, whichever happened first.
90 base::TimeTicks upgrade_detected_time_;
92 // The date the binaries were built.
93 base::Time build_date_;
95 // We use this factory to create callback tasks for UpgradeDetected. We pass
96 // the task to the actual upgrade detection code, which is in
97 // DetectUpgradeTask.
98 base::WeakPtrFactory<UpgradeDetectorImpl> weak_factory_;
100 DISALLOW_COPY_AND_ASSIGN(UpgradeDetectorImpl);
104 #endif // CHROME_BROWSER_UPGRADE_DETECTOR_IMPL_H_