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

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

Issue 8142028: When critical updates have been installed and the user has been idle for quite some time, show a ... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 2 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
« no previous file with comments | « chrome/browser/upgrade_detector.h ('k') | chrome/browser/upgrade_detector_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "chrome/browser/upgrade_detector.h" 5 #include "chrome/browser/upgrade_detector.h"
6 6
7 #include "base/bind.h"
8 #include "base/command_line.h"
7 #include "chrome/browser/prefs/pref_service.h" 9 #include "chrome/browser/prefs/pref_service.h"
10 #include "chrome/browser/ui/browser_list.h"
8 #include "chrome/common/chrome_notification_types.h" 11 #include "chrome/common/chrome_notification_types.h"
12 #include "chrome/common/chrome_switches.h"
9 #include "chrome/common/pref_names.h" 13 #include "chrome/common/pref_names.h"
10 #include "content/common/notification_service.h" 14 #include "content/common/notification_service.h"
11 #include "grit/theme_resources.h" 15 #include "grit/theme_resources.h"
12 16
17 // How long to wait between checks for whether the user has been idle.
18 static const int kIdleRepeatingTimerWait = 10; // Minutes (seconds if testing).
19
20 // How much idle time (since last input even was detected) must have passed
21 // until we notify that a critical update has occurred.
22 static const int kIdleAmount = 2; // Hours (or seconds, if testing).
23
24 bool UseTestingIntervals() {
25 // If a command line parameter specifying how long the upgrade check should
26 // be, we assume it is for testing and switch to using seconds instead of
27 // hours.
28 const CommandLine& cmd_line = *CommandLine::ForCurrentProcess();
29 return !cmd_line.GetSwitchValueASCII(
30 switches::kCheckForUpdateIntervalSec).empty();
31 }
32
13 // static 33 // static
14 void UpgradeDetector::RegisterPrefs(PrefService* prefs) { 34 void UpgradeDetector::RegisterPrefs(PrefService* prefs) {
15 prefs->RegisterBooleanPref(prefs::kRestartLastSessionOnShutdown, false); 35 prefs->RegisterBooleanPref(prefs::kRestartLastSessionOnShutdown, false);
16 } 36 }
17 37
18 int UpgradeDetector::GetIconResourceID(UpgradeNotificationIconType type) { 38 int UpgradeDetector::GetIconResourceID(UpgradeNotificationIconType type) {
19 bool badge = type == UPGRADE_ICON_TYPE_BADGE; 39 bool badge = type == UPGRADE_ICON_TYPE_BADGE;
20 switch (upgrade_notification_stage_) { 40 switch (upgrade_notification_stage_) {
41 case UPGRADE_ANNOYANCE_CRITICAL:
42 // The critical annoyance state, somewhat ironically, re-purposes the
43 // icon for the second highest severity state, since that state has the
44 // icon most closely resembling the one requested of this feature and the
45 // critical annoyance is never part of the sliding scale of severity
46 // anyway (always shown on its own).
47 return badge ? IDR_UPDATE_BADGE3 : IDR_UPDATE_MENU3;
21 case UPGRADE_ANNOYANCE_SEVERE: 48 case UPGRADE_ANNOYANCE_SEVERE:
22 return badge ? IDR_UPDATE_BADGE4 : IDR_UPDATE_MENU4; 49 return badge ? IDR_UPDATE_BADGE4 : IDR_UPDATE_MENU4;
23 case UPGRADE_ANNOYANCE_HIGH: 50 case UPGRADE_ANNOYANCE_HIGH:
24 return badge ? IDR_UPDATE_BADGE3 : IDR_UPDATE_MENU3; 51 return badge ? IDR_UPDATE_BADGE3 : IDR_UPDATE_MENU3;
25 case UPGRADE_ANNOYANCE_ELEVATED: 52 case UPGRADE_ANNOYANCE_ELEVATED:
26 return badge ? IDR_UPDATE_BADGE2 : IDR_UPDATE_MENU2; 53 return badge ? IDR_UPDATE_BADGE2 : IDR_UPDATE_MENU2;
27 case UPGRADE_ANNOYANCE_LOW: 54 case UPGRADE_ANNOYANCE_LOW:
28 return badge ? IDR_UPDATE_BADGE : IDR_UPDATE_MENU; 55 return badge ? IDR_UPDATE_BADGE : IDR_UPDATE_MENU;
29 default: 56 default:
30 return 0; 57 return 0;
31 } 58 }
32 } 59 }
33 60
34 UpgradeDetector::UpgradeDetector() 61 UpgradeDetector::UpgradeDetector()
35 : upgrade_notification_stage_(UPGRADE_ANNOYANCE_NONE), 62 : is_critical_upgrade_(false),
63 critical_update_acknowledged_(false),
64 upgrade_notification_stage_(UPGRADE_ANNOYANCE_NONE),
36 notify_upgrade_(false) { 65 notify_upgrade_(false) {
37 } 66 }
38 67
39 UpgradeDetector::~UpgradeDetector() { 68 UpgradeDetector::~UpgradeDetector() {
40 } 69 }
41 70
42 void UpgradeDetector::NotifyUpgradeDetected() { 71 void UpgradeDetector::NotifyUpgradeDetected() {
43 upgrade_detected_time_ = base::Time::Now(); 72 upgrade_detected_time_ = base::Time::Now();
73 critical_update_acknowledged_ = false;
44 } 74 }
45 75
46 void UpgradeDetector::NotifyUpgradeRecommended() { 76 void UpgradeDetector::NotifyUpgradeRecommended() {
47 notify_upgrade_ = true; 77 notify_upgrade_ = true;
48 78
49 NotificationService::current()->Notify( 79 NotificationService::current()->Notify(
50 chrome::NOTIFICATION_UPGRADE_RECOMMENDED, 80 chrome::NOTIFICATION_UPGRADE_RECOMMENDED,
51 Source<UpgradeDetector>(this), 81 Source<UpgradeDetector>(this),
52 NotificationService::NoDetails()); 82 NotificationService::NoDetails());
83
84 if (is_critical_upgrade_) {
85 int idle_timer = UseTestingIntervals() ?
86 kIdleRepeatingTimerWait :
87 kIdleRepeatingTimerWait * 60; // To minutes.
88 idle_check_timer_.Start(FROM_HERE,
89 base::TimeDelta::FromSeconds(idle_timer),
90 this, &UpgradeDetector::CheckIdle);
91 }
53 } 92 }
93
94 void UpgradeDetector::CheckIdle() {
95 // CalculateIdleState expects an interval in seconds.
96 int idle_time_allowed = UseTestingIntervals() ? kIdleAmount :
97 kIdleAmount * 60 * 60;
98
99 CalculateIdleState(
100 idle_time_allowed, base::Bind(&UpgradeDetector::IdleCallback,
101 base::Unretained(this)));
102 }
103
104 void UpgradeDetector::IdleCallback(IdleState state) {
105 switch (state) {
106 case IDLE_STATE_LOCKED:
107 // Computer is locked, auto-restart.
108 idle_check_timer_.Stop();
109 BrowserList::AttemptRestart();
110 break;
111 case IDLE_STATE_IDLE:
112 // Computer has been idle for long enough, show warning.
113 idle_check_timer_.Stop();
114 NotificationService::current()->Notify(
115 chrome::NOTIFICATION_CRITICAL_UPGRADE_INSTALLED,
116 Source<UpgradeDetector>(this),
117 NotificationService::NoDetails());
118 break;
119 case IDLE_STATE_ACTIVE:
120 case IDLE_STATE_UNKNOWN:
121 break;
122 default:
123 NOTREACHED(); // Need to add any new value above (either providing
124 // automatic restart or show notification to user).
125 break;
126 }
127 }
OLDNEW
« no previous file with comments | « chrome/browser/upgrade_detector.h ('k') | chrome/browser/upgrade_detector_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698