| 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 "base/files/file_path.h" |
| 11 #include "base/sys_info.h" |
| 12 #include "base/task_scheduler/post_task.h" |
| 10 #include "chrome/browser/lifetime/application_lifetime.h" | 13 #include "chrome/browser/lifetime/application_lifetime.h" |
| 11 #include "chromeos/cryptohome/homedir_methods.h" | 14 #include "chromeos/cryptohome/homedir_methods.h" |
| 12 #include "chromeos/dbus/cryptohome_client.h" | 15 #include "chromeos/dbus/cryptohome_client.h" |
| 13 #include "chromeos/dbus/dbus_thread_manager.h" | 16 #include "chromeos/dbus/dbus_thread_manager.h" |
| 14 | 17 |
| 15 namespace { | 18 namespace { |
| 16 | 19 |
| 17 constexpr char kJsScreenPath[] = "login.EncryptionMigrationScreen"; | 20 constexpr char kJsScreenPath[] = "login.EncryptionMigrationScreen"; |
| 18 | 21 |
| 22 // Path to the mount point to check the available space. |
| 23 constexpr char kCheckStoragePath[] = "/home"; |
| 24 |
| 25 // The minimum size of available space to start the migration. |
| 26 constexpr int64_t kMinimumAvailableStorage = 10LL * 1024 * 1024; // 10MB |
| 27 |
| 19 // JS API callbacks names. | 28 // JS API callbacks names. |
| 20 constexpr char kJsApiStartMigration[] = "startMigration"; | 29 constexpr char kJsApiStartMigration[] = "startMigration"; |
| 21 constexpr char kJsApiSkipMigration[] = "skipMigration"; | 30 constexpr char kJsApiSkipMigration[] = "skipMigration"; |
| 22 constexpr char kJsApiRequestRestart[] = "requestRestart"; | 31 constexpr char kJsApiRequestRestart[] = "requestRestart"; |
| 23 | 32 |
| 24 } // namespace | 33 } // namespace |
| 25 | 34 |
| 26 namespace chromeos { | 35 namespace chromeos { |
| 27 | 36 |
| 28 EncryptionMigrationScreenHandler::EncryptionMigrationScreenHandler() | 37 EncryptionMigrationScreenHandler::EncryptionMigrationScreenHandler() |
| (...skipping 23 matching lines...) Expand all Loading... |
| 52 if (page_is_ready()) | 61 if (page_is_ready()) |
| 53 Initialize(); | 62 Initialize(); |
| 54 } | 63 } |
| 55 | 64 |
| 56 void EncryptionMigrationScreenHandler::SetUserContext( | 65 void EncryptionMigrationScreenHandler::SetUserContext( |
| 57 const UserContext& user_context) { | 66 const UserContext& user_context) { |
| 58 user_context_ = user_context; | 67 user_context_ = user_context; |
| 59 } | 68 } |
| 60 | 69 |
| 61 void EncryptionMigrationScreenHandler::SetShouldResume(bool should_resume) { | 70 void EncryptionMigrationScreenHandler::SetShouldResume(bool should_resume) { |
| 62 if (current_ui_state_ == INITIAL && should_resume) { | 71 should_resume_ = should_resume; |
| 63 // TODO(fukino): Wait until the battery gets enough level. | |
| 64 StartMigration(); | |
| 65 } | |
| 66 } | 72 } |
| 67 | 73 |
| 68 void EncryptionMigrationScreenHandler::SetContinueLoginCallback( | 74 void EncryptionMigrationScreenHandler::SetContinueLoginCallback( |
| 69 ContinueLoginCallback callback) { | 75 ContinueLoginCallback callback) { |
| 70 continue_login_callback_ = std::move(callback); | 76 continue_login_callback_ = std::move(callback); |
| 71 } | 77 } |
| 72 | 78 |
| 79 void EncryptionMigrationScreenHandler::SetupInitialView() { |
| 80 CheckAvailableStorage(); |
| 81 } |
| 82 |
| 73 void EncryptionMigrationScreenHandler::DeclareLocalizedValues( | 83 void EncryptionMigrationScreenHandler::DeclareLocalizedValues( |
| 74 ::login::LocalizedValuesBuilder* builder) {} | 84 ::login::LocalizedValuesBuilder* builder) {} |
| 75 | 85 |
| 76 void EncryptionMigrationScreenHandler::Initialize() { | 86 void EncryptionMigrationScreenHandler::Initialize() { |
| 77 if (!page_is_ready() || !delegate_) | 87 if (!page_is_ready() || !delegate_) |
| 78 return; | 88 return; |
| 79 | 89 |
| 80 if (show_on_init_) { | 90 if (show_on_init_) { |
| 81 Show(); | 91 Show(); |
| 82 show_on_init_ = false; | 92 show_on_init_ = false; |
| 83 } | 93 } |
| 84 } | 94 } |
| 85 | 95 |
| 86 void EncryptionMigrationScreenHandler::RegisterMessages() { | 96 void EncryptionMigrationScreenHandler::RegisterMessages() { |
| 87 AddCallback(kJsApiStartMigration, | 97 AddCallback(kJsApiStartMigration, |
| 88 &EncryptionMigrationScreenHandler::HandleStartMigration); | 98 &EncryptionMigrationScreenHandler::HandleStartMigration); |
| 89 AddCallback(kJsApiSkipMigration, | 99 AddCallback(kJsApiSkipMigration, |
| 90 &EncryptionMigrationScreenHandler::HandleSkipMigration); | 100 &EncryptionMigrationScreenHandler::HandleSkipMigration); |
| 91 AddCallback(kJsApiRequestRestart, | 101 AddCallback(kJsApiRequestRestart, |
| 92 &EncryptionMigrationScreenHandler::HandleRequestRestart); | 102 &EncryptionMigrationScreenHandler::HandleRequestRestart); |
| 93 } | 103 } |
| 94 | 104 |
| 95 void EncryptionMigrationScreenHandler::HandleStartMigration() { | 105 void EncryptionMigrationScreenHandler::HandleStartMigration() { |
| 96 // TODO(fukino): Wait until the battery gets enough level. | |
| 97 StartMigration(); | 106 StartMigration(); |
| 98 } | 107 } |
| 99 | 108 |
| 100 void EncryptionMigrationScreenHandler::HandleSkipMigration() { | 109 void EncryptionMigrationScreenHandler::HandleSkipMigration() { |
| 101 // If the user skips migration, we mount the cryptohome without performing the | 110 // If the user skips migration, we mount the cryptohome without performing the |
| 102 // migration by reusing UserContext and LoginPerformer which were used in the | 111 // migration by reusing UserContext and LoginPerformer which were used in the |
| 103 // previous attempt and dropping |is_forcing_dircrypto| flag in UserContext. | 112 // previous attempt and dropping |is_forcing_dircrypto| flag in UserContext. |
| 104 // In this case, the user can not launch ARC apps in the session, and will be | 113 // In this case, the user can not launch ARC apps in the session, and will be |
| 105 // asked to do the migration again in the next log-in attempt. | 114 // asked to do the migration again in the next log-in attempt. |
| 106 if (!continue_login_callback_.is_null()) { | 115 if (!continue_login_callback_.is_null()) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 117 } | 126 } |
| 118 | 127 |
| 119 void EncryptionMigrationScreenHandler::UpdateUIState(UIState state) { | 128 void EncryptionMigrationScreenHandler::UpdateUIState(UIState state) { |
| 120 if (state == current_ui_state_) | 129 if (state == current_ui_state_) |
| 121 return; | 130 return; |
| 122 | 131 |
| 123 current_ui_state_ = state; | 132 current_ui_state_ = state; |
| 124 CallJS("setUIState", static_cast<int>(state)); | 133 CallJS("setUIState", static_cast<int>(state)); |
| 125 } | 134 } |
| 126 | 135 |
| 136 void EncryptionMigrationScreenHandler::CheckAvailableStorage() { |
| 137 base::PostTaskWithTraitsAndReplyWithResult( |
| 138 FROM_HERE, |
| 139 base::TaskTraits().MayBlock().WithPriority( |
| 140 base::TaskPriority::USER_VISIBLE), |
| 141 base::Bind(&base::SysInfo::AmountOfFreeDiskSpace, |
| 142 base::FilePath(kCheckStoragePath)), |
| 143 base::Bind(&EncryptionMigrationScreenHandler::OnGetAvailableStorage, |
| 144 weak_ptr_factory_.GetWeakPtr())); |
| 145 } |
| 146 |
| 147 void EncryptionMigrationScreenHandler::OnGetAvailableStorage(int64_t size) { |
| 148 if (size < kMinimumAvailableStorage) { |
| 149 UpdateUIState(NOT_ENOUGH_STORAGE); |
| 150 CallJS("setIsResuming", should_resume_); |
| 151 } else { |
| 152 if (should_resume_) { |
| 153 // TODO(fukino): Check the battery level. |
| 154 StartMigration(); |
| 155 } else { |
| 156 UpdateUIState(READY); |
| 157 } |
| 158 } |
| 159 } |
| 160 |
| 127 void EncryptionMigrationScreenHandler::StartMigration() { | 161 void EncryptionMigrationScreenHandler::StartMigration() { |
| 128 DBusThreadManager::Get() | 162 DBusThreadManager::Get() |
| 129 ->GetCryptohomeClient() | 163 ->GetCryptohomeClient() |
| 130 ->SetDircryptoMigrationProgressHandler( | 164 ->SetDircryptoMigrationProgressHandler( |
| 131 base::Bind(&EncryptionMigrationScreenHandler::OnMigrationProgress, | 165 base::Bind(&EncryptionMigrationScreenHandler::OnMigrationProgress, |
| 132 weak_ptr_factory_.GetWeakPtr())); | 166 weak_ptr_factory_.GetWeakPtr())); |
| 133 | 167 |
| 134 // |auth_key| is created in the same manner as CryptohomeAuthenticator. | 168 // |auth_key| is created in the same manner as CryptohomeAuthenticator. |
| 135 const Key* key = user_context_.GetKey(); | 169 const Key* key = user_context_.GetKey(); |
| 136 // If the |key| is a plain text password, crash rather than attempting to | 170 // If the |key| is a plain text password, crash rather than attempting to |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 void EncryptionMigrationScreenHandler::OnMigrationRequested(bool success) { | 216 void EncryptionMigrationScreenHandler::OnMigrationRequested(bool success) { |
| 183 // This function is called when MigrateToDircrypto is correctly requested. | 217 // This function is called when MigrateToDircrypto is correctly requested. |
| 184 // It does not mean that the migration is completed. We should know the | 218 // It does not mean that the migration is completed. We should know the |
| 185 // completion by DircryptoMigrationProgressHandler. success == false means a | 219 // completion by DircryptoMigrationProgressHandler. success == false means a |
| 186 // failure in DBus communication. | 220 // failure in DBus communication. |
| 187 // TODO(fukino): Handle this case. Should we retry or restart? | 221 // TODO(fukino): Handle this case. Should we retry or restart? |
| 188 DCHECK(success); | 222 DCHECK(success); |
| 189 } | 223 } |
| 190 | 224 |
| 191 } // namespace chromeos | 225 } // namespace chromeos |
| OLD | NEW |