| Index: chrome/browser/ui/webui/chromeos/login/encryption_migration_screen_handler.cc
|
| diff --git a/chrome/browser/ui/webui/chromeos/login/encryption_migration_screen_handler.cc b/chrome/browser/ui/webui/chromeos/login/encryption_migration_screen_handler.cc
|
| index e864c38cc6277356c1e6ee588cca6b36a1adeda0..6b118ce1b8ce5b8487a98b1925bee907bf3e9833 100644
|
| --- a/chrome/browser/ui/webui/chromeos/login/encryption_migration_screen_handler.cc
|
| +++ b/chrome/browser/ui/webui/chromeos/login/encryption_migration_screen_handler.cc
|
| @@ -7,13 +7,17 @@
|
| #include <string>
|
| #include <utility>
|
|
|
| +#include "base/command_line.h"
|
| #include "base/files/file_path.h"
|
| #include "base/sys_info.h"
|
| #include "base/task_scheduler/post_task.h"
|
| #include "chrome/browser/lifetime/application_lifetime.h"
|
| +#include "chromeos/chromeos_switches.h"
|
| #include "chromeos/cryptohome/homedir_methods.h"
|
| #include "chromeos/dbus/cryptohome_client.h"
|
| #include "chromeos/dbus/dbus_thread_manager.h"
|
| +#include "chromeos/dbus/power_manager/power_supply_properties.pb.h"
|
| +#include "chromeos/dbus/power_manager_client.h"
|
|
|
| namespace {
|
|
|
| @@ -25,11 +29,19 @@ constexpr char kCheckStoragePath[] = "/home";
|
| // The minimum size of available space to start the migration.
|
| constexpr int64_t kMinimumAvailableStorage = 10LL * 1024 * 1024; // 10MB
|
|
|
| +// The minimum battery level to start the migration.
|
| +constexpr double kMinimumBatteryPercent = 30;
|
| +
|
| // JS API callbacks names.
|
| constexpr char kJsApiStartMigration[] = "startMigration";
|
| constexpr char kJsApiSkipMigration[] = "skipMigration";
|
| constexpr char kJsApiRequestRestart[] = "requestRestart";
|
|
|
| +bool IsTestingUI() {
|
| + return base::CommandLine::ForCurrentProcess()->HasSwitch(
|
| + chromeos::switches::kTestEncryptionMigrationUI);
|
| +}
|
| +
|
| } // namespace
|
|
|
| namespace chromeos {
|
| @@ -37,9 +49,11 @@ namespace chromeos {
|
| EncryptionMigrationScreenHandler::EncryptionMigrationScreenHandler()
|
| : BaseScreenHandler(kScreenId), weak_ptr_factory_(this) {
|
| set_call_js_prefix(kJsScreenPath);
|
| + DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver(this);
|
| }
|
|
|
| EncryptionMigrationScreenHandler::~EncryptionMigrationScreenHandler() {
|
| + DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver(this);
|
| if (delegate_)
|
| delegate_->OnViewDestroyed(this);
|
| }
|
| @@ -69,6 +83,7 @@ void EncryptionMigrationScreenHandler::SetUserContext(
|
|
|
| void EncryptionMigrationScreenHandler::SetShouldResume(bool should_resume) {
|
| should_resume_ = should_resume;
|
| + CallJS("setIsResuming", should_resume_);
|
| }
|
|
|
| void EncryptionMigrationScreenHandler::SetContinueLoginCallback(
|
| @@ -102,8 +117,23 @@ void EncryptionMigrationScreenHandler::RegisterMessages() {
|
| &EncryptionMigrationScreenHandler::HandleRequestRestart);
|
| }
|
|
|
| +void EncryptionMigrationScreenHandler::PowerChanged(
|
| + const power_manager::PowerSupplyProperties& proto) {
|
| + current_battery_percent_ = proto.battery_percent();
|
| + CallJS("setBatteryPercent", current_battery_percent_,
|
| + current_battery_percent_ >= kMinimumBatteryPercent);
|
| +
|
| + // If the migration was already requested and the bettery level is enough now,
|
| + // The migration should start immediately.
|
| + if (current_battery_percent_ >= kMinimumBatteryPercent &&
|
| + should_migrate_on_enough_battery_) {
|
| + should_migrate_on_enough_battery_ = false;
|
| + StartMigration();
|
| + }
|
| +}
|
| +
|
| void EncryptionMigrationScreenHandler::HandleStartMigration() {
|
| - StartMigration();
|
| + WaitBatteryAndMigrate();
|
| }
|
|
|
| void EncryptionMigrationScreenHandler::HandleSkipMigration() {
|
| @@ -131,6 +161,11 @@ void EncryptionMigrationScreenHandler::UpdateUIState(UIState state) {
|
|
|
| current_ui_state_ = state;
|
| CallJS("setUIState", static_cast<int>(state));
|
| +
|
| + // When this handler is about to show the READY screen, we should get the
|
| + // latest battery status and show it on the screen.
|
| + if (state == UIState::READY)
|
| + DBusThreadManager::Get()->GetPowerManagerClient()->RequestStatusUpdate();
|
| }
|
|
|
| void EncryptionMigrationScreenHandler::CheckAvailableStorage() {
|
| @@ -145,20 +180,31 @@ void EncryptionMigrationScreenHandler::CheckAvailableStorage() {
|
| }
|
|
|
| void EncryptionMigrationScreenHandler::OnGetAvailableStorage(int64_t size) {
|
| - if (size < kMinimumAvailableStorage) {
|
| - UpdateUIState(NOT_ENOUGH_STORAGE);
|
| - CallJS("setIsResuming", should_resume_);
|
| - } else {
|
| + if (size >= kMinimumAvailableStorage || IsTestingUI()) {
|
| if (should_resume_) {
|
| - // TODO(fukino): Check the battery level.
|
| - StartMigration();
|
| + WaitBatteryAndMigrate();
|
| } else {
|
| - UpdateUIState(READY);
|
| + UpdateUIState(UIState::READY);
|
| }
|
| + } else {
|
| + UpdateUIState(UIState::NOT_ENOUGH_STORAGE);
|
| }
|
| }
|
|
|
| +void EncryptionMigrationScreenHandler::WaitBatteryAndMigrate() {
|
| + if (current_battery_percent_ >= kMinimumBatteryPercent) {
|
| + StartMigration();
|
| + return;
|
| + }
|
| + UpdateUIState(UIState::READY);
|
| +
|
| + should_migrate_on_enough_battery_ = true;
|
| + DBusThreadManager::Get()->GetPowerManagerClient()->RequestStatusUpdate();
|
| +}
|
| +
|
| void EncryptionMigrationScreenHandler::StartMigration() {
|
| + UpdateUIState(UIState::MIGRATING);
|
| +
|
| DBusThreadManager::Get()
|
| ->GetCryptohomeClient()
|
| ->SetDircryptoMigrationProgressHandler(
|
| @@ -182,7 +228,6 @@ void EncryptionMigrationScreenHandler::StartMigration() {
|
| cryptohome::Authorization(auth_key),
|
| base::Bind(&EncryptionMigrationScreenHandler::OnMigrationRequested,
|
| weak_ptr_factory_.GetWeakPtr()));
|
| - UpdateUIState(UIState::MIGRATING);
|
| }
|
|
|
| void EncryptionMigrationScreenHandler::OnMigrationProgress(
|
|
|