Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(169)

Side by Side Diff: chrome/browser/ui/webui/help/version_updater_chromeos.cc

Issue 2795603002: Add an update warning for downloading over mobile data (Closed)
Patch Set: Ignore this as I uploaded a new CL Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
11 #include "base/strings/string_number_conversions.h"
11 #include "chrome/browser/browser_process.h" 12 #include "chrome/browser/browser_process.h"
12 #include "chrome/browser/chromeos/login/startup_utils.h" 13 #include "chrome/browser/chromeos/login/startup_utils.h"
13 #include "chrome/browser/chromeos/login/wizard_controller.h" 14 #include "chrome/browser/chromeos/login/wizard_controller.h"
14 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos.h" 15 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos.h"
15 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos_fact ory.h" 16 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos_fact ory.h"
16 #include "chrome/browser/chromeos/settings/cros_settings.h" 17 #include "chrome/browser/chromeos/settings/cros_settings.h"
17 #include "chrome/browser/ui/webui/help/help_utils_chromeos.h" 18 #include "chrome/browser/ui/webui/help/help_utils_chromeos.h"
18 #include "chrome/grit/generated_resources.h" 19 #include "chrome/grit/generated_resources.h"
19 #include "chromeos/dbus/dbus_thread_manager.h" 20 #include "chromeos/dbus/dbus_thread_manager.h"
20 #include "chromeos/dbus/power_manager_client.h" 21 #include "chromeos/dbus/power_manager_client.h"
(...skipping 21 matching lines...) Expand all
42 NETWORK_STATUS_DISALLOWED, 43 NETWORK_STATUS_DISALLOWED,
43 // Device is in offline state. 44 // Device is in offline state.
44 NETWORK_STATUS_OFFLINE 45 NETWORK_STATUS_OFFLINE
45 }; 46 };
46 47
47 const bool kDefaultAutoUpdateDisabled = false; 48 const bool kDefaultAutoUpdateDisabled = false;
48 49
49 NetworkStatus GetNetworkStatus(const chromeos::NetworkState* network) { 50 NetworkStatus GetNetworkStatus(const chromeos::NetworkState* network) {
50 if (!network || !network->IsConnectedState()) // Offline state. 51 if (!network || !network->IsConnectedState()) // Offline state.
51 return NETWORK_STATUS_OFFLINE; 52 return NETWORK_STATUS_OFFLINE;
52
53 // The connection type checking strategy must be the same as the one 53 // The connection type checking strategy must be the same as the one
54 // used in update engine. 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 if (network->type() == shill::kTypeCellular && 57 // Allow updates over cellular by default in chrome, as update engine still
58 !help_utils_chromeos::IsUpdateOverCellularAllowed()) { 58 // need to check device policy and user preferences during checking for update
59 return NETWORK_STATUS_DISALLOWED; 59 // to decide whether to proceed to downloading.
60 }
61 return NETWORK_STATUS_ALLOWED; 60 return NETWORK_STATUS_ALLOWED;
62 } 61 }
63 62
64 // Returns true if auto-update is disabled by the system administrator. 63 // Returns true if auto-update is disabled by the system administrator.
65 bool IsAutoUpdateDisabled() { 64 bool IsAutoUpdateDisabled() {
66 bool update_disabled = kDefaultAutoUpdateDisabled; 65 bool update_disabled = kDefaultAutoUpdateDisabled;
67 chromeos::CrosSettings* settings = chromeos::CrosSettings::Get(); 66 chromeos::CrosSettings* settings = chromeos::CrosSettings::Get();
68 if (!settings) 67 if (!settings)
69 return update_disabled; 68 return update_disabled;
70 const base::Value* update_disabled_value = 69 const base::Value* update_disabled_value =
71 settings->GetPref(chromeos::kUpdateDisabled); 70 settings->GetPref(chromeos::kUpdateDisabled);
72 if (update_disabled_value) 71 if (update_disabled_value)
73 CHECK(update_disabled_value->GetAsBoolean(&update_disabled)); 72 CHECK(update_disabled_value->GetAsBoolean(&update_disabled));
74 return update_disabled; 73 return update_disabled;
75 } 74 }
76 75
77 // Returns whether an update is allowed. If not, it calls the callback with 76 // Returns whether an update is allowed. If not, it calls the callback with
78 // the appropriate status. 77 // the appropriate status.
79 bool EnsureCanUpdate(const VersionUpdater::StatusCallback& callback) { 78 bool EnsureCanUpdate(const VersionUpdater::StatusCallback& callback) {
80 if (IsAutoUpdateDisabled()) { 79 if (IsAutoUpdateDisabled()) {
81 callback.Run(VersionUpdater::DISABLED_BY_ADMIN, 0, 80 callback.Run(VersionUpdater::DISABLED_BY_ADMIN, 0, std::string(), 0,
82 l10n_util::GetStringUTF16(IDS_UPGRADE_DISABLED_BY_POLICY)); 81 l10n_util::GetStringUTF16(IDS_UPGRADE_DISABLED_BY_POLICY));
83 return false; 82 return false;
84 } 83 }
85 84
86 chromeos::NetworkStateHandler* network_state_handler = 85 chromeos::NetworkStateHandler* network_state_handler =
87 chromeos::NetworkHandler::Get()->network_state_handler(); 86 chromeos::NetworkHandler::Get()->network_state_handler();
88 const chromeos::NetworkState* network = 87 const chromeos::NetworkState* network =
89 network_state_handler->DefaultNetwork(); 88 network_state_handler->DefaultNetwork();
90 89
91 // Don't allow an update if we're currently offline or connected 90 // Don't allow an update if we're currently offline or connected
92 // to a network for which updates are disallowed. 91 // to a network for which updates are disallowed.
93 NetworkStatus status = GetNetworkStatus(network); 92 NetworkStatus status = GetNetworkStatus(network);
94 if (status == NETWORK_STATUS_OFFLINE) { 93 if (status == NETWORK_STATUS_OFFLINE) {
95 callback.Run(VersionUpdater::FAILED_OFFLINE, 0, 94 callback.Run(VersionUpdater::FAILED_OFFLINE, 0, std::string(), 0,
96 l10n_util::GetStringUTF16(IDS_UPGRADE_OFFLINE)); 95 l10n_util::GetStringUTF16(IDS_UPGRADE_OFFLINE));
97 return false; 96 return false;
98 } else if (status == NETWORK_STATUS_DISALLOWED) { 97 } else if (status == NETWORK_STATUS_DISALLOWED) {
99 base::string16 message = 98 base::string16 message =
100 l10n_util::GetStringFUTF16( 99 l10n_util::GetStringFUTF16(
101 IDS_UPGRADE_DISALLOWED, 100 IDS_UPGRADE_DISALLOWED,
102 help_utils_chromeos::GetConnectionTypeAsUTF16(network->type())); 101 help_utils_chromeos::GetConnectionTypeAsUTF16(network->type()));
103 callback.Run(VersionUpdater::FAILED_CONNECTION_TYPE_DISALLOWED, 0, message); 102 callback.Run(VersionUpdater::FAILED_CONNECTION_TYPE_DISALLOWED, 0,
103 std::string(), 0, message);
104 return false; 104 return false;
105 } 105 }
106 106
107 return true; 107 return true;
108 } 108 }
109 109
110 } // namespace 110 } // namespace
111 111
112 VersionUpdater* VersionUpdater::Create(content::WebContents* web_contents) { 112 VersionUpdater* VersionUpdater::Create(content::WebContents* web_contents) {
113 return new VersionUpdaterCros(web_contents); 113 return new VersionUpdaterCros(web_contents);
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 ? OwnerSettingsServiceChromeOSFactory::GetInstance() 162 ? OwnerSettingsServiceChromeOSFactory::GetInstance()
163 ->GetForBrowserContext(context_) 163 ->GetForBrowserContext(context_)
164 : nullptr; 164 : nullptr;
165 // For local owner set the field in the policy blob. 165 // For local owner set the field in the policy blob.
166 if (service) 166 if (service)
167 service->SetString(chromeos::kReleaseChannel, channel); 167 service->SetString(chromeos::kReleaseChannel, channel);
168 DBusThreadManager::Get()->GetUpdateEngineClient()-> 168 DBusThreadManager::Get()->GetUpdateEngineClient()->
169 SetChannel(channel, is_powerwash_allowed); 169 SetChannel(channel, is_powerwash_allowed);
170 } 170 }
171 171
172 void VersionUpdaterCros::SetUpdateOverCellularTarget(
173 const StatusCallback& callback,
174 const std::string& target_version,
175 int64_t target_size) {
176 callback_ = callback;
177 DBusThreadManager::Get()
178 ->GetUpdateEngineClient()
179 ->SetUpdateOverCellularTarget(
180 target_version, target_size,
181 base::Bind(&VersionUpdaterCros::OnSetUpdateOverCellularTarget,
182 weak_ptr_factory_.GetWeakPtr()));
183 }
184
185 void VersionUpdaterCros::OnSetUpdateOverCellularTarget(bool success) {
186 if (success)
187 // Target is set successfully, so we can proceed to update.
188 CheckForUpdate(callback_, VersionUpdater::PromoteCallback());
189 else
190 // TODO(weidongg/691108): invoke callback to signal about page to show
191 // appropriate error message.
192 LOG(ERROR) << "Error setting update over cellular target.";
193 }
194
172 void VersionUpdaterCros::GetChannel(bool get_current_channel, 195 void VersionUpdaterCros::GetChannel(bool get_current_channel,
173 const ChannelCallback& cb) { 196 const ChannelCallback& cb) {
174 UpdateEngineClient* update_engine_client = 197 UpdateEngineClient* update_engine_client =
175 DBusThreadManager::Get()->GetUpdateEngineClient(); 198 DBusThreadManager::Get()->GetUpdateEngineClient();
176 199
177 // Request the channel information. Bind to a weak_ptr bound method rather 200 // Request the channel information. Bind to a weak_ptr bound method rather
178 // than passing |cb| directly so that |cb| does not outlive |this|. 201 // than passing |cb| directly so that |cb| does not outlive |this|.
179 update_engine_client->GetChannel( 202 update_engine_client->GetChannel(
180 get_current_channel, base::Bind(&VersionUpdaterCros::OnGetChannel, 203 get_current_channel, base::Bind(&VersionUpdaterCros::OnGetChannel,
181 weak_ptr_factory_.GetWeakPtr(), cb)); 204 weak_ptr_factory_.GetWeakPtr(), cb));
(...skipping 29 matching lines...) Expand all
211 VersionUpdaterCros::~VersionUpdaterCros() { 234 VersionUpdaterCros::~VersionUpdaterCros() {
212 UpdateEngineClient* update_engine_client = 235 UpdateEngineClient* update_engine_client =
213 DBusThreadManager::Get()->GetUpdateEngineClient(); 236 DBusThreadManager::Get()->GetUpdateEngineClient();
214 update_engine_client->RemoveObserver(this); 237 update_engine_client->RemoveObserver(this);
215 } 238 }
216 239
217 void VersionUpdaterCros::UpdateStatusChanged( 240 void VersionUpdaterCros::UpdateStatusChanged(
218 const UpdateEngineClient::Status& status) { 241 const UpdateEngineClient::Status& status) {
219 Status my_status = UPDATED; 242 Status my_status = UPDATED;
220 int progress = 0; 243 int progress = 0;
244 std::string version = status.new_version;
245 int64_t size = status.new_size;
221 base::string16 message; 246 base::string16 message;
222 247
223 // If the updater is currently idle, just show the last operation (unless it 248 // If the updater is currently idle, just show the last operation (unless it
224 // was previously checking for an update -- in that case, the system is 249 // was previously checking for an update -- in that case, the system is
225 // up to date now). See http://crbug.com/120063 for details. 250 // up to date now). See http://crbug.com/120063 for details.
226 UpdateEngineClient::UpdateStatusOperation operation_to_show = status.status; 251 UpdateEngineClient::UpdateStatusOperation operation_to_show = status.status;
227 if (status.status == UpdateEngineClient::UPDATE_STATUS_IDLE && 252 if (status.status == UpdateEngineClient::UPDATE_STATUS_IDLE &&
228 last_operation_ != 253 last_operation_ !=
229 UpdateEngineClient::UPDATE_STATUS_CHECKING_FOR_UPDATE) { 254 UpdateEngineClient::UPDATE_STATUS_CHECKING_FOR_UPDATE) {
230 operation_to_show = last_operation_; 255 operation_to_show = last_operation_;
(...skipping 10 matching lines...) Expand all
241 break; 266 break;
242 case UpdateEngineClient::UPDATE_STATUS_CHECKING_FOR_UPDATE: 267 case UpdateEngineClient::UPDATE_STATUS_CHECKING_FOR_UPDATE:
243 my_status = CHECKING; 268 my_status = CHECKING;
244 break; 269 break;
245 case UpdateEngineClient::UPDATE_STATUS_DOWNLOADING: 270 case UpdateEngineClient::UPDATE_STATUS_DOWNLOADING:
246 progress = static_cast<int>(round(status.download_progress * 100)); 271 progress = static_cast<int>(round(status.download_progress * 100));
247 // Fall through. 272 // Fall through.
248 case UpdateEngineClient::UPDATE_STATUS_UPDATE_AVAILABLE: 273 case UpdateEngineClient::UPDATE_STATUS_UPDATE_AVAILABLE:
249 my_status = UPDATING; 274 my_status = UPDATING;
250 break; 275 break;
276 case UpdateEngineClient::UPDATE_STATUS_NEED_PERMISSION_TO_UPDATE:
277 my_status = NEED_PERMISSION_TO_UPDATE;
278 message = base::Int64ToString16(status.new_size);
279 break;
251 case UpdateEngineClient::UPDATE_STATUS_VERIFYING: 280 case UpdateEngineClient::UPDATE_STATUS_VERIFYING:
252 case UpdateEngineClient::UPDATE_STATUS_FINALIZING: 281 case UpdateEngineClient::UPDATE_STATUS_FINALIZING:
253 // Once the download is finished, keep the progress at 100; it shouldn't 282 // Once the download is finished, keep the progress at 100; it shouldn't
254 // go down while the status is the same. 283 // go down while the status is the same.
255 progress = 100; 284 progress = 100;
256 my_status = UPDATING; 285 my_status = UPDATING;
257 break; 286 break;
258 case UpdateEngineClient::UPDATE_STATUS_UPDATED_NEED_REBOOT: 287 case UpdateEngineClient::UPDATE_STATUS_UPDATED_NEED_REBOOT:
259 my_status = NEARLY_UPDATED; 288 my_status = NEARLY_UPDATED;
260 break; 289 break;
261 default: 290 default:
262 break; 291 break;
263 } 292 }
264 293
265 callback_.Run(my_status, progress, message); 294 callback_.Run(my_status, progress, version, size, message);
266 last_operation_ = status.status; 295 last_operation_ = status.status;
267 296
268 if (check_for_update_when_idle_ && 297 if (check_for_update_when_idle_ &&
269 status.status == UpdateEngineClient::UPDATE_STATUS_IDLE) { 298 status.status == UpdateEngineClient::UPDATE_STATUS_IDLE) {
270 CheckForUpdate(callback_, VersionUpdater::PromoteCallback()); 299 CheckForUpdate(callback_, VersionUpdater::PromoteCallback());
271 } 300 }
272 } 301 }
273 302
274 void VersionUpdaterCros::OnUpdateCheck( 303 void VersionUpdaterCros::OnUpdateCheck(
275 UpdateEngineClient::UpdateCheckResult result) { 304 UpdateEngineClient::UpdateCheckResult result) {
276 // If version updating is not implemented, this binary is the most up-to-date 305 // If version updating is not implemented, this binary is the most up-to-date
277 // possible with respect to automatic updating. 306 // possible with respect to automatic updating.
278 if (result == UpdateEngineClient::UPDATE_RESULT_NOTIMPLEMENTED) 307 if (result == UpdateEngineClient::UPDATE_RESULT_NOTIMPLEMENTED)
279 callback_.Run(UPDATED, 0, base::string16()); 308 callback_.Run(UPDATED, 0, std::string(), 0, base::string16());
280 } 309 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/help/version_updater_chromeos.h ('k') | chrome/browser/ui/webui/settings/about_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698