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

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: bind user context to lifetime of setup app 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/values.h" 12 #include "base/values.h"
13 #include "chrome/browser/extensions/extension_service.h" 13 #include "chrome/browser/extensions/extension_service.h"
14 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/signin/easy_unlock_toggle_flow.h" 15 #include "chrome/browser/signin/easy_unlock_toggle_flow.h"
16 #include "chrome/browser/signin/screenlock_bridge.h" 16 #include "chrome/browser/signin/screenlock_bridge.h"
17 #include "chrome/browser/ui/extensions/application_launch.h" 17 #include "chrome/browser/ui/extensions/application_launch.h"
18 #include "chrome/common/extensions/extension_constants.h" 18 #include "chrome/common/extensions/extension_constants.h"
19 #include "chrome/common/pref_names.h" 19 #include "chrome/common/pref_names.h"
20 #include "components/pref_registry/pref_registry_syncable.h" 20 #include "components/pref_registry/pref_registry_syncable.h"
21 #include "content/public/browser/browser_thread.h"
21 #include "extensions/browser/extension_system.h" 22 #include "extensions/browser/extension_system.h"
22 23
23 #if defined(OS_CHROMEOS) 24 #if defined(OS_CHROMEOS)
25 #include "apps/app_lifetime_monitor_factory.h"
26 #include "base/thread_task_runner_handle.h"
27 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_key_manager.h"
28 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_reauth.h"
29 #include "chrome/browser/chromeos/login/session/user_session_manager.h"
24 #include "chrome/browser/chromeos/profiles/profile_helper.h" 30 #include "chrome/browser/chromeos/profiles/profile_helper.h"
25 #include "components/user_manager/user_manager.h" 31 #include "components/user_manager/user_manager.h"
26 #endif 32 #endif
27 33
28 namespace { 34 namespace {
29 35
30 // Key name of the local device permit record dictonary in kEasyUnlockPairing. 36 // Key name of the local device permit record dictonary in kEasyUnlockPairing.
31 const char kKeyPermitAccess[] = "permitAccess"; 37 const char kKeyPermitAccess[] = "permitAccess";
32 38
33 // Key name of the remote device list in kEasyUnlockPairing. 39 // Key name of the remote device list in kEasyUnlockPairing.
34 const char kKeyDevices[] = "devices"; 40 const char kKeyDevices[] = "devices";
35 41
36 // Key name of the phone public key in a device dictionary. 42 // Key name of the phone public key in a device dictionary.
37 const char kKeyPhoneId[] = "permitRecord.id"; 43 const char kKeyPhoneId[] = "permitRecord.id";
38 44
39 } // namespace 45 } // namespace
40 46
41 EasyUnlockServiceRegular::EasyUnlockServiceRegular(Profile* profile) 47 EasyUnlockServiceRegular::EasyUnlockServiceRegular(Profile* profile)
42 : EasyUnlockService(profile), 48 : EasyUnlockService(profile),
43 turn_off_flow_status_(EasyUnlockService::IDLE) { 49 turn_off_flow_status_(EasyUnlockService::IDLE),
50 weak_ptr_factory_(this) {
44 } 51 }
45 52
46 EasyUnlockServiceRegular::~EasyUnlockServiceRegular() { 53 EasyUnlockServiceRegular::~EasyUnlockServiceRegular() {
47 } 54 }
48 55
49 EasyUnlockService::Type EasyUnlockServiceRegular::GetType() const { 56 EasyUnlockService::Type EasyUnlockServiceRegular::GetType() const {
50 return EasyUnlockService::TYPE_REGULAR; 57 return EasyUnlockService::TYPE_REGULAR;
51 } 58 }
52 59
53 std::string EasyUnlockServiceRegular::GetUserEmail() const { 60 std::string EasyUnlockServiceRegular::GetUserEmail() const {
54 return ScreenlockBridge::GetAuthenticatedUserEmail(profile()); 61 return ScreenlockBridge::GetAuthenticatedUserEmail(profile());
55 } 62 }
56 63
57 void EasyUnlockServiceRegular::LaunchSetup() { 64 void EasyUnlockServiceRegular::LaunchSetup() {
65 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
66 #if defined(OS_CHROMEOS)
67 // Force the user to reauthenticate by showing a modal overlay (similar to the
68 // lock screen). The password obtained from the reauth is cached for a short
69 // period of time and used to create the cryptohome keys for sign-in.
70 if (short_lived_user_context_ && short_lived_user_context_->user_context()) {
71 OpenSetupApp();
72 } else {
73 bool reauth_success = chromeos::EasyUnlockReauth::ReauthForUserContext(
74 base::Bind(&EasyUnlockServiceRegular::OnUserContextFromReauth,
75 weak_ptr_factory_.GetWeakPtr()));
76 if (!reauth_success)
77 OpenSetupApp();
78 }
79 #else
80 OpenSetupApp();
81 #endif
82 }
83
84 #if defined(OS_CHROMEOS)
85 void EasyUnlockServiceRegular::OnUserContextFromReauth(
86 const chromeos::UserContext& user_context) {
87 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
88 short_lived_user_context_.reset(new chromeos::ShortLivedUserContext(
89 user_context,
90 apps::AppLifetimeMonitorFactory::GetForProfile(profile()),
91 base::ThreadTaskRunnerHandle::Get().get()));
92
93 OpenSetupApp();
94 }
95
96 void EasyUnlockServiceRegular::OnKeysRefreshedForSetDevices(bool success) {
97 // If the keys were refreshed successfully, the hardlock state should be
98 // cleared, and Smart Lock can be used normally.
99 CheckCryptohomeKeysAndMaybeHardlock();
100 }
101 #endif
102
103 void EasyUnlockServiceRegular::OpenSetupApp() {
58 ExtensionService* service = 104 ExtensionService* service =
59 extensions::ExtensionSystem::Get(profile())->extension_service(); 105 extensions::ExtensionSystem::Get(profile())->extension_service();
60 const extensions::Extension* extension = 106 const extensions::Extension* extension =
61 service->GetExtensionById(extension_misc::kEasyUnlockAppId, false); 107 service->GetExtensionById(extension_misc::kEasyUnlockAppId, false);
62 108
63 OpenApplication(AppLaunchParams( 109 OpenApplication(AppLaunchParams(
64 profile(), extension, extensions::LAUNCH_CONTAINER_WINDOW, NEW_WINDOW)); 110 profile(), extension, extensions::LAUNCH_CONTAINER_WINDOW, NEW_WINDOW));
65 } 111 }
66 112
67 const base::DictionaryValue* EasyUnlockServiceRegular::GetPermitAccess() const { 113 const base::DictionaryValue* EasyUnlockServiceRegular::GetPermitAccess() const {
(...skipping 28 matching lines...) Expand all
96 return devices; 142 return devices;
97 143
98 return NULL; 144 return NULL;
99 } 145 }
100 146
101 void EasyUnlockServiceRegular::SetRemoteDevices( 147 void EasyUnlockServiceRegular::SetRemoteDevices(
102 const base::ListValue& devices) { 148 const base::ListValue& devices) {
103 DictionaryPrefUpdate pairing_update(profile()->GetPrefs(), 149 DictionaryPrefUpdate pairing_update(profile()->GetPrefs(),
104 prefs::kEasyUnlockPairing); 150 prefs::kEasyUnlockPairing);
105 pairing_update->SetWithoutPathExpansion(kKeyDevices, devices.DeepCopy()); 151 pairing_update->SetWithoutPathExpansion(kKeyDevices, devices.DeepCopy());
152
153 #if defined(OS_CHROMEOS)
154 if (short_lived_user_context_ && short_lived_user_context_->user_context() &&
155 !devices.empty()) {
156 // We may already have the password cached, so proceed to create the
157 // cryptohome keys for sign-in or the system will be hardlocked.
158 chromeos::UserContext* user_context =
159 short_lived_user_context_->user_context();
160 chromeos::EasyUnlockKeyManager* key_manager =
161 chromeos::UserSessionManager::GetInstance()->GetEasyUnlockKeyManager();
162 key_manager->RefreshKeys(
163 *user_context,
164 devices,
165 base::Bind(&EasyUnlockServiceRegular::OnKeysRefreshedForSetDevices,
166 weak_ptr_factory_.GetWeakPtr()));
167 } else {
168 CheckCryptohomeKeysAndMaybeHardlock();
169 }
170 #else
106 CheckCryptohomeKeysAndMaybeHardlock(); 171 CheckCryptohomeKeysAndMaybeHardlock();
172 #endif
107 } 173 }
108 174
109 void EasyUnlockServiceRegular::ClearRemoteDevices() { 175 void EasyUnlockServiceRegular::ClearRemoteDevices() {
110 DictionaryPrefUpdate pairing_update(profile()->GetPrefs(), 176 DictionaryPrefUpdate pairing_update(profile()->GetPrefs(),
111 prefs::kEasyUnlockPairing); 177 prefs::kEasyUnlockPairing);
112 pairing_update->RemoveWithoutPathExpansion(kKeyDevices, NULL); 178 pairing_update->RemoveWithoutPathExpansion(kKeyDevices, NULL);
113 CheckCryptohomeKeysAndMaybeHardlock(); 179 CheckCryptohomeKeysAndMaybeHardlock();
114 } 180 }
115 181
116 void EasyUnlockServiceRegular::RunTurnOffFlow() { 182 void EasyUnlockServiceRegular::RunTurnOffFlow() {
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 void EasyUnlockServiceRegular::InitializeInternal() { 243 void EasyUnlockServiceRegular::InitializeInternal() {
178 registrar_.Init(profile()->GetPrefs()); 244 registrar_.Init(profile()->GetPrefs());
179 registrar_.Add( 245 registrar_.Add(
180 prefs::kEasyUnlockAllowed, 246 prefs::kEasyUnlockAllowed,
181 base::Bind(&EasyUnlockServiceRegular::OnPrefsChanged, 247 base::Bind(&EasyUnlockServiceRegular::OnPrefsChanged,
182 base::Unretained(this))); 248 base::Unretained(this)));
183 OnPrefsChanged(); 249 OnPrefsChanged();
184 } 250 }
185 251
186 void EasyUnlockServiceRegular::ShutdownInternal() { 252 void EasyUnlockServiceRegular::ShutdownInternal() {
253 #if defined(OS_CHROMEOS)
254 short_lived_user_context_.reset();
255 #endif
256
187 turn_off_flow_.reset(); 257 turn_off_flow_.reset();
188 turn_off_flow_status_ = EasyUnlockService::IDLE; 258 turn_off_flow_status_ = EasyUnlockService::IDLE;
189 registrar_.RemoveAll(); 259 registrar_.RemoveAll();
190 } 260 }
191 261
192 bool EasyUnlockServiceRegular::IsAllowedInternal() { 262 bool EasyUnlockServiceRegular::IsAllowedInternal() {
193 #if defined(OS_CHROMEOS) 263 #if defined(OS_CHROMEOS)
194 if (!user_manager::UserManager::Get()->IsLoggedInAsRegularUser()) 264 if (!user_manager::UserManager::Get()->IsLoggedInAsRegularUser())
195 return false; 265 return false;
196 266
(...skipping 30 matching lines...) Expand all
227 297
228 if (!success) { 298 if (!success) {
229 SetTurnOffFlowStatus(FAIL); 299 SetTurnOffFlowStatus(FAIL);
230 return; 300 return;
231 } 301 }
232 302
233 ClearRemoteDevices(); 303 ClearRemoteDevices();
234 SetTurnOffFlowStatus(IDLE); 304 SetTurnOffFlowStatus(IDLE);
235 ReloadApp(); 305 ReloadApp();
236 } 306 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698