Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(405)

Side by Side Diff: chrome/browser/upgrade_detector.h

Issue 7046096: Refactor UpgradeDetector. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sync and address finnur's comments in set 2 Created 9 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_UPGRADE_DETECTOR_H_ 5 #ifndef CHROME_BROWSER_UPGRADE_DETECTOR_H_
6 #define CHROME_BROWSER_UPGRADE_DETECTOR_H_ 6 #define CHROME_BROWSER_UPGRADE_DETECTOR_H_
7 #pragma once 7 #pragma once
8 8
9 #include "base/timer.h" 9 #include "base/timer.h"
10 #include "ui/gfx/image.h" 10 #include "ui/gfx/image.h"
11 11
12 template <typename T> struct DefaultSingletonTraits;
13 class PrefService; 12 class PrefService;
14 13
15 /////////////////////////////////////////////////////////////////////////////// 14 ///////////////////////////////////////////////////////////////////////////////
16 // UpgradeDetector 15 // UpgradeDetector
17 // 16 //
18 // This class is a singleton class that monitors when an upgrade happens in the 17 // 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 18 // 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: 19 // if our version is lower we send out a notification upon:
21 // a) Detecting an upgrade and... 20 // a) Detecting an upgrade and...
22 // b) When we think the user should be notified about the upgrade. 21 // 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. 22 // The latter happens much later, since we don't want to be too annoying.
24 // 23 //
25 class UpgradeDetector { 24 class UpgradeDetector {
26 public: 25 public:
27 // The Homeland Security Upgrade Advisory System. 26 // The Homeland Security Upgrade Advisory System.
28 enum UpgradeNotificationAnnoyanceLevel { 27 enum UpgradeNotificationAnnoyanceLevel {
29 UPGRADE_ANNOYANCE_NONE = 0, // What? Me worry? 28 UPGRADE_ANNOYANCE_NONE = 0, // What? Me worry?
30 UPGRADE_ANNOYANCE_LOW, // Green. 29 UPGRADE_ANNOYANCE_LOW, // Green.
31 UPGRADE_ANNOYANCE_ELEVATED, // Yellow. 30 UPGRADE_ANNOYANCE_ELEVATED, // Yellow.
32 UPGRADE_ANNOYANCE_HIGH, // Red. 31 UPGRADE_ANNOYANCE_HIGH, // Red.
33 UPGRADE_ANNOYANCE_SEVERE, // Orange. 32 UPGRADE_ANNOYANCE_SEVERE, // Orange.
34 }; 33 };
35 34
36 // The two types of icons we know about. 35 // The two types of icons we know about.
37 enum UpgradeNotificationIconType { 36 enum UpgradeNotificationIconType {
38 UPGRADE_ICON_TYPE_BADGE = 0, // For overlay badging of the wrench menu. 37 UPGRADE_ICON_TYPE_BADGE = 0, // For overlay badging of the wrench menu.
39 UPGRADE_ICON_TYPE_MENU_ICON, // For showing in the wrench menu. 38 UPGRADE_ICON_TYPE_MENU_ICON, // For showing in the wrench menu.
40 }; 39 };
41 40
42 // Returns the singleton instance. 41 // Returns the singleton implementation instance.
43 static UpgradeDetector* GetInstance(); 42 static UpgradeDetector* GetInstance();
44 43
45 ~UpgradeDetector(); 44 virtual ~UpgradeDetector();
46 45
47 static void RegisterPrefs(PrefService* prefs); 46 static void RegisterPrefs(PrefService* prefs);
48 47
49 bool notify_upgrade() { return notify_upgrade_; } 48 bool notify_upgrade() { return notify_upgrade_; }
50 49
51 // Retrieves the right icon ID based on the degree of severity (see 50 // Retrieves the right icon ID based on the degree of severity (see
52 // UpgradeNotificationAnnoyanceLevel, each level has an an accompanying icon 51 // UpgradeNotificationAnnoyanceLevel, each level has an an accompanying icon
53 // to go with it). |type| determines which class of icons the caller wants, 52 // to go with it). |type| determines which class of icons the caller wants,
54 // either an icon appropriate for badging the wrench menu or one to display 53 // either an icon appropriate for badging the wrench menu or one to display
55 // within the wrench menu. 54 // within the wrench menu.
56 int GetIconResourceID(UpgradeNotificationIconType type); 55 int GetIconResourceID(UpgradeNotificationIconType type);
57 56
58 private: 57 protected:
59 friend struct DefaultSingletonTraits<UpgradeDetector>;
60
61 UpgradeDetector(); 58 UpgradeDetector();
62 59
63 // Launches a task on the file thread to check if we have the latest version. 60 // Sends out UPGRADE_DETECTED notification and record upgrade_detected_time_.
64 void CheckForUpgrade(); 61 void NotifyUpgradeDetected();
65 62
66 // Sends out a notification and starts a one shot timer to wait until 63 // Sends out UPGRADE_RECOMMENDED notification and set notify_upgrade_.
67 // notifying the user. 64 void NotifyUpgradeRecommended();
68 void UpgradeDetected();
69 65
70 // The function that sends out a notification (after a certain time has 66 // Accessors.
71 // elapsed) that lets the rest of the UI know we should start notifying the 67 const base::Time& upgrade_detected_time() const {
72 // user that a new version is available. 68 return upgrade_detected_time_;
73 void NotifyOnUpgrade(); 69 }
74 70
75 // We periodically check to see if Chrome has been upgraded. 71 void set_upgrade_notification_stage(UpgradeNotificationAnnoyanceLevel stage) {
76 base::RepeatingTimer<UpgradeDetector> detect_upgrade_timer_; 72 upgrade_notification_stage_ = stage;
73 }
77 74
78 // After we detect an upgrade we start a recurring timer to see if enough time 75 private:
79 // has passed and we should start notifying the user.
80 base::RepeatingTimer<UpgradeDetector> upgrade_notification_timer_;
81
82 // We use this factory to create callback tasks for UpgradeDetected. We pass
83 // the task to the actual upgrade detection code, which is in
84 // DetectUpgradeTask.
85 ScopedRunnableMethodFactory<UpgradeDetector> method_factory_;
86
87 // When the upgrade was detected. 76 // When the upgrade was detected.
88 base::Time upgrade_detected_time_; 77 base::Time upgrade_detected_time_;
89 78
90 // True if this build is a dev or canary channel build.
91 bool is_unstable_channel_;
92
93 // The stage at which the annoyance level for upgrade notifications is at. 79 // The stage at which the annoyance level for upgrade notifications is at.
94 UpgradeNotificationAnnoyanceLevel upgrade_notification_stage_; 80 UpgradeNotificationAnnoyanceLevel upgrade_notification_stage_;
95 81
96 // Whether we have waited long enough after detecting an upgrade (to see 82 // Whether we have waited long enough after detecting an upgrade (to see
97 // is we should start nagging about upgrading). 83 // is we should start nagging about upgrading).
98 bool notify_upgrade_; 84 bool notify_upgrade_;
99 85
100 DISALLOW_COPY_AND_ASSIGN(UpgradeDetector); 86 DISALLOW_COPY_AND_ASSIGN(UpgradeDetector);
101 }; 87 };
102 88
103 #endif // CHROME_BROWSER_UPGRADE_DETECTOR_H_ 89 #endif // CHROME_BROWSER_UPGRADE_DETECTOR_H_
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/upgrade_detector_chromeos.cc ('k') | chrome/browser/upgrade_detector.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698