Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / upgrade_detector.h
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
8 #include "base/timer/timer.h"
9 #include "chrome/browser/chrome_notification_types.h"
10 #include "chrome/browser/idle.h"
11 #include "ui/gfx/image/image.h"
12
13 class PrefRegistrySimple;
14
15 ///////////////////////////////////////////////////////////////////////////////
16 // UpgradeDetector
17 //
18 // This class is a singleton class that monitors when an upgrade happens in the
19 // background. We basically ask Omaha what it thinks the latest version is and
20 // if our version is lower we send out a notification upon:
21 //   a) Detecting an upgrade and...
22 //   b) When we think the user should be notified about the upgrade.
23 // The latter happens much later, since we don't want to be too annoying.
24 //
25 class UpgradeDetector {
26  public:
27   // The Homeland Security Upgrade Advisory System.
28   enum UpgradeNotificationAnnoyanceLevel {
29     UPGRADE_ANNOYANCE_NONE = 0,  // What? Me worry?
30     UPGRADE_ANNOYANCE_LOW,       // Green.
31     UPGRADE_ANNOYANCE_ELEVATED,  // Yellow.
32     UPGRADE_ANNOYANCE_HIGH,      // Red.
33     UPGRADE_ANNOYANCE_SEVERE,    // Orange.
34     UPGRADE_ANNOYANCE_CRITICAL,  // Red exclamation mark.
35   };
36
37   // Returns the singleton implementation instance.
38   static UpgradeDetector* GetInstance();
39
40   virtual ~UpgradeDetector();
41
42   static void RegisterPrefs(PrefRegistrySimple* registry);
43
44   // Whether the user should be notified about an upgrade.
45   bool notify_upgrade() const { return notify_upgrade_; }
46
47   // Whether the upgrade recommendation is due to Chrome being outdated.
48   bool is_outdated_install() const {
49     return upgrade_available_ == UPGRADE_NEEDED_OUTDATED_INSTALL;
50   }
51
52   // Whether the upgrade recommendation is due to Chrome being outdated AND
53   // auto-update is turned off.
54   bool is_outdated_install_no_au() const {
55     return upgrade_available_ == UPGRADE_NEEDED_OUTDATED_INSTALL_NO_AU;
56   }
57
58   // Notifify this object that the user has acknowledged the critical update
59   // so we don't need to complain about it for now.
60   void acknowledge_critical_update() {
61     critical_update_acknowledged_ = true;
62   }
63
64   // Whether the user has acknowledged the critical update.
65   bool critical_update_acknowledged() const {
66     return critical_update_acknowledged_;
67   }
68
69   bool is_factory_reset_required() const { return is_factory_reset_required_; }
70
71   // Retrieves the right icon ID based on the degree of severity (see
72   // UpgradeNotificationAnnoyanceLevel, each level has an an accompanying icon
73   // to go with it) to display within the wrench menu.
74   int GetIconResourceID();
75
76   UpgradeNotificationAnnoyanceLevel upgrade_notification_stage() const {
77     return upgrade_notification_stage_;
78   }
79
80  protected:
81   enum UpgradeAvailable {
82     // If no update is available and current install is recent enough.
83     UPGRADE_AVAILABLE_NONE,
84     // If a regular update is available.
85     UPGRADE_AVAILABLE_REGULAR,
86     // If a critical update to Chrome has been installed, such as a zero-day
87     // fix.
88     UPGRADE_AVAILABLE_CRITICAL,
89     // If no update to Chrome has been installed for more than the recommended
90     // time.
91     UPGRADE_NEEDED_OUTDATED_INSTALL,
92     // If no update to Chrome has been installed for more than the recommended
93     // time AND auto-update is turned off.
94     UPGRADE_NEEDED_OUTDATED_INSTALL_NO_AU,
95   };
96
97   UpgradeDetector();
98
99   // Sends out UPGRADE_RECOMMENDED notification and set notify_upgrade_.
100   void NotifyUpgradeRecommended();
101
102   // Triggers a critical update, which starts a timer that checks the machine
103   // idle state. Protected and virtual so that it could be overridden by tests.
104   virtual void TriggerCriticalUpdate();
105
106   UpgradeAvailable upgrade_available() const { return upgrade_available_; }
107   void set_upgrade_available(UpgradeAvailable available) {
108     upgrade_available_ = available;
109   }
110
111   void set_best_effort_experiment_updates_available(bool available) {
112     best_effort_experiment_updates_available_ = available;
113   }
114
115   bool critical_experiment_updates_available() const {
116     return critical_experiment_updates_available_;
117   }
118   void set_critical_experiment_updates_available(bool available) {
119     critical_experiment_updates_available_ = available;
120   }
121
122   void set_critical_update_acknowledged(bool acknowledged) {
123     critical_update_acknowledged_ = acknowledged;
124   }
125
126   void set_upgrade_notification_stage(UpgradeNotificationAnnoyanceLevel stage) {
127     upgrade_notification_stage_ = stage;
128   }
129
130   void set_is_factory_reset_required(bool is_factory_reset_required) {
131     is_factory_reset_required_ = is_factory_reset_required;
132   }
133
134  private:
135   // Initiates an Idle check. See IdleCallback below.
136   void CheckIdle();
137
138   // The callback for the IdleCheck. Tells us whether Chrome has received any
139   // input events since the specified time.
140   void IdleCallback(IdleState state);
141
142   // Triggers a global notification of the specified |type|.
143   void TriggerNotification(chrome::NotificationType type);
144
145   // Whether any software updates are available (experiment updates are tracked
146   // separately via additional member variables below).
147   UpgradeAvailable upgrade_available_;
148
149   // Whether "best effort" experiment updates are available.
150   bool best_effort_experiment_updates_available_;
151
152   // Whether "critical" experiment updates are available.
153   bool critical_experiment_updates_available_;
154
155   // Whether the user has acknowledged the critical update.
156   bool critical_update_acknowledged_;
157
158   // Whether a factory reset is needed to complete an update.
159   bool is_factory_reset_required_;
160
161   // A timer to check to see if we've been idle for long enough to show the
162   // critical warning. Should only be set if |upgrade_available_| is
163   // UPGRADE_AVAILABLE_CRITICAL.
164   base::RepeatingTimer<UpgradeDetector> idle_check_timer_;
165
166   // The stage at which the annoyance level for upgrade notifications is at.
167   UpgradeNotificationAnnoyanceLevel upgrade_notification_stage_;
168
169   // Whether we have waited long enough after detecting an upgrade (to see
170   // is we should start nagging about upgrading).
171   bool notify_upgrade_;
172
173   DISALLOW_COPY_AND_ASSIGN(UpgradeDetector);
174 };
175
176 #endif  // CHROME_BROWSER_UPGRADE_DETECTOR_H_