| 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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 } | 106 } |
| 107 | 107 |
| 108 } // namespace | 108 } // namespace |
| 109 | 109 |
| 110 VersionUpdater* VersionUpdater::Create() { | 110 VersionUpdater* VersionUpdater::Create() { |
| 111 return new VersionUpdaterCros; | 111 return new VersionUpdaterCros; |
| 112 } | 112 } |
| 113 | 113 |
| 114 void VersionUpdaterCros::GetUpdateStatus(const StatusCallback& callback) { | 114 void VersionUpdaterCros::GetUpdateStatus(const StatusCallback& callback) { |
| 115 callback_ = callback; | 115 callback_ = callback; |
| 116 |
| 116 if (!EnsureCanUpdate(callback)) | 117 if (!EnsureCanUpdate(callback)) |
| 117 return; | 118 return; |
| 118 | 119 |
| 119 UpdateEngineClient* update_engine_client = | 120 UpdateEngineClient* update_engine_client = |
| 120 DBusThreadManager::Get()->GetUpdateEngineClient(); | 121 DBusThreadManager::Get()->GetUpdateEngineClient(); |
| 121 if (!update_engine_client->HasObserver(this)) | 122 if (!update_engine_client->HasObserver(this)) |
| 122 update_engine_client->AddObserver(this); | 123 update_engine_client->AddObserver(this); |
| 123 | 124 |
| 124 this->UpdateStatusChanged( | 125 this->UpdateStatusChanged( |
| 125 DBusThreadManager::Get()->GetUpdateEngineClient()->GetLastStatus()); | 126 DBusThreadManager::Get()->GetUpdateEngineClient()->GetLastStatus()); |
| 126 } | 127 } |
| 127 | 128 |
| 128 void VersionUpdaterCros::CheckForUpdate(const StatusCallback& callback) { | 129 void VersionUpdaterCros::CheckForUpdate(const StatusCallback& callback) { |
| 129 callback_ = callback; | 130 callback_ = callback; |
| 130 | 131 |
| 131 if (!EnsureCanUpdate(callback)) | 132 if (!EnsureCanUpdate(callback)) |
| 132 return; | 133 return; |
| 133 | 134 |
| 134 UpdateEngineClient* update_engine_client = | 135 UpdateEngineClient* update_engine_client = |
| 135 DBusThreadManager::Get()->GetUpdateEngineClient(); | 136 DBusThreadManager::Get()->GetUpdateEngineClient(); |
| 136 if (!update_engine_client->HasObserver(this)) | 137 if (!update_engine_client->HasObserver(this)) |
| 137 update_engine_client->AddObserver(this); | 138 update_engine_client->AddObserver(this); |
| 138 | 139 |
| 140 if (update_engine_client->GetLastStatus().status != |
| 141 UpdateEngineClient::UPDATE_STATUS_IDLE) { |
| 142 check_for_update_when_idle_ = true; |
| 143 return; |
| 144 } |
| 145 check_for_update_when_idle_ = false; |
| 146 |
| 139 // Make sure that libcros is loaded and OOBE is complete. | 147 // Make sure that libcros is loaded and OOBE is complete. |
| 140 if (!WizardController::default_controller() || | 148 if (!WizardController::default_controller() || |
| 141 chromeos::StartupUtils::IsDeviceRegistered()) { | 149 chromeos::StartupUtils::IsDeviceRegistered()) { |
| 142 update_engine_client->RequestUpdateCheck( | 150 update_engine_client->RequestUpdateCheck(base::Bind( |
| 143 base::Bind(&VersionUpdaterCros::OnUpdateCheck, | 151 &VersionUpdaterCros::OnUpdateCheck, weak_ptr_factory_.GetWeakPtr())); |
| 144 weak_ptr_factory_.GetWeakPtr())); | |
| 145 } | 152 } |
| 146 } | 153 } |
| 147 | 154 |
| 148 void VersionUpdaterCros::RelaunchBrowser() const { | 155 void VersionUpdaterCros::RelaunchBrowser() const { |
| 149 DBusThreadManager::Get()->GetPowerManagerClient()->RequestRestart(); | 156 DBusThreadManager::Get()->GetPowerManagerClient()->RequestRestart(); |
| 150 } | 157 } |
| 151 | 158 |
| 152 void VersionUpdaterCros::SetChannel(const std::string& channel, | 159 void VersionUpdaterCros::SetChannel(const std::string& channel, |
| 153 bool is_powerwash_allowed) { | 160 bool is_powerwash_allowed) { |
| 154 if (user_manager::UserManager::Get()->IsCurrentUserOwner()) { | 161 if (user_manager::UserManager::Get()->IsCurrentUserOwner()) { |
| 155 // For local owner set the field in the policy blob. | 162 // For local owner set the field in the policy blob. |
| 156 CrosSettings::Get()->SetString(chromeos::kReleaseChannel, channel); | 163 CrosSettings::Get()->SetString(chromeos::kReleaseChannel, channel); |
| 157 } | 164 } |
| 158 DBusThreadManager::Get()->GetUpdateEngineClient()-> | 165 DBusThreadManager::Get()->GetUpdateEngineClient()-> |
| 159 SetChannel(channel, is_powerwash_allowed); | 166 SetChannel(channel, is_powerwash_allowed); |
| 160 } | 167 } |
| 161 | 168 |
| 162 void VersionUpdaterCros::GetChannel(bool get_current_channel, | 169 void VersionUpdaterCros::GetChannel(bool get_current_channel, |
| 163 const ChannelCallback& cb) { | 170 const ChannelCallback& cb) { |
| 164 UpdateEngineClient* update_engine_client = | 171 UpdateEngineClient* update_engine_client = |
| 165 DBusThreadManager::Get()->GetUpdateEngineClient(); | 172 DBusThreadManager::Get()->GetUpdateEngineClient(); |
| 166 | 173 |
| 167 // Request the channel information. | 174 // Request the channel information. |
| 168 update_engine_client->GetChannel(get_current_channel, cb); | 175 update_engine_client->GetChannel(get_current_channel, cb); |
| 169 } | 176 } |
| 170 | 177 |
| 171 VersionUpdaterCros::VersionUpdaterCros() | 178 VersionUpdaterCros::VersionUpdaterCros() |
| 172 : last_operation_(UpdateEngineClient::UPDATE_STATUS_IDLE), | 179 : last_operation_(UpdateEngineClient::UPDATE_STATUS_IDLE), |
| 180 check_for_update_when_idle_(false), |
| 173 weak_ptr_factory_(this) { | 181 weak_ptr_factory_(this) { |
| 174 } | 182 } |
| 175 | 183 |
| 176 VersionUpdaterCros::~VersionUpdaterCros() { | 184 VersionUpdaterCros::~VersionUpdaterCros() { |
| 177 UpdateEngineClient* update_engine_client = | 185 UpdateEngineClient* update_engine_client = |
| 178 DBusThreadManager::Get()->GetUpdateEngineClient(); | 186 DBusThreadManager::Get()->GetUpdateEngineClient(); |
| 179 update_engine_client->RemoveObserver(this); | 187 update_engine_client->RemoveObserver(this); |
| 180 } | 188 } |
| 181 | 189 |
| 182 void VersionUpdaterCros::UpdateStatusChanged( | 190 void VersionUpdaterCros::UpdateStatusChanged( |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 break; | 230 break; |
| 223 case UpdateEngineClient::UPDATE_STATUS_UPDATED_NEED_REBOOT: | 231 case UpdateEngineClient::UPDATE_STATUS_UPDATED_NEED_REBOOT: |
| 224 my_status = NEARLY_UPDATED; | 232 my_status = NEARLY_UPDATED; |
| 225 break; | 233 break; |
| 226 default: | 234 default: |
| 227 break; | 235 break; |
| 228 } | 236 } |
| 229 | 237 |
| 230 callback_.Run(my_status, progress, message); | 238 callback_.Run(my_status, progress, message); |
| 231 last_operation_ = status.status; | 239 last_operation_ = status.status; |
| 240 |
| 241 if (check_for_update_when_idle_ && |
| 242 status.status == UpdateEngineClient::UPDATE_STATUS_IDLE) { |
| 243 CheckForUpdate(callback_); |
| 244 } |
| 232 } | 245 } |
| 233 | 246 |
| 234 void VersionUpdaterCros::OnUpdateCheck( | 247 void VersionUpdaterCros::OnUpdateCheck( |
| 235 UpdateEngineClient::UpdateCheckResult result) { | 248 UpdateEngineClient::UpdateCheckResult result) { |
| 236 // If version updating is not implemented, this binary is the most up-to-date | 249 // If version updating is not implemented, this binary is the most up-to-date |
| 237 // possible with respect to automatic updating. | 250 // possible with respect to automatic updating. |
| 238 if (result == UpdateEngineClient::UPDATE_RESULT_NOTIMPLEMENTED) | 251 if (result == UpdateEngineClient::UPDATE_RESULT_NOTIMPLEMENTED) |
| 239 callback_.Run(UPDATED, 0, base::string16()); | 252 callback_.Run(UPDATED, 0, base::string16()); |
| 240 } | 253 } |
| OLD | NEW |