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