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 FirstScreen { | |
Ilya Sherman
2017/04/28 21:07:52
Optional nit: Mebbe use enum class here?
fukino
2017/04/29 14:40:31
Done.
| |
61 FIRST_SCREEN_READY = 0, | |
62 FIRST_SCREEN_RESUME = 1, | |
63 FIRST_SCREEN_LOW_STORAGE = 2, | |
64 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.
| |
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 UserChoice { | |
71 USER_CHOICE_UPDATE = 0, | |
72 USER_CHOICE_SKIP = 1, | |
73 USER_CHOICE_MAX | |
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 |
54 } // namespace | 81 } // namespace |
55 | 82 |
56 namespace chromeos { | 83 namespace chromeos { |
57 | 84 |
58 EncryptionMigrationScreenHandler::EncryptionMigrationScreenHandler() | 85 EncryptionMigrationScreenHandler::EncryptionMigrationScreenHandler() |
(...skipping 121 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, | 207 // If the migration was already requested and the bettery level is enough now, |
181 // The migration should start immediately. | 208 // The migration should start immediately. |
182 if (current_battery_percent_ >= kMinimumBatteryPercent && | 209 if (current_battery_percent_ >= kMinimumBatteryPercent && |
183 should_migrate_on_enough_battery_) { | 210 should_migrate_on_enough_battery_) { |
184 should_migrate_on_enough_battery_ = false; | 211 should_migrate_on_enough_battery_ = false; |
185 StartMigration(); | 212 StartMigration(); |
186 } | 213 } |
187 } | 214 } |
188 | 215 |
189 void EncryptionMigrationScreenHandler::HandleStartMigration() { | 216 void EncryptionMigrationScreenHandler::HandleStartMigration() { |
217 UMA_HISTOGRAM_ENUMERATION(kUmaNameUserChoice, USER_CHOICE_UPDATE, | |
218 USER_CHOICE_MAX); | |
190 WaitBatteryAndMigrate(); | 219 WaitBatteryAndMigrate(); |
191 } | 220 } |
192 | 221 |
193 void EncryptionMigrationScreenHandler::HandleSkipMigration() { | 222 void EncryptionMigrationScreenHandler::HandleSkipMigration() { |
223 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.
| |
224 USER_CHOICE_MAX); | |
194 // If the user skips migration, we mount the cryptohome without performing the | 225 // If the user skips migration, we mount the cryptohome without performing the |
195 // migration by reusing UserContext and LoginPerformer which were used in the | 226 // migration by reusing UserContext and LoginPerformer which were used in the |
196 // previous attempt and dropping |is_forcing_dircrypto| flag in UserContext. | 227 // 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 | 228 // 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. | 229 // asked to do the migration again in the next log-in attempt. |
199 if (!continue_login_callback_.is_null()) { | 230 if (!continue_login_callback_.is_null()) { |
200 user_context_.SetIsForcingDircrypto(false); | 231 user_context_.SetIsForcingDircrypto(false); |
201 std::move(continue_login_callback_).Run(user_context_); | 232 std::move(continue_login_callback_).Run(user_context_); |
202 } | 233 } |
203 } | 234 } |
(...skipping 28 matching lines...) Expand all Loading... | |
232 base::TaskPriority::USER_VISIBLE), | 263 base::TaskPriority::USER_VISIBLE), |
233 base::Bind(&base::SysInfo::AmountOfFreeDiskSpace, | 264 base::Bind(&base::SysInfo::AmountOfFreeDiskSpace, |
234 base::FilePath(kCheckStoragePath)), | 265 base::FilePath(kCheckStoragePath)), |
235 base::Bind(&EncryptionMigrationScreenHandler::OnGetAvailableStorage, | 266 base::Bind(&EncryptionMigrationScreenHandler::OnGetAvailableStorage, |
236 weak_ptr_factory_.GetWeakPtr())); | 267 weak_ptr_factory_.GetWeakPtr())); |
237 } | 268 } |
238 | 269 |
239 void EncryptionMigrationScreenHandler::OnGetAvailableStorage(int64_t size) { | 270 void EncryptionMigrationScreenHandler::OnGetAvailableStorage(int64_t size) { |
240 if (size >= kMinimumAvailableStorage || IsTestingUI()) { | 271 if (size >= kMinimumAvailableStorage || IsTestingUI()) { |
241 if (should_resume_) { | 272 if (should_resume_) { |
273 UMA_HISTOGRAM_ENUMERATION(kUmaNameFirstScreen, FIRST_SCREEN_RESUME, | |
274 FIRST_SCREEN_MAX); | |
242 WaitBatteryAndMigrate(); | 275 WaitBatteryAndMigrate(); |
243 } else { | 276 } else { |
277 UMA_HISTOGRAM_ENUMERATION(kUmaNameFirstScreen, FIRST_SCREEN_READY, | |
278 FIRST_SCREEN_MAX); | |
244 UpdateUIState(UIState::READY); | 279 UpdateUIState(UIState::READY); |
245 } | 280 } |
246 } else { | 281 } else { |
282 UMA_HISTOGRAM_ENUMERATION(kUmaNameFirstScreen, FIRST_SCREEN_LOW_STORAGE, | |
283 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
| |
247 CallJS("setAvailableSpaceInString", ui::FormatBytes(size)); | 284 CallJS("setAvailableSpaceInString", ui::FormatBytes(size)); |
248 CallJS("setNecessarySpaceInString", | 285 CallJS("setNecessarySpaceInString", |
249 ui::FormatBytes(kMinimumAvailableStorage)); | 286 ui::FormatBytes(kMinimumAvailableStorage)); |
250 UpdateUIState(UIState::NOT_ENOUGH_STORAGE); | 287 UpdateUIState(UIState::NOT_ENOUGH_STORAGE); |
251 } | 288 } |
252 } | 289 } |
253 | 290 |
254 void EncryptionMigrationScreenHandler::WaitBatteryAndMigrate() { | 291 void EncryptionMigrationScreenHandler::WaitBatteryAndMigrate() { |
255 if (current_battery_percent_ >= kMinimumBatteryPercent) { | 292 if (current_battery_percent_ >= kMinimumBatteryPercent) { |
256 StartMigration(); | 293 StartMigration(); |
257 return; | 294 return; |
258 } | 295 } |
259 UpdateUIState(UIState::READY); | 296 UpdateUIState(UIState::READY); |
260 | 297 |
261 should_migrate_on_enough_battery_ = true; | 298 should_migrate_on_enough_battery_ = true; |
262 DBusThreadManager::Get()->GetPowerManagerClient()->RequestStatusUpdate(); | 299 DBusThreadManager::Get()->GetPowerManagerClient()->RequestStatusUpdate(); |
263 } | 300 } |
264 | 301 |
265 void EncryptionMigrationScreenHandler::StartMigration() { | 302 void EncryptionMigrationScreenHandler::StartMigration() { |
266 UpdateUIState(UIState::MIGRATING); | 303 UpdateUIState(UIState::MIGRATING); |
304 initial_battery_percent_ = current_battery_percent_; | |
267 | 305 |
268 // Mount the existing eCryptfs vault to a temporary location for migration. | 306 // Mount the existing eCryptfs vault to a temporary location for migration. |
269 cryptohome::MountParameters mount(false); | 307 cryptohome::MountParameters mount(false); |
270 mount.to_migrate_from_ecryptfs = true; | 308 mount.to_migrate_from_ecryptfs = true; |
271 cryptohome::HomedirMethods::GetInstance()->MountEx( | 309 cryptohome::HomedirMethods::GetInstance()->MountEx( |
272 cryptohome::Identification(user_context_.GetAccountId()), | 310 cryptohome::Identification(user_context_.GetAccountId()), |
273 cryptohome::Authorization(GetAuthKey()), mount, | 311 cryptohome::Authorization(GetAuthKey()), mount, |
274 base::Bind(&EncryptionMigrationScreenHandler::OnMountExistingVault, | 312 base::Bind(&EncryptionMigrationScreenHandler::OnMountExistingVault, |
275 weak_ptr_factory_.GetWeakPtr())); | 313 weak_ptr_factory_.GetWeakPtr())); |
276 } | 314 } |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
355 uint64_t total) { | 393 uint64_t total) { |
356 switch (status) { | 394 switch (status) { |
357 case cryptohome::DIRCRYPTO_MIGRATION_INITIALIZING: | 395 case cryptohome::DIRCRYPTO_MIGRATION_INITIALIZING: |
358 UpdateUIState(UIState::MIGRATING); | 396 UpdateUIState(UIState::MIGRATING); |
359 break; | 397 break; |
360 case cryptohome::DIRCRYPTO_MIGRATION_IN_PROGRESS: | 398 case cryptohome::DIRCRYPTO_MIGRATION_IN_PROGRESS: |
361 UpdateUIState(UIState::MIGRATING); | 399 UpdateUIState(UIState::MIGRATING); |
362 CallJS("setMigrationProgress", static_cast<double>(current) / total); | 400 CallJS("setMigrationProgress", static_cast<double>(current) / total); |
363 break; | 401 break; |
364 case cryptohome::DIRCRYPTO_MIGRATION_SUCCESS: | 402 case cryptohome::DIRCRYPTO_MIGRATION_SUCCESS: |
403 // If the battery level decreased during migration, record the consumed | |
404 // battery level. | |
405 if (current_battery_percent_ < initial_battery_percent_) { | |
406 UMA_HISTOGRAM_PERCENTAGE( | |
407 kUmaNameConsumedBatteryPercent, | |
408 static_cast<int>(std::round(initial_battery_percent_ - | |
409 current_battery_percent_))); | |
410 } | |
365 // Restart immediately after successful migration. | 411 // Restart immediately after successful migration. |
366 DBusThreadManager::Get()->GetPowerManagerClient()->RequestRestart(); | 412 DBusThreadManager::Get()->GetPowerManagerClient()->RequestRestart(); |
367 break; | 413 break; |
368 case cryptohome::DIRCRYPTO_MIGRATION_FAILED: | 414 case cryptohome::DIRCRYPTO_MIGRATION_FAILED: |
369 // Stop listening to the progress updates. | 415 // Stop listening to the progress updates. |
370 DBusThreadManager::Get() | 416 DBusThreadManager::Get() |
371 ->GetCryptohomeClient() | 417 ->GetCryptohomeClient() |
372 ->SetDircryptoMigrationProgressHandler( | 418 ->SetDircryptoMigrationProgressHandler( |
373 CryptohomeClient::DircryptoMigrationProgessHandler()); | 419 CryptohomeClient::DircryptoMigrationProgessHandler()); |
374 // Shows error screen after removing user directory is completed. | 420 // Shows error screen after removing user directory is completed. |
375 RemoveCryptohome(); | 421 RemoveCryptohome(); |
376 break; | 422 break; |
377 default: | 423 default: |
378 break; | 424 break; |
379 } | 425 } |
380 } | 426 } |
381 | 427 |
382 void EncryptionMigrationScreenHandler::OnMigrationRequested(bool success) { | 428 void EncryptionMigrationScreenHandler::OnMigrationRequested(bool success) { |
383 LOG_IF(ERROR, !success) << "Requesting MigrateToDircrypto failed."; | 429 LOG_IF(ERROR, !success) << "Requesting MigrateToDircrypto failed."; |
384 UpdateUIState(UIState::MIGRATION_FAILED); | 430 UpdateUIState(UIState::MIGRATION_FAILED); |
385 } | 431 } |
386 | 432 |
387 } // namespace chromeos | 433 } // namespace chromeos |
OLD | NEW |