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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_SIGNIN_EASY_UNLOCK_SERVICE_REGULAR_H_
6 #define CHROME_BROWSER_SIGNIN_EASY_UNLOCK_SERVICE_REGULAR_H_
10 #include "base/callback.h"
11 #include "base/macros.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/prefs/pref_change_registrar.h"
14 #include "base/time/time.h"
15 #include "chrome/browser/signin/easy_unlock_service.h"
16 #include "chrome/browser/signin/screenlock_bridge.h"
18 #if defined(OS_CHROMEOS)
19 #include "chrome/browser/chromeos/login/easy_unlock/short_lived_user_context.h"
23 class DictionaryValue
;
28 class ToggleEasyUnlockResponse
;
31 namespace proximity_auth
{
32 class CryptAuthClient
;
35 class EasyUnlockAppManager
;
36 class EasyUnlockToggleFlow
;
39 // EasyUnlockService instance that should be used for regular, non-signin
41 class EasyUnlockServiceRegular
: public EasyUnlockService
,
42 public ScreenlockBridge::Observer
{
44 explicit EasyUnlockServiceRegular(Profile
* profile
);
45 ~EasyUnlockServiceRegular() override
;
48 // EasyUnlockService implementation:
49 EasyUnlockService::Type
GetType() const override
;
50 std::string
GetUserEmail() const override
;
51 void LaunchSetup() override
;
52 const base::DictionaryValue
* GetPermitAccess() const override
;
53 void SetPermitAccess(const base::DictionaryValue
& permit
) override
;
54 void ClearPermitAccess() override
;
55 const base::ListValue
* GetRemoteDevices() const override
;
56 void SetRemoteDevices(const base::ListValue
& devices
) override
;
57 void RunTurnOffFlow() override
;
58 void ResetTurnOffFlow() override
;
59 TurnOffFlowStatus
GetTurnOffFlowStatus() const override
;
60 std::string
GetChallenge() const override
;
61 std::string
GetWrappedSecret() const override
;
62 void RecordEasySignInOutcome(const std::string
& user_id
,
63 bool success
) const override
;
64 void RecordPasswordLoginEvent(const std::string
& user_id
) const override
;
65 void StartAutoPairing(const AutoPairingResultCallback
& callback
) override
;
66 void SetAutoPairingResult(bool success
, const std::string
& error
) override
;
67 void InitializeInternal() override
;
68 void ShutdownInternal() override
;
69 bool IsAllowedInternal() const override
;
70 void OnWillFinalizeUnlock(bool success
) override
;
71 void OnSuspendDone() override
;
73 // ScreenlockBridge::Observer implementation:
75 ScreenlockBridge::LockHandler::ScreenType screen_type
) override
;
76 void OnScreenDidUnlock(
77 ScreenlockBridge::LockHandler::ScreenType screen_type
) override
;
78 void OnFocusedUserChanged(const std::string
& user_id
) override
;
81 // Callback when the controlling pref changes.
82 void OnPrefsChanged();
84 // Sets the new turn-off flow status.
85 void SetTurnOffFlowStatus(TurnOffFlowStatus status
);
87 // Callback for ToggleEasyUnlock CryptAuth API.
88 void OnToggleEasyUnlockApiComplete(
89 const cryptauth::ToggleEasyUnlockResponse
& response
);
90 void OnToggleEasyUnlockApiFailed(const std::string
& error_message
);
92 #if defined(OS_CHROMEOS)
93 // Called with the user's credentials (e.g. username and password) after the
94 // user reauthenticates to begin setup.
95 void OnUserContextFromReauth(const chromeos::UserContext
& user_context
);
97 // Called after a cryptohome RemoveKey or RefreshKey operation to set the
98 // proper hardlock state if the operation is successful.
99 void SetHardlockAfterKeyOperation(
100 EasyUnlockScreenlockStateHandler::HardlockState state_on_success
,
103 scoped_ptr
<chromeos::ShortLivedUserContext
> short_lived_user_context_
;
106 // Updates local state with the preference from the user's profile, so they
107 // can be accessed on the sign-in screen.
108 void SyncProfilePrefsToLocalState();
110 PrefChangeRegistrar registrar_
;
112 TurnOffFlowStatus turn_off_flow_status_
;
113 scoped_ptr
<proximity_auth::CryptAuthClient
> cryptauth_client_
;
115 AutoPairingResultCallback auto_pairing_callback_
;
117 // True if the user just unlocked the screen using Easy Unlock. Reset once
118 // the screen unlocks. Used to distinguish Easy Unlock-powered unlocks from
119 // password-based unlocks for metrics.
120 bool will_unlock_using_easy_unlock_
;
122 // The timestamp for the most recent time when the lock screen was shown. The
123 // lock screen is typically shown when the user awakens her computer from
124 // sleep -- e.g. by opening the lid -- but can also be shown if the screen is
125 // locked but the computer does not go to sleep.
126 base::TimeTicks lock_screen_last_shown_timestamp_
;
128 base::WeakPtrFactory
<EasyUnlockServiceRegular
> weak_ptr_factory_
;
130 DISALLOW_COPY_AND_ASSIGN(EasyUnlockServiceRegular
);
133 #endif // CHROME_BROWSER_SIGNIN_EASY_UNLOCK_SERVICE_REGULAR_H_