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/app/vector_icons/vector_icons.h" | 9 #include "chrome/app/vector_icons/vector_icons.h" |
10 #include "chrome/browser/chrome_notification_types.h" | 10 #include "chrome/browser/chrome_notification_types.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 | 26 |
27 bool UseTestingIntervals() { | 27 bool UseTestingIntervals() { |
28 // If a command line parameter specifying how long the upgrade check should | 28 // If a command line parameter specifying how long the upgrade check should |
29 // be, we assume it is for testing and switch to using seconds instead of | 29 // be, we assume it is for testing and switch to using seconds instead of |
30 // hours. | 30 // hours. |
31 const base::CommandLine& cmd_line = *base::CommandLine::ForCurrentProcess(); | 31 const base::CommandLine& cmd_line = *base::CommandLine::ForCurrentProcess(); |
32 return !cmd_line.GetSwitchValueASCII( | 32 return !cmd_line.GetSwitchValueASCII( |
33 switches::kCheckForUpdateIntervalSec).empty(); | 33 switches::kCheckForUpdateIntervalSec).empty(); |
34 } | 34 } |
35 | 35 |
| 36 UpgradeDetector::UpgradeObserver::~UpgradeObserver() {} |
| 37 |
36 // static | 38 // static |
37 void UpgradeDetector::RegisterPrefs(PrefRegistrySimple* registry) { | 39 void UpgradeDetector::RegisterPrefs(PrefRegistrySimple* registry) { |
38 registry->RegisterBooleanPref(prefs::kAttemptedToEnableAutoupdate, false); | 40 registry->RegisterBooleanPref(prefs::kAttemptedToEnableAutoupdate, false); |
39 } | 41 } |
40 | 42 |
41 gfx::Image UpgradeDetector::GetIcon() { | 43 gfx::Image UpgradeDetector::GetIcon() { |
42 SkColor color = gfx::kPlaceholderColor; | 44 SkColor color = gfx::kPlaceholderColor; |
43 switch (upgrade_notification_stage_) { | 45 switch (upgrade_notification_stage_) { |
44 case UPGRADE_ANNOYANCE_NONE: | 46 case UPGRADE_ANNOYANCE_NONE: |
45 return gfx::Image(); | 47 return gfx::Image(); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 if (upgrade_available_ == UPGRADE_NEEDED_OUTDATED_INSTALL) { | 82 if (upgrade_available_ == UPGRADE_NEEDED_OUTDATED_INSTALL) { |
81 TriggerNotification(chrome::NOTIFICATION_OUTDATED_INSTALL); | 83 TriggerNotification(chrome::NOTIFICATION_OUTDATED_INSTALL); |
82 } else if (upgrade_available_ == UPGRADE_NEEDED_OUTDATED_INSTALL_NO_AU) { | 84 } else if (upgrade_available_ == UPGRADE_NEEDED_OUTDATED_INSTALL_NO_AU) { |
83 TriggerNotification(chrome::NOTIFICATION_OUTDATED_INSTALL_NO_AU); | 85 TriggerNotification(chrome::NOTIFICATION_OUTDATED_INSTALL_NO_AU); |
84 } else if (upgrade_available_ == UPGRADE_AVAILABLE_CRITICAL || | 86 } else if (upgrade_available_ == UPGRADE_AVAILABLE_CRITICAL || |
85 critical_experiment_updates_available_) { | 87 critical_experiment_updates_available_) { |
86 TriggerCriticalUpdate(); | 88 TriggerCriticalUpdate(); |
87 } | 89 } |
88 } | 90 } |
89 | 91 |
| 92 void UpgradeDetector::NotifyUpdateOverCellularAvailable() { |
| 93 for (auto& observer : observer_list_) |
| 94 observer.OnUpdateOverCellularAvailable(); |
| 95 } |
| 96 |
90 void UpgradeDetector::TriggerCriticalUpdate() { | 97 void UpgradeDetector::TriggerCriticalUpdate() { |
91 const base::TimeDelta idle_timer = UseTestingIntervals() ? | 98 const base::TimeDelta idle_timer = UseTestingIntervals() ? |
92 base::TimeDelta::FromSeconds(kIdleRepeatingTimerWait) : | 99 base::TimeDelta::FromSeconds(kIdleRepeatingTimerWait) : |
93 base::TimeDelta::FromMinutes(kIdleRepeatingTimerWait); | 100 base::TimeDelta::FromMinutes(kIdleRepeatingTimerWait); |
94 idle_check_timer_.Start(FROM_HERE, idle_timer, this, | 101 idle_check_timer_.Start(FROM_HERE, idle_timer, this, |
95 &UpgradeDetector::CheckIdle); | 102 &UpgradeDetector::CheckIdle); |
96 } | 103 } |
97 | 104 |
98 void UpgradeDetector::CheckIdle() { | 105 void UpgradeDetector::CheckIdle() { |
99 // CalculateIdleState expects an interval in seconds. | 106 // CalculateIdleState expects an interval in seconds. |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 break; | 138 break; |
132 case ui::IDLE_STATE_ACTIVE: | 139 case ui::IDLE_STATE_ACTIVE: |
133 case ui::IDLE_STATE_UNKNOWN: | 140 case ui::IDLE_STATE_UNKNOWN: |
134 break; | 141 break; |
135 default: | 142 default: |
136 NOTREACHED(); // Need to add any new value above (either providing | 143 NOTREACHED(); // Need to add any new value above (either providing |
137 // automatic restart or show notification to user). | 144 // automatic restart or show notification to user). |
138 break; | 145 break; |
139 } | 146 } |
140 } | 147 } |
| 148 |
| 149 void UpgradeDetector::AddObserver(UpgradeObserver* observer) { |
| 150 observer_list_.AddObserver(observer); |
| 151 } |
| 152 |
| 153 void UpgradeDetector::RemoveObserver(UpgradeObserver* observer) { |
| 154 observer_list_.RemoveObserver(observer); |
| 155 } |
OLD | NEW |