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

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

Issue 11440020: Add an outdated upgrade bubble view. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: More CR comments addressed and now a testable version without current time test yet. Created 7 years, 11 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_impl.h" 5 #include "chrome/browser/upgrade_detector_impl.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/file_path.h" 11 #include "base/file_path.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/singleton.h" 13 #include "base/memory/singleton.h"
14 #include "base/path_service.h" 14 #include "base/path_service.h"
15 #include "base/string_number_conversions.h" 15 #include "base/string_number_conversions.h"
16 #include "base/string_util.h" 16 #include "base/string_util.h"
17 #include "base/time.h"
18 #include "base/utf_string_conversions.h" 17 #include "base/utf_string_conversions.h"
19 #include "chrome/common/chrome_switches.h" 18 #include "chrome/common/chrome_switches.h"
20 #include "chrome/common/chrome_version_info.h" 19 #include "chrome/common/chrome_version_info.h"
21 #include "chrome/installer/util/browser_distribution.h" 20 #include "chrome/installer/util/browser_distribution.h"
22 #include "content/public/browser/browser_thread.h" 21 #include "content/public/browser/browser_thread.h"
23 #include "ui/base/resource/resource_bundle.h" 22 #include "ui/base/resource/resource_bundle.h"
24 23
25 #if defined(OS_WIN) 24 #if defined(OS_WIN)
26 #include "chrome/installer/util/install_util.h" 25 #include "chrome/installer/util/install_util.h"
27 #elif defined(OS_MACOSX) 26 #elif defined(OS_MACOSX)
(...skipping 19 matching lines...) Expand all
47 const int kNotifyCycleTimeForTestingMs = 500; // Half a second. 46 const int kNotifyCycleTimeForTestingMs = 500; // Half a second.
48 47
49 std::string CmdLineInterval() { 48 std::string CmdLineInterval() {
50 const CommandLine& cmd_line = *CommandLine::ForCurrentProcess(); 49 const CommandLine& cmd_line = *CommandLine::ForCurrentProcess();
51 return cmd_line.GetSwitchValueASCII(switches::kCheckForUpdateIntervalSec); 50 return cmd_line.GetSwitchValueASCII(switches::kCheckForUpdateIntervalSec);
52 } 51 }
53 52
54 bool IsTesting() { 53 bool IsTesting() {
55 const CommandLine& cmd_line = *CommandLine::ForCurrentProcess(); 54 const CommandLine& cmd_line = *CommandLine::ForCurrentProcess();
56 return cmd_line.HasSwitch(switches::kSimulateUpgrade) || 55 return cmd_line.HasSwitch(switches::kSimulateUpgrade) ||
57 cmd_line.HasSwitch(switches::kCheckForUpdateIntervalSec); 56 cmd_line.HasSwitch(switches::kCheckForUpdateIntervalSec) ||
57 cmd_line.HasSwitch(switches::kSimulateCriticalUpdate) ||
58 cmd_line.HasSwitch(switches::kSimulateOutdated);
58 } 59 }
59 60
60 // How often to check for an upgrade. 61 // How often to check for an upgrade.
61 int GetCheckForUpgradeEveryMs() { 62 int GetCheckForUpgradeEveryMs() {
62 // Check for a value passed via the command line. 63 // Check for a value passed via the command line.
63 int interval_ms; 64 int interval_ms;
64 std::string interval = CmdLineInterval(); 65 std::string interval = CmdLineInterval();
65 if (!interval.empty() && base::StringToInt(interval, &interval_ms)) 66 if (!interval.empty() && base::StringToInt(interval, &interval_ms))
66 return interval_ms * 1000; // Command line value is in seconds. 67 return interval_ms * 1000; // Command line value is in seconds.
67 68
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 UpgradeDetectorImpl::UpgradeDetectorImpl() 156 UpgradeDetectorImpl::UpgradeDetectorImpl()
156 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), 157 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)),
157 is_unstable_channel_(false) { 158 is_unstable_channel_(false) {
158 CommandLine command_line(*CommandLine::ForCurrentProcess()); 159 CommandLine command_line(*CommandLine::ForCurrentProcess());
159 if (command_line.HasSwitch(switches::kDisableBackgroundNetworking)) 160 if (command_line.HasSwitch(switches::kDisableBackgroundNetworking))
160 return; 161 return;
161 if (command_line.HasSwitch(switches::kSimulateUpgrade)) { 162 if (command_line.HasSwitch(switches::kSimulateUpgrade)) {
162 UpgradeDetected(); 163 UpgradeDetected();
163 return; 164 return;
164 } 165 }
166 if (command_line.HasSwitch(switches::kSimulateCriticalUpdate)) {
167 is_critical_upgrade_ = true;
168 UpgradeDetected();
169 return;
170 }
171 if (command_line.HasSwitch(switches::kSimulateOutdated)) {
172 is_outdated_install_ = true;
173 UpgradeDetected();
174 return;
175 }
176 base::Time::FromString(__DATE__, &build_date_);
165 // Windows: only enable upgrade notifications for official builds. 177 // Windows: only enable upgrade notifications for official builds.
166 // Mac: only enable them if the updater (Keystone) is present. 178 // Mac: only enable them if the updater (Keystone) is present.
167 // Linux (and other POSIX): always enable regardless of branding. 179 // Linux (and other POSIX): always enable regardless of branding.
168 #if (defined(OS_WIN) && defined(GOOGLE_CHROME_BUILD)) || defined(OS_POSIX) 180 #if (defined(OS_WIN) && defined(GOOGLE_CHROME_BUILD)) || defined(OS_POSIX)
169 #if defined(OS_MACOSX) 181 #if defined(OS_MACOSX)
170 if (keystone_glue::KeystoneEnabled()) 182 if (keystone_glue::KeystoneEnabled())
171 #endif 183 #endif
172 { 184 {
173 detect_upgrade_timer_.Start(FROM_HERE, 185 detect_upgrade_timer_.Start(FROM_HERE,
174 base::TimeDelta::FromMilliseconds(GetCheckForUpgradeEveryMs()), 186 base::TimeDelta::FromMilliseconds(GetCheckForUpgradeEveryMs()),
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 } 227 }
216 228
217 void UpgradeDetectorImpl::NotifyOnUpgrade() { 229 void UpgradeDetectorImpl::NotifyOnUpgrade() {
218 base::TimeDelta delta = base::Time::Now() - upgrade_detected_time(); 230 base::TimeDelta delta = base::Time::Now() - upgrade_detected_time();
219 231
220 // We'll make testing more convenient by switching to seconds of waiting 232 // We'll make testing more convenient by switching to seconds of waiting
221 // instead of days between flipping severity. 233 // instead of days between flipping severity.
222 bool is_testing = IsTesting(); 234 bool is_testing = IsTesting();
223 int64 time_passed = is_testing ? delta.InSeconds() : delta.InHours(); 235 int64 time_passed = is_testing ? delta.InSeconds() : delta.InHours();
224 236
237 bool is_critical_or_oudated = is_critical_upgrade_ || is_outdated_install_;
225 if (is_unstable_channel_) { 238 if (is_unstable_channel_) {
226 // There's only one threat level for unstable channels like dev and 239 // There's only one threat level for unstable channels like dev and
227 // canary, and it hits after one hour. During testing, it hits after one 240 // canary, and it hits after one hour. During testing, it hits after one
228 // minute. 241 // minute.
229 const int kUnstableThreshold = 1; 242 const int kUnstableThreshold = 1;
230 243
231 if (is_critical_upgrade_) 244 if (is_critical_or_oudated)
232 set_upgrade_notification_stage(UPGRADE_ANNOYANCE_CRITICAL); 245 set_upgrade_notification_stage(UPGRADE_ANNOYANCE_CRITICAL);
233 else if (time_passed >= kUnstableThreshold) { 246 else if (time_passed >= kUnstableThreshold) {
234 set_upgrade_notification_stage(UPGRADE_ANNOYANCE_LOW); 247 set_upgrade_notification_stage(UPGRADE_ANNOYANCE_LOW);
235 248
236 // That's as high as it goes. 249 // That's as high as it goes.
237 upgrade_notification_timer_.Stop(); 250 upgrade_notification_timer_.Stop();
238 } else { 251 } else {
239 return; // Not ready to recommend upgrade. 252 return; // Not ready to recommend upgrade.
240 } 253 }
241 } else { 254 } else {
242 const int kMultiplier = is_testing ? 1 : 24; 255 const int kMultiplier = is_testing ? 1 : 24;
243 // 14 days when not testing, otherwise 14 seconds. 256 // 14 days when not testing, otherwise 14 seconds.
244 const int kSevereThreshold = 14 * kMultiplier; 257 const int kSevereThreshold = 14 * kMultiplier;
245 const int kHighThreshold = 7 * kMultiplier; 258 const int kHighThreshold = 7 * kMultiplier;
246 const int kElevatedThreshold = 4 * kMultiplier; 259 const int kElevatedThreshold = 4 * kMultiplier;
247 const int kLowThreshold = 2 * kMultiplier; 260 const int kLowThreshold = 2 * kMultiplier;
248 261
249 // These if statements must be sorted (highest interval first). 262 // These if statements must be sorted (highest interval first).
250 if (time_passed >= kSevereThreshold || is_critical_upgrade_) { 263 if (time_passed >= kSevereThreshold || is_critical_or_oudated) {
251 set_upgrade_notification_stage( 264 set_upgrade_notification_stage(
252 is_critical_upgrade_ ? UPGRADE_ANNOYANCE_CRITICAL : 265 is_critical_or_oudated ? UPGRADE_ANNOYANCE_CRITICAL :
253 UPGRADE_ANNOYANCE_SEVERE); 266 UPGRADE_ANNOYANCE_SEVERE);
254 267
255 // We can't get any higher, baby. 268 // We can't get any higher, baby.
256 upgrade_notification_timer_.Stop(); 269 upgrade_notification_timer_.Stop();
257 } else if (time_passed >= kHighThreshold) { 270 } else if (time_passed >= kHighThreshold) {
258 set_upgrade_notification_stage(UPGRADE_ANNOYANCE_HIGH); 271 set_upgrade_notification_stage(UPGRADE_ANNOYANCE_HIGH);
259 } else if (time_passed >= kElevatedThreshold) { 272 } else if (time_passed >= kElevatedThreshold) {
260 set_upgrade_notification_stage(UPGRADE_ANNOYANCE_ELEVATED); 273 set_upgrade_notification_stage(UPGRADE_ANNOYANCE_ELEVATED);
261 } else if (time_passed >= kLowThreshold) { 274 } else if (time_passed >= kLowThreshold) {
262 set_upgrade_notification_stage(UPGRADE_ANNOYANCE_LOW); 275 set_upgrade_notification_stage(UPGRADE_ANNOYANCE_LOW);
263 } else { 276 } else {
264 return; // Not ready to recommend upgrade. 277 return; // Not ready to recommend upgrade.
265 } 278 }
266 } 279 }
267 280
268 NotifyUpgradeRecommended(); 281 NotifyUpgradeRecommended();
269 } 282 }
270 283
271 // static 284 // static
272 UpgradeDetectorImpl* UpgradeDetectorImpl::GetInstance() { 285 UpgradeDetectorImpl* UpgradeDetectorImpl::GetInstance() {
273 return Singleton<UpgradeDetectorImpl>::get(); 286 return Singleton<UpgradeDetectorImpl>::get();
274 } 287 }
275 288
276 // static 289 // static
277 UpgradeDetector* UpgradeDetector::GetInstance() { 290 UpgradeDetector* UpgradeDetector::GetInstance() {
278 return UpgradeDetectorImpl::GetInstance(); 291 return UpgradeDetectorImpl::GetInstance();
279 } 292 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698