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

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

Issue 2838303003: cros: Remove user directory when encryption migration fails. (Closed)
Patch Set: Add a comment about token invalidation. 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/ui/webui/chromeos/login/encryption_migration_screen_handler.h ('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 <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/browser_process.h"
16 #include "chrome/browser/lifetime/application_lifetime.h" 16 #include "chrome/browser/lifetime/application_lifetime.h"
17 #include "chrome/grit/generated_resources.h" 17 #include "chrome/grit/generated_resources.h"
18 #include "chromeos/chromeos_switches.h" 18 #include "chromeos/chromeos_switches.h"
19 #include "chromeos/cryptohome/async_method_caller.h"
19 #include "chromeos/cryptohome/homedir_methods.h" 20 #include "chromeos/cryptohome/homedir_methods.h"
20 #include "chromeos/dbus/cryptohome_client.h" 21 #include "chromeos/dbus/cryptohome_client.h"
21 #include "chromeos/dbus/dbus_thread_manager.h" 22 #include "chromeos/dbus/dbus_thread_manager.h"
22 #include "chromeos/dbus/power_manager/power_supply_properties.pb.h" 23 #include "chromeos/dbus/power_manager/power_supply_properties.pb.h"
23 #include "chromeos/dbus/power_manager_client.h" 24 #include "chromeos/dbus/power_manager_client.h"
24 #include "components/login/localized_values_builder.h" 25 #include "components/login/localized_values_builder.h"
26 #include "components/user_manager/user_manager.h"
25 #include "content/public/browser/browser_thread.h" 27 #include "content/public/browser/browser_thread.h"
26 #include "device/power_save_blocker/power_save_blocker.h" 28 #include "device/power_save_blocker/power_save_blocker.h"
27 #include "ui/base/text/bytes_formatting.h" 29 #include "ui/base/text/bytes_formatting.h"
28 30
29 namespace { 31 namespace {
30 32
31 constexpr char kJsScreenPath[] = "login.EncryptionMigrationScreen"; 33 constexpr char kJsScreenPath[] = "login.EncryptionMigrationScreen";
32 34
33 // Path to the mount point to check the available space. 35 // Path to the mount point to check the available space.
34 constexpr char kCheckStoragePath[] = "/home"; 36 constexpr char kCheckStoragePath[] = "/home";
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 content::BrowserThread::FILE))); 307 content::BrowserThread::FILE)));
306 } 308 }
307 } 309 }
308 310
309 void EncryptionMigrationScreenHandler::StopBlockingPowerSave() { 311 void EncryptionMigrationScreenHandler::StopBlockingPowerSave() {
310 if (power_save_blocker_.get()) { 312 if (power_save_blocker_.get()) {
311 power_save_blocker_.reset(); 313 power_save_blocker_.reset();
312 } 314 }
313 } 315 }
314 316
317 void EncryptionMigrationScreenHandler::RemoveCryptohome() {
318 // Set invalid token status so that user is forced to go through Gaia on the
319 // next sign-in.
320 user_manager::UserManager::Get()->SaveUserOAuthStatus(
321 user_context_.GetAccountId(),
322 user_manager::User::OAUTH2_TOKEN_STATUS_INVALID);
323 cryptohome::AsyncMethodCaller::GetInstance()->AsyncRemove(
324 cryptohome::Identification(user_context_.GetAccountId()),
325 base::Bind(&EncryptionMigrationScreenHandler::OnRemoveCryptohome,
326 weak_ptr_factory_.GetWeakPtr()));
327 }
328
329 void EncryptionMigrationScreenHandler::OnRemoveCryptohome(
330 bool success,
331 cryptohome::MountError return_code) {
332 LOG_IF(ERROR, !success) << "Removing cryptohome failed. return code: "
333 << return_code;
334 UpdateUIState(UIState::MIGRATION_FAILED);
335 }
336
315 cryptohome::KeyDefinition EncryptionMigrationScreenHandler::GetAuthKey() { 337 cryptohome::KeyDefinition EncryptionMigrationScreenHandler::GetAuthKey() {
316 // |auth_key| is created in the same manner as CryptohomeAuthenticator. 338 // |auth_key| is created in the same manner as CryptohomeAuthenticator.
317 const Key* key = user_context_.GetKey(); 339 const Key* key = user_context_.GetKey();
318 // If the |key| is a plain text password, crash rather than attempting to 340 // If the |key| is a plain text password, crash rather than attempting to
319 // mount the cryptohome with a plain text password. 341 // mount the cryptohome with a plain text password.
320 CHECK_NE(Key::KEY_TYPE_PASSWORD_PLAIN, key->GetKeyType()); 342 CHECK_NE(Key::KEY_TYPE_PASSWORD_PLAIN, key->GetKeyType());
321 // Set the authentication's key label to an empty string, which is a wildcard 343 // Set the authentication's key label to an empty string, which is a wildcard
322 // allowing any key to match. This is necessary because cryptohomes created by 344 // allowing any key to match. This is necessary because cryptohomes created by
323 // Chrome OS M38 and older will have a legacy key with no label while those 345 // Chrome OS M38 and older will have a legacy key with no label while those
324 // created by Chrome OS M39 and newer will have a key with the label 346 // created by Chrome OS M39 and newer will have a key with the label
(...skipping 12 matching lines...) Expand all
337 break; 359 break;
338 case cryptohome::DIRCRYPTO_MIGRATION_IN_PROGRESS: 360 case cryptohome::DIRCRYPTO_MIGRATION_IN_PROGRESS:
339 UpdateUIState(UIState::MIGRATING); 361 UpdateUIState(UIState::MIGRATING);
340 CallJS("setMigrationProgress", static_cast<double>(current) / total); 362 CallJS("setMigrationProgress", static_cast<double>(current) / total);
341 break; 363 break;
342 case cryptohome::DIRCRYPTO_MIGRATION_SUCCESS: 364 case cryptohome::DIRCRYPTO_MIGRATION_SUCCESS:
343 // Restart immediately after successful migration. 365 // Restart immediately after successful migration.
344 DBusThreadManager::Get()->GetPowerManagerClient()->RequestRestart(); 366 DBusThreadManager::Get()->GetPowerManagerClient()->RequestRestart();
345 break; 367 break;
346 case cryptohome::DIRCRYPTO_MIGRATION_FAILED: 368 case cryptohome::DIRCRYPTO_MIGRATION_FAILED:
347 UpdateUIState(UIState::MIGRATION_FAILED);
348 // Stop listening to the progress updates. 369 // Stop listening to the progress updates.
349 DBusThreadManager::Get() 370 DBusThreadManager::Get()
350 ->GetCryptohomeClient() 371 ->GetCryptohomeClient()
351 ->SetDircryptoMigrationProgressHandler( 372 ->SetDircryptoMigrationProgressHandler(
352 CryptohomeClient::DircryptoMigrationProgessHandler()); 373 CryptohomeClient::DircryptoMigrationProgessHandler());
374 // Shows error screen after removing user directory is completed.
375 RemoveCryptohome();
353 break; 376 break;
354 default: 377 default:
355 break; 378 break;
356 } 379 }
357 } 380 }
358 381
359 void EncryptionMigrationScreenHandler::OnMigrationRequested(bool success) { 382 void EncryptionMigrationScreenHandler::OnMigrationRequested(bool success) {
360 // This function is called when MigrateToDircrypto is correctly requested. 383 LOG_IF(ERROR, !success) << "Requesting MigrateToDircrypto failed.";
361 // It does not mean that the migration is completed. We should know the 384 UpdateUIState(UIState::MIGRATION_FAILED);
362 // completion by DircryptoMigrationProgressHandler. success == false means a
363 // failure in DBus communication.
364 // TODO(fukino): Handle this case. Should we retry or restart?
365 DCHECK(success);
366 } 385 }
367 386
368 } // namespace chromeos 387 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/chromeos/login/encryption_migration_screen_handler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698