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

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

Issue 585213002: [Easy signin] Wire up userClick auth attempt to easy unlock app and back (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@easy_signin_focused_user_changed_observer
Patch Set: fix screenlock private test Created 6 years, 2 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 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.h" 5 #include "chrome/browser/signin/easy_unlock_service.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/metrics/field_trial.h" 10 #include "base/metrics/field_trial.h"
11 #include "base/prefs/pref_service.h" 11 #include "base/prefs/pref_service.h"
12 #include "base/values.h" 12 #include "base/values.h"
13 #include "chrome/browser/extensions/component_loader.h" 13 #include "chrome/browser/extensions/component_loader.h"
14 #include "chrome/browser/extensions/extension_service.h" 14 #include "chrome/browser/extensions/extension_service.h"
15 #include "chrome/browser/profiles/profile.h" 15 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/browser/signin/easy_unlock_screenlock_state_handler.h" 16 #include "chrome/browser/signin/easy_unlock_auth_attempt.h"
17 #include "chrome/browser/signin/easy_unlock_service_factory.h" 17 #include "chrome/browser/signin/easy_unlock_service_factory.h"
18 #include "chrome/browser/signin/easy_unlock_service_observer.h" 18 #include "chrome/browser/signin/easy_unlock_service_observer.h"
19 #include "chrome/browser/signin/screenlock_bridge.h" 19 #include "chrome/browser/signin/screenlock_bridge.h"
20 #include "chrome/common/chrome_switches.h" 20 #include "chrome/common/chrome_switches.h"
21 #include "chrome/common/extensions/api/easy_unlock_private.h" 21 #include "chrome/common/extensions/api/easy_unlock_private.h"
22 #include "chrome/common/extensions/extension_constants.h" 22 #include "chrome/common/extensions/extension_constants.h"
23 #include "chrome/common/pref_names.h" 23 #include "chrome/common/pref_names.h"
24 #include "components/pref_registry/pref_registry_syncable.h" 24 #include "components/pref_registry/pref_registry_syncable.h"
25 #include "device/bluetooth/bluetooth_adapter.h" 25 #include "device/bluetooth/bluetooth_adapter.h"
26 #include "device/bluetooth/bluetooth_adapter_factory.h" 26 #include "device/bluetooth/bluetooth_adapter_factory.h"
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 return NULL; 196 return NULL;
197 if (!screenlock_state_handler_) { 197 if (!screenlock_state_handler_) {
198 screenlock_state_handler_.reset(new EasyUnlockScreenlockStateHandler( 198 screenlock_state_handler_.reset(new EasyUnlockScreenlockStateHandler(
199 GetUserEmail(), 199 GetUserEmail(),
200 GetType() == TYPE_REGULAR ? profile_->GetPrefs() : NULL, 200 GetType() == TYPE_REGULAR ? profile_->GetPrefs() : NULL,
201 ScreenlockBridge::Get())); 201 ScreenlockBridge::Get()));
202 } 202 }
203 return screenlock_state_handler_.get(); 203 return screenlock_state_handler_.get();
204 } 204 }
205 205
206 bool EasyUnlockService::UpdateScreenlockState(
207 EasyUnlockScreenlockStateHandler::State state) {
208 EasyUnlockScreenlockStateHandler* handler = GetScreenlockStateHandler();
209 if (!handler)
210 return false;
211
212 handler->ChangeState(state);
213
214 if (state != EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED)
215 auth_attempt_.reset();
216 return true;
217 }
218
219 void EasyUnlockService::AttemptAuth(const std::string& user_id) {
220 auth_attempt_.reset(new EasyUnlockAuthAttempt(
221 profile_,
222 GetUserEmail(),
223 GetType() == TYPE_REGULAR ? EasyUnlockAuthAttempt::TYPE_UNLOCK
224 : EasyUnlockAuthAttempt::TYPE_SIGNIN));
225 if (!auth_attempt_->Start(user_id))
226 auth_attempt_.reset();
227 }
228
229 void EasyUnlockService::FinalizeUnlock(bool success) {
230 if (auth_attempt_)
231 auth_attempt_->FinalizeUnlock(GetUserEmail(), success);
232 auth_attempt_.reset();
233 }
234
235 void EasyUnlockService::FinalizeSignin(const std::string& key) {
236 if (!auth_attempt_)
237 return;
238 std::string wrapped_secret = GetWrappedSecret();
239 if (!wrapped_secret.empty())
240 auth_attempt_->FinalizeSignin(GetUserEmail(), wrapped_secret, key);
241 auth_attempt_.reset();
242 }
243
206 void EasyUnlockService::AddObserver(EasyUnlockServiceObserver* observer) { 244 void EasyUnlockService::AddObserver(EasyUnlockServiceObserver* observer) {
207 observers_.AddObserver(observer); 245 observers_.AddObserver(observer);
208 } 246 }
209 247
210 void EasyUnlockService::RemoveObserver(EasyUnlockServiceObserver* observer) { 248 void EasyUnlockService::RemoveObserver(EasyUnlockServiceObserver* observer) {
211 observers_.RemoveObserver(observer); 249 observers_.RemoveObserver(observer);
212 } 250 }
213 251
214 void EasyUnlockService::Shutdown() { 252 void EasyUnlockService::Shutdown() {
215 if (shut_down_) 253 if (shut_down_)
216 return; 254 return;
217 shut_down_ = true; 255 shut_down_ = true;
218 256
219 ShutdownInternal(); 257 ShutdownInternal();
220 258
221 weak_ptr_factory_.InvalidateWeakPtrs(); 259 weak_ptr_factory_.InvalidateWeakPtrs();
222 260
223 ResetScreenlockStateHandler(); 261 ResetScreenlockState();
224 bluetooth_detector_.reset(); 262 bluetooth_detector_.reset();
225 #if defined(OS_CHROMEOS) 263 #if defined(OS_CHROMEOS)
226 power_monitor_.reset(); 264 power_monitor_.reset();
227 #endif 265 #endif
228 } 266 }
229 267
230 void EasyUnlockService::LoadApp() { 268 void EasyUnlockService::LoadApp() {
231 DCHECK(IsAllowed()); 269 DCHECK(IsAllowed());
232 270
233 #if defined(GOOGLE_CHROME_BUILD) 271 #if defined(GOOGLE_CHROME_BUILD)
(...skipping 20 matching lines...) Expand all
254 extensions::ExtensionSystem::Get(profile_)->extension_service(); 292 extensions::ExtensionSystem::Get(profile_)->extension_service();
255 extension_service->EnableExtension(extension_misc::kEasyUnlockAppId); 293 extension_service->EnableExtension(extension_misc::kEasyUnlockAppId);
256 294
257 NotifyUserUpdated(); 295 NotifyUserUpdated();
258 } 296 }
259 #endif // defined(GOOGLE_CHROME_BUILD) 297 #endif // defined(GOOGLE_CHROME_BUILD)
260 } 298 }
261 299
262 void EasyUnlockService::DisableAppIfLoaded() { 300 void EasyUnlockService::DisableAppIfLoaded() {
263 // Make sure lock screen state set by the extension gets reset. 301 // Make sure lock screen state set by the extension gets reset.
264 ResetScreenlockStateHandler(); 302 ResetScreenlockState();
265 303
266 extensions::ComponentLoader* loader = GetComponentLoader(profile_); 304 extensions::ComponentLoader* loader = GetComponentLoader(profile_);
267 if (!loader->Exists(extension_misc::kEasyUnlockAppId)) 305 if (!loader->Exists(extension_misc::kEasyUnlockAppId))
268 return; 306 return;
269 307
270 ExtensionService* extension_service = 308 ExtensionService* extension_service =
271 extensions::ExtensionSystem::Get(profile_)->extension_service(); 309 extensions::ExtensionSystem::Get(profile_)->extension_service();
272 extension_service->DisableExtension(extension_misc::kEasyUnlockAppId, 310 extension_service->DisableExtension(extension_misc::kEasyUnlockAppId,
273 extensions::Extension::DISABLE_RELOAD); 311 extensions::Extension::DISABLE_RELOAD);
274 } 312 }
275 313
276 void EasyUnlockService::UnloadApp() { 314 void EasyUnlockService::UnloadApp() {
277 GetComponentLoader(profile_)->Remove(extension_misc::kEasyUnlockAppId); 315 GetComponentLoader(profile_)->Remove(extension_misc::kEasyUnlockAppId);
278 } 316 }
279 317
280 void EasyUnlockService::ReloadApp() { 318 void EasyUnlockService::ReloadApp() {
281 // Make sure lock screen state set by the extension gets reset. 319 // Make sure lock screen state set by the extension gets reset.
282 ResetScreenlockStateHandler(); 320 ResetScreenlockState();
283 321
284 if (!GetComponentLoader(profile_)->Exists(extension_misc::kEasyUnlockAppId)) 322 if (!GetComponentLoader(profile_)->Exists(extension_misc::kEasyUnlockAppId))
285 return; 323 return;
286 extensions::ExtensionSystem* extension_system = 324 extensions::ExtensionSystem* extension_system =
287 extensions::ExtensionSystem::Get(profile_); 325 extensions::ExtensionSystem::Get(profile_);
288 extension_system->extension_service()->ReloadExtension( 326 extension_system->extension_service()->ReloadExtension(
289 extension_misc::kEasyUnlockAppId); 327 extension_misc::kEasyUnlockAppId);
290 NotifyUserUpdated(); 328 NotifyUserUpdated();
291 } 329 }
292 330
(...skipping 15 matching lines...) Expand all
308 346
309 void EasyUnlockService::NotifyUserUpdated() { 347 void EasyUnlockService::NotifyUserUpdated() {
310 std::string user_id = GetUserEmail(); 348 std::string user_id = GetUserEmail();
311 if (user_id.empty()) 349 if (user_id.empty())
312 return; 350 return;
313 351
314 // Notify the easy unlock app that the user info changed. 352 // Notify the easy unlock app that the user info changed.
315 extensions::api::easy_unlock_private::UserInfo info; 353 extensions::api::easy_unlock_private::UserInfo info;
316 info.user_id = user_id; 354 info.user_id = user_id;
317 info.logged_in = GetType() == TYPE_REGULAR; 355 info.logged_in = GetType() == TYPE_REGULAR;
318 info.data_ready = GetRemoteDevices() != NULL; 356 info.data_ready = info.logged_in || GetRemoteDevices() != NULL;
319 357
320 scoped_ptr<base::ListValue> args(new base::ListValue()); 358 scoped_ptr<base::ListValue> args(new base::ListValue());
321 args->Append(info.ToValue().release()); 359 args->Append(info.ToValue().release());
322 360
323 scoped_ptr<extensions::Event> event(new extensions::Event( 361 scoped_ptr<extensions::Event> event(new extensions::Event(
324 extensions::api::easy_unlock_private::OnUserInfoUpdated::kEventName, 362 extensions::api::easy_unlock_private::OnUserInfoUpdated::kEventName,
325 args.Pass())); 363 args.Pass()));
326 364
327 extensions::EventRouter::Get(profile_)->DispatchEventToExtension( 365 extensions::EventRouter::Get(profile_)->DispatchEventToExtension(
328 extension_misc::kEasyUnlockAppId, event.Pass()); 366 extension_misc::kEasyUnlockAppId, event.Pass());
329 } 367 }
330 368
331 void EasyUnlockService::NotifyTurnOffOperationStatusChanged() { 369 void EasyUnlockService::NotifyTurnOffOperationStatusChanged() {
332 FOR_EACH_OBSERVER( 370 FOR_EACH_OBSERVER(
333 EasyUnlockServiceObserver, observers_, OnTurnOffOperationStatusChanged()); 371 EasyUnlockServiceObserver, observers_, OnTurnOffOperationStatusChanged());
334 } 372 }
335 373
336 void EasyUnlockService::ResetScreenlockStateHandler() { 374 void EasyUnlockService::ResetScreenlockState() {
337 screenlock_state_handler_.reset(); 375 screenlock_state_handler_.reset();
376 auth_attempt_.reset();
338 } 377 }
339 378
340 void EasyUnlockService::Initialize() { 379 void EasyUnlockService::Initialize() {
341 InitializeInternal(); 380 InitializeInternal();
342 381
343 #if defined(OS_CHROMEOS) 382 #if defined(OS_CHROMEOS)
344 // Only start Bluetooth detection for ChromeOS since the feature is 383 // Only start Bluetooth detection for ChromeOS since the feature is
345 // only offered on ChromeOS. Enabling this on non-ChromeOS platforms 384 // only offered on ChromeOS. Enabling this on non-ChromeOS platforms
346 // previously introduced a performance regression: http://crbug.com/404482 385 // previously introduced a performance regression: http://crbug.com/404482
347 // Make sure not to reintroduce a performance regression if re-enabling on 386 // Make sure not to reintroduce a performance regression if re-enabling on
348 // additional platforms. 387 // additional platforms.
349 // TODO(xiyuan): Revisit when non-chromeos platforms are supported. 388 // TODO(xiyuan): Revisit when non-chromeos platforms are supported.
350 bluetooth_detector_->Initialize(); 389 bluetooth_detector_->Initialize();
351 #endif // defined(OS_CHROMEOS) 390 #endif // defined(OS_CHROMEOS)
352 } 391 }
353 392
354 void EasyUnlockService::OnBluetoothAdapterPresentChanged() { 393 void EasyUnlockService::OnBluetoothAdapterPresentChanged() {
355 UpdateAppState(); 394 UpdateAppState();
356 } 395 }
357 396
OLDNEW
« no previous file with comments | « chrome/browser/signin/easy_unlock_service.h ('k') | chrome/browser/signin/easy_unlock_service_regular.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698