OLD | NEW |
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 #ifndef CHROME_BROWSER_SIGNIN_EASY_UNLOCK_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_SIGNIN_EASY_UNLOCK_SERVICE_H_ |
6 #define CHROME_BROWSER_SIGNIN_EASY_UNLOCK_SERVICE_H_ | 6 #define CHROME_BROWSER_SIGNIN_EASY_UNLOCK_SERVICE_H_ |
7 | 7 |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/callback_forward.h" | 11 #include "base/callback_forward.h" |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
15 #include "base/observer_list.h" | 15 #include "base/observer_list.h" |
16 #include "chrome/browser/signin/chrome_proximity_auth_client.h" | 16 #include "chrome/browser/signin/chrome_proximity_auth_client.h" |
17 #include "chrome/browser/signin/easy_unlock_auth_attempt.h" | 17 #include "chrome/browser/signin/easy_unlock_auth_attempt.h" |
18 #include "chrome/browser/signin/easy_unlock_metrics.h" | 18 #include "chrome/browser/signin/easy_unlock_metrics.h" |
19 #include "chrome/browser/signin/easy_unlock_screenlock_state_handler.h" | 19 #include "chrome/browser/signin/easy_unlock_screenlock_state_handler.h" |
20 #include "components/keyed_service/core/keyed_service.h" | 20 #include "components/keyed_service/core/keyed_service.h" |
21 #include "components/proximity_auth/remote_device.h" | 21 #include "components/proximity_auth/remote_device.h" |
22 #include "components/proximity_auth/screenlock_state.h" | 22 #include "components/proximity_auth/screenlock_state.h" |
23 | 23 |
24 #if defined(OS_CHROMEOS) | 24 #if defined(OS_CHROMEOS) |
25 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_types.h" | 25 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_types.h" |
26 #endif | 26 #endif |
27 | 27 |
| 28 class AccountId; |
| 29 |
28 namespace base { | 30 namespace base { |
29 class DictionaryValue; | 31 class DictionaryValue; |
30 class ListValue; | 32 class ListValue; |
31 } | 33 } |
32 | 34 |
33 namespace user_manager { | 35 namespace user_manager { |
34 class User; | 36 class User; |
35 } | 37 } |
36 | 38 |
37 namespace user_prefs { | 39 namespace user_prefs { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 // logged in and his profile is initialized. | 80 // logged in and his profile is initialized. |
79 static EasyUnlockService* GetForUser(const user_manager::User& user); | 81 static EasyUnlockService* GetForUser(const user_manager::User& user); |
80 | 82 |
81 // Registers Easy Unlock profile preferences. | 83 // Registers Easy Unlock profile preferences. |
82 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); | 84 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); |
83 | 85 |
84 // Registers Easy Unlock local state entries. | 86 // Registers Easy Unlock local state entries. |
85 static void RegisterPrefs(PrefRegistrySimple* registry); | 87 static void RegisterPrefs(PrefRegistrySimple* registry); |
86 | 88 |
87 // Removes the hardlock state for the given user. | 89 // Removes the hardlock state for the given user. |
88 static void ResetLocalStateForUser(const std::string& user_id); | 90 static void ResetLocalStateForUser(const AccountId& account_id); |
89 | 91 |
90 // Returns the user's preferences. | 92 // Returns the user's preferences. |
91 static UserSettings GetUserSettings(const std::string& user_id); | 93 static UserSettings GetUserSettings(const AccountId& account_id); |
92 | 94 |
93 // Returns the identifier for the device. | 95 // Returns the identifier for the device. |
94 static std::string GetDeviceId(); | 96 static std::string GetDeviceId(); |
95 | 97 |
96 // Returns the EasyUnlockService type. | 98 // Returns the EasyUnlockService type. |
97 virtual Type GetType() const = 0; | 99 virtual Type GetType() const = 0; |
98 | 100 |
99 // Returns the user currently associated with the service. | 101 // Returns the user currently associated with the service. |
100 virtual std::string GetUserEmail() const = 0; | 102 virtual AccountId GetAccountId() const = 0; |
101 | 103 |
102 // Launches Easy Unlock setup app. | 104 // Launches Easy Unlock setup app. |
103 virtual void LaunchSetup() = 0; | 105 virtual void LaunchSetup() = 0; |
104 | 106 |
105 // Gets/Sets/Clears the permit access for the local device. | 107 // Gets/Sets/Clears the permit access for the local device. |
106 virtual const base::DictionaryValue* GetPermitAccess() const = 0; | 108 virtual const base::DictionaryValue* GetPermitAccess() const = 0; |
107 virtual void SetPermitAccess(const base::DictionaryValue& permit) = 0; | 109 virtual void SetPermitAccess(const base::DictionaryValue& permit) = 0; |
108 virtual void ClearPermitAccess() = 0; | 110 virtual void ClearPermitAccess() = 0; |
109 | 111 |
110 // Gets/Sets the remote devices list. | 112 // Gets/Sets the remote devices list. |
(...skipping 14 matching lines...) Expand all Loading... |
125 // service. | 127 // service. |
126 virtual std::string GetChallenge() const = 0; | 128 virtual std::string GetChallenge() const = 0; |
127 | 129 |
128 // Retrieved wrapped secret that should be used to unlock cryptohome for the | 130 // Retrieved wrapped secret that should be used to unlock cryptohome for the |
129 // user currently associated with the service. If the service does not support | 131 // user currently associated with the service. If the service does not support |
130 // signin (i.e. service for a regular profile) or there is no secret available | 132 // signin (i.e. service for a regular profile) or there is no secret available |
131 // for the user, returns an empty string. | 133 // for the user, returns an empty string. |
132 virtual std::string GetWrappedSecret() const = 0; | 134 virtual std::string GetWrappedSecret() const = 0; |
133 | 135 |
134 // Records metrics for Easy sign-in outcome for the given user. | 136 // Records metrics for Easy sign-in outcome for the given user. |
135 virtual void RecordEasySignInOutcome(const std::string& user_id, | 137 virtual void RecordEasySignInOutcome(const AccountId& account_id, |
136 bool success) const = 0; | 138 bool success) const = 0; |
137 | 139 |
138 // Records metrics for password based flow for the given user. | 140 // Records metrics for password based flow for the given user. |
139 virtual void RecordPasswordLoginEvent(const std::string& user_id) const = 0; | 141 virtual void RecordPasswordLoginEvent(const AccountId& account_id) const = 0; |
140 | 142 |
141 // Starts auto pairing. | 143 // Starts auto pairing. |
142 typedef base::Callback<void(bool success, const std::string& error)> | 144 typedef base::Callback<void(bool success, const std::string& error)> |
143 AutoPairingResultCallback; | 145 AutoPairingResultCallback; |
144 virtual void StartAutoPairing(const AutoPairingResultCallback& callback) = 0; | 146 virtual void StartAutoPairing(const AutoPairingResultCallback& callback) = 0; |
145 | 147 |
146 // Sets auto pairing result. | 148 // Sets auto pairing result. |
147 virtual void SetAutoPairingResult(bool success, const std::string& error) = 0; | 149 virtual void SetAutoPairingResult(bool success, const std::string& error) = 0; |
148 | 150 |
149 // Sets the service up and schedules service initialization. | 151 // Sets the service up and schedules service initialization. |
(...skipping 26 matching lines...) Expand all Loading... |
176 // Updates the user pod on the signin/lock screen for the user associated with | 178 // Updates the user pod on the signin/lock screen for the user associated with |
177 // the service to reflect the provided screenlock state. | 179 // the service to reflect the provided screenlock state. |
178 bool UpdateScreenlockState(proximity_auth::ScreenlockState state); | 180 bool UpdateScreenlockState(proximity_auth::ScreenlockState state); |
179 | 181 |
180 // Returns the screenlock state if it is available. Otherwise STATE_INACTIVE | 182 // Returns the screenlock state if it is available. Otherwise STATE_INACTIVE |
181 // is returned. | 183 // is returned. |
182 proximity_auth::ScreenlockState GetScreenlockState(); | 184 proximity_auth::ScreenlockState GetScreenlockState(); |
183 | 185 |
184 // Starts an auth attempt for the user associated with the service. The | 186 // Starts an auth attempt for the user associated with the service. The |
185 // attempt type (unlock vs. signin) will depend on the service type. | 187 // attempt type (unlock vs. signin) will depend on the service type. |
186 void AttemptAuth(const std::string& user_id); | 188 void AttemptAuth(const AccountId& account_id); |
187 | 189 |
188 // Similar to above but a callback is invoked after the auth attempt is | 190 // Similar to above but a callback is invoked after the auth attempt is |
189 // finalized instead of default unlock/sign-in. | 191 // finalized instead of default unlock/sign-in. |
190 typedef EasyUnlockAuthAttempt::FinalizedCallback AttemptAuthCallback; | 192 typedef EasyUnlockAuthAttempt::FinalizedCallback AttemptAuthCallback; |
191 void AttemptAuth(const std::string& user_id, | 193 void AttemptAuth(const AccountId& account_id, |
192 const AttemptAuthCallback& callback); | 194 const AttemptAuthCallback& callback); |
193 | 195 |
194 // Finalizes the previously started auth attempt for easy unlock. If called on | 196 // Finalizes the previously started auth attempt for easy unlock. If called on |
195 // signin profile service, it will cancel the current auth attempt if one | 197 // signin profile service, it will cancel the current auth attempt if one |
196 // exists. | 198 // exists. |
197 void FinalizeUnlock(bool success); | 199 void FinalizeUnlock(bool success); |
198 | 200 |
199 // Finalizes previously started auth attempt for easy signin. If called on | 201 // Finalizes previously started auth attempt for easy signin. If called on |
200 // regular profile service, it will cancel the current auth attempt if one | 202 // regular profile service, it will cancel the current auth attempt if one |
201 // exists. | 203 // exists. |
202 void FinalizeSignin(const std::string& secret); | 204 void FinalizeSignin(const std::string& secret); |
203 | 205 |
204 // Handles Easy Unlock auth failure for the user. | 206 // Handles Easy Unlock auth failure for the user. |
205 void HandleAuthFailure(const std::string& user_id); | 207 void HandleAuthFailure(const AccountId& account_id); |
206 | 208 |
207 // Checks the consistency between pairing data and cryptohome keys. Set | 209 // Checks the consistency between pairing data and cryptohome keys. Set |
208 // hardlock state if the two do not match. | 210 // hardlock state if the two do not match. |
209 void CheckCryptohomeKeysAndMaybeHardlock(); | 211 void CheckCryptohomeKeysAndMaybeHardlock(); |
210 | 212 |
211 // Marks the Easy Unlock screen lock state as the one associated with the | 213 // Marks the Easy Unlock screen lock state as the one associated with the |
212 // trial run initiated by Easy Unlock app. | 214 // trial run initiated by Easy Unlock app. |
213 void SetTrialRun(); | 215 void SetTrialRun(); |
214 | 216 |
215 // Records that the user clicked on the lock icon during the trial run | 217 // Records that the user clicked on the lock icon during the trial run |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 void SetScreenlockHardlockedState( | 284 void SetScreenlockHardlockedState( |
283 EasyUnlockScreenlockStateHandler::HardlockState state); | 285 EasyUnlockScreenlockStateHandler::HardlockState state); |
284 | 286 |
285 const EasyUnlockScreenlockStateHandler* screenlock_state_handler() const { | 287 const EasyUnlockScreenlockStateHandler* screenlock_state_handler() const { |
286 return screenlock_state_handler_.get(); | 288 return screenlock_state_handler_.get(); |
287 } | 289 } |
288 | 290 |
289 // Saves hardlock state for the given user. Update UI if the currently | 291 // Saves hardlock state for the given user. Update UI if the currently |
290 // associated user is the same. | 292 // associated user is the same. |
291 void SetHardlockStateForUser( | 293 void SetHardlockStateForUser( |
292 const std::string& user_id, | 294 const AccountId& account_id, |
293 EasyUnlockScreenlockStateHandler::HardlockState state); | 295 EasyUnlockScreenlockStateHandler::HardlockState state); |
294 | 296 |
295 // Returns the authentication event for a recent password sign-in or unlock, | 297 // Returns the authentication event for a recent password sign-in or unlock, |
296 // according to the current state of the service. | 298 // according to the current state of the service. |
297 EasyUnlockAuthEvent GetPasswordAuthEvent() const; | 299 EasyUnlockAuthEvent GetPasswordAuthEvent() const; |
298 | 300 |
299 // Called by subclasses when remote devices allowed to unlock the screen | 301 // Called by subclasses when remote devices allowed to unlock the screen |
300 // are loaded for |user_id|. | 302 // are loaded for |account_id|. |
301 void SetProximityAuthDevices( | 303 void SetProximityAuthDevices( |
302 const std::string& user_id, | 304 const AccountId& account_id, |
303 const proximity_auth::RemoteDeviceList& remote_devices); | 305 const proximity_auth::RemoteDeviceList& remote_devices); |
304 | 306 |
305 private: | 307 private: |
306 // A class to detect whether a bluetooth adapter is present. | 308 // A class to detect whether a bluetooth adapter is present. |
307 class BluetoothDetector; | 309 class BluetoothDetector; |
308 | 310 |
309 // Initializes the service after EasyUnlockAppManager is ready. | 311 // Initializes the service after EasyUnlockAppManager is ready. |
310 void InitializeOnAppManagerReady(); | 312 void InitializeOnAppManagerReady(); |
311 | 313 |
312 // Gets |screenlock_state_handler_|. Returns NULL if Easy Unlock is not | 314 // Gets |screenlock_state_handler_|. Returns NULL if Easy Unlock is not |
313 // allowed. Otherwise, if |screenlock_state_handler_| is not set, an instance | 315 // allowed. Otherwise, if |screenlock_state_handler_| is not set, an instance |
314 // is created. Do not cache the returned value, as it may go away if Easy | 316 // is created. Do not cache the returned value, as it may go away if Easy |
315 // Unlock gets disabled. | 317 // Unlock gets disabled. |
316 EasyUnlockScreenlockStateHandler* GetScreenlockStateHandler(); | 318 EasyUnlockScreenlockStateHandler* GetScreenlockStateHandler(); |
317 | 319 |
318 // Callback when Bluetooth adapter present state changes. | 320 // Callback when Bluetooth adapter present state changes. |
319 void OnBluetoothAdapterPresentChanged(); | 321 void OnBluetoothAdapterPresentChanged(); |
320 | 322 |
321 #if defined(OS_CHROMEOS) | 323 #if defined(OS_CHROMEOS) |
322 // Callback for get key operation from CheckCryptohomeKeysAndMaybeHardlock. | 324 // Callback for get key operation from CheckCryptohomeKeysAndMaybeHardlock. |
323 void OnCryptohomeKeysFetchedForChecking( | 325 void OnCryptohomeKeysFetchedForChecking( |
324 const std::string& user_id, | 326 const AccountId& account_id, |
325 const std::set<std::string> paired_devices, | 327 const std::set<std::string> paired_devices, |
326 bool success, | 328 bool success, |
327 const chromeos::EasyUnlockDeviceKeyDataList& key_data_list); | 329 const chromeos::EasyUnlockDeviceKeyDataList& key_data_list); |
328 #endif | 330 #endif |
329 | 331 |
330 // Updates the service to state for handling system suspend. | 332 // Updates the service to state for handling system suspend. |
331 void PrepareForSuspend(); | 333 void PrepareForSuspend(); |
332 | 334 |
333 // Called when the system resumes from a suspended state. | 335 // Called when the system resumes from a suspended state. |
334 void OnSuspendDone(); | 336 void OnSuspendDone(); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 bool tpm_key_checked_; | 373 bool tpm_key_checked_; |
372 | 374 |
373 base::ObserverList<EasyUnlockServiceObserver> observers_; | 375 base::ObserverList<EasyUnlockServiceObserver> observers_; |
374 | 376 |
375 base::WeakPtrFactory<EasyUnlockService> weak_ptr_factory_; | 377 base::WeakPtrFactory<EasyUnlockService> weak_ptr_factory_; |
376 | 378 |
377 DISALLOW_COPY_AND_ASSIGN(EasyUnlockService); | 379 DISALLOW_COPY_AND_ASSIGN(EasyUnlockService); |
378 }; | 380 }; |
379 | 381 |
380 #endif // CHROME_BROWSER_SIGNIN_EASY_UNLOCK_SERVICE_H_ | 382 #endif // CHROME_BROWSER_SIGNIN_EASY_UNLOCK_SERVICE_H_ |
OLD | NEW |