| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/chromeos/login/encryption_migration_screen_han
dler.h" | 5 #include "chrome/browser/ui/webui/chromeos/login/encryption_migration_screen_han
dler.h" |
| 6 | 6 |
| 7 #include <cmath> | 7 #include <cmath> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "ash/system/devicetype_utils.h" | 11 #include "ash/system/devicetype_utils.h" |
| 12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 13 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
| 14 #include "base/metrics/histogram_macros.h" | 14 #include "base/metrics/histogram_macros.h" |
| 15 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
| 16 #include "base/strings/stringprintf.h" | 16 #include "base/strings/stringprintf.h" |
| 17 #include "base/sys_info.h" | 17 #include "base/sys_info.h" |
| 18 #include "base/task_scheduler/post_task.h" | 18 #include "base/task_scheduler/post_task.h" |
| 19 #include "chrome/browser/browser_process.h" | 19 #include "chrome/browser/browser_process.h" |
| 20 #include "chrome/browser/chromeos/arc/arc_migration_constants.h" |
| 20 #include "chrome/browser/chromeos/login/ui/login_feedback.h" | 21 #include "chrome/browser/chromeos/login/ui/login_feedback.h" |
| 21 #include "chrome/browser/lifetime/application_lifetime.h" | 22 #include "chrome/browser/lifetime/application_lifetime.h" |
| 22 #include "chrome/browser/profiles/profile.h" | 23 #include "chrome/browser/profiles/profile.h" |
| 23 #include "chrome/grit/generated_resources.h" | 24 #include "chrome/grit/generated_resources.h" |
| 24 #include "chromeos/chromeos_switches.h" | 25 #include "chromeos/chromeos_switches.h" |
| 25 #include "chromeos/cryptohome/async_method_caller.h" | 26 #include "chromeos/cryptohome/async_method_caller.h" |
| 26 #include "chromeos/cryptohome/homedir_methods.h" | 27 #include "chromeos/cryptohome/homedir_methods.h" |
| 27 #include "chromeos/dbus/cryptohome_client.h" | 28 #include "chromeos/dbus/cryptohome_client.h" |
| 28 #include "chromeos/dbus/dbus_thread_manager.h" | 29 #include "chromeos/dbus/dbus_thread_manager.h" |
| 29 #include "chromeos/dbus/power_manager/power_supply_properties.pb.h" | 30 #include "chromeos/dbus/power_manager/power_supply_properties.pb.h" |
| 30 #include "chromeos/dbus/power_manager_client.h" | 31 #include "chromeos/dbus/power_manager_client.h" |
| 31 #include "components/login/localized_values_builder.h" | 32 #include "components/login/localized_values_builder.h" |
| 32 #include "components/user_manager/user_manager.h" | 33 #include "components/user_manager/user_manager.h" |
| 33 #include "content/public/browser/browser_thread.h" | 34 #include "content/public/browser/browser_thread.h" |
| 34 #include "device/power_save_blocker/power_save_blocker.h" | 35 #include "device/power_save_blocker/power_save_blocker.h" |
| 35 #include "ui/base/text/bytes_formatting.h" | 36 #include "ui/base/text/bytes_formatting.h" |
| 36 | 37 |
| 37 namespace { | 38 namespace { |
| 38 | 39 |
| 39 constexpr char kJsScreenPath[] = "login.EncryptionMigrationScreen"; | 40 constexpr char kJsScreenPath[] = "login.EncryptionMigrationScreen"; |
| 40 | 41 |
| 41 // Path to the mount point to check the available space. | 42 // Path to the mount point to check the available space. |
| 42 constexpr char kCheckStoragePath[] = "/home"; | 43 constexpr char kCheckStoragePath[] = "/home"; |
| 43 | 44 |
| 44 // The minimum size of available space to start the migration. | |
| 45 constexpr int64_t kMinimumAvailableStorage = 10LL * 1024 * 1024; // 10MB | |
| 46 | |
| 47 // The minimum battery level to start the migration. | |
| 48 constexpr double kMinimumBatteryPercent = 30; | |
| 49 | |
| 50 // JS API callbacks names. | 45 // JS API callbacks names. |
| 51 constexpr char kJsApiStartMigration[] = "startMigration"; | 46 constexpr char kJsApiStartMigration[] = "startMigration"; |
| 52 constexpr char kJsApiSkipMigration[] = "skipMigration"; | 47 constexpr char kJsApiSkipMigration[] = "skipMigration"; |
| 53 constexpr char kJsApiRequestRestart[] = "requestRestart"; | 48 constexpr char kJsApiRequestRestart[] = "requestRestart"; |
| 54 constexpr char kJsApiOpenFeedbackDialog[] = "openFeedbackDialog"; | 49 constexpr char kJsApiOpenFeedbackDialog[] = "openFeedbackDialog"; |
| 55 | 50 |
| 56 // UMA names. | 51 // UMA names. |
| 57 constexpr char kUmaNameFirstScreen[] = "Cryptohome.MigrationUI.FirstScreen"; | 52 constexpr char kUmaNameFirstScreen[] = "Cryptohome.MigrationUI.FirstScreen"; |
| 58 constexpr char kUmaNameUserChoice[] = "Cryptohome.MigrationUI.UserChoice"; | 53 constexpr char kUmaNameUserChoice[] = "Cryptohome.MigrationUI.UserChoice"; |
| 59 constexpr char kUmaNameConsumedBatteryPercent[] = | 54 constexpr char kUmaNameConsumedBatteryPercent[] = |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 AddCallback(kJsApiRequestRestart, | 207 AddCallback(kJsApiRequestRestart, |
| 213 &EncryptionMigrationScreenHandler::HandleRequestRestart); | 208 &EncryptionMigrationScreenHandler::HandleRequestRestart); |
| 214 AddCallback(kJsApiOpenFeedbackDialog, | 209 AddCallback(kJsApiOpenFeedbackDialog, |
| 215 &EncryptionMigrationScreenHandler::HandleOpenFeedbackDialog); | 210 &EncryptionMigrationScreenHandler::HandleOpenFeedbackDialog); |
| 216 } | 211 } |
| 217 | 212 |
| 218 void EncryptionMigrationScreenHandler::PowerChanged( | 213 void EncryptionMigrationScreenHandler::PowerChanged( |
| 219 const power_manager::PowerSupplyProperties& proto) { | 214 const power_manager::PowerSupplyProperties& proto) { |
| 220 current_battery_percent_ = proto.battery_percent(); | 215 current_battery_percent_ = proto.battery_percent(); |
| 221 CallJS("setBatteryState", current_battery_percent_, | 216 CallJS("setBatteryState", current_battery_percent_, |
| 222 current_battery_percent_ >= kMinimumBatteryPercent, | 217 current_battery_percent_ >= arc::kMigrationMinimumBatteryPercent, |
| 223 proto.battery_state() == | 218 proto.battery_state() == |
| 224 power_manager::PowerSupplyProperties_BatteryState_CHARGING); | 219 power_manager::PowerSupplyProperties_BatteryState_CHARGING); |
| 225 | 220 |
| 226 // If the migration was already requested and the bettery level is enough now, | 221 // If the migration was already requested and the bettery level is enough now, |
| 227 // The migration should start immediately. | 222 // The migration should start immediately. |
| 228 if (current_battery_percent_ >= kMinimumBatteryPercent && | 223 if (current_battery_percent_ >= arc::kMigrationMinimumBatteryPercent && |
| 229 should_migrate_on_enough_battery_) { | 224 should_migrate_on_enough_battery_) { |
| 230 should_migrate_on_enough_battery_ = false; | 225 should_migrate_on_enough_battery_ = false; |
| 231 StartMigration(); | 226 StartMigration(); |
| 232 } | 227 } |
| 233 } | 228 } |
| 234 | 229 |
| 235 void EncryptionMigrationScreenHandler::HandleStartMigration() { | 230 void EncryptionMigrationScreenHandler::HandleStartMigration() { |
| 236 RecordUserChoice(UserChoice::USER_CHOICE_UPDATE); | 231 RecordUserChoice(UserChoice::USER_CHOICE_UPDATE); |
| 237 WaitBatteryAndMigrate(); | 232 WaitBatteryAndMigrate(); |
| 238 } | 233 } |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 void EncryptionMigrationScreenHandler::CheckAvailableStorage() { | 280 void EncryptionMigrationScreenHandler::CheckAvailableStorage() { |
| 286 base::PostTaskWithTraitsAndReplyWithResult( | 281 base::PostTaskWithTraitsAndReplyWithResult( |
| 287 FROM_HERE, {base::MayBlock(), base::TaskPriority::USER_VISIBLE}, | 282 FROM_HERE, {base::MayBlock(), base::TaskPriority::USER_VISIBLE}, |
| 288 base::Bind(&base::SysInfo::AmountOfFreeDiskSpace, | 283 base::Bind(&base::SysInfo::AmountOfFreeDiskSpace, |
| 289 base::FilePath(kCheckStoragePath)), | 284 base::FilePath(kCheckStoragePath)), |
| 290 base::Bind(&EncryptionMigrationScreenHandler::OnGetAvailableStorage, | 285 base::Bind(&EncryptionMigrationScreenHandler::OnGetAvailableStorage, |
| 291 weak_ptr_factory_.GetWeakPtr())); | 286 weak_ptr_factory_.GetWeakPtr())); |
| 292 } | 287 } |
| 293 | 288 |
| 294 void EncryptionMigrationScreenHandler::OnGetAvailableStorage(int64_t size) { | 289 void EncryptionMigrationScreenHandler::OnGetAvailableStorage(int64_t size) { |
| 295 if (size >= kMinimumAvailableStorage || IsTestingUI()) { | 290 if (size >= arc::kMigrationMinimumAvailableStorage || IsTestingUI()) { |
| 296 if (should_resume_) { | 291 if (should_resume_) { |
| 297 RecordFirstScreen(FirstScreen::FIRST_SCREEN_RESUME); | 292 RecordFirstScreen(FirstScreen::FIRST_SCREEN_RESUME); |
| 298 WaitBatteryAndMigrate(); | 293 WaitBatteryAndMigrate(); |
| 299 } else { | 294 } else { |
| 300 RecordFirstScreen(FirstScreen::FIRST_SCREEN_READY); | 295 RecordFirstScreen(FirstScreen::FIRST_SCREEN_READY); |
| 301 UpdateUIState(UIState::READY); | 296 UpdateUIState(UIState::READY); |
| 302 } | 297 } |
| 303 } else { | 298 } else { |
| 304 RecordFirstScreen(FirstScreen::FIRST_SCREEN_LOW_STORAGE); | 299 RecordFirstScreen(FirstScreen::FIRST_SCREEN_LOW_STORAGE); |
| 305 CallJS("setAvailableSpaceInString", ui::FormatBytes(size)); | 300 CallJS("setAvailableSpaceInString", ui::FormatBytes(size)); |
| 306 CallJS("setNecessarySpaceInString", | 301 CallJS("setNecessarySpaceInString", |
| 307 ui::FormatBytes(kMinimumAvailableStorage)); | 302 ui::FormatBytes(arc::kMigrationMinimumAvailableStorage)); |
| 308 UpdateUIState(UIState::NOT_ENOUGH_STORAGE); | 303 UpdateUIState(UIState::NOT_ENOUGH_STORAGE); |
| 309 } | 304 } |
| 310 } | 305 } |
| 311 | 306 |
| 312 void EncryptionMigrationScreenHandler::WaitBatteryAndMigrate() { | 307 void EncryptionMigrationScreenHandler::WaitBatteryAndMigrate() { |
| 313 if (current_battery_percent_ >= kMinimumBatteryPercent) { | 308 if (current_battery_percent_ >= arc::kMigrationMinimumBatteryPercent) { |
| 314 StartMigration(); | 309 StartMigration(); |
| 315 return; | 310 return; |
| 316 } | 311 } |
| 317 UpdateUIState(UIState::READY); | 312 UpdateUIState(UIState::READY); |
| 318 | 313 |
| 319 should_migrate_on_enough_battery_ = true; | 314 should_migrate_on_enough_battery_ = true; |
| 320 DBusThreadManager::Get()->GetPowerManagerClient()->RequestStatusUpdate(); | 315 DBusThreadManager::Get()->GetPowerManagerClient()->RequestStatusUpdate(); |
| 321 } | 316 } |
| 322 | 317 |
| 323 void EncryptionMigrationScreenHandler::StartMigration() { | 318 void EncryptionMigrationScreenHandler::StartMigration() { |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 447 } | 442 } |
| 448 | 443 |
| 449 void EncryptionMigrationScreenHandler::OnMigrationRequested(bool success) { | 444 void EncryptionMigrationScreenHandler::OnMigrationRequested(bool success) { |
| 450 if (!success) { | 445 if (!success) { |
| 451 LOG(ERROR) << "Requesting MigrateToDircrypto failed."; | 446 LOG(ERROR) << "Requesting MigrateToDircrypto failed."; |
| 452 UpdateUIState(UIState::MIGRATION_FAILED); | 447 UpdateUIState(UIState::MIGRATION_FAILED); |
| 453 } | 448 } |
| 454 } | 449 } |
| 455 | 450 |
| 456 } // namespace chromeos | 451 } // namespace chromeos |
| OLD | NEW |