| 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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "chrome/browser/chromeos/dbus/dbus_thread_manager.h" | 9 #include "chrome/browser/chromeos/dbus/dbus_thread_manager.h" |
| 10 #include "chrome/browser/chromeos/dbus/power_manager_client.h" | 10 #include "chrome/browser/chromeos/dbus/power_manager_client.h" |
| 11 #include "chrome/browser/chromeos/login/wizard_controller.h" | 11 #include "chrome/browser/chromeos/login/wizard_controller.h" |
| 12 | 12 |
| 13 using chromeos::DBusThreadManager; | 13 using chromeos::DBusThreadManager; |
| 14 using chromeos::UpdateEngineClient; | 14 using chromeos::UpdateEngineClient; |
| 15 using chromeos::WizardController; | 15 using chromeos::WizardController; |
| 16 | 16 |
| 17 VersionUpdater* VersionUpdater::Create() { | 17 VersionUpdater* VersionUpdater::Create() { |
| 18 return static_cast<VersionUpdater*>(new VersionUpdaterCros); | 18 return static_cast<VersionUpdater*>(new VersionUpdaterCros); |
| 19 } | 19 } |
| 20 | 20 |
| 21 bool VersionUpdaterCros::CanBeUpdated() const { | |
| 22 return true; | |
| 23 } | |
| 24 | |
| 25 void VersionUpdaterCros::CheckForUpdate(const StatusCallback& callback) { | 21 void VersionUpdaterCros::CheckForUpdate(const StatusCallback& callback) { |
| 26 callback_ = callback; | 22 callback_ = callback; |
| 27 | 23 |
| 28 UpdateEngineClient* update_engine_client = | 24 UpdateEngineClient* update_engine_client = |
| 29 DBusThreadManager::Get()->GetUpdateEngineClient(); | 25 DBusThreadManager::Get()->GetUpdateEngineClient(); |
| 30 update_engine_client->AddObserver(this); | 26 update_engine_client->AddObserver(this); |
| 31 | 27 |
| 32 // Make sure that libcros is loaded and OOBE is complete. | 28 // Make sure that libcros is loaded and OOBE is complete. |
| 33 if (!WizardController::default_controller() || | 29 if (!WizardController::default_controller() || |
| 34 WizardController::IsDeviceRegistered()) { | 30 WizardController::IsDeviceRegistered()) { |
| 35 update_engine_client->RequestUpdateCheck( | 31 update_engine_client->RequestUpdateCheck( |
| 36 UpdateEngineClient::EmptyUpdateCheckCallback()); | 32 UpdateEngineClient::EmptyUpdateCheckCallback()); |
| 37 } | 33 } |
| 38 } | 34 } |
| 39 | 35 |
| 40 void VersionUpdaterCros::RelaunchBrowser() const { | 36 void VersionUpdaterCros::RelaunchBrowser() const { |
| 41 DBusThreadManager::Get()->GetPowerManagerClient()->RequestRestart(); | 37 DBusThreadManager::Get()->GetPowerManagerClient()->RequestRestart(); |
| 42 } | 38 } |
| 43 | 39 |
| 40 VersionUpdaterCros::VersionUpdaterCros() {} |
| 41 |
| 44 VersionUpdaterCros::~VersionUpdaterCros() { | 42 VersionUpdaterCros::~VersionUpdaterCros() { |
| 45 UpdateEngineClient* update_engine_client = | 43 UpdateEngineClient* update_engine_client = |
| 46 DBusThreadManager::Get()->GetUpdateEngineClient(); | 44 DBusThreadManager::Get()->GetUpdateEngineClient(); |
| 47 update_engine_client->RemoveObserver(this); | 45 update_engine_client->RemoveObserver(this); |
| 48 } | 46 } |
| 49 | 47 |
| 50 void VersionUpdaterCros::UpdateStatusChanged( | 48 void VersionUpdaterCros::UpdateStatusChanged( |
| 51 const UpdateEngineClient::Status& status) OVERRIDE { | 49 const UpdateEngineClient::Status& status) { |
| 52 Status my_status = UPDATED; | 50 Status my_status = UPDATED; |
| 53 int progress = 0; | 51 int progress = 0; |
| 54 | 52 |
| 55 switch (status.status) { | 53 switch (status.status) { |
| 56 case UpdateEngineClient::UPDATE_STATUS_CHECKING_FOR_UPDATE: | 54 case UpdateEngineClient::UPDATE_STATUS_CHECKING_FOR_UPDATE: |
| 57 my_status = CHECKING; | 55 my_status = CHECKING; |
| 58 break; | 56 break; |
| 59 case UpdateEngineClient::UPDATE_STATUS_DOWNLOADING: | 57 case UpdateEngineClient::UPDATE_STATUS_DOWNLOADING: |
| 60 progress = static_cast<int>(status.download_progress * 100.0); | 58 progress = static_cast<int>(status.download_progress * 100.0); |
| 61 // Fall through. | 59 // Fall through. |
| 62 case UpdateEngineClient::UPDATE_STATUS_UPDATE_AVAILABLE: | 60 case UpdateEngineClient::UPDATE_STATUS_UPDATE_AVAILABLE: |
| 63 case UpdateEngineClient::UPDATE_STATUS_VERIFYING: | 61 case UpdateEngineClient::UPDATE_STATUS_VERIFYING: |
| 64 case UpdateEngineClient::UPDATE_STATUS_FINALIZING: | 62 case UpdateEngineClient::UPDATE_STATUS_FINALIZING: |
| 65 my_status = UPDATING; | 63 my_status = UPDATING; |
| 66 break; | 64 break; |
| 67 case UpdateEngineClient::UPDATE_STATUS_UPDATED_NEED_REBOOT: | 65 case UpdateEngineClient::UPDATE_STATUS_UPDATED_NEED_REBOOT: |
| 68 my_status = NEARLY_UPDATED; | 66 my_status = NEARLY_UPDATED; |
| 69 break; | 67 break; |
| 70 default: | 68 default: |
| 71 break; | 69 break; |
| 72 } | 70 } |
| 73 | 71 |
| 74 callback_.Run(my_status, progress); | 72 callback_.Run(my_status, progress); |
| 75 } | 73 } |
| OLD | NEW |