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

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

Issue 668213003: Reauthenticate the user before launching Smart Lock setup app. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month 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/metrics/field_trial.h" 9 #include "base/metrics/field_trial.h"
10 #include "base/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
11 #include "base/prefs/scoped_user_pref_update.h" 11 #include "base/prefs/scoped_user_pref_update.h"
12 #include "base/thread_task_runner_handle.h"
12 #include "base/values.h" 13 #include "base/values.h"
13 #include "chrome/browser/extensions/extension_service.h" 14 #include "chrome/browser/extensions/extension_service.h"
14 #include "chrome/browser/profiles/profile.h" 15 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/signin/easy_unlock_toggle_flow.h" 16 #include "chrome/browser/signin/easy_unlock_toggle_flow.h"
16 #include "chrome/browser/signin/screenlock_bridge.h" 17 #include "chrome/browser/signin/screenlock_bridge.h"
17 #include "chrome/browser/ui/extensions/application_launch.h" 18 #include "chrome/browser/ui/extensions/application_launch.h"
18 #include "chrome/common/extensions/extension_constants.h" 19 #include "chrome/common/extensions/extension_constants.h"
19 #include "chrome/common/pref_names.h" 20 #include "chrome/common/pref_names.h"
20 #include "components/pref_registry/pref_registry_syncable.h" 21 #include "components/pref_registry/pref_registry_syncable.h"
22 #include "content/public/browser/browser_thread.h"
21 #include "extensions/browser/extension_system.h" 23 #include "extensions/browser/extension_system.h"
22 24
23 #if defined(OS_CHROMEOS) 25 #if defined(OS_CHROMEOS)
26 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_key_manager.h"
27 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_reauth.h"
28 #include "chrome/browser/chromeos/login/session/user_session_manager.h"
24 #include "chrome/browser/chromeos/profiles/profile_helper.h" 29 #include "chrome/browser/chromeos/profiles/profile_helper.h"
25 #include "components/user_manager/user_manager.h" 30 #include "components/user_manager/user_manager.h"
26 #endif 31 #endif
27 32
28 namespace { 33 namespace {
29 34
30 // Key name of the local device permit record dictonary in kEasyUnlockPairing. 35 // Key name of the local device permit record dictonary in kEasyUnlockPairing.
31 const char kKeyPermitAccess[] = "permitAccess"; 36 const char kKeyPermitAccess[] = "permitAccess";
32 37
33 // Key name of the remote device list in kEasyUnlockPairing. 38 // Key name of the remote device list in kEasyUnlockPairing.
34 const char kKeyDevices[] = "devices"; 39 const char kKeyDevices[] = "devices";
35 40
36 // Key name of the phone public key in a device dictionary. 41 // Key name of the phone public key in a device dictionary.
37 const char kKeyPhoneId[] = "permitRecord.id"; 42 const char kKeyPhoneId[] = "permitRecord.id";
38 43
39 } // namespace 44 } // namespace
40 45
41 EasyUnlockServiceRegular::EasyUnlockServiceRegular(Profile* profile) 46 EasyUnlockServiceRegular::EasyUnlockServiceRegular(Profile* profile)
42 : EasyUnlockService(profile), 47 : EasyUnlockService(profile),
43 turn_off_flow_status_(EasyUnlockService::IDLE) { 48 turn_off_flow_status_(EasyUnlockService::IDLE),
49 weak_ptr_factory_(this) {
44 } 50 }
45 51
46 EasyUnlockServiceRegular::~EasyUnlockServiceRegular() { 52 EasyUnlockServiceRegular::~EasyUnlockServiceRegular() {
47 } 53 }
48 54
49 EasyUnlockService::Type EasyUnlockServiceRegular::GetType() const { 55 EasyUnlockService::Type EasyUnlockServiceRegular::GetType() const {
50 return EasyUnlockService::TYPE_REGULAR; 56 return EasyUnlockService::TYPE_REGULAR;
51 } 57 }
52 58
53 std::string EasyUnlockServiceRegular::GetUserEmail() const { 59 std::string EasyUnlockServiceRegular::GetUserEmail() const {
54 return ScreenlockBridge::GetAuthenticatedUserEmail(profile()); 60 return ScreenlockBridge::GetAuthenticatedUserEmail(profile());
55 } 61 }
56 62
57 void EasyUnlockServiceRegular::LaunchSetup() { 63 void EasyUnlockServiceRegular::LaunchSetup() {
64 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
65 #if defined(OS_CHROMEOS)
66 // Force the user to reauthenticate by showing a modal overlay (similar to the
67 // lock screen). The password obtained from the reauth is cached for a short
68 // period of time and used to create the cryptohome keys for sign-in.
69 if (short_lived_user_context_ && short_lived_user_context_->user_context()) {
70 OpenSetupApp();
71 } else {
72 bool reauth_success = chromeos::EasyUnlockReauth::ReauthForUserContext(
73 base::Bind(&EasyUnlockServiceRegular::OnUserContextFromReauth,
74 weak_ptr_factory_.GetWeakPtr()));
75 if (!reauth_success)
76 OpenSetupApp();
77 }
78 #else
79 OpenSetupApp();
80 #endif
81 }
82
83 #if defined(OS_CHROMEOS)
84 void EasyUnlockServiceRegular::OnUserContextFromReauth(
85 const chromeos::UserContext& user_context) {
86 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
87 short_lived_user_context_.reset(new chromeos::ShortLivedUserContext(
88 user_context, base::ThreadTaskRunnerHandle::Get().get()));
89 OpenSetupApp();
90 }
91
92 void EasyUnlockServiceRegular::OnKeysRefreshedForSetDevices(bool success) {
93 // If the keys were refreshed successfully, the hardlock state should be
94 // cleared, and Smart Lock can be used normally.
95 CheckCryptohomeKeysAndMaybeHardlock();
96 }
97 #endif
98
99 void EasyUnlockServiceRegular::OpenSetupApp() {
58 ExtensionService* service = 100 ExtensionService* service =
59 extensions::ExtensionSystem::Get(profile())->extension_service(); 101 extensions::ExtensionSystem::Get(profile())->extension_service();
60 const extensions::Extension* extension = 102 const extensions::Extension* extension =
61 service->GetExtensionById(extension_misc::kEasyUnlockAppId, false); 103 service->GetExtensionById(extension_misc::kEasyUnlockAppId, false);
62 104
63 OpenApplication(AppLaunchParams( 105 OpenApplication(AppLaunchParams(
64 profile(), extension, extensions::LAUNCH_CONTAINER_WINDOW, NEW_WINDOW)); 106 profile(), extension, extensions::LAUNCH_CONTAINER_WINDOW, NEW_WINDOW));
65 } 107 }
66 108
67 const base::DictionaryValue* EasyUnlockServiceRegular::GetPermitAccess() const { 109 const base::DictionaryValue* EasyUnlockServiceRegular::GetPermitAccess() const {
(...skipping 28 matching lines...) Expand all
96 return devices; 138 return devices;
97 139
98 return NULL; 140 return NULL;
99 } 141 }
100 142
101 void EasyUnlockServiceRegular::SetRemoteDevices( 143 void EasyUnlockServiceRegular::SetRemoteDevices(
102 const base::ListValue& devices) { 144 const base::ListValue& devices) {
103 DictionaryPrefUpdate pairing_update(profile()->GetPrefs(), 145 DictionaryPrefUpdate pairing_update(profile()->GetPrefs(),
104 prefs::kEasyUnlockPairing); 146 prefs::kEasyUnlockPairing);
105 pairing_update->SetWithoutPathExpansion(kKeyDevices, devices.DeepCopy()); 147 pairing_update->SetWithoutPathExpansion(kKeyDevices, devices.DeepCopy());
148
149 #if defined(OS_CHROMEOS)
150 if (short_lived_user_context_ && short_lived_user_context_->user_context() &&
151 !devices.empty()) {
tbarzic 2014/10/27 21:44:44 I concerned about the case where user does not fin
xiyuan 2014/10/28 20:38:03 Agree. We probably should make sure |short_lived_u
Tim Song 2014/10/31 17:57:37 Done. I put the logic binding the user context to
152 // We may already have the password cached, so proceed to create the
153 // cryptohome keys for sign-in or the system will be hardlocked.
154 chromeos::UserContext* user_context =
155 short_lived_user_context_->user_context();
156 chromeos::EasyUnlockKeyManager* key_manager =
157 chromeos::UserSessionManager::GetInstance()->GetEasyUnlockKeyManager();
158 key_manager->RefreshKeys(
159 *user_context,
160 devices,
161 base::Bind(&EasyUnlockServiceRegular::OnKeysRefreshedForSetDevices,
162 weak_ptr_factory_.GetWeakPtr()));
tbarzic 2014/10/27 21:44:43 reset user context? also, can we make sure the con
Tim Song 2014/10/31 17:57:37 Done.
163 } else {
164 CheckCryptohomeKeysAndMaybeHardlock();
165 }
166 #else
106 CheckCryptohomeKeysAndMaybeHardlock(); 167 CheckCryptohomeKeysAndMaybeHardlock();
168 #endif
107 } 169 }
108 170
109 void EasyUnlockServiceRegular::ClearRemoteDevices() { 171 void EasyUnlockServiceRegular::ClearRemoteDevices() {
110 DictionaryPrefUpdate pairing_update(profile()->GetPrefs(), 172 DictionaryPrefUpdate pairing_update(profile()->GetPrefs(),
111 prefs::kEasyUnlockPairing); 173 prefs::kEasyUnlockPairing);
112 pairing_update->RemoveWithoutPathExpansion(kKeyDevices, NULL); 174 pairing_update->RemoveWithoutPathExpansion(kKeyDevices, NULL);
113 CheckCryptohomeKeysAndMaybeHardlock(); 175 CheckCryptohomeKeysAndMaybeHardlock();
114 } 176 }
115 177
116 void EasyUnlockServiceRegular::RunTurnOffFlow() { 178 void EasyUnlockServiceRegular::RunTurnOffFlow() {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 void EasyUnlockServiceRegular::InitializeInternal() { 228 void EasyUnlockServiceRegular::InitializeInternal() {
167 registrar_.Init(profile()->GetPrefs()); 229 registrar_.Init(profile()->GetPrefs());
168 registrar_.Add( 230 registrar_.Add(
169 prefs::kEasyUnlockAllowed, 231 prefs::kEasyUnlockAllowed,
170 base::Bind(&EasyUnlockServiceRegular::OnPrefsChanged, 232 base::Bind(&EasyUnlockServiceRegular::OnPrefsChanged,
171 base::Unretained(this))); 233 base::Unretained(this)));
172 OnPrefsChanged(); 234 OnPrefsChanged();
173 } 235 }
174 236
175 void EasyUnlockServiceRegular::ShutdownInternal() { 237 void EasyUnlockServiceRegular::ShutdownInternal() {
238 #if defined(OS_CHROMEOS)
239 short_lived_user_context_.reset();
240 #endif
241
176 turn_off_flow_.reset(); 242 turn_off_flow_.reset();
177 turn_off_flow_status_ = EasyUnlockService::IDLE; 243 turn_off_flow_status_ = EasyUnlockService::IDLE;
178 registrar_.RemoveAll(); 244 registrar_.RemoveAll();
179 } 245 }
180 246
181 bool EasyUnlockServiceRegular::IsAllowedInternal() { 247 bool EasyUnlockServiceRegular::IsAllowedInternal() {
182 #if defined(OS_CHROMEOS) 248 #if defined(OS_CHROMEOS)
183 if (!user_manager::UserManager::Get()->IsLoggedInAsRegularUser()) 249 if (!user_manager::UserManager::Get()->IsLoggedInAsRegularUser())
184 return false; 250 return false;
185 251
(...skipping 30 matching lines...) Expand all
216 282
217 if (!success) { 283 if (!success) {
218 SetTurnOffFlowStatus(FAIL); 284 SetTurnOffFlowStatus(FAIL);
219 return; 285 return;
220 } 286 }
221 287
222 ClearRemoteDevices(); 288 ClearRemoteDevices();
223 SetTurnOffFlowStatus(IDLE); 289 SetTurnOffFlowStatus(IDLE);
224 ReloadApp(); 290 ReloadApp();
225 } 291 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698