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 "components/proximity_auth/screenlock_bridge.h"
17 #include "google_apis/gaia/oauth2_token_service.h"
19 #if defined(OS_CHROMEOS)
20 #include "chrome/browser/chromeos/login/easy_unlock/short_lived_user_context.h"
24 class DictionaryValue
;
29 class ToggleEasyUnlockResponse
;
32 namespace proximity_auth
{
33 class CryptAuthClient
;
34 class CryptAuthGCMManager
;
35 class CryptAuthEnrollmentManager
;
36 class CryptAuthDeviceManager
;
39 class EasyUnlockAppManager
;
40 class EasyUnlockToggleFlow
;
43 // EasyUnlockService instance that should be used for regular, non-signin
45 class EasyUnlockServiceRegular
46 : public EasyUnlockService
,
47 public proximity_auth::ScreenlockBridge::Observer
,
48 public OAuth2TokenService::Observer
{
50 explicit EasyUnlockServiceRegular(Profile
* profile
);
51 ~EasyUnlockServiceRegular() override
;
53 // Returns the CryptAuthEnrollmentManager, which manages the profile's
54 // CryptAuth enrollment.
55 proximity_auth::CryptAuthEnrollmentManager
* GetCryptAuthEnrollmentManager();
57 // Returns the CryptAuthEnrollmentManager, which manages the profile's
58 // synced devices from CryptAuth.
59 proximity_auth::CryptAuthDeviceManager
* GetCryptAuthDeviceManager();
62 // EasyUnlockService implementation:
63 EasyUnlockService::Type
GetType() const override
;
64 std::string
GetUserEmail() const override
;
65 void LaunchSetup() override
;
66 const base::DictionaryValue
* GetPermitAccess() const override
;
67 void SetPermitAccess(const base::DictionaryValue
& permit
) override
;
68 void ClearPermitAccess() override
;
69 const base::ListValue
* GetRemoteDevices() const override
;
70 void SetRemoteDevices(const base::ListValue
& devices
) override
;
71 void RunTurnOffFlow() override
;
72 void ResetTurnOffFlow() override
;
73 TurnOffFlowStatus
GetTurnOffFlowStatus() const override
;
74 std::string
GetChallenge() const override
;
75 std::string
GetWrappedSecret() const override
;
76 void RecordEasySignInOutcome(const std::string
& user_id
,
77 bool success
) const override
;
78 void RecordPasswordLoginEvent(const std::string
& user_id
) const override
;
79 void StartAutoPairing(const AutoPairingResultCallback
& callback
) override
;
80 void SetAutoPairingResult(bool success
, const std::string
& error
) override
;
81 void InitializeInternal() override
;
82 void ShutdownInternal() override
;
83 bool IsAllowedInternal() const override
;
84 void OnWillFinalizeUnlock(bool success
) override
;
85 void OnSuspendDone() override
;
87 // OAuth2TokenService::Observer:
88 void OnRefreshTokenAvailable(const std::string
& account_id
) override
;
90 // proximity_auth::ScreenlockBridge::Observer implementation:
91 void OnScreenDidLock(proximity_auth::ScreenlockBridge::LockHandler::ScreenType
92 screen_type
) override
;
93 void OnScreenDidUnlock(
94 proximity_auth::ScreenlockBridge::LockHandler::ScreenType screen_type
)
96 void OnFocusedUserChanged(const std::string
& user_id
) override
;
99 // Callback when the controlling pref changes.
100 void OnPrefsChanged();
102 // Sets the new turn-off flow status.
103 void SetTurnOffFlowStatus(TurnOffFlowStatus status
);
105 // Callback for ToggleEasyUnlock CryptAuth API.
106 void OnToggleEasyUnlockApiComplete(
107 const cryptauth::ToggleEasyUnlockResponse
& response
);
108 void OnToggleEasyUnlockApiFailed(const std::string
& error_message
);
110 #if defined(OS_CHROMEOS)
111 // Called with the user's credentials (e.g. username and password) after the
112 // user reauthenticates to begin setup.
113 void OnUserContextFromReauth(const chromeos::UserContext
& user_context
);
115 // Called after a cryptohome RemoveKey or RefreshKey operation to set the
116 // proper hardlock state if the operation is successful.
117 void SetHardlockAfterKeyOperation(
118 EasyUnlockScreenlockStateHandler::HardlockState state_on_success
,
121 // Initializes the managers that communicate with CryptAuth.
122 void InitializeCryptAuth();
124 scoped_ptr
<chromeos::ShortLivedUserContext
> short_lived_user_context_
;
127 // Updates local state with the preference from the user's profile, so they
128 // can be accessed on the sign-in screen.
129 void SyncProfilePrefsToLocalState();
131 // Returns the base GcmDeviceInfo proto containing the device's platform and
132 // version information.
133 cryptauth::GcmDeviceInfo
GetGcmDeviceInfo();
135 PrefChangeRegistrar registrar_
;
137 TurnOffFlowStatus turn_off_flow_status_
;
138 scoped_ptr
<proximity_auth::CryptAuthClient
> cryptauth_client_
;
140 AutoPairingResultCallback auto_pairing_callback_
;
142 // True if the user just unlocked the screen using Easy Unlock. Reset once
143 // the screen unlocks. Used to distinguish Easy Unlock-powered unlocks from
144 // password-based unlocks for metrics.
145 bool will_unlock_using_easy_unlock_
;
147 // The timestamp for the most recent time when the lock screen was shown. The
148 // lock screen is typically shown when the user awakens her computer from
149 // sleep -- e.g. by opening the lid -- but can also be shown if the screen is
150 // locked but the computer does not go to sleep.
151 base::TimeTicks lock_screen_last_shown_timestamp_
;
153 // Managers responsible for handling syncing and communications with
155 scoped_ptr
<proximity_auth::CryptAuthGCMManager
> gcm_manager_
;
156 scoped_ptr
<proximity_auth::CryptAuthEnrollmentManager
> enrollment_manager_
;
157 scoped_ptr
<proximity_auth::CryptAuthDeviceManager
> device_manager_
;
159 base::WeakPtrFactory
<EasyUnlockServiceRegular
> weak_ptr_factory_
;
161 DISALLOW_COPY_AND_ASSIGN(EasyUnlockServiceRegular
);
164 #endif // CHROME_BROWSER_SIGNIN_EASY_UNLOCK_SERVICE_REGULAR_H_