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

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

Issue 2811713002: Check the available storage size before starting encryption migration. (Closed)
Patch Set: . 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 <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";
fukino 2017/04/10 12:08:50 I'd like to call statvfs to a path on the stateful
xiyuan 2017/04/10 17:24:55 I am fine with using hard-coded "/home". I am not
fukino 2017/04/10 23:04:58 I call statvfs on "/home" to check the available s
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
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 if (should_resume_) {
81 // TODO(fukino): Handle the following case.
xiyuan 2017/04/10 17:24:55 Why not always start with CheckAvailableStorage()
fukino 2017/04/12 01:43:05 You are right. It is much simpler to always start
82 //
83 // 1) User A starts migration, but shuts down the device during migration.
84 // 2) User B signs in to the device and fills the storage.
85 // 3) User A signs in. The user needs resume the migration, but no space.
86 //
87 // If we don't handle this case, the user A's profile can be wiped due to
88 // the failure of migration in step 3. (or B's profile can be wiped by
89 // periodical disk cleanup.)
90 // By providing "Sign out" option for this situation, we might be able to
91 // avoid profile removal.
92 StartMigration();
93 } else {
94 CheckAvailableStorage();
95 }
96 }
97
73 void EncryptionMigrationScreenHandler::DeclareLocalizedValues( 98 void EncryptionMigrationScreenHandler::DeclareLocalizedValues(
74 ::login::LocalizedValuesBuilder* builder) {} 99 ::login::LocalizedValuesBuilder* builder) {}
75 100
76 void EncryptionMigrationScreenHandler::Initialize() { 101 void EncryptionMigrationScreenHandler::Initialize() {
77 if (!page_is_ready() || !delegate_) 102 if (!page_is_ready() || !delegate_)
78 return; 103 return;
79 104
80 if (show_on_init_) { 105 if (show_on_init_) {
81 Show(); 106 Show();
82 show_on_init_ = false; 107 show_on_init_ = false;
83 } 108 }
84 } 109 }
85 110
86 void EncryptionMigrationScreenHandler::RegisterMessages() { 111 void EncryptionMigrationScreenHandler::RegisterMessages() {
87 AddCallback(kJsApiStartMigration, 112 AddCallback(kJsApiStartMigration,
88 &EncryptionMigrationScreenHandler::HandleStartMigration); 113 &EncryptionMigrationScreenHandler::HandleStartMigration);
89 AddCallback(kJsApiSkipMigration, 114 AddCallback(kJsApiSkipMigration,
90 &EncryptionMigrationScreenHandler::HandleSkipMigration); 115 &EncryptionMigrationScreenHandler::HandleSkipMigration);
91 AddCallback(kJsApiRequestRestart, 116 AddCallback(kJsApiRequestRestart,
92 &EncryptionMigrationScreenHandler::HandleRequestRestart); 117 &EncryptionMigrationScreenHandler::HandleRequestRestart);
93 } 118 }
94 119
95 void EncryptionMigrationScreenHandler::HandleStartMigration() { 120 void EncryptionMigrationScreenHandler::HandleStartMigration() {
96 // TODO(fukino): Wait until the battery gets enough level.
97 StartMigration(); 121 StartMigration();
98 } 122 }
99 123
100 void EncryptionMigrationScreenHandler::HandleSkipMigration() { 124 void EncryptionMigrationScreenHandler::HandleSkipMigration() {
101 // If the user skips migration, we mount the cryptohome without performing the 125 // If the user skips migration, we mount the cryptohome without performing the
102 // migration by reusing UserContext and LoginPerformer which were used in the 126 // migration by reusing UserContext and LoginPerformer which were used in the
103 // previous attempt and dropping |is_forcing_dircrypto| flag in UserContext. 127 // 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 128 // 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. 129 // asked to do the migration again in the next log-in attempt.
106 if (!continue_login_callback_.is_null()) { 130 if (!continue_login_callback_.is_null()) {
(...skipping 10 matching lines...) Expand all
117 } 141 }
118 142
119 void EncryptionMigrationScreenHandler::UpdateUIState(UIState state) { 143 void EncryptionMigrationScreenHandler::UpdateUIState(UIState state) {
120 if (state == current_ui_state_) 144 if (state == current_ui_state_)
121 return; 145 return;
122 146
123 current_ui_state_ = state; 147 current_ui_state_ = state;
124 CallJS("setUIState", static_cast<int>(state)); 148 CallJS("setUIState", static_cast<int>(state));
125 } 149 }
126 150
151 void EncryptionMigrationScreenHandler::CheckAvailableStorage() {
152 base::PostTaskWithTraitsAndReplyWithResult(
153 FROM_HERE,
154 base::TaskTraits().MayBlock().WithPriority(
155 base::TaskPriority::USER_VISIBLE),
156 base::Bind(&base::SysInfo::AmountOfFreeDiskSpace,
157 base::FilePath(kCheckStoragePath)),
158 base::Bind(&EncryptionMigrationScreenHandler::OnGetAvailableStorage,
159 weak_ptr_factory_.GetWeakPtr()));
160 }
161
162 void EncryptionMigrationScreenHandler::OnGetAvailableStorage(int64_t size) {
163 if (size < kMinimumAvailableStorage) {
164 UpdateUIState(NOT_ENOUGH_STORAGE);
165 } else {
166 // TODO(fukino): Check the battery level.
167 UpdateUIState(READY);
168 }
169 }
170
127 void EncryptionMigrationScreenHandler::StartMigration() { 171 void EncryptionMigrationScreenHandler::StartMigration() {
128 DBusThreadManager::Get() 172 DBusThreadManager::Get()
129 ->GetCryptohomeClient() 173 ->GetCryptohomeClient()
130 ->SetDircryptoMigrationProgressHandler( 174 ->SetDircryptoMigrationProgressHandler(
131 base::Bind(&EncryptionMigrationScreenHandler::OnMigrationProgress, 175 base::Bind(&EncryptionMigrationScreenHandler::OnMigrationProgress,
132 weak_ptr_factory_.GetWeakPtr())); 176 weak_ptr_factory_.GetWeakPtr()));
133 177
134 // |auth_key| is created in the same manner as CryptohomeAuthenticator. 178 // |auth_key| is created in the same manner as CryptohomeAuthenticator.
135 const Key* key = user_context_.GetKey(); 179 const Key* key = user_context_.GetKey();
136 // If the |key| is a plain text password, crash rather than attempting to 180 // 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
182 void EncryptionMigrationScreenHandler::OnMigrationRequested(bool success) { 226 void EncryptionMigrationScreenHandler::OnMigrationRequested(bool success) {
183 // This function is called when MigrateToDircrypto is correctly requested. 227 // This function is called when MigrateToDircrypto is correctly requested.
184 // It does not mean that the migration is completed. We should know the 228 // It does not mean that the migration is completed. We should know the
185 // completion by DircryptoMigrationProgressHandler. success == false means a 229 // completion by DircryptoMigrationProgressHandler. success == false means a
186 // failure in DBus communication. 230 // failure in DBus communication.
187 // TODO(fukino): Handle this case. Should we retry or restart? 231 // TODO(fukino): Handle this case. Should we retry or restart?
188 DCHECK(success); 232 DCHECK(success);
189 } 233 }
190 234
191 } // namespace chromeos 235 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698