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

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

Issue 789793005: Revert of Clean up Smart Lock cryptohome keys logic: (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 }
107 } 94 }
108 95
109 void EasyUnlockServiceRegular::SetHardlockAfterKeyOperation( 96 void EasyUnlockServiceRegular::OnKeysRefreshedForSetDevices(bool success) {
110 EasyUnlockScreenlockStateHandler::HardlockState state_on_success, 97 // If the keys were refreshed successfully, the hardlock state should be
111 bool success) { 98 // cleared, so Smart Lock can be used normally. Otherwise, we fall back to
112 if (success) 99 // a hardlock state to force the user to type in their credentials again.
113 SetHardlockStateForUser(GetUserEmail(), state_on_success); 100 if (success) {
101 SetHardlockStateForUser(GetUserEmail(),
102 EasyUnlockScreenlockStateHandler::NO_HARDLOCK);
103 }
114 104
115 // Even if the refresh keys operation suceeded, we still fetch and check the 105 // Even if the keys refresh suceeded, we still fetch the cryptohome keys as a
116 // cryptohome keys against the keys in local preferences as a sanity check. 106 // sanity check.
117 CheckCryptohomeKeysAndMaybeHardlock(); 107 CheckCryptohomeKeysAndMaybeHardlock();
118 } 108 }
119 #endif 109 #endif
120 110
121 void EasyUnlockServiceRegular::OpenSetupApp() { 111 void EasyUnlockServiceRegular::OpenSetupApp() {
122 ExtensionService* service = 112 ExtensionService* service =
123 extensions::ExtensionSystem::Get(profile())->extension_service(); 113 extensions::ExtensionSystem::Get(profile())->extension_service();
124 const extensions::Extension* extension = 114 const extensions::Extension* extension =
125 service->GetExtensionById(extension_misc::kEasyUnlockAppId, false); 115 service->GetExtensionById(extension_misc::kEasyUnlockAppId, false);
126 116
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 if (pairing_dict && pairing_dict->GetList(kKeyDevices, &devices)) 150 if (pairing_dict && pairing_dict->GetList(kKeyDevices, &devices))
161 return devices; 151 return devices;
162 152
163 return NULL; 153 return NULL;
164 } 154 }
165 155
166 void EasyUnlockServiceRegular::SetRemoteDevices( 156 void EasyUnlockServiceRegular::SetRemoteDevices(
167 const base::ListValue& devices) { 157 const base::ListValue& devices) {
168 DictionaryPrefUpdate pairing_update(profile()->GetPrefs(), 158 DictionaryPrefUpdate pairing_update(profile()->GetPrefs(),
169 prefs::kEasyUnlockPairing); 159 prefs::kEasyUnlockPairing);
170 if (devices.empty()) 160 pairing_update->SetWithoutPathExpansion(kKeyDevices, devices.DeepCopy());
171 pairing_update->RemoveWithoutPathExpansion(kKeyDevices, NULL);
172 else
173 pairing_update->SetWithoutPathExpansion(kKeyDevices, devices.DeepCopy());
174 161
175 #if defined(OS_CHROMEOS) 162 #if defined(OS_CHROMEOS)
176 // TODO(tengs): Investigate if we can determine if the remote devices were set 163 // TODO(tengs): Investigate if we can determine if the remote devices were set
177 // from sync or from the setup app. 164 // from sync or from the setup app.
178 if (short_lived_user_context_ && short_lived_user_context_->user_context()) { 165 if (short_lived_user_context_ && short_lived_user_context_->user_context() &&
166 !devices.empty()) {
179 // We may already have the password cached, so proceed to create the 167 // We may already have the password cached, so proceed to create the
180 // cryptohome keys for sign-in or the system will be hardlocked. 168 // cryptohome keys for sign-in or the system will be hardlocked.
181 chromeos::UserSessionManager::GetInstance() 169 chromeos::UserSessionManager::GetInstance()->GetEasyUnlockKeyManager()
182 ->GetEasyUnlockKeyManager()
183 ->RefreshKeys( 170 ->RefreshKeys(
184 *short_lived_user_context_->user_context(), devices, 171 *short_lived_user_context_->user_context(),
185 base::Bind(&EasyUnlockServiceRegular::SetHardlockAfterKeyOperation, 172 devices,
186 weak_ptr_factory_.GetWeakPtr(), 173 base::Bind(&EasyUnlockServiceRegular::OnKeysRefreshedForSetDevices,
187 EasyUnlockScreenlockStateHandler::NO_HARDLOCK)); 174 weak_ptr_factory_.GetWeakPtr()));
188 } else { 175 } else {
189 CheckCryptohomeKeysAndMaybeHardlock(); 176 CheckCryptohomeKeysAndMaybeHardlock();
190 } 177 }
191 #else 178 #else
192 CheckCryptohomeKeysAndMaybeHardlock(); 179 CheckCryptohomeKeysAndMaybeHardlock();
193 #endif 180 #endif
194 } 181 }
195 182
183 void EasyUnlockServiceRegular::ClearRemoteDevices() {
184 DictionaryPrefUpdate pairing_update(profile()->GetPrefs(),
185 prefs::kEasyUnlockPairing);
186 pairing_update->RemoveWithoutPathExpansion(kKeyDevices, NULL);
187 CheckCryptohomeKeysAndMaybeHardlock();
188 }
189
196 void EasyUnlockServiceRegular::RunTurnOffFlow() { 190 void EasyUnlockServiceRegular::RunTurnOffFlow() {
197 if (turn_off_flow_status_ == PENDING) 191 if (turn_off_flow_status_ == PENDING)
198 return; 192 return;
199 193
200 SetTurnOffFlowStatus(PENDING); 194 SetTurnOffFlowStatus(PENDING);
201 195
202 // Currently there should only be one registered phone. 196 // Currently there should only be one registered phone.
203 // TODO(xiyuan): Revisit this when server supports toggle for all or 197 // TODO(xiyuan): Revisit this when server supports toggle for all or
204 // there are multiple phones. 198 // there are multiple phones.
205 const base::DictionaryValue* pairing_dict = 199 const base::DictionaryValue* pairing_dict =
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 } 295 }
302 296
303 void EasyUnlockServiceRegular::OnTurnOffFlowFinished(bool success) { 297 void EasyUnlockServiceRegular::OnTurnOffFlowFinished(bool success) {
304 turn_off_flow_.reset(); 298 turn_off_flow_.reset();
305 299
306 if (!success) { 300 if (!success) {
307 SetTurnOffFlowStatus(FAIL); 301 SetTurnOffFlowStatus(FAIL);
308 return; 302 return;
309 } 303 }
310 304
311 SetRemoteDevices(base::ListValue()); 305 ClearRemoteDevices();
312 SetTurnOffFlowStatus(IDLE); 306 SetTurnOffFlowStatus(IDLE);
313 ReloadApp(); 307 ReloadApp();
314 } 308 }
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