easy_unlock_service.h revision 5b892326406927b709cdaf6c384d4ababf456332
15f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)// Copyright 2014 The Chromium Authors. All rights reserved.
25f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)// found in the LICENSE file.
45f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
55f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#ifndef CHROME_BROWSER_SIGNIN_EASY_UNLOCK_SERVICE_H_
65f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#define CHROME_BROWSER_SIGNIN_EASY_UNLOCK_SERVICE_H_
75f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
834680572440d7894ef8dafce81d8039ed80726a2Torne (Richard Coles)#include <set>
91320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include <string>
101320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
115f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include "base/macros.h"
126e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "base/memory/scoped_ptr.h"
135f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include "base/memory/weak_ptr.h"
146e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "base/observer_list.h"
151320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "chrome/browser/signin/easy_unlock_screenlock_state_handler.h"
165f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include "components/keyed_service/core/keyed_service.h"
175f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
1834680572440d7894ef8dafce81d8039ed80726a2Torne (Richard Coles)#if defined(OS_CHROMEOS)
1934680572440d7894ef8dafce81d8039ed80726a2Torne (Richard Coles)#include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_types.h"
2034680572440d7894ef8dafce81d8039ed80726a2Torne (Richard Coles)#endif
2134680572440d7894ef8dafce81d8039ed80726a2Torne (Richard Coles)
226e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)namespace base {
236e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)class DictionaryValue;
246e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)class ListValue;
256e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)}
266e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
2734680572440d7894ef8dafce81d8039ed80726a2Torne (Richard Coles)namespace user_manager {
2834680572440d7894ef8dafce81d8039ed80726a2Torne (Richard Coles)class User;
2934680572440d7894ef8dafce81d8039ed80726a2Torne (Richard Coles)}
3034680572440d7894ef8dafce81d8039ed80726a2Torne (Richard Coles)
315f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)namespace user_prefs {
325f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)class PrefRegistrySyncable;
335f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)}
345f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
351320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciclass EasyUnlockAuthAttempt;
366e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)class EasyUnlockServiceObserver;
375f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)class Profile;
3834680572440d7894ef8dafce81d8039ed80726a2Torne (Richard Coles)class PrefRegistrySimple;
395f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
405f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)class EasyUnlockService : public KeyedService {
415f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) public:
426e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  enum TurnOffFlowStatus {
436e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    IDLE,
446e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    PENDING,
456e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    FAIL,
466e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  };
476e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
481320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  enum Type {
491320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    TYPE_REGULAR,
501320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    TYPE_SIGNIN
511320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  };
525f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
535f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  // Gets EasyUnlockService instance.
545f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  static EasyUnlockService* Get(Profile* profile);
555f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
5634680572440d7894ef8dafce81d8039ed80726a2Torne (Richard Coles)  // Gets EasyUnlockService instance associated with a user if the user is
5734680572440d7894ef8dafce81d8039ed80726a2Torne (Richard Coles)  // logged in and his profile is initialized.
5834680572440d7894ef8dafce81d8039ed80726a2Torne (Richard Coles)  static EasyUnlockService* GetForUser(const user_manager::User& user);
5934680572440d7894ef8dafce81d8039ed80726a2Torne (Richard Coles)
605f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  // Registers Easy Unlock profile preferences.
615f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
625f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
6334680572440d7894ef8dafce81d8039ed80726a2Torne (Richard Coles)  // Registers Easy Unlock local state entries.
6434680572440d7894ef8dafce81d8039ed80726a2Torne (Richard Coles)  static void RegisterPrefs(PrefRegistrySimple* registry);
6534680572440d7894ef8dafce81d8039ed80726a2Torne (Richard Coles)
6634680572440d7894ef8dafce81d8039ed80726a2Torne (Richard Coles)  // Removes the hardlock state for the given user.
675b892326406927b709cdaf6c384d4ababf456332Ben Murdoch  static void ResetLocalStateForUser(const std::string& user_id);
6834680572440d7894ef8dafce81d8039ed80726a2Torne (Richard Coles)
691675a649fd7a8b3cb80ffddae2dc181f122353c5Ben Murdoch  // Returns true if Easy sign-in is enabled.
701675a649fd7a8b3cb80ffddae2dc181f122353c5Ben Murdoch  static bool IsSignInEnabled();
711675a649fd7a8b3cb80ffddae2dc181f122353c5Ben Murdoch
721320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Returns the EasyUnlockService type.
731320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  virtual Type GetType() const = 0;
741320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
751320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Returns the user currently associated with the service.
761320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  virtual std::string GetUserEmail() const = 0;
771320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
785f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  // Launches Easy Unlock Setup app.
791320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  virtual void LaunchSetup() = 0;
801320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
811320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Gets/Sets/Clears the permit access for the local device.
821320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  virtual const base::DictionaryValue* GetPermitAccess() const = 0;
831320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  virtual void SetPermitAccess(const base::DictionaryValue& permit) = 0;
841320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  virtual void ClearPermitAccess() = 0;
851320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
861320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Gets/Sets/Clears the remote devices list.
871320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  virtual const base::ListValue* GetRemoteDevices() const = 0;
881320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  virtual void SetRemoteDevices(const base::ListValue& devices) = 0;
891320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  virtual void ClearRemoteDevices() = 0;
901320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
911320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Runs the flow for turning Easy unlock off.
921320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  virtual void RunTurnOffFlow() = 0;
931320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
941320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Resets the turn off flow if one is in progress.
951320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  virtual void ResetTurnOffFlow() = 0;
961320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
971320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Returns the current turn off flow status.
981320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  virtual TurnOffFlowStatus GetTurnOffFlowStatus() const = 0;
991320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
1001320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Gets the challenge bytes for the user currently associated with the
1011320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // service.
1021320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  virtual std::string GetChallenge() const = 0;
1031320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
1041320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Retrieved wrapped secret that should be used to unlock cryptohome for the
1051320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // user currently associated with the service. If the service does not support
1061320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // signin (i.e. service for a regular profile) or there is no secret available
1071320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // for the user, returns an empty string.
1081320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  virtual std::string GetWrappedSecret() const = 0;
1095f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
110ab8f6f0bd665d3c1ff476eb06c58c42630e462d4Ben Murdoch  // Records metrics for Easy sign-in outcome for the given user.
111ab8f6f0bd665d3c1ff476eb06c58c42630e462d4Ben Murdoch  virtual void RecordEasySignInOutcome(const std::string& user_id,
112ab8f6f0bd665d3c1ff476eb06c58c42630e462d4Ben Murdoch                                       bool success) const = 0;
113ab8f6f0bd665d3c1ff476eb06c58c42630e462d4Ben Murdoch
114ab8f6f0bd665d3c1ff476eb06c58c42630e462d4Ben Murdoch  // Records metrics for password based flow for the given user.
115ab8f6f0bd665d3c1ff476eb06c58c42630e462d4Ben Murdoch  virtual void RecordPasswordLoginEvent(const std::string& user_id) const = 0;
116ab8f6f0bd665d3c1ff476eb06c58c42630e462d4Ben Murdoch
1175f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  // Whether easy unlock is allowed to be used. If the controlling preference
1185f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  // is set (from policy), this returns the preference value. Otherwise, it is
1195f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  // permitted either the flag is enabled or its field trial is enabled.
1205f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  bool IsAllowed();
1215f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
12234680572440d7894ef8dafce81d8039ed80726a2Torne (Richard Coles)  // Sets the hardlock state for the associated user.
12334680572440d7894ef8dafce81d8039ed80726a2Torne (Richard Coles)  void SetHardlockState(EasyUnlockScreenlockStateHandler::HardlockState state);
12434680572440d7894ef8dafce81d8039ed80726a2Torne (Richard Coles)
12534680572440d7894ef8dafce81d8039ed80726a2Torne (Richard Coles)  // Returns the hardlock state for the associated user.
12634680572440d7894ef8dafce81d8039ed80726a2Torne (Richard Coles)  EasyUnlockScreenlockStateHandler::HardlockState GetHardlockState() const;
12734680572440d7894ef8dafce81d8039ed80726a2Torne (Richard Coles)
12834680572440d7894ef8dafce81d8039ed80726a2Torne (Richard Coles)  // Ensures the hardlock state is visible even when there is no cryptohome
12934680572440d7894ef8dafce81d8039ed80726a2Torne (Richard Coles)  // keys and no state update from the app.
13034680572440d7894ef8dafce81d8039ed80726a2Torne (Richard Coles)  void MaybeShowHardlockUI();
13134680572440d7894ef8dafce81d8039ed80726a2Torne (Richard Coles)
1321320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Updates the user pod on the signin/lock screen for the user associated with
1331320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // the service to reflect the provided screenlock state.
1341320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  bool UpdateScreenlockState(EasyUnlockScreenlockStateHandler::State state);
1356e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
1361320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Starts an auth attempt for the user associated with the service. The
1371320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // attempt type (unlock vs. signin) will depend on the service type.
1381320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  void AttemptAuth(const std::string& user_id);
1396e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
1401320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Finalizes the previously started auth attempt for easy unlock. If called on
1411320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // signin profile service, it will cancel the current auth attempt if one
1421320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // exists.
1431320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  void FinalizeUnlock(bool success);
1446e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
1451320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Finalizes previously started auth attempt for easy signin. If called on
1461320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // regular profile service, it will cancel the current auth attempt if one
1471320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // exists.
1481320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  void FinalizeSignin(const std::string& secret);
1496e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
15034680572440d7894ef8dafce81d8039ed80726a2Torne (Richard Coles)  // Checks the consistency between pairing data and cryptohome keys. Set
15134680572440d7894ef8dafce81d8039ed80726a2Torne (Richard Coles)  // hardlock state if the two do not match.
15234680572440d7894ef8dafce81d8039ed80726a2Torne (Richard Coles)  void CheckCryptohomeKeysAndMaybeHardlock();
15334680572440d7894ef8dafce81d8039ed80726a2Torne (Richard Coles)
1545b892326406927b709cdaf6c384d4ababf456332Ben Murdoch  // Marks the Easy Unlock screen lock state as the one associated with the
1555b892326406927b709cdaf6c384d4ababf456332Ben Murdoch  // trial run initiated by Easy Unlock app.
1565b892326406927b709cdaf6c384d4ababf456332Ben Murdoch  void SetTrialRun();
1575b892326406927b709cdaf6c384d4ababf456332Ben Murdoch
1586e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  void AddObserver(EasyUnlockServiceObserver* observer);
1596e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  void RemoveObserver(EasyUnlockServiceObserver* observer);
1606e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
1611320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci protected:
1621320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  explicit EasyUnlockService(Profile* profile);
1631320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  virtual ~EasyUnlockService();
1646e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
1651320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Does a service type specific initialization.
1661320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  virtual void InitializeInternal() = 0;
16703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)
1681320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Does a service type specific shutdown. Called from |Shutdown|.
1691320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  virtual void ShutdownInternal() = 0;
17003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)
1711320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Service type specific tests for whether the service is allowed. Returns
1721320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // false if service is not allowed. If true is returned, the service may still
1731320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // not be allowed if common tests fail (e.g. if Bluetooth is not available).
1741320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  virtual bool IsAllowedInternal() = 0;
1751320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
1761320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // KeyedService override:
1771320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  virtual void Shutdown() OVERRIDE;
1781320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
1791320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Exposes the profile to which the service is attached to subclasses.
1801320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  Profile* profile() const { return profile_; }
1811320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
1821320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Installs the Easy unlock component app if it isn't installed and enables
1831320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // the app if it is disabled.
1845f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  void LoadApp();
18503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)
1861320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Disables the Easy unlock component app if it's loaded.
1871320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  void DisableAppIfLoaded();
1881320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
1891320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Unloads the Easy unlock component app if it's loaded.
1905f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  void UnloadApp();
19103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)
1921320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Reloads the Easy unlock component app if it's loaded.
1931320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  void ReloadApp();
1941320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
19503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  // Checks whether Easy unlock should be running and updates app state.
19603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  void UpdateAppState();
19703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)
1981320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Notifies the easy unlock app that the user state has been updated.
1991320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  void NotifyUserUpdated();
2005f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
2011320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Notifies observers that the turn off flow status changed.
2021320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  void NotifyTurnOffOperationStatusChanged();
20303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)
2041320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Resets the screenlock state set by this service.
2051320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  void ResetScreenlockState();
20603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)
20734680572440d7894ef8dafce81d8039ed80726a2Torne (Richard Coles)  // Updates |screenlock_state_handler_|'s hardlocked state.
20834680572440d7894ef8dafce81d8039ed80726a2Torne (Richard Coles)  void SetScreenlockHardlockedState(
20934680572440d7894ef8dafce81d8039ed80726a2Torne (Richard Coles)      EasyUnlockScreenlockStateHandler::HardlockState state);
21034680572440d7894ef8dafce81d8039ed80726a2Torne (Richard Coles)
211ab8f6f0bd665d3c1ff476eb06c58c42630e462d4Ben Murdoch  const EasyUnlockScreenlockStateHandler* screenlock_state_handler() const {
212ab8f6f0bd665d3c1ff476eb06c58c42630e462d4Ben Murdoch    return screenlock_state_handler_.get();
213ab8f6f0bd665d3c1ff476eb06c58c42630e462d4Ben Murdoch  }
214ab8f6f0bd665d3c1ff476eb06c58c42630e462d4Ben Murdoch
2151320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci private:
2161320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // A class to detect whether a bluetooth adapter is present.
2171320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  class BluetoothDetector;
2181320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
2191320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Initializes the service after ExtensionService is ready.
2201320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  void Initialize();
2211320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
2221320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Gets |screenlock_state_handler_|. Returns NULL if Easy Unlock is not
2231320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // allowed. Otherwise, if |screenlock_state_handler_| is not set, an instance
2241320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // is created. Do not cache the returned value, as it may go away if Easy
2251320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Unlock gets disabled.
2261320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  EasyUnlockScreenlockStateHandler* GetScreenlockStateHandler();
2271320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
2281320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Callback when Bluetooth adapter present state changes.
2291320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  void OnBluetoothAdapterPresentChanged();
2306e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
23134680572440d7894ef8dafce81d8039ed80726a2Torne (Richard Coles)  // Saves hardlock state for the given user. Update UI if the currently
23234680572440d7894ef8dafce81d8039ed80726a2Torne (Richard Coles)  // associated user is the same.
23334680572440d7894ef8dafce81d8039ed80726a2Torne (Richard Coles)  void SetHardlockStateForUser(
23434680572440d7894ef8dafce81d8039ed80726a2Torne (Richard Coles)      const std::string& user_id,
23534680572440d7894ef8dafce81d8039ed80726a2Torne (Richard Coles)      EasyUnlockScreenlockStateHandler::HardlockState state);
23634680572440d7894ef8dafce81d8039ed80726a2Torne (Richard Coles)
23734680572440d7894ef8dafce81d8039ed80726a2Torne (Richard Coles)#if defined(OS_CHROMEOS)
23834680572440d7894ef8dafce81d8039ed80726a2Torne (Richard Coles)  // Callback for get key operation from CheckCryptohomeKeysAndMaybeHardlock.
23934680572440d7894ef8dafce81d8039ed80726a2Torne (Richard Coles)  void OnCryptohomeKeysFetchedForChecking(
24034680572440d7894ef8dafce81d8039ed80726a2Torne (Richard Coles)      const std::string& user_id,
24134680572440d7894ef8dafce81d8039ed80726a2Torne (Richard Coles)      const std::set<std::string> paired_devices,
24234680572440d7894ef8dafce81d8039ed80726a2Torne (Richard Coles)      bool success,
24334680572440d7894ef8dafce81d8039ed80726a2Torne (Richard Coles)      const chromeos::EasyUnlockDeviceKeyDataList& key_data_list);
24434680572440d7894ef8dafce81d8039ed80726a2Torne (Richard Coles)#endif
24534680572440d7894ef8dafce81d8039ed80726a2Torne (Richard Coles)
2465b892326406927b709cdaf6c384d4ababf456332Ben Murdoch  // Updates the service to state for handling system suspend.
2475b892326406927b709cdaf6c384d4ababf456332Ben Murdoch  void PrepareForSuspend();
2485b892326406927b709cdaf6c384d4ababf456332Ben Murdoch
2495f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  Profile* profile_;
2501320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
2516e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // Created lazily in |GetScreenlockStateHandler|.
2526e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  scoped_ptr<EasyUnlockScreenlockStateHandler> screenlock_state_handler_;
2536e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
2541320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // The handler for the current auth attempt. Set iff an auth attempt is in
2551320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // progress.
2561320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  scoped_ptr<EasyUnlockAuthAttempt> auth_attempt_;
2571320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
2581320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  scoped_ptr<BluetoothDetector> bluetooth_detector_;
2591320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
2601320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#if defined(OS_CHROMEOS)
2611320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Monitors suspend and wake state of ChromeOS.
2621320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  class PowerMonitor;
2631320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  scoped_ptr<PowerMonitor> power_monitor_;
2641320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#endif
2651320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
2661320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Whether the service has been shut down.
2671320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  bool shut_down_;
2681320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
2696e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  ObserverList<EasyUnlockServiceObserver> observers_;
2706e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
2715f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  base::WeakPtrFactory<EasyUnlockService> weak_ptr_factory_;
2725f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
2735f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(EasyUnlockService);
2745f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)};
2755f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
2765f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#endif  // CHROME_BROWSER_SIGNIN_EASY_UNLOCK_SERVICE_H_
277