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

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

Issue 421643002: Make UpgradeDetector listen to VariationsService changes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 6 years, 4 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) 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 "base/prefs/pref_registry_simple.h" 9 #include "base/prefs/pref_registry_simple.h"
10 #include "chrome/browser/chrome_notification_types.h" 10 #include "chrome/browser/chrome_notification_types.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 return IDR_UPDATE_MENU_SEVERITY_HIGH; 52 return IDR_UPDATE_MENU_SEVERITY_HIGH;
53 case UPGRADE_ANNOYANCE_CRITICAL: 53 case UPGRADE_ANNOYANCE_CRITICAL:
54 return IDR_UPDATE_MENU_SEVERITY_HIGH; 54 return IDR_UPDATE_MENU_SEVERITY_HIGH;
55 } 55 }
56 NOTREACHED(); 56 NOTREACHED();
57 return 0; 57 return 0;
58 } 58 }
59 59
60 UpgradeDetector::UpgradeDetector() 60 UpgradeDetector::UpgradeDetector()
61 : upgrade_available_(UPGRADE_AVAILABLE_NONE), 61 : upgrade_available_(UPGRADE_AVAILABLE_NONE),
62 best_effort_experiment_updates_available_(false),
63 critical_experiment_updates_available_(false),
62 critical_update_acknowledged_(false), 64 critical_update_acknowledged_(false),
63 upgrade_notification_stage_(UPGRADE_ANNOYANCE_NONE), 65 upgrade_notification_stage_(UPGRADE_ANNOYANCE_NONE),
64 notify_upgrade_(false) { 66 notify_upgrade_(false) {
65 } 67 }
66 68
67 UpgradeDetector::~UpgradeDetector() { 69 UpgradeDetector::~UpgradeDetector() {
68 } 70 }
69 71
70 void UpgradeDetector::NotifyUpgradeDetected() {
71 upgrade_detected_time_ = base::Time::Now();
72 critical_update_acknowledged_ = false;
73 }
74
75 void UpgradeDetector::NotifyUpgradeRecommended() { 72 void UpgradeDetector::NotifyUpgradeRecommended() {
76 notify_upgrade_ = true; 73 notify_upgrade_ = true;
77 74
78 content::NotificationService::current()->Notify( 75 TriggerNotification(chrome::NOTIFICATION_UPGRADE_RECOMMENDED);
79 chrome::NOTIFICATION_UPGRADE_RECOMMENDED, 76 if (upgrade_available_ == UPGRADE_NEEDED_OUTDATED_INSTALL) {
80 content::Source<UpgradeDetector>(this), 77 TriggerNotification(chrome::NOTIFICATION_OUTDATED_INSTALL);
81 content::NotificationService::NoDetails()); 78 } else if (upgrade_available_ == UPGRADE_NEEDED_OUTDATED_INSTALL_NO_AU) {
79 TriggerNotification(chrome::NOTIFICATION_OUTDATED_INSTALL_NO_AU);
80 } else if (upgrade_available_ == UPGRADE_AVAILABLE_CRITICAL ||
81 critical_experiment_updates_available_) {
sky 2014/08/04 18:24:07 nit: align with ( on previous line.
Alexei Svitkine (slow) 2014/08/04 19:43:10 Done.
82 TriggerCriticalUpdate();
83 }
84 }
82 85
83 switch (upgrade_available_) { 86 void UpgradeDetector::TriggerCriticalUpdate() {
84 case UPGRADE_NEEDED_OUTDATED_INSTALL: { 87 const base::TimeDelta idle_timer = UseTestingIntervals() ?
85 content::NotificationService::current()->Notify( 88 base::TimeDelta::FromSeconds(kIdleRepeatingTimerWait) :
86 chrome::NOTIFICATION_OUTDATED_INSTALL, 89 base::TimeDelta::FromMinutes(kIdleRepeatingTimerWait);
87 content::Source<UpgradeDetector>(this), 90 idle_check_timer_.Start(FROM_HERE, idle_timer, this,
88 content::NotificationService::NoDetails()); 91 &UpgradeDetector::CheckIdle);
89 break;
90 }
91 case UPGRADE_NEEDED_OUTDATED_INSTALL_NO_AU: {
92 content::NotificationService::current()->Notify(
93 chrome::NOTIFICATION_OUTDATED_INSTALL_NO_AU,
94 content::Source<UpgradeDetector>(this),
95 content::NotificationService::NoDetails());
96 break;
97 }
98 case UPGRADE_AVAILABLE_CRITICAL: {
99 int idle_timer = UseTestingIntervals() ?
100 kIdleRepeatingTimerWait :
101 kIdleRepeatingTimerWait * 60; // To minutes.
102 idle_check_timer_.Start(FROM_HERE,
103 base::TimeDelta::FromSeconds(idle_timer),
104 this, &UpgradeDetector::CheckIdle);
105 break;
106 }
107 default:
108 break;
109 }
110 } 92 }
111 93
112 void UpgradeDetector::CheckIdle() { 94 void UpgradeDetector::CheckIdle() {
113 // CalculateIdleState expects an interval in seconds. 95 // CalculateIdleState expects an interval in seconds.
114 int idle_time_allowed = UseTestingIntervals() ? kIdleAmount : 96 int idle_time_allowed = UseTestingIntervals() ? kIdleAmount :
115 kIdleAmount * 60 * 60; 97 kIdleAmount * 60 * 60;
116 98
117 CalculateIdleState( 99 CalculateIdleState(
118 idle_time_allowed, base::Bind(&UpgradeDetector::IdleCallback, 100 idle_time_allowed, base::Bind(&UpgradeDetector::IdleCallback,
119 base::Unretained(this))); 101 base::Unretained(this)));
120 } 102 }
121 103
104 void UpgradeDetector::TriggerNotification(chrome::NotificationType type) {
105 content::NotificationService::current()->Notify(
106 type,
107 content::Source<UpgradeDetector>(this),
108 content::NotificationService::NoDetails());
109 }
110
122 void UpgradeDetector::IdleCallback(IdleState state) { 111 void UpgradeDetector::IdleCallback(IdleState state) {
123 // Don't proceed while an incognito window is open. The timer will still 112 // Don't proceed while an incognito window is open. The timer will still
124 // keep firing, so this function will get a chance to re-evaluate this. 113 // keep firing, so this function will get a chance to re-evaluate this.
125 if (chrome::IsOffTheRecordSessionActive()) 114 if (chrome::IsOffTheRecordSessionActive())
126 return; 115 return;
127 116
128 switch (state) { 117 switch (state) {
129 case IDLE_STATE_LOCKED: 118 case IDLE_STATE_LOCKED:
130 // Computer is locked, auto-restart. 119 // Computer is locked, auto-restart.
131 idle_check_timer_.Stop(); 120 idle_check_timer_.Stop();
132 chrome::AttemptRestart(); 121 chrome::AttemptRestart();
133 break; 122 break;
134 case IDLE_STATE_IDLE: 123 case IDLE_STATE_IDLE:
135 // Computer has been idle for long enough, show warning. 124 // Computer has been idle for long enough, show warning.
136 idle_check_timer_.Stop(); 125 idle_check_timer_.Stop();
137 content::NotificationService::current()->Notify( 126 TriggerNotification(chrome::NOTIFICATION_CRITICAL_UPGRADE_INSTALLED);
138 chrome::NOTIFICATION_CRITICAL_UPGRADE_INSTALLED,
139 content::Source<UpgradeDetector>(this),
140 content::NotificationService::NoDetails());
141 break; 127 break;
142 case IDLE_STATE_ACTIVE: 128 case IDLE_STATE_ACTIVE:
143 case IDLE_STATE_UNKNOWN: 129 case IDLE_STATE_UNKNOWN:
144 break; 130 break;
145 default: 131 default:
146 NOTREACHED(); // Need to add any new value above (either providing 132 NOTREACHED(); // Need to add any new value above (either providing
147 // automatic restart or show notification to user). 133 // automatic restart or show notification to user).
148 break; 134 break;
149 } 135 }
150 } 136 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698