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

Side by Side Diff: chrome/browser/ui/webui/options/chromeos/about_page_handler.cc

Issue 8585025: chromeos: Change all clients of UpdateLibrary to use UpdateEngineClient. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address comments Created 9 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/webui/options/chromeos/about_page_handler.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/options/chromeos/about_page_handler.h" 5 #include "chrome/browser/ui/webui/options/chromeos/about_page_handler.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/bind_helpers.h" 11 #include "base/bind_helpers.h"
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/i18n/time_formatting.h" 13 #include "base/i18n/time_formatting.h"
14 #include "base/string16.h" 14 #include "base/string16.h"
15 #include "base/string_number_conversions.h" 15 #include "base/string_number_conversions.h"
16 #include "base/time.h" 16 #include "base/time.h"
17 #include "base/utf_string_conversions.h" 17 #include "base/utf_string_conversions.h"
18 #include "base/values.h" 18 #include "base/values.h"
19 #include "chrome/browser/chromeos/cros/cros_library.h"
20 #include "chrome/browser/chromeos/cros/update_library.h"
21 #include "chrome/browser/chromeos/dbus/dbus_thread_manager.h" 19 #include "chrome/browser/chromeos/dbus/dbus_thread_manager.h"
22 #include "chrome/browser/chromeos/dbus/power_manager_client.h" 20 #include "chrome/browser/chromeos/dbus/power_manager_client.h"
21 #include "chrome/browser/chromeos/dbus/update_engine_client.h"
23 #include "chrome/browser/chromeos/login/user_manager.h" 22 #include "chrome/browser/chromeos/login/user_manager.h"
24 #include "chrome/browser/chromeos/login/wizard_controller.h" 23 #include "chrome/browser/chromeos/login/wizard_controller.h"
25 #include "chrome/browser/chromeos/user_cros_settings_provider.h" 24 #include "chrome/browser/chromeos/user_cros_settings_provider.h"
26 #include "chrome/browser/google/google_util.h" 25 #include "chrome/browser/google/google_util.h"
27 #include "chrome/common/chrome_version_info.h" 26 #include "chrome/common/chrome_version_info.h"
28 #include "chrome/common/url_constants.h" 27 #include "chrome/common/url_constants.h"
29 #include "content/public/common/content_client.h" 28 #include "content/public/common/content_client.h"
30 #include "googleurl/src/gurl.h" 29 #include "googleurl/src/gurl.h"
31 #include "grit/chromium_strings.h" 30 #include "grit/chromium_strings.h"
32 #include "grit/generated_resources.h" 31 #include "grit/generated_resources.h"
(...skipping 24 matching lines...) Expand all
57 size_t end) { 56 size_t end) {
58 DCHECK(end > start); 57 DCHECK(end > start);
59 return text.substr(start, end - start); 58 return text.substr(start, end - start);
60 } 59 }
61 60
62 } // namespace 61 } // namespace
63 62
64 namespace chromeos { 63 namespace chromeos {
65 64
66 class AboutPageHandler::UpdateObserver 65 class AboutPageHandler::UpdateObserver
67 : public UpdateLibrary::Observer { 66 : public UpdateEngineClient::Observer {
68 public: 67 public:
69 explicit UpdateObserver(AboutPageHandler* handler) : page_handler_(handler) {} 68 explicit UpdateObserver(AboutPageHandler* handler) : page_handler_(handler) {}
70 virtual ~UpdateObserver() {} 69 virtual ~UpdateObserver() {}
71 70
72 AboutPageHandler* page_handler() const { return page_handler_; } 71 AboutPageHandler* page_handler() const { return page_handler_; }
73 72
74 private: 73 private:
75 virtual void UpdateStatusChanged(const UpdateLibrary::Status& status) { 74 virtual void UpdateStatusChanged(
75 const UpdateEngineClient::Status& status) OVERRIDE {
76 page_handler_->UpdateStatus(status); 76 page_handler_->UpdateStatus(status);
77 } 77 }
78 78
79 AboutPageHandler* page_handler_; 79 AboutPageHandler* page_handler_;
80 80
81 DISALLOW_COPY_AND_ASSIGN(UpdateObserver); 81 DISALLOW_COPY_AND_ASSIGN(UpdateObserver);
82 }; 82 };
83 83
84 AboutPageHandler::AboutPageHandler() 84 AboutPageHandler::AboutPageHandler()
85 : CrosOptionsPageUIHandler( 85 : CrosOptionsPageUIHandler(
86 new UserCrosSettingsProvider), 86 new UserCrosSettingsProvider),
87 progress_(-1), 87 progress_(-1),
88 sticky_(false), 88 sticky_(false),
89 started_(false) 89 started_(false)
90 {} 90 {}
91 91
92 AboutPageHandler::~AboutPageHandler() { 92 AboutPageHandler::~AboutPageHandler() {
93 if (update_observer_.get()) { 93 if (update_observer_.get()) {
94 CrosLibrary::Get()->GetUpdateLibrary()-> 94 DBusThreadManager::Get()->GetUpdateEngineClient()->
95 RemoveObserver(update_observer_.get()); 95 RemoveObserver(update_observer_.get());
96 } 96 }
97 } 97 }
98 98
99 void AboutPageHandler::GetLocalizedValues(DictionaryValue* localized_strings) { 99 void AboutPageHandler::GetLocalizedValues(DictionaryValue* localized_strings) {
100 DCHECK(localized_strings); 100 DCHECK(localized_strings);
101 101
102 static OptionsStringResource resources[] = { 102 static OptionsStringResource resources[] = {
103 { "firmware", IDS_ABOUT_PAGE_FIRMWARE }, 103 { "firmware", IDS_ABOUT_PAGE_FIRMWARE },
104 { "product", IDS_PRODUCT_OS_NAME }, 104 { "product", IDS_PRODUCT_OS_NAME },
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 void AboutPageHandler::PageReady(const ListValue* args) { 251 void AboutPageHandler::PageReady(const ListValue* args) {
252 // Version information is loaded from a callback 252 // Version information is loaded from a callback
253 loader_.GetVersion(&consumer_, 253 loader_.GetVersion(&consumer_,
254 base::Bind(&AboutPageHandler::OnOSVersion, 254 base::Bind(&AboutPageHandler::OnOSVersion,
255 base::Unretained(this)), 255 base::Unretained(this)),
256 VersionLoader::VERSION_FULL); 256 VersionLoader::VERSION_FULL);
257 loader_.GetFirmware(&consumer_, 257 loader_.GetFirmware(&consumer_,
258 base::Bind(&AboutPageHandler::OnOSFirmware, 258 base::Bind(&AboutPageHandler::OnOSFirmware,
259 base::Unretained(this))); 259 base::Unretained(this)));
260 260
261 UpdateLibrary* update_library = 261 UpdateEngineClient* update_engine_client =
262 CrosLibrary::Get()->GetUpdateLibrary(); 262 DBusThreadManager::Get()->GetUpdateEngineClient();
263 263
264 update_observer_.reset(new UpdateObserver(this)); 264 update_observer_.reset(new UpdateObserver(this));
265 update_library->AddObserver(update_observer_.get()); 265 update_engine_client->AddObserver(update_observer_.get());
266 266
267 // Update the WebUI page with the current status. See comments below. 267 // Update the WebUI page with the current status. See comments below.
268 UpdateStatus(update_library->status()); 268 UpdateStatus(update_engine_client->GetLastStatus());
269 269
270 // Initiate update check. UpdateStatus() below will be called when we 270 // Initiate update check. UpdateStatus() below will be called when we
271 // get update status via update_observer_. If the update has been 271 // get update status via update_observer_. If the update has been
272 // already complete, update_observer_ won't receive a notification. 272 // already complete, update_observer_ won't receive a notification.
273 // This is why we manually update the WebUI page above. 273 // This is why we manually update the WebUI page above.
274 CheckNow(NULL); 274 CheckNow(NULL);
275 275
276 // Request the channel information. Use the observer to track the about 276 // Request the channel information. Use the observer to track the about
277 // page handler and ensure it does not get deleted before the callback. 277 // page handler and ensure it does not get deleted before the callback.
278 update_library->GetReleaseTrack(UpdateSelectedChannel, 278 update_engine_client->GetReleaseTrack(
279 update_observer_.get()); 279 base::Bind(UpdateSelectedChannel, update_observer_.get()));
280 } 280 }
281 281
282 void AboutPageHandler::SetReleaseTrack(const ListValue* args) { 282 void AboutPageHandler::SetReleaseTrack(const ListValue* args) {
283 if (!UserManager::Get()->current_user_is_owner()) { 283 if (!UserManager::Get()->current_user_is_owner()) {
284 LOG(WARNING) << "Non-owner tried to change release track."; 284 LOG(WARNING) << "Non-owner tried to change release track.";
285 return; 285 return;
286 } 286 }
287 const std::string channel = UTF16ToUTF8(ExtractStringValue(args)); 287 const std::string channel = UTF16ToUTF8(ExtractStringValue(args));
288 CrosLibrary::Get()->GetUpdateLibrary()->SetReleaseTrack(channel); 288 DBusThreadManager::Get()->GetUpdateEngineClient()->SetReleaseTrack(channel);
289 } 289 }
290 290
291 void AboutPageHandler::CheckNow(const ListValue* args) { 291 void AboutPageHandler::CheckNow(const ListValue* args) {
292 // Make sure that libcros is loaded and OOBE is complete. 292 // Make sure that libcros is loaded and OOBE is complete.
293 if (!WizardController::default_controller() || 293 if (!WizardController::default_controller() ||
294 WizardController::IsDeviceRegistered()) { 294 WizardController::IsDeviceRegistered()) {
295 CrosLibrary::Get()->GetUpdateLibrary()-> 295 DBusThreadManager::Get()->GetUpdateEngineClient()->
296 RequestUpdateCheck(NULL, // no callback 296 RequestUpdateCheck(UpdateEngineClient::EmptyUpdateCheckCallback());
297 NULL); // no userdata
298 } 297 }
299 } 298 }
300 299
301 void AboutPageHandler::RestartNow(const ListValue* args) { 300 void AboutPageHandler::RestartNow(const ListValue* args) {
302 DBusThreadManager::Get()->GetPowerManagerClient()->RequestRestart(); 301 DBusThreadManager::Get()->GetPowerManagerClient()->RequestRestart();
303 } 302 }
304 303
305 void AboutPageHandler::UpdateStatus( 304 void AboutPageHandler::UpdateStatus(
306 const UpdateLibrary::Status& status) { 305 const UpdateEngineClient::Status& status) {
307 string16 message; 306 string16 message;
308 std::string image = "up-to-date"; 307 std::string image = "up-to-date";
309 bool enabled = false; 308 bool enabled = false;
310 309
311 switch (status.status) { 310 switch (status.status) {
312 case UPDATE_STATUS_IDLE: 311 case UpdateEngineClient::UPDATE_STATUS_IDLE:
313 if (!sticky_) { 312 if (!sticky_) {
314 message = l10n_util::GetStringFUTF16(IDS_UPGRADE_ALREADY_UP_TO_DATE, 313 message = l10n_util::GetStringFUTF16(IDS_UPGRADE_ALREADY_UP_TO_DATE,
315 l10n_util::GetStringUTF16(IDS_PRODUCT_OS_NAME)); 314 l10n_util::GetStringUTF16(IDS_PRODUCT_OS_NAME));
316 enabled = true; 315 enabled = true;
317 } 316 }
318 break; 317 break;
319 case UPDATE_STATUS_CHECKING_FOR_UPDATE: 318 case UpdateEngineClient::UPDATE_STATUS_CHECKING_FOR_UPDATE:
320 message = l10n_util::GetStringUTF16(IDS_UPGRADE_CHECK_STARTED); 319 message = l10n_util::GetStringUTF16(IDS_UPGRADE_CHECK_STARTED);
321 sticky_ = false; 320 sticky_ = false;
322 break; 321 break;
323 case UPDATE_STATUS_UPDATE_AVAILABLE: 322 case UpdateEngineClient::UPDATE_STATUS_UPDATE_AVAILABLE:
324 message = l10n_util::GetStringUTF16(IDS_UPDATE_AVAILABLE); 323 message = l10n_util::GetStringUTF16(IDS_UPDATE_AVAILABLE);
325 started_ = true; 324 started_ = true;
326 break; 325 break;
327 case UPDATE_STATUS_DOWNLOADING: 326 case UpdateEngineClient::UPDATE_STATUS_DOWNLOADING:
328 { 327 {
329 int progress = static_cast<int>(status.download_progress * 100.0); 328 int progress = static_cast<int>(status.download_progress * 100.0);
330 if (progress != progress_) { 329 if (progress != progress_) {
331 progress_ = progress; 330 progress_ = progress;
332 message = l10n_util::GetStringFUTF16Int(IDS_UPDATE_DOWNLOADING, 331 message = l10n_util::GetStringFUTF16Int(IDS_UPDATE_DOWNLOADING,
333 progress_); 332 progress_);
334 } 333 }
335 started_ = true; 334 started_ = true;
336 } 335 }
337 break; 336 break;
338 case UPDATE_STATUS_VERIFYING: 337 case UpdateEngineClient::UPDATE_STATUS_VERIFYING:
339 message = l10n_util::GetStringUTF16(IDS_UPDATE_VERIFYING); 338 message = l10n_util::GetStringUTF16(IDS_UPDATE_VERIFYING);
340 started_ = true; 339 started_ = true;
341 break; 340 break;
342 case UPDATE_STATUS_FINALIZING: 341 case UpdateEngineClient::UPDATE_STATUS_FINALIZING:
343 message = l10n_util::GetStringUTF16(IDS_UPDATE_FINALIZING); 342 message = l10n_util::GetStringUTF16(IDS_UPDATE_FINALIZING);
344 started_ = true; 343 started_ = true;
345 break; 344 break;
346 case UPDATE_STATUS_UPDATED_NEED_REBOOT: 345 case UpdateEngineClient::UPDATE_STATUS_UPDATED_NEED_REBOOT:
347 message = l10n_util::GetStringUTF16(IDS_UPDATE_COMPLETED); 346 message = l10n_util::GetStringUTF16(IDS_UPDATE_COMPLETED);
348 image = "available"; 347 image = "available";
349 sticky_ = true; 348 sticky_ = true;
350 break; 349 break;
351 default: 350 default:
352 // case UPDATE_STATUS_ERROR: 351 // case UpdateEngineClient::UPDATE_STATUS_ERROR:
353 // case UPDATE_STATUS_REPORTING_ERROR_EVENT: 352 // case UpdateEngineClient::UPDATE_STATUS_REPORTING_ERROR_EVENT:
354 353
355 // The error is only displayed if we were able to determine an 354 // The error is only displayed if we were able to determine an
356 // update was available. 355 // update was available.
357 if (started_) { 356 if (started_) {
358 message = l10n_util::GetStringUTF16(IDS_UPDATE_ERROR); 357 message = l10n_util::GetStringUTF16(IDS_UPDATE_ERROR);
359 image = "fail"; 358 image = "fail";
360 enabled = true; 359 enabled = true;
361 sticky_ = true; 360 sticky_ = true;
362 started_ = false; 361 started_ = false;
363 } 362 }
364 break; 363 break;
365 } 364 }
366 if (message.size()) { 365 if (message.size()) {
367 scoped_ptr<Value> update_message(Value::CreateStringValue(message)); 366 scoped_ptr<Value> update_message(Value::CreateStringValue(message));
368 // "Checking for update..." needs to be shown for a while, so users 367 // "Checking for update..." needs to be shown for a while, so users
369 // can read it, hence insert delay for this. 368 // can read it, hence insert delay for this.
370 scoped_ptr<Value> insert_delay(Value::CreateBooleanValue( 369 scoped_ptr<Value> insert_delay(Value::CreateBooleanValue(
371 status.status == UPDATE_STATUS_CHECKING_FOR_UPDATE)); 370 status.status ==
371 UpdateEngineClient::UPDATE_STATUS_CHECKING_FOR_UPDATE));
372 web_ui_->CallJavascriptFunction("AboutPage.updateStatusCallback", 372 web_ui_->CallJavascriptFunction("AboutPage.updateStatusCallback",
373 *update_message, *insert_delay); 373 *update_message, *insert_delay);
374 374
375 scoped_ptr<Value> enabled_value(Value::CreateBooleanValue(enabled)); 375 scoped_ptr<Value> enabled_value(Value::CreateBooleanValue(enabled));
376 web_ui_->CallJavascriptFunction("AboutPage.updateEnableCallback", 376 web_ui_->CallJavascriptFunction("AboutPage.updateEnableCallback",
377 *enabled_value); 377 *enabled_value);
378 378
379 scoped_ptr<Value> image_string(Value::CreateStringValue(image)); 379 scoped_ptr<Value> image_string(Value::CreateStringValue(image));
380 web_ui_->CallJavascriptFunction("AboutPage.setUpdateImage", 380 web_ui_->CallJavascriptFunction("AboutPage.setUpdateImage",
381 *image_string); 381 *image_string);
382 } 382 }
383 // We'll change the "Check For Update" button to "Restart" button. 383 // We'll change the "Check For Update" button to "Restart" button.
384 if (status.status == UPDATE_STATUS_UPDATED_NEED_REBOOT) { 384 if (status.status == UpdateEngineClient::UPDATE_STATUS_UPDATED_NEED_REBOOT) {
385 web_ui_->CallJavascriptFunction("AboutPage.changeToRestartButton"); 385 web_ui_->CallJavascriptFunction("AboutPage.changeToRestartButton");
386 } 386 }
387 } 387 }
388 388
389 void AboutPageHandler::OnOSVersion(VersionLoader::Handle handle, 389 void AboutPageHandler::OnOSVersion(VersionLoader::Handle handle,
390 std::string version) { 390 std::string version) {
391 if (version.size()) { 391 if (version.size()) {
392 scoped_ptr<Value> version_string(Value::CreateStringValue(version)); 392 scoped_ptr<Value> version_string(Value::CreateStringValue(version));
393 web_ui_->CallJavascriptFunction("AboutPage.updateOSVersionCallback", 393 web_ui_->CallJavascriptFunction("AboutPage.updateOSVersionCallback",
394 *version_string); 394 *version_string);
395 } 395 }
396 } 396 }
397 397
398 void AboutPageHandler::OnOSFirmware(VersionLoader::Handle handle, 398 void AboutPageHandler::OnOSFirmware(VersionLoader::Handle handle,
399 std::string firmware) { 399 std::string firmware) {
400 if (firmware.size()) { 400 if (firmware.size()) {
401 scoped_ptr<Value> firmware_string(Value::CreateStringValue(firmware)); 401 scoped_ptr<Value> firmware_string(Value::CreateStringValue(firmware));
402 web_ui_->CallJavascriptFunction("AboutPage.updateOSFirmwareCallback", 402 web_ui_->CallJavascriptFunction("AboutPage.updateOSFirmwareCallback",
403 *firmware_string); 403 *firmware_string);
404 } 404 }
405 } 405 }
406 406
407 // Callback from UpdateEngine with channel information. 407 // Callback from UpdateEngine with channel information.
408 // static 408 // static
409 void AboutPageHandler::UpdateSelectedChannel(void* user_data, 409 void AboutPageHandler::UpdateSelectedChannel(UpdateObserver* observer,
410 const char* channel) { 410 const std::string& channel) {
411 if (!user_data || !channel) { 411 if (DBusThreadManager::Get()->GetUpdateEngineClient()
412 LOG(WARNING) << "UpdateSelectedChannel returned NULL."; 412 ->HasObserver(observer)) {
413 return; 413 // If UpdateEngineClient still has the observer, then the page handler
414 } 414 // is valid.
415 UpdateObserver* observer = static_cast<UpdateObserver*>(user_data);
416 if (CrosLibrary::Get()->GetUpdateLibrary()->HasObserver(observer)) {
417 // If UpdateLibrary still has the observer, then the page handler is valid.
418 AboutPageHandler* handler = observer->page_handler(); 415 AboutPageHandler* handler = observer->page_handler();
419 scoped_ptr<Value> channel_string(Value::CreateStringValue(channel)); 416 scoped_ptr<Value> channel_string(Value::CreateStringValue(channel));
420 handler->web_ui_->CallJavascriptFunction( 417 handler->web_ui_->CallJavascriptFunction(
421 "AboutPage.updateSelectedOptionCallback", *channel_string); 418 "AboutPage.updateSelectedOptionCallback", *channel_string);
422 } 419 }
423 } 420 }
424 421
425 } // namespace chromeos 422 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/options/chromeos/about_page_handler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698