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 "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) { |
17 set_call_js_prefix(kJsScreenPath); | 26 set_call_js_prefix(kJsScreenPath); |
18 } | 27 } |
19 | 28 |
20 EncryptionMigrationScreenHandler::~EncryptionMigrationScreenHandler() { | 29 EncryptionMigrationScreenHandler::~EncryptionMigrationScreenHandler() { |
(...skipping 12 matching lines...) Expand all Loading... | |
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 chrome::AttemptRestart(); | |
xiyuan
2017/03/30 17:55:40
IMHO, continuing signing in would be be better tha
fukino
2017/03/31 02:29:52
I agree with it.
I changed the button on the final
| |
83 } | |
84 | |
85 void EncryptionMigrationScreenHandler::UpdateUIState(UIState state) { | |
86 if (state == current_ui_state_) | |
87 return; | |
88 | |
89 current_ui_state_ = state; | |
90 CallJS("setUIState", static_cast<int>(state)); | |
91 } | |
92 | |
93 void EncryptionMigrationScreenHandler::StartMigration() { | |
94 DBusThreadManager::Get() | |
95 ->GetCryptohomeClient() | |
96 ->SetDircryptoMigrationProgressHandler( | |
97 base::Bind(&EncryptionMigrationScreenHandler::OnMigrationProgress, | |
98 base::Unretained(this))); | |
99 | |
100 // |auth_key| is created in the same manner as CryptohomeAuthenticator. | |
101 const Key* key = user_context_.GetKey(); | |
102 // If the |key| is a plain text password, crash rather than attempting to | |
103 // mount the cryptohome with a plain text password. | |
104 CHECK_NE(Key::KEY_TYPE_PASSWORD_PLAIN, key->GetKeyType()); | |
105 // Set the authentication's key label to an empty string, which is a wildcard | |
106 // allowing any key to match. This is necessary because cryptohomes created by | |
107 // Chrome OS M38 and older will have a legacy key with no label while those | |
108 // created by Chrome OS M39 and newer will have a key with the label | |
109 // kCryptohomeGAIAKeyLabel. | |
110 const cryptohome::KeyDefinition auth_key(key->GetSecret(), std::string(), | |
111 cryptohome::PRIV_DEFAULT); | |
112 cryptohome::HomedirMethods::GetInstance()->MigrateToDircrypto( | |
113 cryptohome::Identification(user_context_.GetAccountId()), | |
114 cryptohome::Authorization(auth_key), | |
115 base::Bind(&EncryptionMigrationScreenHandler::OnMigrationRequested, | |
116 base::Unretained(this))); | |
xiyuan
2017/03/30 17:55:40
Let's use a WeakPtr instead of Unretained even tho
fukino
2017/03/31 02:29:52
Done.
| |
117 } | |
118 | |
119 void EncryptionMigrationScreenHandler::OnMigrationProgress( | |
120 cryptohome::DircryptoMigrationStatus status, | |
121 uint64_t current, | |
122 uint64_t total) { | |
123 switch (status) { | |
124 case cryptohome::DIRCRYPTO_MIGRATION_INITIALIZING: | |
125 UpdateUIState(UIState::MIGRATING); | |
126 break; | |
127 case cryptohome::DIRCRYPTO_MIGRATION_IN_PROGRESS: | |
128 UpdateUIState(UIState::MIGRATING); | |
129 CallJS("setMigrationProgress", static_cast<double>(current) / total); | |
130 break; | |
131 case cryptohome::DIRCRYPTO_MIGRATION_SUCCESS: | |
132 case cryptohome::DIRCRYPTO_MIGRATION_FAILED: | |
133 UpdateUIState(status == cryptohome::DIRCRYPTO_MIGRATION_SUCCESS | |
134 ? UIState::MIGRATION_SUCCEEDED | |
135 : UIState::MIGRATION_FAILED); | |
136 // Stop listening to the progress updates. | |
137 DBusThreadManager::Get() | |
138 ->GetCryptohomeClient() | |
139 ->SetDircryptoMigrationProgressHandler( | |
140 CryptohomeClient::DircryptoMigrationProgessHandler()); | |
141 break; | |
142 default: | |
143 break; | |
144 } | |
145 } | |
146 | |
147 void EncryptionMigrationScreenHandler::OnMigrationRequested(bool success) { | |
148 // This function is called when MigrateToDircrypto is correctly requested. | |
149 // It does not mean that the migration is completed. We should know the | |
150 // completion by DircryptoMigrationProgressHandler. success == false means a | |
151 // failure in DBus communication. | |
152 // TODO(fukino): Handle this case. Should we retry or restart? | |
153 DCHECK(success); | |
154 } | |
155 | |
56 } // namespace chromeos | 156 } // namespace chromeos |
OLD | NEW |