Chromium Code Reviews| 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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 66 chromeos::CrosSettings* settings = chromeos::CrosSettings::Get(); | 66 chromeos::CrosSettings* settings = chromeos::CrosSettings::Get(); |
| 67 if (!settings) | 67 if (!settings) |
| 68 return update_disabled; | 68 return update_disabled; |
| 69 const base::Value* update_disabled_value = | 69 const base::Value* update_disabled_value = |
| 70 settings->GetPref(chromeos::kUpdateDisabled); | 70 settings->GetPref(chromeos::kUpdateDisabled); |
| 71 if (update_disabled_value) | 71 if (update_disabled_value) |
| 72 CHECK(update_disabled_value->GetAsBoolean(&update_disabled)); | 72 CHECK(update_disabled_value->GetAsBoolean(&update_disabled)); |
| 73 return update_disabled; | 73 return update_disabled; |
| 74 } | 74 } |
| 75 | 75 |
| 76 } // namespace | 76 // Returns whether an update is allowed. If not, it calls the callback with |
| 77 | 77 // the appropriate status. |
| 78 VersionUpdater* VersionUpdater::Create() { | 78 bool EnsureCanUpdate(const VersionUpdater::StatusCallback& callback) { |
| 79 return new VersionUpdaterCros; | |
| 80 } | |
| 81 | |
| 82 void VersionUpdaterCros::CheckForUpdate(const StatusCallback& callback) { | |
| 83 callback_ = callback; | |
| 84 | |
| 85 if (IsAutoUpdateDisabled()) { | 79 if (IsAutoUpdateDisabled()) { |
| 86 callback_.Run(FAILED, 0, | 80 callback.Run(VersionUpdater::FAILED, 0, |
| 87 l10n_util::GetStringUTF16(IDS_UPGRADE_DISABLED_BY_POLICY)); | 81 l10n_util::GetStringUTF16(IDS_UPGRADE_DISABLED_BY_POLICY)); |
| 88 return; | 82 return false; |
| 89 } | 83 } |
| 90 | 84 |
| 91 chromeos::NetworkStateHandler* network_state_handler = | 85 chromeos::NetworkStateHandler* network_state_handler = |
| 92 chromeos::NetworkHandler::Get()->network_state_handler(); | 86 chromeos::NetworkHandler::Get()->network_state_handler(); |
| 93 const chromeos::NetworkState* network = | 87 const chromeos::NetworkState* network = |
| 94 network_state_handler->DefaultNetwork(); | 88 network_state_handler->DefaultNetwork(); |
| 95 | 89 |
| 96 // Don't proceed to update if we're currently offline or connected | 90 // Don't allow an update if we're currently offline or connected |
| 97 // to a network for which updates are disallowed. | 91 // to a network for which updates are disallowed. |
| 98 NetworkStatus status = GetNetworkStatus(network); | 92 NetworkStatus status = GetNetworkStatus(network); |
| 99 if (status == NETWORK_STATUS_OFFLINE) { | 93 if (status == NETWORK_STATUS_OFFLINE) { |
| 100 callback_.Run(FAILED_OFFLINE, 0, | 94 callback.Run(VersionUpdater::FAILED_OFFLINE, 0, |
| 101 l10n_util::GetStringUTF16(IDS_UPGRADE_OFFLINE)); | 95 l10n_util::GetStringUTF16(IDS_UPGRADE_OFFLINE)); |
| 102 return; | 96 return false; |
| 103 } else if (status == NETWORK_STATUS_DISALLOWED) { | 97 } else if (status == NETWORK_STATUS_DISALLOWED) { |
| 104 base::string16 message = | 98 base::string16 message = |
| 105 l10n_util::GetStringFUTF16( | 99 l10n_util::GetStringFUTF16( |
| 106 IDS_UPGRADE_DISALLOWED, | 100 IDS_UPGRADE_DISALLOWED, |
| 107 help_utils_chromeos::GetConnectionTypeAsUTF16(network->type())); | 101 help_utils_chromeos::GetConnectionTypeAsUTF16(network->type())); |
| 108 callback_.Run(FAILED_CONNECTION_TYPE_DISALLOWED, 0, message); | 102 callback.Run(VersionUpdater::FAILED_CONNECTION_TYPE_DISALLOWED, 0, message); |
| 103 return false; | |
| 104 } | |
| 105 | |
| 106 return true; | |
| 107 } | |
| 108 | |
| 109 } // namespace | |
| 110 | |
| 111 VersionUpdater* VersionUpdater::Create() { | |
| 112 return new VersionUpdaterCros; | |
| 113 } | |
| 114 | |
| 115 void VersionUpdaterCros::GetUpdateStatus(const StatusCallback& callback) { | |
| 116 callback_ = callback; | |
| 117 if (!EnsureCanUpdate(callback)) | |
| 109 return; | 118 return; |
| 110 } | |
| 111 | 119 |
| 112 UpdateEngineClient* update_engine_client = | 120 UpdateEngineClient* update_engine_client = |
| 113 DBusThreadManager::Get()->GetUpdateEngineClient(); | 121 DBusThreadManager::Get()->GetUpdateEngineClient(); |
| 114 update_engine_client->AddObserver(this); | 122 if (!update_engine_client->HasObserver(this)) |
| 123 update_engine_client->AddObserver(this); | |
| 124 | |
| 125 this->UpdateStatusChanged( | |
| 126 DBusThreadManager::Get()->GetUpdateEngineClient()->GetLastStatus()); | |
| 127 } | |
| 128 | |
| 129 void VersionUpdaterCros::CheckForUpdate(const StatusCallback& callback) { | |
| 130 callback_ = callback; | |
| 131 | |
| 132 if (!EnsureCanUpdate(callback)) | |
| 133 return; | |
| 134 | |
| 135 UpdateEngineClient* update_engine_client = | |
| 136 DBusThreadManager::Get()->GetUpdateEngineClient(); | |
| 137 if (!update_engine_client->HasObserver(this)) | |
|
michaelpg
2014/08/14 22:52:57
Note that this is an existing "bug" (a NOT_REACHED
| |
| 138 update_engine_client->AddObserver(this); | |
| 115 | 139 |
| 116 // Make sure that libcros is loaded and OOBE is complete. | 140 // Make sure that libcros is loaded and OOBE is complete. |
| 117 if (!WizardController::default_controller() || | 141 if (!WizardController::default_controller() || |
| 118 chromeos::StartupUtils::IsDeviceRegistered()) { | 142 chromeos::StartupUtils::IsDeviceRegistered()) { |
| 119 update_engine_client->RequestUpdateCheck( | 143 update_engine_client->RequestUpdateCheck( |
| 120 base::Bind(&VersionUpdaterCros::OnUpdateCheck, | 144 base::Bind(&VersionUpdaterCros::OnUpdateCheck, |
| 121 weak_ptr_factory_.GetWeakPtr())); | 145 weak_ptr_factory_.GetWeakPtr())); |
| 122 } | 146 } |
| 123 } | 147 } |
| 124 | 148 |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 208 last_operation_ = status.status; | 232 last_operation_ = status.status; |
| 209 } | 233 } |
| 210 | 234 |
| 211 void VersionUpdaterCros::OnUpdateCheck( | 235 void VersionUpdaterCros::OnUpdateCheck( |
| 212 UpdateEngineClient::UpdateCheckResult result) { | 236 UpdateEngineClient::UpdateCheckResult result) { |
| 213 // If version updating is not implemented, this binary is the most up-to-date | 237 // If version updating is not implemented, this binary is the most up-to-date |
| 214 // possible with respect to automatic updating. | 238 // possible with respect to automatic updating. |
| 215 if (result == UpdateEngineClient::UPDATE_RESULT_NOTIMPLEMENTED) | 239 if (result == UpdateEngineClient::UPDATE_RESULT_NOTIMPLEMENTED) |
| 216 callback_.Run(UPDATED, 0, base::string16()); | 240 callback_.Run(UPDATED, 0, base::string16()); |
| 217 } | 241 } |
| OLD | NEW |