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/ui/webui/help/version_updater_chromeos.h" | 5 #include "chrome/browser/ui/webui/help/version_updater_chromeos.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 chromeos::CrosSettings* settings = chromeos::CrosSettings::Get(); | 65 chromeos::CrosSettings* settings = chromeos::CrosSettings::Get(); |
66 if (!settings) | 66 if (!settings) |
67 return update_disabled; | 67 return update_disabled; |
68 const base::Value* update_disabled_value = | 68 const base::Value* update_disabled_value = |
69 settings->GetPref(chromeos::kUpdateDisabled); | 69 settings->GetPref(chromeos::kUpdateDisabled); |
70 if (update_disabled_value) | 70 if (update_disabled_value) |
71 CHECK(update_disabled_value->GetAsBoolean(&update_disabled)); | 71 CHECK(update_disabled_value->GetAsBoolean(&update_disabled)); |
72 return update_disabled; | 72 return update_disabled; |
73 } | 73 } |
74 | 74 |
75 // Returns whether an update is allowed. If not, it calls the callback with | |
76 // the appropriate status. | |
77 bool EnsureCanUpdate(const VersionUpdater::StatusCallback& callback) { | |
78 if (IsAutoUpdateDisabled()) { | |
79 callback.Run(VersionUpdater::FAILED, 0, | |
80 l10n_util::GetStringUTF16(IDS_UPGRADE_DISABLED_BY_POLICY)); | |
81 return false; | |
82 } | |
83 | |
84 chromeos::NetworkStateHandler* network_state_handler = | |
85 chromeos::NetworkHandler::Get()->network_state_handler(); | |
86 const chromeos::NetworkState* network = | |
87 network_state_handler->DefaultNetwork(); | |
88 | |
89 // Don't allow an update if we're currently offline or connected | |
90 // to a network for which updates are disallowed. | |
91 NetworkStatus status = GetNetworkStatus(network); | |
92 if (status == NETWORK_STATUS_OFFLINE) { | |
93 callback.Run(VersionUpdater::FAILED_OFFLINE, 0, | |
94 l10n_util::GetStringUTF16(IDS_UPGRADE_OFFLINE)); | |
95 return false; | |
96 } else if (status == NETWORK_STATUS_DISALLOWED) { | |
97 base::string16 message = | |
98 l10n_util::GetStringFUTF16( | |
99 IDS_UPGRADE_DISALLOWED, | |
100 help_utils_chromeos::GetConnectionTypeAsUTF16(network->type())); | |
101 callback.Run(VersionUpdater::FAILED_CONNECTION_TYPE_DISALLOWED, 0, message); | |
102 return false; | |
103 } | |
104 | |
105 return true; | |
106 } | |
107 | |
108 } // namespace | 75 } // namespace |
109 | 76 |
110 VersionUpdater* VersionUpdater::Create() { | 77 VersionUpdater* VersionUpdater::Create() { |
111 return new VersionUpdaterCros; | 78 return new VersionUpdaterCros; |
112 } | 79 } |
113 | 80 |
114 void VersionUpdaterCros::GetUpdateStatus(const StatusCallback& callback) { | 81 void VersionUpdaterCros::GetUpdateStatus(const StatusCallback& callback) { |
115 callback_ = callback; | 82 callback_ = callback; |
116 if (!EnsureCanUpdate(callback)) | 83 if (!EnsureCanUpdate(callback)) |
117 return; | 84 return; |
(...skipping 11 matching lines...) Expand all Loading... |
129 callback_ = callback; | 96 callback_ = callback; |
130 | 97 |
131 if (!EnsureCanUpdate(callback)) | 98 if (!EnsureCanUpdate(callback)) |
132 return; | 99 return; |
133 | 100 |
134 UpdateEngineClient* update_engine_client = | 101 UpdateEngineClient* update_engine_client = |
135 DBusThreadManager::Get()->GetUpdateEngineClient(); | 102 DBusThreadManager::Get()->GetUpdateEngineClient(); |
136 if (!update_engine_client->HasObserver(this)) | 103 if (!update_engine_client->HasObserver(this)) |
137 update_engine_client->AddObserver(this); | 104 update_engine_client->AddObserver(this); |
138 | 105 |
| 106 if (update_engine_client->GetLastStatus().status != |
| 107 UpdateEngineClient::UPDATE_STATUS_IDLE) { |
| 108 check_for_update_when_idle_ = true; |
| 109 return; |
| 110 } |
| 111 check_for_update_when_idle_ = false; |
| 112 |
139 // Make sure that libcros is loaded and OOBE is complete. | 113 // Make sure that libcros is loaded and OOBE is complete. |
140 if (!WizardController::default_controller() || | 114 if (can_update_for_testing_ || !WizardController::default_controller() || |
141 chromeos::StartupUtils::IsDeviceRegistered()) { | 115 chromeos::StartupUtils::IsDeviceRegistered()) { |
142 update_engine_client->RequestUpdateCheck( | 116 update_engine_client->RequestUpdateCheck(base::Bind( |
143 base::Bind(&VersionUpdaterCros::OnUpdateCheck, | 117 &VersionUpdaterCros::OnUpdateCheck, weak_ptr_factory_.GetWeakPtr())); |
144 weak_ptr_factory_.GetWeakPtr())); | |
145 } | 118 } |
146 } | 119 } |
147 | 120 |
148 void VersionUpdaterCros::RelaunchBrowser() const { | 121 void VersionUpdaterCros::RelaunchBrowser() const { |
149 DBusThreadManager::Get()->GetPowerManagerClient()->RequestRestart(); | 122 DBusThreadManager::Get()->GetPowerManagerClient()->RequestRestart(); |
150 } | 123 } |
151 | 124 |
152 void VersionUpdaterCros::SetChannel(const std::string& channel, | 125 void VersionUpdaterCros::SetChannel(const std::string& channel, |
153 bool is_powerwash_allowed) { | 126 bool is_powerwash_allowed) { |
154 if (user_manager::UserManager::Get()->IsCurrentUserOwner()) { | 127 if (user_manager::UserManager::Get()->IsCurrentUserOwner()) { |
155 // For local owner set the field in the policy blob. | 128 // For local owner set the field in the policy blob. |
156 CrosSettings::Get()->SetString(chromeos::kReleaseChannel, channel); | 129 CrosSettings::Get()->SetString(chromeos::kReleaseChannel, channel); |
157 } | 130 } |
158 DBusThreadManager::Get()->GetUpdateEngineClient()-> | 131 DBusThreadManager::Get()->GetUpdateEngineClient()-> |
159 SetChannel(channel, is_powerwash_allowed); | 132 SetChannel(channel, is_powerwash_allowed); |
160 } | 133 } |
161 | 134 |
162 void VersionUpdaterCros::GetChannel(bool get_current_channel, | 135 void VersionUpdaterCros::GetChannel(bool get_current_channel, |
163 const ChannelCallback& cb) { | 136 const ChannelCallback& cb) { |
164 UpdateEngineClient* update_engine_client = | 137 UpdateEngineClient* update_engine_client = |
165 DBusThreadManager::Get()->GetUpdateEngineClient(); | 138 DBusThreadManager::Get()->GetUpdateEngineClient(); |
166 | 139 |
167 // Request the channel information. | 140 // Request the channel information. |
168 update_engine_client->GetChannel(get_current_channel, cb); | 141 update_engine_client->GetChannel(get_current_channel, cb); |
169 } | 142 } |
170 | 143 |
171 VersionUpdaterCros::VersionUpdaterCros() | 144 VersionUpdaterCros::VersionUpdaterCros() |
172 : last_operation_(UpdateEngineClient::UPDATE_STATUS_IDLE), | 145 : last_operation_(UpdateEngineClient::UPDATE_STATUS_IDLE), |
| 146 check_for_update_when_idle_(false), |
173 weak_ptr_factory_(this) { | 147 weak_ptr_factory_(this) { |
174 } | 148 } |
175 | 149 |
176 VersionUpdaterCros::~VersionUpdaterCros() { | 150 VersionUpdaterCros::~VersionUpdaterCros() { |
177 UpdateEngineClient* update_engine_client = | 151 UpdateEngineClient* update_engine_client = |
178 DBusThreadManager::Get()->GetUpdateEngineClient(); | 152 DBusThreadManager::Get()->GetUpdateEngineClient(); |
179 update_engine_client->RemoveObserver(this); | 153 update_engine_client->RemoveObserver(this); |
180 } | 154 } |
181 | 155 |
182 void VersionUpdaterCros::UpdateStatusChanged( | 156 void VersionUpdaterCros::UpdateStatusChanged( |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 break; | 196 break; |
223 case UpdateEngineClient::UPDATE_STATUS_UPDATED_NEED_REBOOT: | 197 case UpdateEngineClient::UPDATE_STATUS_UPDATED_NEED_REBOOT: |
224 my_status = NEARLY_UPDATED; | 198 my_status = NEARLY_UPDATED; |
225 break; | 199 break; |
226 default: | 200 default: |
227 break; | 201 break; |
228 } | 202 } |
229 | 203 |
230 callback_.Run(my_status, progress, message); | 204 callback_.Run(my_status, progress, message); |
231 last_operation_ = status.status; | 205 last_operation_ = status.status; |
| 206 |
| 207 if (check_for_update_when_idle_ && |
| 208 status.status == UpdateEngineClient::UPDATE_STATUS_IDLE) { |
| 209 CheckForUpdate(callback_); |
| 210 } |
232 } | 211 } |
233 | 212 |
234 void VersionUpdaterCros::OnUpdateCheck( | 213 void VersionUpdaterCros::OnUpdateCheck( |
235 UpdateEngineClient::UpdateCheckResult result) { | 214 UpdateEngineClient::UpdateCheckResult result) { |
236 // If version updating is not implemented, this binary is the most up-to-date | 215 // If version updating is not implemented, this binary is the most up-to-date |
237 // possible with respect to automatic updating. | 216 // possible with respect to automatic updating. |
238 if (result == UpdateEngineClient::UPDATE_RESULT_NOTIMPLEMENTED) | 217 if (result == UpdateEngineClient::UPDATE_RESULT_NOTIMPLEMENTED) |
239 callback_.Run(UPDATED, 0, base::string16()); | 218 callback_.Run(UPDATED, 0, base::string16()); |
240 } | 219 } |
| 220 |
| 221 bool VersionUpdaterCros::EnsureCanUpdate(const StatusCallback& callback) { |
| 222 if (can_update_for_testing_) |
| 223 return true; |
| 224 |
| 225 if (IsAutoUpdateDisabled()) { |
| 226 callback.Run(VersionUpdater::FAILED, 0, |
| 227 l10n_util::GetStringUTF16(IDS_UPGRADE_DISABLED_BY_POLICY)); |
| 228 return false; |
| 229 } |
| 230 |
| 231 chromeos::NetworkStateHandler* network_state_handler = |
| 232 chromeos::NetworkHandler::Get()->network_state_handler(); |
| 233 const chromeos::NetworkState* network = |
| 234 network_state_handler->DefaultNetwork(); |
| 235 |
| 236 // Don't allow an update if we're currently offline or connected |
| 237 // to a network for which updates are disallowed. |
| 238 NetworkStatus status = GetNetworkStatus(network); |
| 239 if (status == NETWORK_STATUS_OFFLINE) { |
| 240 callback.Run(VersionUpdater::FAILED_OFFLINE, 0, |
| 241 l10n_util::GetStringUTF16(IDS_UPGRADE_OFFLINE)); |
| 242 return false; |
| 243 } else if (status == NETWORK_STATUS_DISALLOWED) { |
| 244 base::string16 message = |
| 245 l10n_util::GetStringFUTF16( |
| 246 IDS_UPGRADE_DISALLOWED, |
| 247 help_utils_chromeos::GetConnectionTypeAsUTF16(network->type())); |
| 248 callback.Run(VersionUpdater::FAILED_CONNECTION_TYPE_DISALLOWED, 0, message); |
| 249 return false; |
| 250 } |
| 251 |
| 252 return true; |
| 253 } |
OLD | NEW |