| 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 19 matching lines...) Expand all Loading... |
| 30 using chromeos::DBusThreadManager; | 30 using chromeos::DBusThreadManager; |
| 31 using chromeos::OwnerSettingsServiceChromeOS; | 31 using chromeos::OwnerSettingsServiceChromeOS; |
| 32 using chromeos::OwnerSettingsServiceChromeOSFactory; | 32 using chromeos::OwnerSettingsServiceChromeOSFactory; |
| 33 using chromeos::UpdateEngineClient; | 33 using chromeos::UpdateEngineClient; |
| 34 using chromeos::WizardController; | 34 using chromeos::WizardController; |
| 35 | 35 |
| 36 namespace { | 36 namespace { |
| 37 | 37 |
| 38 // Network status in the context of device update. | 38 // Network status in the context of device update. |
| 39 enum NetworkStatus { | 39 enum NetworkStatus { |
| 40 // It's allowed in device policy to use current network for update. | 40 // It's allowed to use current network for update. |
| 41 NETWORK_STATUS_ALLOWED = 0, | 41 NETWORK_STATUS_ALLOWED = 0, |
| 42 // It's disallowed in device policy to use current network for update. | 42 // It's disallowed to use current network for update. |
| 43 NETWORK_STATUS_DISALLOWED, | 43 NETWORK_STATUS_DISALLOWED, |
| 44 // Device is in offline state. | 44 // Device is in offline state. |
| 45 NETWORK_STATUS_OFFLINE | 45 NETWORK_STATUS_OFFLINE |
| 46 }; | 46 }; |
| 47 | 47 |
| 48 const bool kDefaultAutoUpdateDisabled = false; | 48 const bool kDefaultAutoUpdateDisabled = false; |
| 49 | 49 |
| 50 NetworkStatus GetNetworkStatus(const chromeos::NetworkState* network) { | 50 NetworkStatus GetNetworkStatus(bool interactive, |
| 51 const chromeos::NetworkState* network) { |
| 51 if (!network || !network->IsConnectedState()) // Offline state. | 52 if (!network || !network->IsConnectedState()) // Offline state. |
| 52 return NETWORK_STATUS_OFFLINE; | 53 return NETWORK_STATUS_OFFLINE; |
| 53 // The connection type checking strategy must be the same as the one | 54 |
| 54 // used in update engine. | |
| 55 if (network->type() == shill::kTypeBluetooth) | 55 if (network->type() == shill::kTypeBluetooth) |
| 56 return NETWORK_STATUS_DISALLOWED; | 56 return NETWORK_STATUS_DISALLOWED; |
| 57 // Allow updates over cellular by default in chrome, as update engine still | 57 |
| 58 // needs to check device policy and user preferences when checking for | 58 if (network->type() == shill::kTypeCellular && |
| 59 // updates to decide whether to proceed to downloading. | 59 !help_utils_chromeos::IsUpdateOverCellularAllowed(interactive)) { |
| 60 return NETWORK_STATUS_DISALLOWED; |
| 61 } |
| 60 return NETWORK_STATUS_ALLOWED; | 62 return NETWORK_STATUS_ALLOWED; |
| 61 } | 63 } |
| 62 | 64 |
| 63 // Returns true if auto-update is disabled by the system administrator. | 65 // Returns true if auto-update is disabled by the system administrator. |
| 64 bool IsAutoUpdateDisabled() { | 66 bool IsAutoUpdateDisabled() { |
| 65 bool update_disabled = kDefaultAutoUpdateDisabled; | 67 bool update_disabled = kDefaultAutoUpdateDisabled; |
| 66 chromeos::CrosSettings* settings = chromeos::CrosSettings::Get(); | 68 chromeos::CrosSettings* settings = chromeos::CrosSettings::Get(); |
| 67 if (!settings) | 69 if (!settings) |
| 68 return update_disabled; | 70 return update_disabled; |
| 69 const base::Value* update_disabled_value = | 71 const base::Value* update_disabled_value = |
| 70 settings->GetPref(chromeos::kUpdateDisabled); | 72 settings->GetPref(chromeos::kUpdateDisabled); |
| 71 if (update_disabled_value) | 73 if (update_disabled_value) |
| 72 CHECK(update_disabled_value->GetAsBoolean(&update_disabled)); | 74 CHECK(update_disabled_value->GetAsBoolean(&update_disabled)); |
| 73 return update_disabled; | 75 return update_disabled; |
| 74 } | 76 } |
| 75 | 77 |
| 76 // Returns whether an update is allowed. If not, it calls the callback with | 78 // Returns whether an update is allowed. If not, it calls the callback with |
| 77 // the appropriate status. | 79 // the appropriate status. |interactive| indicates whether the user is actively |
| 78 bool EnsureCanUpdate(const VersionUpdater::StatusCallback& callback) { | 80 // checking for updates. |
| 81 bool EnsureCanUpdate(bool interactive, |
| 82 const VersionUpdater::StatusCallback& callback) { |
| 79 if (IsAutoUpdateDisabled()) { | 83 if (IsAutoUpdateDisabled()) { |
| 80 callback.Run(VersionUpdater::DISABLED_BY_ADMIN, 0, std::string(), 0, | 84 callback.Run(VersionUpdater::DISABLED_BY_ADMIN, 0, std::string(), 0, |
| 81 l10n_util::GetStringUTF16(IDS_UPGRADE_DISABLED_BY_POLICY)); | 85 l10n_util::GetStringUTF16(IDS_UPGRADE_DISABLED_BY_POLICY)); |
| 82 return false; | 86 return false; |
| 83 } | 87 } |
| 84 | 88 |
| 85 chromeos::NetworkStateHandler* network_state_handler = | 89 chromeos::NetworkStateHandler* network_state_handler = |
| 86 chromeos::NetworkHandler::Get()->network_state_handler(); | 90 chromeos::NetworkHandler::Get()->network_state_handler(); |
| 87 const chromeos::NetworkState* network = | 91 const chromeos::NetworkState* network = |
| 88 network_state_handler->DefaultNetwork(); | 92 network_state_handler->DefaultNetwork(); |
| 89 | 93 |
| 90 // Don't allow an update if we're currently offline or connected | 94 // Don't allow an update if we're currently offline or connected |
| 91 // to a network for which updates are disallowed. | 95 // to a network for which updates are disallowed. |
| 92 NetworkStatus status = GetNetworkStatus(network); | 96 NetworkStatus status = GetNetworkStatus(interactive, network); |
| 93 if (status == NETWORK_STATUS_OFFLINE) { | 97 if (status == NETWORK_STATUS_OFFLINE) { |
| 94 callback.Run(VersionUpdater::FAILED_OFFLINE, 0, std::string(), 0, | 98 callback.Run(VersionUpdater::FAILED_OFFLINE, 0, std::string(), 0, |
| 95 l10n_util::GetStringUTF16(IDS_UPGRADE_OFFLINE)); | 99 l10n_util::GetStringUTF16(IDS_UPGRADE_OFFLINE)); |
| 96 return false; | 100 return false; |
| 97 } else if (status == NETWORK_STATUS_DISALLOWED) { | 101 } else if (status == NETWORK_STATUS_DISALLOWED) { |
| 98 base::string16 message = | 102 base::string16 message = |
| 99 l10n_util::GetStringFUTF16( | 103 l10n_util::GetStringFUTF16( |
| 100 IDS_UPGRADE_DISALLOWED, | 104 IDS_UPGRADE_DISALLOWED, |
| 101 help_utils_chromeos::GetConnectionTypeAsUTF16(network->type())); | 105 help_utils_chromeos::GetConnectionTypeAsUTF16(network->type())); |
| 102 callback.Run(VersionUpdater::FAILED_CONNECTION_TYPE_DISALLOWED, 0, | 106 callback.Run(VersionUpdater::FAILED_CONNECTION_TYPE_DISALLOWED, 0, |
| 103 std::string(), 0, message); | 107 std::string(), 0, message); |
| 104 return false; | 108 return false; |
| 105 } | 109 } |
| 106 | 110 |
| 107 return true; | 111 return true; |
| 108 } | 112 } |
| 109 | 113 |
| 110 } // namespace | 114 } // namespace |
| 111 | 115 |
| 112 VersionUpdater* VersionUpdater::Create(content::WebContents* web_contents) { | 116 VersionUpdater* VersionUpdater::Create(content::WebContents* web_contents) { |
| 113 return new VersionUpdaterCros(web_contents); | 117 return new VersionUpdaterCros(web_contents); |
| 114 } | 118 } |
| 115 | 119 |
| 116 void VersionUpdaterCros::GetUpdateStatus(const StatusCallback& callback) { | 120 void VersionUpdaterCros::GetUpdateStatus(const StatusCallback& callback) { |
| 117 callback_ = callback; | 121 callback_ = callback; |
| 118 | 122 |
| 119 if (!EnsureCanUpdate(callback)) | 123 // User is not actively checking for updates. |
| 124 if (!EnsureCanUpdate(false /* interactive */, callback)) |
| 120 return; | 125 return; |
| 121 | 126 |
| 122 UpdateEngineClient* update_engine_client = | 127 UpdateEngineClient* update_engine_client = |
| 123 DBusThreadManager::Get()->GetUpdateEngineClient(); | 128 DBusThreadManager::Get()->GetUpdateEngineClient(); |
| 124 if (!update_engine_client->HasObserver(this)) | 129 if (!update_engine_client->HasObserver(this)) |
| 125 update_engine_client->AddObserver(this); | 130 update_engine_client->AddObserver(this); |
| 126 | 131 |
| 127 this->UpdateStatusChanged( | 132 this->UpdateStatusChanged( |
| 128 DBusThreadManager::Get()->GetUpdateEngineClient()->GetLastStatus()); | 133 DBusThreadManager::Get()->GetUpdateEngineClient()->GetLastStatus()); |
| 129 } | 134 } |
| 130 | 135 |
| 131 void VersionUpdaterCros::CheckForUpdate(const StatusCallback& callback, | 136 void VersionUpdaterCros::CheckForUpdate(const StatusCallback& callback, |
| 132 const PromoteCallback&) { | 137 const PromoteCallback&) { |
| 133 callback_ = callback; | 138 callback_ = callback; |
| 134 | 139 |
| 135 if (!EnsureCanUpdate(callback)) | 140 // User is actively checking for updates. |
| 141 if (!EnsureCanUpdate(true /* interactive */, callback)) |
| 136 return; | 142 return; |
| 137 | 143 |
| 138 UpdateEngineClient* update_engine_client = | 144 UpdateEngineClient* update_engine_client = |
| 139 DBusThreadManager::Get()->GetUpdateEngineClient(); | 145 DBusThreadManager::Get()->GetUpdateEngineClient(); |
| 140 if (!update_engine_client->HasObserver(this)) | 146 if (!update_engine_client->HasObserver(this)) |
| 141 update_engine_client->AddObserver(this); | 147 update_engine_client->AddObserver(this); |
| 142 | 148 |
| 143 if (update_engine_client->GetLastStatus().status != | 149 if (update_engine_client->GetLastStatus().status != |
| 144 UpdateEngineClient::UPDATE_STATUS_IDLE) { | 150 UpdateEngineClient::UPDATE_STATUS_IDLE) { |
| 145 check_for_update_when_idle_ = true; | 151 check_for_update_when_idle_ = true; |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 } | 308 } |
| 303 } | 309 } |
| 304 | 310 |
| 305 void VersionUpdaterCros::OnUpdateCheck( | 311 void VersionUpdaterCros::OnUpdateCheck( |
| 306 UpdateEngineClient::UpdateCheckResult result) { | 312 UpdateEngineClient::UpdateCheckResult result) { |
| 307 // If version updating is not implemented, this binary is the most up-to-date | 313 // If version updating is not implemented, this binary is the most up-to-date |
| 308 // possible with respect to automatic updating. | 314 // possible with respect to automatic updating. |
| 309 if (result == UpdateEngineClient::UPDATE_RESULT_NOTIMPLEMENTED) | 315 if (result == UpdateEngineClient::UPDATE_RESULT_NOTIMPLEMENTED) |
| 310 callback_.Run(UPDATED, 0, std::string(), 0, base::string16()); | 316 callback_.Run(UPDATED, 0, std::string(), 0, base::string16()); |
| 311 } | 317 } |
| OLD | NEW |