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

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

Issue 2784273003: Implement a basic UI flow for cryptohome encryption migration. (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 "chrome/browser/lifetime/application_lifetime.h"
8 #include "chromeos/cryptohome/homedir_methods.h"
9 #include "chromeos/dbus/cryptohome_client.h"
10 #include "chromeos/dbus/dbus_thread_manager.h"
11
7 namespace { 12 namespace {
8 13
9 constexpr char kJsScreenPath[] = "login.EncryptionMigrationScreen"; 14 constexpr char kJsScreenPath[] = "login.EncryptionMigrationScreen";
10 15
16 // JS API callbacks names.
17 constexpr char kJsApiStartMigration[] = "startMigration";
18 constexpr char kJsApiRequestRestart[] = "requestRestart";
19
11 } // namespace 20 } // namespace
12 21
13 namespace chromeos { 22 namespace chromeos {
14 23
15 EncryptionMigrationScreenHandler::EncryptionMigrationScreenHandler() 24 EncryptionMigrationScreenHandler::EncryptionMigrationScreenHandler()
16 : BaseScreenHandler(kScreenId) { 25 : BaseScreenHandler(kScreenId), weak_ptr_factory_(this) {
17 set_call_js_prefix(kJsScreenPath); 26 set_call_js_prefix(kJsScreenPath);
18 } 27 }
19 28
20 EncryptionMigrationScreenHandler::~EncryptionMigrationScreenHandler() { 29 EncryptionMigrationScreenHandler::~EncryptionMigrationScreenHandler() {
21 if (delegate_) 30 if (delegate_)
22 delegate_->OnViewDestroyed(this); 31 delegate_->OnViewDestroyed(this);
23 } 32 }
24 33
25 void EncryptionMigrationScreenHandler::Show() { 34 void EncryptionMigrationScreenHandler::Show() {
26 if (!page_is_ready() || !delegate_) { 35 if (!page_is_ready() || !delegate_) {
27 show_on_init_ = true; 36 show_on_init_ = true;
28 return; 37 return;
29 } 38 }
30 ShowScreen(kScreenId); 39 ShowScreen(kScreenId);
31 } 40 }
32 41
33 void EncryptionMigrationScreenHandler::Hide() { 42 void EncryptionMigrationScreenHandler::Hide() {
34 show_on_init_ = false; 43 show_on_init_ = false;
35 } 44 }
36 45
37 void EncryptionMigrationScreenHandler::SetDelegate(Delegate* delegate) { 46 void EncryptionMigrationScreenHandler::SetDelegate(Delegate* delegate) {
38 delegate_ = delegate; 47 delegate_ = delegate;
39 if (page_is_ready()) 48 if (page_is_ready())
40 Initialize(); 49 Initialize();
41 } 50 }
42 51
52 void EncryptionMigrationScreenHandler::SetUserContext(
53 const UserContext& user_context) {
54 user_context_ = user_context;
55 }
56
43 void EncryptionMigrationScreenHandler::DeclareLocalizedValues( 57 void EncryptionMigrationScreenHandler::DeclareLocalizedValues(
44 ::login::LocalizedValuesBuilder* builder) {} 58 ::login::LocalizedValuesBuilder* builder) {}
45 59
46 void EncryptionMigrationScreenHandler::Initialize() { 60 void EncryptionMigrationScreenHandler::Initialize() {
47 if (!page_is_ready() || !delegate_) 61 if (!page_is_ready() || !delegate_)
48 return; 62 return;
49 63
50 if (show_on_init_) { 64 if (show_on_init_) {
51 Show(); 65 Show();
52 show_on_init_ = false; 66 show_on_init_ = false;
53 } 67 }
54 } 68 }
55 69
70 void EncryptionMigrationScreenHandler::RegisterMessages() {
71 AddCallback(kJsApiStartMigration,
72 &EncryptionMigrationScreenHandler::HandleStartMigration);
73 AddCallback(kJsApiRequestRestart,
74 &EncryptionMigrationScreenHandler::HandleRequestRestart);
75 }
76
77 void EncryptionMigrationScreenHandler::HandleStartMigration() {
78 StartMigration();
79 }
80
81 void EncryptionMigrationScreenHandler::HandleRequestRestart() {
82 // TODO(fukino): If the migration finished successfully, we don't need to
83 // restart the device. Let's sign in to the desktop using the already-provided
84 // user credential.
85 chrome::AttemptRestart();
86 }
87
88 void EncryptionMigrationScreenHandler::UpdateUIState(UIState state) {
89 if (state == current_ui_state_)
90 return;
91
92 current_ui_state_ = state;
93 CallJS("setUIState", static_cast<int>(state));
94 }
95
96 void EncryptionMigrationScreenHandler::StartMigration() {
97 DBusThreadManager::Get()
98 ->GetCryptohomeClient()
99 ->SetDircryptoMigrationProgressHandler(
100 base::Bind(&EncryptionMigrationScreenHandler::OnMigrationProgress,
101 weak_ptr_factory_.GetWeakPtr()));
102
103 // |auth_key| is created in the same manner as CryptohomeAuthenticator.
104 const Key* key = user_context_.GetKey();
105 // If the |key| is a plain text password, crash rather than attempting to
106 // mount the cryptohome with a plain text password.
107 CHECK_NE(Key::KEY_TYPE_PASSWORD_PLAIN, key->GetKeyType());
108 // Set the authentication's key label to an empty string, which is a wildcard
109 // allowing any key to match. This is necessary because cryptohomes created by
110 // Chrome OS M38 and older will have a legacy key with no label while those
111 // created by Chrome OS M39 and newer will have a key with the label
112 // kCryptohomeGAIAKeyLabel.
113 const cryptohome::KeyDefinition auth_key(key->GetSecret(), std::string(),
114 cryptohome::PRIV_DEFAULT);
115 cryptohome::HomedirMethods::GetInstance()->MigrateToDircrypto(
116 cryptohome::Identification(user_context_.GetAccountId()),
117 cryptohome::Authorization(auth_key),
118 base::Bind(&EncryptionMigrationScreenHandler::OnMigrationRequested,
119 weak_ptr_factory_.GetWeakPtr()));
120 }
121
122 void EncryptionMigrationScreenHandler::OnMigrationProgress(
123 cryptohome::DircryptoMigrationStatus status,
124 uint64_t current,
125 uint64_t total) {
126 switch (status) {
127 case cryptohome::DIRCRYPTO_MIGRATION_INITIALIZING:
128 UpdateUIState(UIState::MIGRATING);
129 break;
130 case cryptohome::DIRCRYPTO_MIGRATION_IN_PROGRESS:
131 UpdateUIState(UIState::MIGRATING);
132 CallJS("setMigrationProgress", static_cast<double>(current) / total);
133 break;
134 case cryptohome::DIRCRYPTO_MIGRATION_SUCCESS:
135 case cryptohome::DIRCRYPTO_MIGRATION_FAILED:
136 UpdateUIState(status == cryptohome::DIRCRYPTO_MIGRATION_SUCCESS
137 ? UIState::MIGRATION_SUCCEEDED
138 : UIState::MIGRATION_FAILED);
139 // Stop listening to the progress updates.
140 DBusThreadManager::Get()
141 ->GetCryptohomeClient()
142 ->SetDircryptoMigrationProgressHandler(
143 CryptohomeClient::DircryptoMigrationProgessHandler());
144 break;
145 default:
146 break;
147 }
148 }
149
150 void EncryptionMigrationScreenHandler::OnMigrationRequested(bool success) {
151 // This function is called when MigrateToDircrypto is correctly requested.
152 // It does not mean that the migration is completed. We should know the
153 // completion by DircryptoMigrationProgressHandler. success == false means a
154 // failure in DBus communication.
155 // TODO(fukino): Handle this case. Should we retry or restart?
156 DCHECK(success);
157 }
158
56 } // namespace chromeos 159 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/chromeos/login/encryption_migration_screen_handler.h ('k') | chromeos/dbus/fake_cryptohome_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698