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

Side by Side Diff: chrome/browser/signin/easy_unlock_service_regular.cc

Issue 808563004: Clean up Smart Lock cryptohome keys logic: (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixes Created 6 years 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/signin/easy_unlock_service_regular.h" 5 #include "chrome/browser/signin/easy_unlock_service_regular.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/prefs/pref_service.h" 9 #include "base/prefs/pref_service.h"
10 #include "base/prefs/scoped_user_pref_update.h" 10 #include "base/prefs/scoped_user_pref_update.h"
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 84
85 #if defined(OS_CHROMEOS) 85 #if defined(OS_CHROMEOS)
86 void EasyUnlockServiceRegular::OnUserContextFromReauth( 86 void EasyUnlockServiceRegular::OnUserContextFromReauth(
87 const chromeos::UserContext& user_context) { 87 const chromeos::UserContext& user_context) {
88 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 88 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
89 short_lived_user_context_.reset(new chromeos::ShortLivedUserContext( 89 short_lived_user_context_.reset(new chromeos::ShortLivedUserContext(
90 user_context, apps::AppLifetimeMonitorFactory::GetForProfile(profile()), 90 user_context, apps::AppLifetimeMonitorFactory::GetForProfile(profile()),
91 base::ThreadTaskRunnerHandle::Get().get())); 91 base::ThreadTaskRunnerHandle::Get().get()));
92 92
93 OpenSetupApp(); 93 OpenSetupApp();
94
95 // Use this opportunity to clear the crytohome keys if it was not already
96 // cleared earlier.
97 const base::ListValue* devices = GetRemoteDevices();
98 if (!devices || devices->empty()) {
99 chromeos::EasyUnlockKeyManager* key_manager =
100 chromeos::UserSessionManager::GetInstance()->GetEasyUnlockKeyManager();
101 key_manager->RefreshKeys(
102 user_context, base::ListValue(),
103 base::Bind(&EasyUnlockServiceRegular::SetHardlockAfterKeyOperation,
104 weak_ptr_factory_.GetWeakPtr(),
105 EasyUnlockScreenlockStateHandler::NO_PAIRING));
106 }
94 } 107 }
95 108
96 void EasyUnlockServiceRegular::OnKeysRefreshedForSetDevices(bool success) { 109 void EasyUnlockServiceRegular::SetHardlockAfterKeyOperation(
97 // If the keys were refreshed successfully, the hardlock state should be 110 EasyUnlockScreenlockStateHandler::HardlockState state_on_success,
98 // cleared, so Smart Lock can be used normally. Otherwise, we fall back to 111 bool success) {
99 // a hardlock state to force the user to type in their credentials again. 112 if (success)
100 if (success) { 113 SetHardlockStateForUser(GetUserEmail(), state_on_success);
101 SetHardlockStateForUser(GetUserEmail(),
102 EasyUnlockScreenlockStateHandler::NO_HARDLOCK);
103 }
104 114
105 // Even if the keys refresh suceeded, we still fetch the cryptohome keys as a 115 // Even if the refresh keys operation suceeded, we still fetch and check the
106 // sanity check. 116 // cryptohome keys against the keys in local preferences as a sanity check.
107 CheckCryptohomeKeysAndMaybeHardlock(); 117 CheckCryptohomeKeysAndMaybeHardlock();
108 } 118 }
109 #endif 119 #endif
110 120
111 void EasyUnlockServiceRegular::OpenSetupApp() { 121 void EasyUnlockServiceRegular::OpenSetupApp() {
112 ExtensionService* service = 122 ExtensionService* service =
113 extensions::ExtensionSystem::Get(profile())->extension_service(); 123 extensions::ExtensionSystem::Get(profile())->extension_service();
114 const extensions::Extension* extension = 124 const extensions::Extension* extension =
115 service->GetExtensionById(extension_misc::kEasyUnlockAppId, false); 125 service->GetExtensionById(extension_misc::kEasyUnlockAppId, false);
116 126
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 if (pairing_dict && pairing_dict->GetList(kKeyDevices, &devices)) 160 if (pairing_dict && pairing_dict->GetList(kKeyDevices, &devices))
151 return devices; 161 return devices;
152 162
153 return NULL; 163 return NULL;
154 } 164 }
155 165
156 void EasyUnlockServiceRegular::SetRemoteDevices( 166 void EasyUnlockServiceRegular::SetRemoteDevices(
157 const base::ListValue& devices) { 167 const base::ListValue& devices) {
158 DictionaryPrefUpdate pairing_update(profile()->GetPrefs(), 168 DictionaryPrefUpdate pairing_update(profile()->GetPrefs(),
159 prefs::kEasyUnlockPairing); 169 prefs::kEasyUnlockPairing);
160 pairing_update->SetWithoutPathExpansion(kKeyDevices, devices.DeepCopy()); 170 if (devices.empty())
171 pairing_update->RemoveWithoutPathExpansion(kKeyDevices, NULL);
172 else
173 pairing_update->SetWithoutPathExpansion(kKeyDevices, devices.DeepCopy());
161 174
162 #if defined(OS_CHROMEOS) 175 #if defined(OS_CHROMEOS)
163 // TODO(tengs): Investigate if we can determine if the remote devices were set 176 // TODO(tengs): Investigate if we can determine if the remote devices were set
164 // from sync or from the setup app. 177 // from sync or from the setup app.
165 if (short_lived_user_context_ && short_lived_user_context_->user_context() && 178 if (short_lived_user_context_ && short_lived_user_context_->user_context()) {
166 !devices.empty()) {
167 // We may already have the password cached, so proceed to create the 179 // We may already have the password cached, so proceed to create the
168 // cryptohome keys for sign-in or the system will be hardlocked. 180 // cryptohome keys for sign-in or the system will be hardlocked.
169 chromeos::UserSessionManager::GetInstance()->GetEasyUnlockKeyManager() 181 chromeos::UserSessionManager::GetInstance()
182 ->GetEasyUnlockKeyManager()
170 ->RefreshKeys( 183 ->RefreshKeys(
171 *short_lived_user_context_->user_context(), 184 *short_lived_user_context_->user_context(), devices,
172 devices, 185 base::Bind(&EasyUnlockServiceRegular::SetHardlockAfterKeyOperation,
173 base::Bind(&EasyUnlockServiceRegular::OnKeysRefreshedForSetDevices, 186 weak_ptr_factory_.GetWeakPtr(),
174 weak_ptr_factory_.GetWeakPtr())); 187 EasyUnlockScreenlockStateHandler::NO_HARDLOCK));
175 } else { 188 } else {
176 CheckCryptohomeKeysAndMaybeHardlock(); 189 CheckCryptohomeKeysAndMaybeHardlock();
177 } 190 }
178 #else 191 #else
179 CheckCryptohomeKeysAndMaybeHardlock(); 192 CheckCryptohomeKeysAndMaybeHardlock();
180 #endif 193 #endif
181 } 194 }
182 195
183 void EasyUnlockServiceRegular::ClearRemoteDevices() {
184 DictionaryPrefUpdate pairing_update(profile()->GetPrefs(),
185 prefs::kEasyUnlockPairing);
186 pairing_update->RemoveWithoutPathExpansion(kKeyDevices, NULL);
187 CheckCryptohomeKeysAndMaybeHardlock();
188 }
189
190 void EasyUnlockServiceRegular::RunTurnOffFlow() { 196 void EasyUnlockServiceRegular::RunTurnOffFlow() {
191 if (turn_off_flow_status_ == PENDING) 197 if (turn_off_flow_status_ == PENDING)
192 return; 198 return;
193 199
194 SetTurnOffFlowStatus(PENDING); 200 SetTurnOffFlowStatus(PENDING);
195 201
196 // Currently there should only be one registered phone. 202 // Currently there should only be one registered phone.
197 // TODO(xiyuan): Revisit this when server supports toggle for all or 203 // TODO(xiyuan): Revisit this when server supports toggle for all or
198 // there are multiple phones. 204 // there are multiple phones.
199 const base::DictionaryValue* pairing_dict = 205 const base::DictionaryValue* pairing_dict =
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 } 301 }
296 302
297 void EasyUnlockServiceRegular::OnTurnOffFlowFinished(bool success) { 303 void EasyUnlockServiceRegular::OnTurnOffFlowFinished(bool success) {
298 turn_off_flow_.reset(); 304 turn_off_flow_.reset();
299 305
300 if (!success) { 306 if (!success) {
301 SetTurnOffFlowStatus(FAIL); 307 SetTurnOffFlowStatus(FAIL);
302 return; 308 return;
303 } 309 }
304 310
305 ClearRemoteDevices(); 311 SetRemoteDevices(base::ListValue());
306 SetTurnOffFlowStatus(IDLE); 312 SetTurnOffFlowStatus(IDLE);
307 ReloadApp(); 313 ReloadApp();
308 } 314 }
OLDNEW
« no previous file with comments | « chrome/browser/signin/easy_unlock_service_regular.h ('k') | chrome/browser/signin/easy_unlock_service_signin_chromeos.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698