Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(70)

Side by Side Diff: chrome/browser/ui/webui/chromeos/login/encryption_migration_screen_handler.cc

Issue 2902093003: arc: Message for a low-battery case of migration notification. (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/chromeos/arc/arc_migration_guide_notification.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 // The minimum size of available space to start the migration.
45 constexpr int64_t kMinimumAvailableStorage = 10LL * 1024 * 1024; // 10MB 46 constexpr int64_t kMinimumAvailableStorage = 10LL * 1024 * 1024; // 10MB
fukino 2017/05/24 08:15:32 optional nit: Maybe we should move kMinimumAvailab
kinaba 2017/05/24 21:58:06 Done.
46 47
47 // The minimum battery level to start the migration.
48 constexpr double kMinimumBatteryPercent = 30;
49
50 // JS API callbacks names. 48 // JS API callbacks names.
51 constexpr char kJsApiStartMigration[] = "startMigration"; 49 constexpr char kJsApiStartMigration[] = "startMigration";
52 constexpr char kJsApiSkipMigration[] = "skipMigration"; 50 constexpr char kJsApiSkipMigration[] = "skipMigration";
53 constexpr char kJsApiRequestRestart[] = "requestRestart"; 51 constexpr char kJsApiRequestRestart[] = "requestRestart";
54 constexpr char kJsApiOpenFeedbackDialog[] = "openFeedbackDialog"; 52 constexpr char kJsApiOpenFeedbackDialog[] = "openFeedbackDialog";
55 53
56 // UMA names. 54 // UMA names.
57 constexpr char kUmaNameFirstScreen[] = "Cryptohome.MigrationUI.FirstScreen"; 55 constexpr char kUmaNameFirstScreen[] = "Cryptohome.MigrationUI.FirstScreen";
58 constexpr char kUmaNameUserChoice[] = "Cryptohome.MigrationUI.UserChoice"; 56 constexpr char kUmaNameUserChoice[] = "Cryptohome.MigrationUI.UserChoice";
59 constexpr char kUmaNameConsumedBatteryPercent[] = 57 constexpr char kUmaNameConsumedBatteryPercent[] =
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 AddCallback(kJsApiRequestRestart, 210 AddCallback(kJsApiRequestRestart,
213 &EncryptionMigrationScreenHandler::HandleRequestRestart); 211 &EncryptionMigrationScreenHandler::HandleRequestRestart);
214 AddCallback(kJsApiOpenFeedbackDialog, 212 AddCallback(kJsApiOpenFeedbackDialog,
215 &EncryptionMigrationScreenHandler::HandleOpenFeedbackDialog); 213 &EncryptionMigrationScreenHandler::HandleOpenFeedbackDialog);
216 } 214 }
217 215
218 void EncryptionMigrationScreenHandler::PowerChanged( 216 void EncryptionMigrationScreenHandler::PowerChanged(
219 const power_manager::PowerSupplyProperties& proto) { 217 const power_manager::PowerSupplyProperties& proto) {
220 current_battery_percent_ = proto.battery_percent(); 218 current_battery_percent_ = proto.battery_percent();
221 CallJS("setBatteryState", current_battery_percent_, 219 CallJS("setBatteryState", current_battery_percent_,
222 current_battery_percent_ >= kMinimumBatteryPercent, 220 current_battery_percent_ >= arc::kMigrationMinimumBatteryPercent,
223 proto.battery_state() == 221 proto.battery_state() ==
224 power_manager::PowerSupplyProperties_BatteryState_CHARGING); 222 power_manager::PowerSupplyProperties_BatteryState_CHARGING);
225 223
226 // If the migration was already requested and the bettery level is enough now, 224 // If the migration was already requested and the bettery level is enough now,
227 // The migration should start immediately. 225 // The migration should start immediately.
228 if (current_battery_percent_ >= kMinimumBatteryPercent && 226 if (current_battery_percent_ >= arc::kMigrationMinimumBatteryPercent &&
229 should_migrate_on_enough_battery_) { 227 should_migrate_on_enough_battery_) {
230 should_migrate_on_enough_battery_ = false; 228 should_migrate_on_enough_battery_ = false;
231 StartMigration(); 229 StartMigration();
232 } 230 }
233 } 231 }
234 232
235 void EncryptionMigrationScreenHandler::HandleStartMigration() { 233 void EncryptionMigrationScreenHandler::HandleStartMigration() {
236 RecordUserChoice(UserChoice::USER_CHOICE_UPDATE); 234 RecordUserChoice(UserChoice::USER_CHOICE_UPDATE);
237 WaitBatteryAndMigrate(); 235 WaitBatteryAndMigrate();
238 } 236 }
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 } else { 301 } else {
304 RecordFirstScreen(FirstScreen::FIRST_SCREEN_LOW_STORAGE); 302 RecordFirstScreen(FirstScreen::FIRST_SCREEN_LOW_STORAGE);
305 CallJS("setAvailableSpaceInString", ui::FormatBytes(size)); 303 CallJS("setAvailableSpaceInString", ui::FormatBytes(size));
306 CallJS("setNecessarySpaceInString", 304 CallJS("setNecessarySpaceInString",
307 ui::FormatBytes(kMinimumAvailableStorage)); 305 ui::FormatBytes(kMinimumAvailableStorage));
308 UpdateUIState(UIState::NOT_ENOUGH_STORAGE); 306 UpdateUIState(UIState::NOT_ENOUGH_STORAGE);
309 } 307 }
310 } 308 }
311 309
312 void EncryptionMigrationScreenHandler::WaitBatteryAndMigrate() { 310 void EncryptionMigrationScreenHandler::WaitBatteryAndMigrate() {
313 if (current_battery_percent_ >= kMinimumBatteryPercent) { 311 if (current_battery_percent_ >= arc::kMigrationMinimumBatteryPercent) {
314 StartMigration(); 312 StartMigration();
315 return; 313 return;
316 } 314 }
317 UpdateUIState(UIState::READY); 315 UpdateUIState(UIState::READY);
318 316
319 should_migrate_on_enough_battery_ = true; 317 should_migrate_on_enough_battery_ = true;
320 DBusThreadManager::Get()->GetPowerManagerClient()->RequestStatusUpdate(); 318 DBusThreadManager::Get()->GetPowerManagerClient()->RequestStatusUpdate();
321 } 319 }
322 320
323 void EncryptionMigrationScreenHandler::StartMigration() { 321 void EncryptionMigrationScreenHandler::StartMigration() {
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 } 445 }
448 446
449 void EncryptionMigrationScreenHandler::OnMigrationRequested(bool success) { 447 void EncryptionMigrationScreenHandler::OnMigrationRequested(bool success) {
450 if (!success) { 448 if (!success) {
451 LOG(ERROR) << "Requesting MigrateToDircrypto failed."; 449 LOG(ERROR) << "Requesting MigrateToDircrypto failed.";
452 UpdateUIState(UIState::MIGRATION_FAILED); 450 UpdateUIState(UIState::MIGRATION_FAILED);
453 } 451 }
454 } 452 }
455 453
456 } // namespace chromeos 454 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/arc/arc_migration_guide_notification.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698