| OLD | NEW |
| 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/browser/prefs/pref_service.h" | 9 #include "chrome/browser/prefs/pref_service.h" |
| 10 #include "chrome/browser/lifetime/application_lifetime.h" | 10 #include "chrome/browser/lifetime/application_lifetime.h" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 case UPGRADE_ANNOYANCE_ELEVATED: | 54 case UPGRADE_ANNOYANCE_ELEVATED: |
| 55 return badge ? IDR_UPDATE_BADGE2 : IDR_UPDATE_MENU2; | 55 return badge ? IDR_UPDATE_BADGE2 : IDR_UPDATE_MENU2; |
| 56 case UPGRADE_ANNOYANCE_LOW: | 56 case UPGRADE_ANNOYANCE_LOW: |
| 57 return badge ? IDR_UPDATE_BADGE : IDR_UPDATE_MENU; | 57 return badge ? IDR_UPDATE_BADGE : IDR_UPDATE_MENU; |
| 58 default: | 58 default: |
| 59 return 0; | 59 return 0; |
| 60 } | 60 } |
| 61 } | 61 } |
| 62 | 62 |
| 63 UpgradeDetector::UpgradeDetector() | 63 UpgradeDetector::UpgradeDetector() |
| 64 : is_critical_upgrade_(false), | 64 : upgrade_required_(UPGRADE_REQUIRED_NONE), |
| 65 critical_update_acknowledged_(false), | 65 critical_update_acknowledged_(false), |
| 66 upgrade_notification_stage_(UPGRADE_ANNOYANCE_NONE), | 66 upgrade_notification_stage_(UPGRADE_ANNOYANCE_NONE), |
| 67 notify_upgrade_(false) { | 67 notify_upgrade_(false) { |
| 68 } | 68 } |
| 69 | 69 |
| 70 UpgradeDetector::~UpgradeDetector() { | 70 UpgradeDetector::~UpgradeDetector() { |
| 71 } | 71 } |
| 72 | 72 |
| 73 void UpgradeDetector::NotifyUpgradeDetected() { | 73 void UpgradeDetector::NotifyUpgradeDetected() { |
| 74 upgrade_detected_time_ = base::Time::Now(); | 74 upgrade_detected_time_ = base::Time::Now(); |
| 75 critical_update_acknowledged_ = false; | 75 critical_update_acknowledged_ = false; |
| 76 } | 76 } |
| 77 | 77 |
| 78 void UpgradeDetector::NotifyUpgradeRecommended() { | 78 void UpgradeDetector::NotifyUpgradeRecommended() { |
| 79 notify_upgrade_ = true; | 79 notify_upgrade_ = true; |
| 80 | 80 |
| 81 content::NotificationService::current()->Notify( | 81 content::NotificationService::current()->Notify( |
| 82 chrome::NOTIFICATION_UPGRADE_RECOMMENDED, | 82 chrome::NOTIFICATION_UPGRADE_RECOMMENDED, |
| 83 content::Source<UpgradeDetector>(this), | 83 content::Source<UpgradeDetector>(this), |
| 84 content::NotificationService::NoDetails()); | 84 content::NotificationService::NoDetails()); |
| 85 | 85 |
| 86 if (is_critical_upgrade_) { | 86 switch (upgrade_required_) { |
| 87 int idle_timer = UseTestingIntervals() ? | 87 case UPGRADE_REQUIRED_OUTDATED: { |
| 88 kIdleRepeatingTimerWait : | 88 content::NotificationService::current()->Notify( |
| 89 kIdleRepeatingTimerWait * 60; // To minutes. | 89 chrome::NOTIFICATION_OUTDATED_INSTALL, |
| 90 idle_check_timer_.Start(FROM_HERE, | 90 content::Source<UpgradeDetector>(this), |
| 91 base::TimeDelta::FromSeconds(idle_timer), | 91 content::NotificationService::NoDetails()); |
| 92 this, &UpgradeDetector::CheckIdle); | 92 break; |
| 93 } |
| 94 case UPGRADE_REQUIRED_CRITICAL: { |
| 95 int idle_timer = UseTestingIntervals() ? |
| 96 kIdleRepeatingTimerWait : |
| 97 kIdleRepeatingTimerWait * 60; // To minutes. |
| 98 idle_check_timer_.Start(FROM_HERE, |
| 99 base::TimeDelta::FromSeconds(idle_timer), |
| 100 this, &UpgradeDetector::CheckIdle); |
| 101 break; |
| 102 } |
| 103 default: |
| 104 break; |
| 93 } | 105 } |
| 94 } | 106 } |
| 95 | 107 |
| 96 void UpgradeDetector::CheckIdle() { | 108 void UpgradeDetector::CheckIdle() { |
| 97 // CalculateIdleState expects an interval in seconds. | 109 // CalculateIdleState expects an interval in seconds. |
| 98 int idle_time_allowed = UseTestingIntervals() ? kIdleAmount : | 110 int idle_time_allowed = UseTestingIntervals() ? kIdleAmount : |
| 99 kIdleAmount * 60 * 60; | 111 kIdleAmount * 60 * 60; |
| 100 | 112 |
| 101 CalculateIdleState( | 113 CalculateIdleState( |
| 102 idle_time_allowed, base::Bind(&UpgradeDetector::IdleCallback, | 114 idle_time_allowed, base::Bind(&UpgradeDetector::IdleCallback, |
| (...skipping 22 matching lines...) Expand all Loading... |
| 125 break; | 137 break; |
| 126 case IDLE_STATE_ACTIVE: | 138 case IDLE_STATE_ACTIVE: |
| 127 case IDLE_STATE_UNKNOWN: | 139 case IDLE_STATE_UNKNOWN: |
| 128 break; | 140 break; |
| 129 default: | 141 default: |
| 130 NOTREACHED(); // Need to add any new value above (either providing | 142 NOTREACHED(); // Need to add any new value above (either providing |
| 131 // automatic restart or show notification to user). | 143 // automatic restart or show notification to user). |
| 132 break; | 144 break; |
| 133 } | 145 } |
| 134 } | 146 } |
| OLD | NEW |