Chromium Code Reviews| Index: chrome/browser/ui/webui/help/version_updater_chromeos.cc |
| diff --git a/chrome/browser/ui/webui/help/version_updater_chromeos.cc b/chrome/browser/ui/webui/help/version_updater_chromeos.cc |
| index f0d8179d6ae38294c85ba1c0b9c1d114eb14f32d..db91ef5170a9db255f1782a27b78564c506f3a6f 100644 |
| --- a/chrome/browser/ui/webui/help/version_updater_chromeos.cc |
| +++ b/chrome/browser/ui/webui/help/version_updater_chromeos.cc |
| @@ -72,39 +72,6 @@ bool IsAutoUpdateDisabled() { |
| return update_disabled; |
| } |
| -// Returns whether an update is allowed. If not, it calls the callback with |
| -// the appropriate status. |
| -bool EnsureCanUpdate(const VersionUpdater::StatusCallback& callback) { |
| - if (IsAutoUpdateDisabled()) { |
| - callback.Run(VersionUpdater::FAILED, 0, |
| - l10n_util::GetStringUTF16(IDS_UPGRADE_DISABLED_BY_POLICY)); |
| - return false; |
| - } |
| - |
| - chromeos::NetworkStateHandler* network_state_handler = |
| - chromeos::NetworkHandler::Get()->network_state_handler(); |
| - const chromeos::NetworkState* network = |
| - network_state_handler->DefaultNetwork(); |
| - |
| - // Don't allow an update if we're currently offline or connected |
| - // to a network for which updates are disallowed. |
| - NetworkStatus status = GetNetworkStatus(network); |
| - if (status == NETWORK_STATUS_OFFLINE) { |
| - callback.Run(VersionUpdater::FAILED_OFFLINE, 0, |
| - l10n_util::GetStringUTF16(IDS_UPGRADE_OFFLINE)); |
| - return false; |
| - } else if (status == NETWORK_STATUS_DISALLOWED) { |
| - base::string16 message = |
| - l10n_util::GetStringFUTF16( |
| - IDS_UPGRADE_DISALLOWED, |
| - help_utils_chromeos::GetConnectionTypeAsUTF16(network->type())); |
| - callback.Run(VersionUpdater::FAILED_CONNECTION_TYPE_DISALLOWED, 0, message); |
| - return false; |
| - } |
| - |
| - return true; |
| -} |
| - |
| } // namespace |
| VersionUpdater* VersionUpdater::Create() { |
| @@ -136,12 +103,18 @@ void VersionUpdaterCros::CheckForUpdate(const StatusCallback& callback) { |
| if (!update_engine_client->HasObserver(this)) |
| update_engine_client->AddObserver(this); |
| + if (update_engine_client->GetLastStatus().status != |
| + UpdateEngineClient::UPDATE_STATUS_IDLE) { |
| + check_for_update_when_idle_ = true; |
| + return; |
| + } |
| + check_for_update_when_idle_ = false; |
| + |
| // Make sure that libcros is loaded and OOBE is complete. |
| - if (!WizardController::default_controller() || |
| + if (can_update_for_testing_ || !WizardController::default_controller() || |
| chromeos::StartupUtils::IsDeviceRegistered()) { |
| - update_engine_client->RequestUpdateCheck( |
| - base::Bind(&VersionUpdaterCros::OnUpdateCheck, |
| - weak_ptr_factory_.GetWeakPtr())); |
| + update_engine_client->RequestUpdateCheck(base::Bind( |
| + &VersionUpdaterCros::OnUpdateCheck, weak_ptr_factory_.GetWeakPtr())); |
| } |
| } |
| @@ -170,6 +143,7 @@ void VersionUpdaterCros::GetChannel(bool get_current_channel, |
| VersionUpdaterCros::VersionUpdaterCros() |
| : last_operation_(UpdateEngineClient::UPDATE_STATUS_IDLE), |
| + check_for_update_when_idle_(false), |
| weak_ptr_factory_(this) { |
| } |
| @@ -229,6 +203,11 @@ void VersionUpdaterCros::UpdateStatusChanged( |
| callback_.Run(my_status, progress, message); |
| last_operation_ = status.status; |
| + |
| + if (check_for_update_when_idle_ && |
| + status.status == UpdateEngineClient::UPDATE_STATUS_IDLE) { |
| + CheckForUpdate(callback_); |
| + } |
| } |
| void VersionUpdaterCros::OnUpdateCheck( |
| @@ -238,3 +217,37 @@ void VersionUpdaterCros::OnUpdateCheck( |
| if (result == UpdateEngineClient::UPDATE_RESULT_NOTIMPLEMENTED) |
| callback_.Run(UPDATED, 0, base::string16()); |
| } |
| + |
| +bool VersionUpdaterCros::EnsureCanUpdate(const StatusCallback& callback) { |
|
James Hawkins
2014/09/18 16:34:03
What change required this being on the VersionUpda
ygorshenin1
2014/09/18 19:46:47
Check of can_update_for_testing_ field.
|
| + if (can_update_for_testing_) |
| + return true; |
| + |
| + if (IsAutoUpdateDisabled()) { |
| + callback.Run(VersionUpdater::FAILED, 0, |
| + l10n_util::GetStringUTF16(IDS_UPGRADE_DISABLED_BY_POLICY)); |
| + return false; |
| + } |
| + |
| + chromeos::NetworkStateHandler* network_state_handler = |
| + chromeos::NetworkHandler::Get()->network_state_handler(); |
| + const chromeos::NetworkState* network = |
| + network_state_handler->DefaultNetwork(); |
| + |
| + // Don't allow an update if we're currently offline or connected |
| + // to a network for which updates are disallowed. |
| + NetworkStatus status = GetNetworkStatus(network); |
| + if (status == NETWORK_STATUS_OFFLINE) { |
| + callback.Run(VersionUpdater::FAILED_OFFLINE, 0, |
| + l10n_util::GetStringUTF16(IDS_UPGRADE_OFFLINE)); |
| + return false; |
| + } else if (status == NETWORK_STATUS_DISALLOWED) { |
| + base::string16 message = |
| + l10n_util::GetStringFUTF16( |
| + IDS_UPGRADE_DISALLOWED, |
| + help_utils_chromeos::GetConnectionTypeAsUTF16(network->type())); |
| + callback.Run(VersionUpdater::FAILED_CONNECTION_TYPE_DISALLOWED, 0, message); |
| + return false; |
| + } |
| + |
| + return true; |
| +} |