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

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

Issue 2819613003: cros: Update design of encryption migration UI for ext4 dircrypto. (Closed)
Patch Set: Address review comments. Created 3 years, 8 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
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 <string> 7 #include <string>
8 #include <utility> 8 #include <utility>
9 9
10 #include "ash/system/devicetype_utils.h"
10 #include "base/command_line.h" 11 #include "base/command_line.h"
11 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
12 #include "base/sys_info.h" 13 #include "base/sys_info.h"
13 #include "base/task_scheduler/post_task.h" 14 #include "base/task_scheduler/post_task.h"
14 #include "chrome/browser/lifetime/application_lifetime.h" 15 #include "chrome/browser/lifetime/application_lifetime.h"
16 #include "chrome/grit/generated_resources.h"
15 #include "chromeos/chromeos_switches.h" 17 #include "chromeos/chromeos_switches.h"
16 #include "chromeos/cryptohome/homedir_methods.h" 18 #include "chromeos/cryptohome/homedir_methods.h"
17 #include "chromeos/dbus/cryptohome_client.h" 19 #include "chromeos/dbus/cryptohome_client.h"
18 #include "chromeos/dbus/dbus_thread_manager.h" 20 #include "chromeos/dbus/dbus_thread_manager.h"
19 #include "chromeos/dbus/power_manager/power_supply_properties.pb.h" 21 #include "chromeos/dbus/power_manager/power_supply_properties.pb.h"
20 #include "chromeos/dbus/power_manager_client.h" 22 #include "chromeos/dbus/power_manager_client.h"
23 #include "components/login/localized_values_builder.h"
24 #include "ui/base/text/bytes_formatting.h"
21 25
22 namespace { 26 namespace {
23 27
24 constexpr char kJsScreenPath[] = "login.EncryptionMigrationScreen"; 28 constexpr char kJsScreenPath[] = "login.EncryptionMigrationScreen";
25 29
26 // Path to the mount point to check the available space. 30 // Path to the mount point to check the available space.
27 constexpr char kCheckStoragePath[] = "/home"; 31 constexpr char kCheckStoragePath[] = "/home";
28 32
29 // The minimum size of available space to start the migration. 33 // The minimum size of available space to start the migration.
30 constexpr int64_t kMinimumAvailableStorage = 10LL * 1024 * 1024; // 10MB 34 constexpr int64_t kMinimumAvailableStorage = 10LL * 1024 * 1024; // 10MB
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 void EncryptionMigrationScreenHandler::SetContinueLoginCallback( 92 void EncryptionMigrationScreenHandler::SetContinueLoginCallback(
89 ContinueLoginCallback callback) { 93 ContinueLoginCallback callback) {
90 continue_login_callback_ = std::move(callback); 94 continue_login_callback_ = std::move(callback);
91 } 95 }
92 96
93 void EncryptionMigrationScreenHandler::SetupInitialView() { 97 void EncryptionMigrationScreenHandler::SetupInitialView() {
94 CheckAvailableStorage(); 98 CheckAvailableStorage();
95 } 99 }
96 100
97 void EncryptionMigrationScreenHandler::DeclareLocalizedValues( 101 void EncryptionMigrationScreenHandler::DeclareLocalizedValues(
98 ::login::LocalizedValuesBuilder* builder) {} 102 ::login::LocalizedValuesBuilder* builder) {
103 builder->Add("migrationReadyTitle", IDS_ENCRYPTION_MIGRATION_READY_TITLE);
104 builder->Add("migrationReadyDescription",
105 ash::SubstituteChromeOSDeviceType(
106 IDS_ENCRYPTION_MIGRATION_READY_DESCRIPTION));
107 builder->Add("migrationMigratingTitle",
108 IDS_ENCRYPTION_MIGRATION_MIGRATING_TITLE);
109 builder->Add("migrationMigratingDescription",
110 ash::SubstituteChromeOSDeviceType(
111 IDS_ENCRYPTION_MIGRATION_MIGRATING_DESCRIPTION));
112 builder->Add("migrationProgressLabel",
113 IDS_ENCRYPTION_MIGRATION_PROGRESS_LABEL);
114 builder->Add("migrationBatteryWarningLabel",
115 IDS_ENCRYPTION_MIGRATION_BATTERY_WARNING_LABEL);
116 builder->Add("migrationAskChargeMessage",
117 ash::SubstituteChromeOSDeviceType(
118 IDS_ENCRYPTION_MIGRATION_ASK_CHARGE_MESSAGE));
119 builder->Add("migrationNecessaryBatteryLevelLabel",
120 IDS_ENCRYPTION_MIGRATION_NECESSARY_BATTERY_LEVEL_MESSAGE);
121 builder->Add("migrationChargingLabel",
122 IDS_ENCRYPTION_MIGRATION_CHARGING_LABEL);
123 builder->Add("migrationFailedTitle", IDS_ENCRYPTION_MIGRATION_FAILED_TITLE);
124 builder->Add("migrationFailedSubtitle",
125 IDS_ENCRYPTION_MIGRATION_FAILED_SUBTITLE);
126 builder->Add("migrationFailedMessage",
127 ash::SubstituteChromeOSDeviceType(
128 IDS_ENCRYPTION_MIGRATION_FAILED_MESSAGE));
129 builder->Add("migrationNospaceWarningLabel",
130 IDS_ENCRYPTION_MIGRATION_NOSPACE_WARNING_LABEL);
131 builder->Add("migrationAskFreeSpaceMessage",
132 IDS_ENCRYPTION_MIGRATION_ASK_FREE_SPACE_MESSAGE);
133 builder->Add("migrationAvailableSpaceLabel",
134 IDS_ENCRYPTION_MIGRATION_AVAILABLE_SPACE_LABEL);
135 builder->Add("migrationNecessarySpaceLabel",
136 IDS_ENCRYPTION_MIGRATION_NECESSARY_SPACE_LABEL);
137 builder->Add("migrationButtonUpdate", IDS_ENCRYPTION_MIGRATION_BUTTON_UPDATE);
138 builder->Add("migrationButtonSkip", IDS_ENCRYPTION_MIGRATION_BUTTON_SKIP);
139 builder->Add("migrationButtonRestart",
140 IDS_ENCRYPTION_MIGRATION_BUTTON_RESTART);
141 builder->Add("migrationButtonContinue",
142 IDS_ENCRYPTION_MIGRATION_BUTTON_CONTINUE);
143 builder->Add("migrationButtonSignIn", IDS_ENCRYPTION_MIGRATION_BUTTON_SIGNIN);
144 }
99 145
100 void EncryptionMigrationScreenHandler::Initialize() { 146 void EncryptionMigrationScreenHandler::Initialize() {
101 if (!page_is_ready() || !delegate_) 147 if (!page_is_ready() || !delegate_)
102 return; 148 return;
103 149
104 DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver(this); 150 DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver(this);
105 151
106 if (show_on_init_) { 152 if (show_on_init_) {
107 Show(); 153 Show();
108 show_on_init_ = false; 154 show_on_init_ = false;
109 } 155 }
110 } 156 }
111 157
112 void EncryptionMigrationScreenHandler::RegisterMessages() { 158 void EncryptionMigrationScreenHandler::RegisterMessages() {
113 AddCallback(kJsApiStartMigration, 159 AddCallback(kJsApiStartMigration,
114 &EncryptionMigrationScreenHandler::HandleStartMigration); 160 &EncryptionMigrationScreenHandler::HandleStartMigration);
115 AddCallback(kJsApiSkipMigration, 161 AddCallback(kJsApiSkipMigration,
116 &EncryptionMigrationScreenHandler::HandleSkipMigration); 162 &EncryptionMigrationScreenHandler::HandleSkipMigration);
117 AddCallback(kJsApiRequestRestart, 163 AddCallback(kJsApiRequestRestart,
118 &EncryptionMigrationScreenHandler::HandleRequestRestart); 164 &EncryptionMigrationScreenHandler::HandleRequestRestart);
119 } 165 }
120 166
121 void EncryptionMigrationScreenHandler::PowerChanged( 167 void EncryptionMigrationScreenHandler::PowerChanged(
122 const power_manager::PowerSupplyProperties& proto) { 168 const power_manager::PowerSupplyProperties& proto) {
123 current_battery_percent_ = proto.battery_percent(); 169 current_battery_percent_ = proto.battery_percent();
124 CallJS("setBatteryPercent", current_battery_percent_, 170 CallJS("setBatteryState", current_battery_percent_,
125 current_battery_percent_ >= kMinimumBatteryPercent); 171 current_battery_percent_ >= kMinimumBatteryPercent,
172 proto.battery_state() ==
173 power_manager::PowerSupplyProperties_BatteryState_CHARGING);
126 174
127 // If the migration was already requested and the bettery level is enough now, 175 // If the migration was already requested and the bettery level is enough now,
128 // The migration should start immediately. 176 // The migration should start immediately.
129 if (current_battery_percent_ >= kMinimumBatteryPercent && 177 if (current_battery_percent_ >= kMinimumBatteryPercent &&
130 should_migrate_on_enough_battery_) { 178 should_migrate_on_enough_battery_) {
131 should_migrate_on_enough_battery_ = false; 179 should_migrate_on_enough_battery_ = false;
132 StartMigration(); 180 StartMigration();
133 } 181 }
134 } 182 }
135 183
136 void EncryptionMigrationScreenHandler::HandleStartMigration() { 184 void EncryptionMigrationScreenHandler::HandleStartMigration() {
137 WaitBatteryAndMigrate(); 185 WaitBatteryAndMigrate();
138 } 186 }
139 187
140 void EncryptionMigrationScreenHandler::HandleSkipMigration() { 188 void EncryptionMigrationScreenHandler::HandleSkipMigration() {
141 // If the user skips migration, we mount the cryptohome without performing the 189 // If the user skips migration, we mount the cryptohome without performing the
142 // migration by reusing UserContext and LoginPerformer which were used in the 190 // migration by reusing UserContext and LoginPerformer which were used in the
143 // previous attempt and dropping |is_forcing_dircrypto| flag in UserContext. 191 // previous attempt and dropping |is_forcing_dircrypto| flag in UserContext.
144 // In this case, the user can not launch ARC apps in the session, and will be 192 // In this case, the user can not launch ARC apps in the session, and will be
145 // asked to do the migration again in the next log-in attempt. 193 // asked to do the migration again in the next log-in attempt.
146 if (!continue_login_callback_.is_null()) { 194 if (!continue_login_callback_.is_null()) {
147 user_context_.SetIsForcingDircrypto(false); 195 user_context_.SetIsForcingDircrypto(false);
148 std::move(continue_login_callback_).Run(user_context_); 196 std::move(continue_login_callback_).Run(user_context_);
149 } 197 }
150 } 198 }
151 199
152 void EncryptionMigrationScreenHandler::HandleRequestRestart() { 200 void EncryptionMigrationScreenHandler::HandleRequestRestart() {
153 // TODO(fukino): If the migration finished successfully, we don't need to
154 // restart the device. Let's sign in to the desktop using the already-provided
155 // user credential.
156 chrome::AttemptRestart(); 201 chrome::AttemptRestart();
157 } 202 }
158 203
159 void EncryptionMigrationScreenHandler::UpdateUIState(UIState state) { 204 void EncryptionMigrationScreenHandler::UpdateUIState(UIState state) {
160 if (state == current_ui_state_) 205 if (state == current_ui_state_)
161 return; 206 return;
162 207
163 current_ui_state_ = state; 208 current_ui_state_ = state;
164 CallJS("setUIState", static_cast<int>(state)); 209 CallJS("setUIState", static_cast<int>(state));
165 210
(...skipping 15 matching lines...) Expand all
181 } 226 }
182 227
183 void EncryptionMigrationScreenHandler::OnGetAvailableStorage(int64_t size) { 228 void EncryptionMigrationScreenHandler::OnGetAvailableStorage(int64_t size) {
184 if (size >= kMinimumAvailableStorage || IsTestingUI()) { 229 if (size >= kMinimumAvailableStorage || IsTestingUI()) {
185 if (should_resume_) { 230 if (should_resume_) {
186 WaitBatteryAndMigrate(); 231 WaitBatteryAndMigrate();
187 } else { 232 } else {
188 UpdateUIState(UIState::READY); 233 UpdateUIState(UIState::READY);
189 } 234 }
190 } else { 235 } else {
236 CallJS("setAvailableSpaceInString", ui::FormatBytes(size));
237 CallJS("setNecessarySpaceInString",
238 ui::FormatBytes(kMinimumAvailableStorage));
191 UpdateUIState(UIState::NOT_ENOUGH_STORAGE); 239 UpdateUIState(UIState::NOT_ENOUGH_STORAGE);
192 } 240 }
193 } 241 }
194 242
195 void EncryptionMigrationScreenHandler::WaitBatteryAndMigrate() { 243 void EncryptionMigrationScreenHandler::WaitBatteryAndMigrate() {
196 if (current_battery_percent_ >= kMinimumBatteryPercent) { 244 if (current_battery_percent_ >= kMinimumBatteryPercent) {
197 StartMigration(); 245 StartMigration();
198 return; 246 return;
199 } 247 }
200 UpdateUIState(UIState::READY); 248 UpdateUIState(UIState::READY);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 uint64_t total) { 285 uint64_t total) {
238 switch (status) { 286 switch (status) {
239 case cryptohome::DIRCRYPTO_MIGRATION_INITIALIZING: 287 case cryptohome::DIRCRYPTO_MIGRATION_INITIALIZING:
240 UpdateUIState(UIState::MIGRATING); 288 UpdateUIState(UIState::MIGRATING);
241 break; 289 break;
242 case cryptohome::DIRCRYPTO_MIGRATION_IN_PROGRESS: 290 case cryptohome::DIRCRYPTO_MIGRATION_IN_PROGRESS:
243 UpdateUIState(UIState::MIGRATING); 291 UpdateUIState(UIState::MIGRATING);
244 CallJS("setMigrationProgress", static_cast<double>(current) / total); 292 CallJS("setMigrationProgress", static_cast<double>(current) / total);
245 break; 293 break;
246 case cryptohome::DIRCRYPTO_MIGRATION_SUCCESS: 294 case cryptohome::DIRCRYPTO_MIGRATION_SUCCESS:
295 // Restart immediately after successful migration.
296 chrome::AttemptRestart();
297 break;
247 case cryptohome::DIRCRYPTO_MIGRATION_FAILED: 298 case cryptohome::DIRCRYPTO_MIGRATION_FAILED:
248 UpdateUIState(status == cryptohome::DIRCRYPTO_MIGRATION_SUCCESS 299 UpdateUIState(UIState::MIGRATION_FAILED);
249 ? UIState::MIGRATION_SUCCEEDED
250 : UIState::MIGRATION_FAILED);
251 // Stop listening to the progress updates. 300 // Stop listening to the progress updates.
252 DBusThreadManager::Get() 301 DBusThreadManager::Get()
253 ->GetCryptohomeClient() 302 ->GetCryptohomeClient()
254 ->SetDircryptoMigrationProgressHandler( 303 ->SetDircryptoMigrationProgressHandler(
255 CryptohomeClient::DircryptoMigrationProgessHandler()); 304 CryptohomeClient::DircryptoMigrationProgessHandler());
256 break; 305 break;
257 default: 306 default:
258 break; 307 break;
259 } 308 }
260 } 309 }
261 310
262 void EncryptionMigrationScreenHandler::OnMigrationRequested(bool success) { 311 void EncryptionMigrationScreenHandler::OnMigrationRequested(bool success) {
263 // This function is called when MigrateToDircrypto is correctly requested. 312 // This function is called when MigrateToDircrypto is correctly requested.
264 // It does not mean that the migration is completed. We should know the 313 // It does not mean that the migration is completed. We should know the
265 // completion by DircryptoMigrationProgressHandler. success == false means a 314 // completion by DircryptoMigrationProgressHandler. success == false means a
266 // failure in DBus communication. 315 // failure in DBus communication.
267 // TODO(fukino): Handle this case. Should we retry or restart? 316 // TODO(fukino): Handle this case. Should we retry or restart?
268 DCHECK(success); 317 DCHECK(success);
269 } 318 }
270 319
271 } // namespace chromeos 320 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698