• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_H_
6 #define CHROME_BROWSER_UPGRADE_DETECTOR_H_
7 #pragma once
8 
9 #include "base/timer.h"
10 
11 template <typename T> struct DefaultSingletonTraits;
12 class PrefService;
13 
14 ///////////////////////////////////////////////////////////////////////////////
15 // UpgradeDetector
16 //
17 // This class is a singleton class that monitors when an upgrade happens in the
18 // background. We basically ask Omaha what it thinks the latest version is and
19 // if our version is lower we send out a notification upon:
20 //   a) Detecting an upgrade and...
21 //   b) When we think the user should be notified about the upgrade.
22 // The latter happens much later, since we don't want to be too annoying.
23 //
24 class UpgradeDetector {
25  public:
26   // The Homeland Security Upgrade Advisory System.
27   enum UpgradeNotificationAnnoyanceLevel {
28     UPGRADE_ANNOYANCE_NONE = 0,  // What? Me worry?
29     UPGRADE_ANNOYANCE_LOW,       // Green.
30     UPGRADE_ANNOYANCE_ELEVATED,  // Yellow.
31     UPGRADE_ANNOYANCE_HIGH,      // Red.
32     UPGRADE_ANNOYANCE_SEVERE,    // Orange.
33   };
34 
35   // Returns the singleton instance.
36   static UpgradeDetector* GetInstance();
37 
38   ~UpgradeDetector();
39 
40   static void RegisterPrefs(PrefService* prefs);
41 
notify_upgrade()42   bool notify_upgrade() { return notify_upgrade_; }
43 
upgrade_notification_stage()44   UpgradeNotificationAnnoyanceLevel upgrade_notification_stage() const {
45     return upgrade_notification_stage_;
46   }
47 
48  private:
49   friend struct DefaultSingletonTraits<UpgradeDetector>;
50 
51   UpgradeDetector();
52 
53   // Launches a task on the file thread to check if we have the latest version.
54   void CheckForUpgrade();
55 
56   // Sends out a notification and starts a one shot timer to wait until
57   // notifying the user.
58   void UpgradeDetected();
59 
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();
64 
65   // We periodically check to see if Chrome has been upgraded.
66   base::RepeatingTimer<UpgradeDetector> detect_upgrade_timer_;
67 
68   // After we detect an upgrade we start a recurring timer to see if enough time
69   // has passed and we should start notifying the user.
70   base::RepeatingTimer<UpgradeDetector> upgrade_notification_timer_;
71 
72   // We use this factory to create callback tasks for UpgradeDetected. We pass
73   // the task to the actual upgrade detection code, which is in
74   // DetectUpgradeTask.
75   ScopedRunnableMethodFactory<UpgradeDetector> method_factory_;
76 
77   // When the upgrade was detected.
78   base::Time upgrade_detected_time_;
79 
80   // Whether this build is a dev channel build or not.
81   bool is_dev_channel_;
82 
83   // The stage at which the annoyance level for upgrade notifications is at.
84   UpgradeNotificationAnnoyanceLevel upgrade_notification_stage_;
85 
86   // Whether we have waited long enough after detecting an upgrade (to see
87   // is we should start nagging about upgrading).
88   bool notify_upgrade_;
89 
90   DISALLOW_COPY_AND_ASSIGN(UpgradeDetector);
91 };
92 
93 #endif  // CHROME_BROWSER_UPGRADE_DETECTOR_H_
94