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

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

Issue 2925973002: Migrate upgrade notifications to observer (Closed)
Patch Set: Fix test failure Created 3 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #include "chrome/browser/upgrade_detector.h" 5 #include "chrome/browser/upgrade_detector.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "chrome/app/vector_icons/vector_icons.h" 9 #include "chrome/app/vector_icons/vector_icons.h"
10 #include "chrome/browser/chrome_notification_types.h"
11 #include "chrome/browser/lifetime/application_lifetime.h" 10 #include "chrome/browser/lifetime/application_lifetime.h"
12 #include "chrome/browser/ui/browser_otr_state.h" 11 #include "chrome/browser/ui/browser_otr_state.h"
13 #include "chrome/common/chrome_switches.h" 12 #include "chrome/common/chrome_switches.h"
14 #include "chrome/common/pref_names.h" 13 #include "chrome/common/pref_names.h"
15 #include "components/prefs/pref_registry_simple.h" 14 #include "components/prefs/pref_registry_simple.h"
16 #include "content/public/browser/notification_service.h"
17 #include "ui/gfx/color_palette.h" 15 #include "ui/gfx/color_palette.h"
18 #include "ui/gfx/paint_vector_icon.h" 16 #include "ui/gfx/paint_vector_icon.h"
19 17
20 // How long to wait between checks for whether the user has been idle. 18 // How long to wait between checks for whether the user has been idle.
21 static const int kIdleRepeatingTimerWait = 10; // Minutes (seconds if testing). 19 static const int kIdleRepeatingTimerWait = 10; // Minutes (seconds if testing).
22 20
23 // How much idle time (since last input even was detected) must have passed 21 // How much idle time (since last input even was detected) must have passed
24 // until we notify that a critical update has occurred. 22 // until we notify that a critical update has occurred.
25 static const int kIdleAmount = 2; // Hours (or seconds, if testing). 23 static const int kIdleAmount = 2; // Hours (or seconds, if testing).
26 24
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 critical_experiment_updates_available_(false), 64 critical_experiment_updates_available_(false),
67 critical_update_acknowledged_(false), 65 critical_update_acknowledged_(false),
68 is_factory_reset_required_(false), 66 is_factory_reset_required_(false),
69 upgrade_notification_stage_(UPGRADE_ANNOYANCE_NONE), 67 upgrade_notification_stage_(UPGRADE_ANNOYANCE_NONE),
70 notify_upgrade_(false) { 68 notify_upgrade_(false) {
71 } 69 }
72 70
73 UpgradeDetector::~UpgradeDetector() { 71 UpgradeDetector::~UpgradeDetector() {
74 } 72 }
75 73
76 void UpgradeDetector::NotifyUpgradeRecommended() { 74 void UpgradeDetector::NotifyOutdatedInstall() {
75 for (auto& observer : observer_list_)
76 observer.OnOutdatedInstall();
77 }
78
79 void UpgradeDetector::NotifyOutdatedInstallNoAU() {
80 for (auto& observer : observer_list_)
81 observer.OnOutdatedInstallNoAU();
82 }
83
84 void UpgradeDetector::NotifyUpgrade() {
77 notify_upgrade_ = true; 85 notify_upgrade_ = true;
78 86
79 TriggerNotification(chrome::NOTIFICATION_UPGRADE_RECOMMENDED); 87 NotifyUpgradeRecommended();
80 if (upgrade_available_ == UPGRADE_NEEDED_OUTDATED_INSTALL) { 88 if (upgrade_available_ == UPGRADE_NEEDED_OUTDATED_INSTALL) {
81 TriggerNotification(chrome::NOTIFICATION_OUTDATED_INSTALL); 89 NotifyOutdatedInstall();
82 } else if (upgrade_available_ == UPGRADE_NEEDED_OUTDATED_INSTALL_NO_AU) { 90 } else if (upgrade_available_ == UPGRADE_NEEDED_OUTDATED_INSTALL_NO_AU) {
83 TriggerNotification(chrome::NOTIFICATION_OUTDATED_INSTALL_NO_AU); 91 NotifyOutdatedInstallNoAU();
84 } else if (upgrade_available_ == UPGRADE_AVAILABLE_CRITICAL || 92 } else if (upgrade_available_ == UPGRADE_AVAILABLE_CRITICAL ||
85 critical_experiment_updates_available_) { 93 critical_experiment_updates_available_) {
86 TriggerCriticalUpdate(); 94 TriggerCriticalUpdate();
87 } 95 }
88 } 96 }
89 97
98 void UpgradeDetector::NotifyUpgradeRecommended() {
99 for (auto& observer : observer_list_)
100 observer.OnUpgradeRecommended();
101 }
102
103 void UpgradeDetector::NotifyCriticalUpgradeInstalled() {
104 for (auto& observer : observer_list_)
105 observer.OnCriticalUpgradeInstalled();
106 }
107
90 void UpgradeDetector::NotifyUpdateOverCellularAvailable() { 108 void UpgradeDetector::NotifyUpdateOverCellularAvailable() {
91 for (auto& observer : observer_list_) 109 for (auto& observer : observer_list_)
92 observer.OnUpdateOverCellularAvailable(); 110 observer.OnUpdateOverCellularAvailable();
93 } 111 }
94 112
95 void UpgradeDetector::TriggerCriticalUpdate() { 113 void UpgradeDetector::TriggerCriticalUpdate() {
96 const base::TimeDelta idle_timer = UseTestingIntervals() ? 114 const base::TimeDelta idle_timer = UseTestingIntervals() ?
97 base::TimeDelta::FromSeconds(kIdleRepeatingTimerWait) : 115 base::TimeDelta::FromSeconds(kIdleRepeatingTimerWait) :
98 base::TimeDelta::FromMinutes(kIdleRepeatingTimerWait); 116 base::TimeDelta::FromMinutes(kIdleRepeatingTimerWait);
99 idle_check_timer_.Start(FROM_HERE, idle_timer, this, 117 idle_check_timer_.Start(FROM_HERE, idle_timer, this,
100 &UpgradeDetector::CheckIdle); 118 &UpgradeDetector::CheckIdle);
101 } 119 }
102 120
103 void UpgradeDetector::CheckIdle() { 121 void UpgradeDetector::CheckIdle() {
104 // CalculateIdleState expects an interval in seconds. 122 // CalculateIdleState expects an interval in seconds.
105 int idle_time_allowed = UseTestingIntervals() ? kIdleAmount : 123 int idle_time_allowed = UseTestingIntervals() ? kIdleAmount :
106 kIdleAmount * 60 * 60; 124 kIdleAmount * 60 * 60;
107 125
108 CalculateIdleState( 126 CalculateIdleState(
109 idle_time_allowed, base::Bind(&UpgradeDetector::IdleCallback, 127 idle_time_allowed, base::Bind(&UpgradeDetector::IdleCallback,
110 base::Unretained(this))); 128 base::Unretained(this)));
111 } 129 }
112 130
113 void UpgradeDetector::TriggerNotification(chrome::NotificationType type) {
114 content::NotificationService::current()->Notify(
115 type,
116 content::Source<UpgradeDetector>(this),
117 content::NotificationService::NoDetails());
118 }
119
120 void UpgradeDetector::IdleCallback(ui::IdleState state) { 131 void UpgradeDetector::IdleCallback(ui::IdleState state) {
121 // Don't proceed while an incognito window is open. The timer will still 132 // Don't proceed while an incognito window is open. The timer will still
122 // keep firing, so this function will get a chance to re-evaluate this. 133 // keep firing, so this function will get a chance to re-evaluate this.
123 if (chrome::IsIncognitoSessionActive()) 134 if (chrome::IsIncognitoSessionActive())
124 return; 135 return;
125 136
126 switch (state) { 137 switch (state) {
127 case ui::IDLE_STATE_LOCKED: 138 case ui::IDLE_STATE_LOCKED:
128 // Computer is locked, auto-restart. 139 // Computer is locked, auto-restart.
129 idle_check_timer_.Stop(); 140 idle_check_timer_.Stop();
130 chrome::AttemptRestart(); 141 chrome::AttemptRestart();
131 break; 142 break;
132 case ui::IDLE_STATE_IDLE: 143 case ui::IDLE_STATE_IDLE:
133 // Computer has been idle for long enough, show warning. 144 // Computer has been idle for long enough, show warning.
134 idle_check_timer_.Stop(); 145 idle_check_timer_.Stop();
135 TriggerNotification(chrome::NOTIFICATION_CRITICAL_UPGRADE_INSTALLED); 146 NotifyCriticalUpgradeInstalled();
136 break; 147 break;
137 case ui::IDLE_STATE_ACTIVE: 148 case ui::IDLE_STATE_ACTIVE:
138 case ui::IDLE_STATE_UNKNOWN: 149 case ui::IDLE_STATE_UNKNOWN:
139 break; 150 break;
140 default: 151 default:
141 NOTREACHED(); // Need to add any new value above (either providing 152 NOTREACHED(); // Need to add any new value above (either providing
142 // automatic restart or show notification to user). 153 // automatic restart or show notification to user).
143 break; 154 break;
144 } 155 }
145 } 156 }
146 157
147 void UpgradeDetector::AddObserver(UpgradeObserver* observer) { 158 void UpgradeDetector::AddObserver(UpgradeObserver* observer) {
148 observer_list_.AddObserver(observer); 159 observer_list_.AddObserver(observer);
149 } 160 }
150 161
151 void UpgradeDetector::RemoveObserver(UpgradeObserver* observer) { 162 void UpgradeDetector::RemoveObserver(UpgradeObserver* observer) {
152 observer_list_.RemoveObserver(observer); 163 observer_list_.RemoveObserver(observer);
153 } 164 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698