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 "ash/system/devicetype_utils.h" | 10 #include "ash/system/devicetype_utils.h" |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
13 #include "base/sys_info.h" | 13 #include "base/sys_info.h" |
14 #include "base/task_scheduler/post_task.h" | 14 #include "base/task_scheduler/post_task.h" |
| 15 #include "chrome/browser/browser_process.h" |
15 #include "chrome/browser/lifetime/application_lifetime.h" | 16 #include "chrome/browser/lifetime/application_lifetime.h" |
16 #include "chrome/grit/generated_resources.h" | 17 #include "chrome/grit/generated_resources.h" |
17 #include "chromeos/chromeos_switches.h" | 18 #include "chromeos/chromeos_switches.h" |
18 #include "chromeos/cryptohome/homedir_methods.h" | 19 #include "chromeos/cryptohome/homedir_methods.h" |
19 #include "chromeos/dbus/cryptohome_client.h" | 20 #include "chromeos/dbus/cryptohome_client.h" |
20 #include "chromeos/dbus/dbus_thread_manager.h" | 21 #include "chromeos/dbus/dbus_thread_manager.h" |
21 #include "chromeos/dbus/power_manager/power_supply_properties.pb.h" | 22 #include "chromeos/dbus/power_manager/power_supply_properties.pb.h" |
22 #include "chromeos/dbus/power_manager_client.h" | 23 #include "chromeos/dbus/power_manager_client.h" |
23 #include "components/login/localized_values_builder.h" | 24 #include "components/login/localized_values_builder.h" |
| 25 #include "content/public/browser/browser_thread.h" |
| 26 #include "device/power_save_blocker/power_save_blocker.h" |
24 #include "ui/base/text/bytes_formatting.h" | 27 #include "ui/base/text/bytes_formatting.h" |
25 | 28 |
26 namespace { | 29 namespace { |
27 | 30 |
28 constexpr char kJsScreenPath[] = "login.EncryptionMigrationScreen"; | 31 constexpr char kJsScreenPath[] = "login.EncryptionMigrationScreen"; |
29 | 32 |
30 // Path to the mount point to check the available space. | 33 // Path to the mount point to check the available space. |
31 constexpr char kCheckStoragePath[] = "/home"; | 34 constexpr char kCheckStoragePath[] = "/home"; |
32 | 35 |
33 // The minimum size of available space to start the migration. | 36 // The minimum size of available space to start the migration. |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 if (state == current_ui_state_) | 208 if (state == current_ui_state_) |
206 return; | 209 return; |
207 | 210 |
208 current_ui_state_ = state; | 211 current_ui_state_ = state; |
209 CallJS("setUIState", static_cast<int>(state)); | 212 CallJS("setUIState", static_cast<int>(state)); |
210 | 213 |
211 // When this handler is about to show the READY screen, we should get the | 214 // When this handler is about to show the READY screen, we should get the |
212 // latest battery status and show it on the screen. | 215 // latest battery status and show it on the screen. |
213 if (state == UIState::READY) | 216 if (state == UIState::READY) |
214 DBusThreadManager::Get()->GetPowerManagerClient()->RequestStatusUpdate(); | 217 DBusThreadManager::Get()->GetPowerManagerClient()->RequestStatusUpdate(); |
| 218 |
| 219 // We should block power save during migration. |
| 220 if (state == UIState::MIGRATING) |
| 221 StartBlockingPowerSave(); |
| 222 else |
| 223 StopBlockingPowerSave(); |
215 } | 224 } |
216 | 225 |
217 void EncryptionMigrationScreenHandler::CheckAvailableStorage() { | 226 void EncryptionMigrationScreenHandler::CheckAvailableStorage() { |
218 base::PostTaskWithTraitsAndReplyWithResult( | 227 base::PostTaskWithTraitsAndReplyWithResult( |
219 FROM_HERE, | 228 FROM_HERE, |
220 base::TaskTraits().MayBlock().WithPriority( | 229 base::TaskTraits().MayBlock().WithPriority( |
221 base::TaskPriority::USER_VISIBLE), | 230 base::TaskPriority::USER_VISIBLE), |
222 base::Bind(&base::SysInfo::AmountOfFreeDiskSpace, | 231 base::Bind(&base::SysInfo::AmountOfFreeDiskSpace, |
223 base::FilePath(kCheckStoragePath)), | 232 base::FilePath(kCheckStoragePath)), |
224 base::Bind(&EncryptionMigrationScreenHandler::OnGetAvailableStorage, | 233 base::Bind(&EncryptionMigrationScreenHandler::OnGetAvailableStorage, |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 ->GetCryptohomeClient() | 286 ->GetCryptohomeClient() |
278 ->SetDircryptoMigrationProgressHandler( | 287 ->SetDircryptoMigrationProgressHandler( |
279 base::Bind(&EncryptionMigrationScreenHandler::OnMigrationProgress, | 288 base::Bind(&EncryptionMigrationScreenHandler::OnMigrationProgress, |
280 weak_ptr_factory_.GetWeakPtr())); | 289 weak_ptr_factory_.GetWeakPtr())); |
281 cryptohome::HomedirMethods::GetInstance()->MigrateToDircrypto( | 290 cryptohome::HomedirMethods::GetInstance()->MigrateToDircrypto( |
282 cryptohome::Identification(user_context_.GetAccountId()), | 291 cryptohome::Identification(user_context_.GetAccountId()), |
283 base::Bind(&EncryptionMigrationScreenHandler::OnMigrationRequested, | 292 base::Bind(&EncryptionMigrationScreenHandler::OnMigrationRequested, |
284 weak_ptr_factory_.GetWeakPtr())); | 293 weak_ptr_factory_.GetWeakPtr())); |
285 } | 294 } |
286 | 295 |
| 296 void EncryptionMigrationScreenHandler::StartBlockingPowerSave() { |
| 297 if (!power_save_blocker_) { |
| 298 power_save_blocker_.reset(new device::PowerSaveBlocker( |
| 299 device::PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, |
| 300 device::PowerSaveBlocker::kReasonOther, |
| 301 "Encryption migration is in progress...", |
| 302 content::BrowserThread::GetTaskRunnerForThread( |
| 303 content::BrowserThread::UI), |
| 304 content::BrowserThread::GetTaskRunnerForThread( |
| 305 content::BrowserThread::FILE))); |
| 306 } |
| 307 } |
| 308 |
| 309 void EncryptionMigrationScreenHandler::StopBlockingPowerSave() { |
| 310 if (power_save_blocker_.get()) { |
| 311 power_save_blocker_.reset(); |
| 312 } |
| 313 } |
| 314 |
287 cryptohome::KeyDefinition EncryptionMigrationScreenHandler::GetAuthKey() { | 315 cryptohome::KeyDefinition EncryptionMigrationScreenHandler::GetAuthKey() { |
288 // |auth_key| is created in the same manner as CryptohomeAuthenticator. | 316 // |auth_key| is created in the same manner as CryptohomeAuthenticator. |
289 const Key* key = user_context_.GetKey(); | 317 const Key* key = user_context_.GetKey(); |
290 // If the |key| is a plain text password, crash rather than attempting to | 318 // If the |key| is a plain text password, crash rather than attempting to |
291 // mount the cryptohome with a plain text password. | 319 // mount the cryptohome with a plain text password. |
292 CHECK_NE(Key::KEY_TYPE_PASSWORD_PLAIN, key->GetKeyType()); | 320 CHECK_NE(Key::KEY_TYPE_PASSWORD_PLAIN, key->GetKeyType()); |
293 // Set the authentication's key label to an empty string, which is a wildcard | 321 // Set the authentication's key label to an empty string, which is a wildcard |
294 // allowing any key to match. This is necessary because cryptohomes created by | 322 // allowing any key to match. This is necessary because cryptohomes created by |
295 // Chrome OS M38 and older will have a legacy key with no label while those | 323 // Chrome OS M38 and older will have a legacy key with no label while those |
296 // created by Chrome OS M39 and newer will have a key with the label | 324 // created by Chrome OS M39 and newer will have a key with the label |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 void EncryptionMigrationScreenHandler::OnMigrationRequested(bool success) { | 359 void EncryptionMigrationScreenHandler::OnMigrationRequested(bool success) { |
332 // This function is called when MigrateToDircrypto is correctly requested. | 360 // This function is called when MigrateToDircrypto is correctly requested. |
333 // It does not mean that the migration is completed. We should know the | 361 // It does not mean that the migration is completed. We should know the |
334 // completion by DircryptoMigrationProgressHandler. success == false means a | 362 // completion by DircryptoMigrationProgressHandler. success == false means a |
335 // failure in DBus communication. | 363 // failure in DBus communication. |
336 // TODO(fukino): Handle this case. Should we retry or restart? | 364 // TODO(fukino): Handle this case. Should we retry or restart? |
337 DCHECK(success); | 365 DCHECK(success); |
338 } | 366 } |
339 | 367 |
340 } // namespace chromeos | 368 } // namespace chromeos |
OLD | NEW |