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> |
| 8 #include <utility> |
| 9 |
7 #include "chrome/browser/lifetime/application_lifetime.h" | 10 #include "chrome/browser/lifetime/application_lifetime.h" |
8 #include "chromeos/cryptohome/homedir_methods.h" | 11 #include "chromeos/cryptohome/homedir_methods.h" |
9 #include "chromeos/dbus/cryptohome_client.h" | 12 #include "chromeos/dbus/cryptohome_client.h" |
10 #include "chromeos/dbus/dbus_thread_manager.h" | 13 #include "chromeos/dbus/dbus_thread_manager.h" |
11 | 14 |
12 namespace { | 15 namespace { |
13 | 16 |
14 constexpr char kJsScreenPath[] = "login.EncryptionMigrationScreen"; | 17 constexpr char kJsScreenPath[] = "login.EncryptionMigrationScreen"; |
15 | 18 |
16 // JS API callbacks names. | 19 // JS API callbacks names. |
17 constexpr char kJsApiStartMigration[] = "startMigration"; | 20 constexpr char kJsApiStartMigration[] = "startMigration"; |
| 21 constexpr char kJsApiSkipMigration[] = "skipMigration"; |
18 constexpr char kJsApiRequestRestart[] = "requestRestart"; | 22 constexpr char kJsApiRequestRestart[] = "requestRestart"; |
19 | 23 |
20 } // namespace | 24 } // namespace |
21 | 25 |
22 namespace chromeos { | 26 namespace chromeos { |
23 | 27 |
24 EncryptionMigrationScreenHandler::EncryptionMigrationScreenHandler() | 28 EncryptionMigrationScreenHandler::EncryptionMigrationScreenHandler() |
25 : BaseScreenHandler(kScreenId), weak_ptr_factory_(this) { | 29 : BaseScreenHandler(kScreenId), weak_ptr_factory_(this) { |
26 set_call_js_prefix(kJsScreenPath); | 30 set_call_js_prefix(kJsScreenPath); |
27 } | 31 } |
(...skipping 19 matching lines...) Expand all Loading... |
47 delegate_ = delegate; | 51 delegate_ = delegate; |
48 if (page_is_ready()) | 52 if (page_is_ready()) |
49 Initialize(); | 53 Initialize(); |
50 } | 54 } |
51 | 55 |
52 void EncryptionMigrationScreenHandler::SetUserContext( | 56 void EncryptionMigrationScreenHandler::SetUserContext( |
53 const UserContext& user_context) { | 57 const UserContext& user_context) { |
54 user_context_ = user_context; | 58 user_context_ = user_context; |
55 } | 59 } |
56 | 60 |
| 61 void EncryptionMigrationScreenHandler::SetContinueLoginCallback( |
| 62 ContinueLoginCallback callback) { |
| 63 continue_login_callback_ = std::move(callback); |
| 64 } |
| 65 |
57 void EncryptionMigrationScreenHandler::DeclareLocalizedValues( | 66 void EncryptionMigrationScreenHandler::DeclareLocalizedValues( |
58 ::login::LocalizedValuesBuilder* builder) {} | 67 ::login::LocalizedValuesBuilder* builder) {} |
59 | 68 |
60 void EncryptionMigrationScreenHandler::Initialize() { | 69 void EncryptionMigrationScreenHandler::Initialize() { |
61 if (!page_is_ready() || !delegate_) | 70 if (!page_is_ready() || !delegate_) |
62 return; | 71 return; |
63 | 72 |
64 if (show_on_init_) { | 73 if (show_on_init_) { |
65 Show(); | 74 Show(); |
66 show_on_init_ = false; | 75 show_on_init_ = false; |
67 } | 76 } |
68 } | 77 } |
69 | 78 |
70 void EncryptionMigrationScreenHandler::RegisterMessages() { | 79 void EncryptionMigrationScreenHandler::RegisterMessages() { |
71 AddCallback(kJsApiStartMigration, | 80 AddCallback(kJsApiStartMigration, |
72 &EncryptionMigrationScreenHandler::HandleStartMigration); | 81 &EncryptionMigrationScreenHandler::HandleStartMigration); |
| 82 AddCallback(kJsApiSkipMigration, |
| 83 &EncryptionMigrationScreenHandler::HandleSkipMigration); |
73 AddCallback(kJsApiRequestRestart, | 84 AddCallback(kJsApiRequestRestart, |
74 &EncryptionMigrationScreenHandler::HandleRequestRestart); | 85 &EncryptionMigrationScreenHandler::HandleRequestRestart); |
75 } | 86 } |
76 | 87 |
77 void EncryptionMigrationScreenHandler::HandleStartMigration() { | 88 void EncryptionMigrationScreenHandler::HandleStartMigration() { |
78 StartMigration(); | 89 StartMigration(); |
79 } | 90 } |
80 | 91 |
| 92 void EncryptionMigrationScreenHandler::HandleSkipMigration() { |
| 93 // If the user skips migration, we mount the cryptohome without performing the |
| 94 // migration by reusing UserContext and LoginPerformer which were used in the |
| 95 // previous attempt and dropping |is_forcing_dircrypto| flag in UserContext. |
| 96 // In this case, the user can not launch ARC apps in the session, and will be |
| 97 // asked to do the migration again in the next log-in attempt. |
| 98 if (!continue_login_callback_.is_null()) { |
| 99 user_context_.SetIsForcingDircrypto(false); |
| 100 std::move(continue_login_callback_).Run(user_context_); |
| 101 } |
| 102 } |
| 103 |
81 void EncryptionMigrationScreenHandler::HandleRequestRestart() { | 104 void EncryptionMigrationScreenHandler::HandleRequestRestart() { |
82 // TODO(fukino): If the migration finished successfully, we don't need to | 105 // 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 | 106 // restart the device. Let's sign in to the desktop using the already-provided |
84 // user credential. | 107 // user credential. |
85 chrome::AttemptRestart(); | 108 chrome::AttemptRestart(); |
86 } | 109 } |
87 | 110 |
88 void EncryptionMigrationScreenHandler::UpdateUIState(UIState state) { | 111 void EncryptionMigrationScreenHandler::UpdateUIState(UIState state) { |
89 if (state == current_ui_state_) | 112 if (state == current_ui_state_) |
90 return; | 113 return; |
(...skipping 19 matching lines...) Expand all Loading... |
110 // Chrome OS M38 and older will have a legacy key with no label while those | 133 // 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 | 134 // created by Chrome OS M39 and newer will have a key with the label |
112 // kCryptohomeGAIAKeyLabel. | 135 // kCryptohomeGAIAKeyLabel. |
113 const cryptohome::KeyDefinition auth_key(key->GetSecret(), std::string(), | 136 const cryptohome::KeyDefinition auth_key(key->GetSecret(), std::string(), |
114 cryptohome::PRIV_DEFAULT); | 137 cryptohome::PRIV_DEFAULT); |
115 cryptohome::HomedirMethods::GetInstance()->MigrateToDircrypto( | 138 cryptohome::HomedirMethods::GetInstance()->MigrateToDircrypto( |
116 cryptohome::Identification(user_context_.GetAccountId()), | 139 cryptohome::Identification(user_context_.GetAccountId()), |
117 cryptohome::Authorization(auth_key), | 140 cryptohome::Authorization(auth_key), |
118 base::Bind(&EncryptionMigrationScreenHandler::OnMigrationRequested, | 141 base::Bind(&EncryptionMigrationScreenHandler::OnMigrationRequested, |
119 weak_ptr_factory_.GetWeakPtr())); | 142 weak_ptr_factory_.GetWeakPtr())); |
| 143 UpdateUIState(UIState::MIGRATING); |
120 } | 144 } |
121 | 145 |
122 void EncryptionMigrationScreenHandler::OnMigrationProgress( | 146 void EncryptionMigrationScreenHandler::OnMigrationProgress( |
123 cryptohome::DircryptoMigrationStatus status, | 147 cryptohome::DircryptoMigrationStatus status, |
124 uint64_t current, | 148 uint64_t current, |
125 uint64_t total) { | 149 uint64_t total) { |
126 switch (status) { | 150 switch (status) { |
127 case cryptohome::DIRCRYPTO_MIGRATION_INITIALIZING: | 151 case cryptohome::DIRCRYPTO_MIGRATION_INITIALIZING: |
128 UpdateUIState(UIState::MIGRATING); | 152 UpdateUIState(UIState::MIGRATING); |
129 break; | 153 break; |
(...skipping 20 matching lines...) Expand all Loading... |
150 void EncryptionMigrationScreenHandler::OnMigrationRequested(bool success) { | 174 void EncryptionMigrationScreenHandler::OnMigrationRequested(bool success) { |
151 // This function is called when MigrateToDircrypto is correctly requested. | 175 // This function is called when MigrateToDircrypto is correctly requested. |
152 // It does not mean that the migration is completed. We should know the | 176 // It does not mean that the migration is completed. We should know the |
153 // completion by DircryptoMigrationProgressHandler. success == false means a | 177 // completion by DircryptoMigrationProgressHandler. success == false means a |
154 // failure in DBus communication. | 178 // failure in DBus communication. |
155 // TODO(fukino): Handle this case. Should we retry or restart? | 179 // TODO(fukino): Handle this case. Should we retry or restart? |
156 DCHECK(success); | 180 DCHECK(success); |
157 } | 181 } |
158 | 182 |
159 } // namespace chromeos | 183 } // namespace chromeos |
OLD | NEW |