Chromium Code Reviews| 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 <string> | 8 #include <string> |
| 8 #include <utility> | 9 #include <utility> |
| 9 | 10 |
| 10 #include "ash/system/devicetype_utils.h" | 11 #include "ash/system/devicetype_utils.h" |
| 11 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 12 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
| 14 #include "base/metrics/histogram_macros.h" | |
| 13 #include "base/sys_info.h" | 15 #include "base/sys_info.h" |
| 14 #include "base/task_scheduler/post_task.h" | 16 #include "base/task_scheduler/post_task.h" |
| 15 #include "chrome/browser/browser_process.h" | 17 #include "chrome/browser/browser_process.h" |
| 16 #include "chrome/browser/lifetime/application_lifetime.h" | 18 #include "chrome/browser/lifetime/application_lifetime.h" |
| 17 #include "chrome/grit/generated_resources.h" | 19 #include "chrome/grit/generated_resources.h" |
| 18 #include "chromeos/chromeos_switches.h" | 20 #include "chromeos/chromeos_switches.h" |
| 19 #include "chromeos/cryptohome/async_method_caller.h" | 21 #include "chromeos/cryptohome/async_method_caller.h" |
| 20 #include "chromeos/cryptohome/homedir_methods.h" | 22 #include "chromeos/cryptohome/homedir_methods.h" |
| 21 #include "chromeos/dbus/cryptohome_client.h" | 23 #include "chromeos/dbus/cryptohome_client.h" |
| 22 #include "chromeos/dbus/dbus_thread_manager.h" | 24 #include "chromeos/dbus/dbus_thread_manager.h" |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 39 constexpr int64_t kMinimumAvailableStorage = 10LL * 1024 * 1024; // 10MB | 41 constexpr int64_t kMinimumAvailableStorage = 10LL * 1024 * 1024; // 10MB |
| 40 | 42 |
| 41 // The minimum battery level to start the migration. | 43 // The minimum battery level to start the migration. |
| 42 constexpr double kMinimumBatteryPercent = 30; | 44 constexpr double kMinimumBatteryPercent = 30; |
| 43 | 45 |
| 44 // JS API callbacks names. | 46 // JS API callbacks names. |
| 45 constexpr char kJsApiStartMigration[] = "startMigration"; | 47 constexpr char kJsApiStartMigration[] = "startMigration"; |
| 46 constexpr char kJsApiSkipMigration[] = "skipMigration"; | 48 constexpr char kJsApiSkipMigration[] = "skipMigration"; |
| 47 constexpr char kJsApiRequestRestart[] = "requestRestart"; | 49 constexpr char kJsApiRequestRestart[] = "requestRestart"; |
| 48 | 50 |
| 51 // UMA names. | |
| 52 constexpr char kUmaNameFirstScreen[] = "Cryptohome.MigrationUI.FirstScreen"; | |
| 53 constexpr char kUmaNameUserChoice[] = "Cryptohome.MigrationUI.UserChoice"; | |
| 54 constexpr char kUmaNameConsumedBatteryPercent[] = | |
| 55 "Cryptohome.MigrationUI.ConsumedBatteryPercent"; | |
| 56 | |
| 57 // This enum must match the numbering for Cryptohome.MigrationUI.FirstScreen in | |
| 58 // histograms.xml. Do not reorder or remove items, only add new items before | |
| 59 // FIRST_SCREEN_MAX. | |
| 60 enum class FirstScreen { | |
| 61 FIRST_SCREEN_READY = 0, | |
| 62 FIRST_SCREEN_RESUME = 1, | |
| 63 FIRST_SCREEN_LOW_STORAGE = 2, | |
| 64 FIRST_SCREEN_COUNT | |
| 65 }; | |
| 66 | |
| 67 // This enum must match the numbering for Cryptohome.MigrationUI.UserChoice in | |
| 68 // histograms.xml. Do not reorder or remove items, only add new items before | |
| 69 // FIRST_SCREEN_MAX. | |
| 70 enum class UserChoice { | |
| 71 USER_CHOICE_UPDATE = 0, | |
| 72 USER_CHOICE_SKIP = 1, | |
| 73 USER_CHOICE_COUNT | |
| 74 }; | |
| 75 | |
| 49 bool IsTestingUI() { | 76 bool IsTestingUI() { |
| 50 return base::CommandLine::ForCurrentProcess()->HasSwitch( | 77 return base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 51 chromeos::switches::kTestEncryptionMigrationUI); | 78 chromeos::switches::kTestEncryptionMigrationUI); |
| 52 } | 79 } |
| 53 | 80 |
| 81 // Wrapper functions for histogram macros to avoid duplication of expanded code. | |
| 82 void RecordFirstScreen(FirstScreen first_screen) { | |
| 83 UMA_HISTOGRAM_ENUMERATION(kUmaNameFirstScreen, static_cast<int>(first_screen), | |
| 84 static_cast<int>(FirstScreen::FIRST_SCREEN_COUNT)); | |
| 85 } | |
| 86 | |
| 87 void RecordUserChoice(UserChoice user_choice) { | |
| 88 UMA_HISTOGRAM_ENUMERATION(kUmaNameUserChoice, static_cast<int>(user_choice), | |
| 89 static_cast<int>(UserChoice::USER_CHOICE_COUNT)); | |
|
Ilya Sherman
2017/05/01 18:02:10
nit: FYI, static_casts are no longer needed for th
fukino
2017/05/02 04:27:34
Oh, I did not know it. Thanks!
I'll update it in a
| |
| 90 } | |
| 91 | |
| 54 } // namespace | 92 } // namespace |
| 55 | 93 |
| 56 namespace chromeos { | 94 namespace chromeos { |
| 57 | 95 |
| 58 EncryptionMigrationScreenHandler::EncryptionMigrationScreenHandler() | 96 EncryptionMigrationScreenHandler::EncryptionMigrationScreenHandler() |
| 59 : BaseScreenHandler(kScreenId), weak_ptr_factory_(this) { | 97 : BaseScreenHandler(kScreenId), weak_ptr_factory_(this) { |
| 60 set_call_js_prefix(kJsScreenPath); | 98 set_call_js_prefix(kJsScreenPath); |
| 61 } | 99 } |
| 62 | 100 |
| 63 EncryptionMigrationScreenHandler::~EncryptionMigrationScreenHandler() { | 101 EncryptionMigrationScreenHandler::~EncryptionMigrationScreenHandler() { |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 180 // If the migration was already requested and the bettery level is enough now, | 218 // If the migration was already requested and the bettery level is enough now, |
| 181 // The migration should start immediately. | 219 // The migration should start immediately. |
| 182 if (current_battery_percent_ >= kMinimumBatteryPercent && | 220 if (current_battery_percent_ >= kMinimumBatteryPercent && |
| 183 should_migrate_on_enough_battery_) { | 221 should_migrate_on_enough_battery_) { |
| 184 should_migrate_on_enough_battery_ = false; | 222 should_migrate_on_enough_battery_ = false; |
| 185 StartMigration(); | 223 StartMigration(); |
| 186 } | 224 } |
| 187 } | 225 } |
| 188 | 226 |
| 189 void EncryptionMigrationScreenHandler::HandleStartMigration() { | 227 void EncryptionMigrationScreenHandler::HandleStartMigration() { |
| 228 RecordUserChoice(UserChoice::USER_CHOICE_UPDATE); | |
| 190 WaitBatteryAndMigrate(); | 229 WaitBatteryAndMigrate(); |
| 191 } | 230 } |
| 192 | 231 |
| 193 void EncryptionMigrationScreenHandler::HandleSkipMigration() { | 232 void EncryptionMigrationScreenHandler::HandleSkipMigration() { |
| 233 RecordUserChoice(UserChoice::USER_CHOICE_SKIP); | |
| 194 // If the user skips migration, we mount the cryptohome without performing the | 234 // If the user skips migration, we mount the cryptohome without performing the |
| 195 // migration by reusing UserContext and LoginPerformer which were used in the | 235 // migration by reusing UserContext and LoginPerformer which were used in the |
| 196 // previous attempt and dropping |is_forcing_dircrypto| flag in UserContext. | 236 // previous attempt and dropping |is_forcing_dircrypto| flag in UserContext. |
| 197 // In this case, the user can not launch ARC apps in the session, and will be | 237 // In this case, the user can not launch ARC apps in the session, and will be |
| 198 // asked to do the migration again in the next log-in attempt. | 238 // asked to do the migration again in the next log-in attempt. |
| 199 if (!continue_login_callback_.is_null()) { | 239 if (!continue_login_callback_.is_null()) { |
| 200 user_context_.SetIsForcingDircrypto(false); | 240 user_context_.SetIsForcingDircrypto(false); |
| 201 std::move(continue_login_callback_).Run(user_context_); | 241 std::move(continue_login_callback_).Run(user_context_); |
| 202 } | 242 } |
| 203 } | 243 } |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 232 base::TaskPriority::USER_VISIBLE), | 272 base::TaskPriority::USER_VISIBLE), |
| 233 base::Bind(&base::SysInfo::AmountOfFreeDiskSpace, | 273 base::Bind(&base::SysInfo::AmountOfFreeDiskSpace, |
| 234 base::FilePath(kCheckStoragePath)), | 274 base::FilePath(kCheckStoragePath)), |
| 235 base::Bind(&EncryptionMigrationScreenHandler::OnGetAvailableStorage, | 275 base::Bind(&EncryptionMigrationScreenHandler::OnGetAvailableStorage, |
| 236 weak_ptr_factory_.GetWeakPtr())); | 276 weak_ptr_factory_.GetWeakPtr())); |
| 237 } | 277 } |
| 238 | 278 |
| 239 void EncryptionMigrationScreenHandler::OnGetAvailableStorage(int64_t size) { | 279 void EncryptionMigrationScreenHandler::OnGetAvailableStorage(int64_t size) { |
| 240 if (size >= kMinimumAvailableStorage || IsTestingUI()) { | 280 if (size >= kMinimumAvailableStorage || IsTestingUI()) { |
| 241 if (should_resume_) { | 281 if (should_resume_) { |
| 282 RecordFirstScreen(FirstScreen::FIRST_SCREEN_RESUME); | |
| 242 WaitBatteryAndMigrate(); | 283 WaitBatteryAndMigrate(); |
| 243 } else { | 284 } else { |
| 285 RecordFirstScreen(FirstScreen::FIRST_SCREEN_READY); | |
| 244 UpdateUIState(UIState::READY); | 286 UpdateUIState(UIState::READY); |
| 245 } | 287 } |
| 246 } else { | 288 } else { |
| 289 RecordFirstScreen(FirstScreen::FIRST_SCREEN_LOW_STORAGE); | |
| 247 CallJS("setAvailableSpaceInString", ui::FormatBytes(size)); | 290 CallJS("setAvailableSpaceInString", ui::FormatBytes(size)); |
| 248 CallJS("setNecessarySpaceInString", | 291 CallJS("setNecessarySpaceInString", |
| 249 ui::FormatBytes(kMinimumAvailableStorage)); | 292 ui::FormatBytes(kMinimumAvailableStorage)); |
| 250 UpdateUIState(UIState::NOT_ENOUGH_STORAGE); | 293 UpdateUIState(UIState::NOT_ENOUGH_STORAGE); |
| 251 } | 294 } |
| 252 } | 295 } |
| 253 | 296 |
| 254 void EncryptionMigrationScreenHandler::WaitBatteryAndMigrate() { | 297 void EncryptionMigrationScreenHandler::WaitBatteryAndMigrate() { |
| 255 if (current_battery_percent_ >= kMinimumBatteryPercent) { | 298 if (current_battery_percent_ >= kMinimumBatteryPercent) { |
| 256 StartMigration(); | 299 StartMigration(); |
| 257 return; | 300 return; |
| 258 } | 301 } |
| 259 UpdateUIState(UIState::READY); | 302 UpdateUIState(UIState::READY); |
| 260 | 303 |
| 261 should_migrate_on_enough_battery_ = true; | 304 should_migrate_on_enough_battery_ = true; |
| 262 DBusThreadManager::Get()->GetPowerManagerClient()->RequestStatusUpdate(); | 305 DBusThreadManager::Get()->GetPowerManagerClient()->RequestStatusUpdate(); |
| 263 } | 306 } |
| 264 | 307 |
| 265 void EncryptionMigrationScreenHandler::StartMigration() { | 308 void EncryptionMigrationScreenHandler::StartMigration() { |
| 266 UpdateUIState(UIState::MIGRATING); | 309 UpdateUIState(UIState::MIGRATING); |
| 310 initial_battery_percent_ = current_battery_percent_; | |
| 267 | 311 |
| 268 // Mount the existing eCryptfs vault to a temporary location for migration. | 312 // Mount the existing eCryptfs vault to a temporary location for migration. |
| 269 cryptohome::MountParameters mount(false); | 313 cryptohome::MountParameters mount(false); |
| 270 mount.to_migrate_from_ecryptfs = true; | 314 mount.to_migrate_from_ecryptfs = true; |
| 271 cryptohome::HomedirMethods::GetInstance()->MountEx( | 315 cryptohome::HomedirMethods::GetInstance()->MountEx( |
| 272 cryptohome::Identification(user_context_.GetAccountId()), | 316 cryptohome::Identification(user_context_.GetAccountId()), |
| 273 cryptohome::Authorization(GetAuthKey()), mount, | 317 cryptohome::Authorization(GetAuthKey()), mount, |
| 274 base::Bind(&EncryptionMigrationScreenHandler::OnMountExistingVault, | 318 base::Bind(&EncryptionMigrationScreenHandler::OnMountExistingVault, |
| 275 weak_ptr_factory_.GetWeakPtr())); | 319 weak_ptr_factory_.GetWeakPtr())); |
| 276 } | 320 } |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 355 uint64_t total) { | 399 uint64_t total) { |
| 356 switch (status) { | 400 switch (status) { |
| 357 case cryptohome::DIRCRYPTO_MIGRATION_INITIALIZING: | 401 case cryptohome::DIRCRYPTO_MIGRATION_INITIALIZING: |
| 358 UpdateUIState(UIState::MIGRATING); | 402 UpdateUIState(UIState::MIGRATING); |
| 359 break; | 403 break; |
| 360 case cryptohome::DIRCRYPTO_MIGRATION_IN_PROGRESS: | 404 case cryptohome::DIRCRYPTO_MIGRATION_IN_PROGRESS: |
| 361 UpdateUIState(UIState::MIGRATING); | 405 UpdateUIState(UIState::MIGRATING); |
| 362 CallJS("setMigrationProgress", static_cast<double>(current) / total); | 406 CallJS("setMigrationProgress", static_cast<double>(current) / total); |
| 363 break; | 407 break; |
| 364 case cryptohome::DIRCRYPTO_MIGRATION_SUCCESS: | 408 case cryptohome::DIRCRYPTO_MIGRATION_SUCCESS: |
| 409 // If the battery level decreased during migration, record the consumed | |
| 410 // battery level. | |
| 411 if (current_battery_percent_ < initial_battery_percent_) { | |
| 412 UMA_HISTOGRAM_PERCENTAGE( | |
| 413 kUmaNameConsumedBatteryPercent, | |
| 414 static_cast<int>(std::round(initial_battery_percent_ - | |
| 415 current_battery_percent_))); | |
| 416 } | |
| 365 // Restart immediately after successful migration. | 417 // Restart immediately after successful migration. |
| 366 DBusThreadManager::Get()->GetPowerManagerClient()->RequestRestart(); | 418 DBusThreadManager::Get()->GetPowerManagerClient()->RequestRestart(); |
| 367 break; | 419 break; |
| 368 case cryptohome::DIRCRYPTO_MIGRATION_FAILED: | 420 case cryptohome::DIRCRYPTO_MIGRATION_FAILED: |
| 369 // Stop listening to the progress updates. | 421 // Stop listening to the progress updates. |
| 370 DBusThreadManager::Get() | 422 DBusThreadManager::Get() |
| 371 ->GetCryptohomeClient() | 423 ->GetCryptohomeClient() |
| 372 ->SetDircryptoMigrationProgressHandler( | 424 ->SetDircryptoMigrationProgressHandler( |
| 373 CryptohomeClient::DircryptoMigrationProgessHandler()); | 425 CryptohomeClient::DircryptoMigrationProgessHandler()); |
| 374 // Shows error screen after removing user directory is completed. | 426 // Shows error screen after removing user directory is completed. |
| 375 RemoveCryptohome(); | 427 RemoveCryptohome(); |
| 376 break; | 428 break; |
| 377 default: | 429 default: |
| 378 break; | 430 break; |
| 379 } | 431 } |
| 380 } | 432 } |
| 381 | 433 |
| 382 void EncryptionMigrationScreenHandler::OnMigrationRequested(bool success) { | 434 void EncryptionMigrationScreenHandler::OnMigrationRequested(bool success) { |
| 383 LOG_IF(ERROR, !success) << "Requesting MigrateToDircrypto failed."; | 435 LOG_IF(ERROR, !success) << "Requesting MigrateToDircrypto failed."; |
| 384 UpdateUIState(UIState::MIGRATION_FAILED); | 436 UpdateUIState(UIState::MIGRATION_FAILED); |
| 385 } | 437 } |
| 386 | 438 |
| 387 } // namespace chromeos | 439 } // namespace chromeos |
| OLD | NEW |