Chromium Code Reviews| 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 d655542a21fdfab84a781bb9927df3cf55a9ed5e..1b9185ded464ce299832fae502c3d46c6a169347 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 |
| @@ -4,12 +4,14 @@ |
| #include "chrome/browser/ui/webui/chromeos/login/encryption_migration_screen_handler.h" |
| +#include <cmath> |
| #include <string> |
| #include <utility> |
| #include "ash/system/devicetype_utils.h" |
| #include "base/command_line.h" |
| #include "base/files/file_path.h" |
| +#include "base/metrics/histogram_macros.h" |
| #include "base/sys_info.h" |
| #include "base/task_scheduler/post_task.h" |
| #include "chrome/browser/browser_process.h" |
| @@ -46,6 +48,31 @@ constexpr char kJsApiStartMigration[] = "startMigration"; |
| constexpr char kJsApiSkipMigration[] = "skipMigration"; |
| constexpr char kJsApiRequestRestart[] = "requestRestart"; |
| +// UMA names. |
| +constexpr char kUmaNameFirstScreen[] = "Cryptohome.MigrationUI.FirstScreen"; |
| +constexpr char kUmaNameUserChoice[] = "Cryptohome.MigrationUI.UserChoice"; |
| +constexpr char kUmaNameConsumedBatteryPercent[] = |
| + "Cryptohome.MigrationUI.ConsumedBatteryPercent"; |
| + |
| +// This enum must match the numbering for Cryptohome.MigrationUI.FirstScreen in |
| +// histograms.xml. Do not reorder or remove items, only add new items before |
| +// FIRST_SCREEN_MAX. |
| +enum FirstScreen { |
|
Ilya Sherman
2017/04/28 21:07:52
Optional nit: Mebbe use enum class here?
fukino
2017/04/29 14:40:31
Done.
|
| + FIRST_SCREEN_READY = 0, |
| + FIRST_SCREEN_RESUME = 1, |
| + FIRST_SCREEN_LOW_STORAGE = 2, |
| + FIRST_SCREEN_MAX |
|
Ilya Sherman
2017/04/28 21:07:52
Optional nit: Typically, "MAX" is used as an alias
fukino
2017/04/29 14:40:31
Agreed. Done.
|
| +}; |
| + |
| +// This enum must match the numbering for Cryptohome.MigrationUI.UserChoice in |
| +// histograms.xml. Do not reorder or remove items, only add new items before |
| +// FIRST_SCREEN_MAX. |
| +enum UserChoice { |
| + USER_CHOICE_UPDATE = 0, |
| + USER_CHOICE_SKIP = 1, |
| + USER_CHOICE_MAX |
| +}; |
| + |
| bool IsTestingUI() { |
| return base::CommandLine::ForCurrentProcess()->HasSwitch( |
| chromeos::switches::kTestEncryptionMigrationUI); |
| @@ -187,10 +214,14 @@ void EncryptionMigrationScreenHandler::PowerChanged( |
| } |
| void EncryptionMigrationScreenHandler::HandleStartMigration() { |
| + UMA_HISTOGRAM_ENUMERATION(kUmaNameUserChoice, USER_CHOICE_UPDATE, |
| + USER_CHOICE_MAX); |
| WaitBatteryAndMigrate(); |
| } |
| void EncryptionMigrationScreenHandler::HandleSkipMigration() { |
| + UMA_HISTOGRAM_ENUMERATION(kUmaNameUserChoice, USER_CHOICE_SKIP, |
|
Ilya Sherman
2017/04/28 21:07:51
Please create a small wrapper function for recordi
fukino
2017/04/29 14:40:31
Done.
|
| + USER_CHOICE_MAX); |
| // If the user skips migration, we mount the cryptohome without performing the |
| // migration by reusing UserContext and LoginPerformer which were used in the |
| // previous attempt and dropping |is_forcing_dircrypto| flag in UserContext. |
| @@ -239,11 +270,17 @@ void EncryptionMigrationScreenHandler::CheckAvailableStorage() { |
| void EncryptionMigrationScreenHandler::OnGetAvailableStorage(int64_t size) { |
| if (size >= kMinimumAvailableStorage || IsTestingUI()) { |
| if (should_resume_) { |
| + UMA_HISTOGRAM_ENUMERATION(kUmaNameFirstScreen, FIRST_SCREEN_RESUME, |
| + FIRST_SCREEN_MAX); |
| WaitBatteryAndMigrate(); |
| } else { |
| + UMA_HISTOGRAM_ENUMERATION(kUmaNameFirstScreen, FIRST_SCREEN_READY, |
| + FIRST_SCREEN_MAX); |
| UpdateUIState(UIState::READY); |
| } |
| } else { |
| + UMA_HISTOGRAM_ENUMERATION(kUmaNameFirstScreen, FIRST_SCREEN_LOW_STORAGE, |
| + FIRST_SCREEN_MAX); |
|
Ilya Sherman
2017/04/28 21:07:52
For this histogram, you could simply set the metri
fukino
2017/04/29 14:40:31
I added a wrapper function for consistency with Us
|
| CallJS("setAvailableSpaceInString", ui::FormatBytes(size)); |
| CallJS("setNecessarySpaceInString", |
| ui::FormatBytes(kMinimumAvailableStorage)); |
| @@ -264,6 +301,7 @@ void EncryptionMigrationScreenHandler::WaitBatteryAndMigrate() { |
| void EncryptionMigrationScreenHandler::StartMigration() { |
| UpdateUIState(UIState::MIGRATING); |
| + initial_battery_percent_ = current_battery_percent_; |
| // Mount the existing eCryptfs vault to a temporary location for migration. |
| cryptohome::MountParameters mount(false); |
| @@ -362,6 +400,14 @@ void EncryptionMigrationScreenHandler::OnMigrationProgress( |
| CallJS("setMigrationProgress", static_cast<double>(current) / total); |
| break; |
| case cryptohome::DIRCRYPTO_MIGRATION_SUCCESS: |
| + // If the battery level decreased during migration, record the consumed |
| + // battery level. |
| + if (current_battery_percent_ < initial_battery_percent_) { |
| + UMA_HISTOGRAM_PERCENTAGE( |
| + kUmaNameConsumedBatteryPercent, |
| + static_cast<int>(std::round(initial_battery_percent_ - |
| + current_battery_percent_))); |
| + } |
| // Restart immediately after successful migration. |
| DBusThreadManager::Get()->GetPowerManagerClient()->RequestRestart(); |
| break; |