easy_unlock_service.h revision e4256316f8b5e8d1ec0df1f7762771622a53fa63
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)
128e4256316f8b5e8d1ec0df1f7762771622a53fa63Ben Murdoch  // Gets the persisted hardlock state. Return true if there is persisted
129e4256316f8b5e8d1ec0df1f7762771622a53fa63Ben Murdoch  // hardlock state and the value would be set to |state|. Otherwise,
130e4256316f8b5e8d1ec0df1f7762771622a53fa63Ben Murdoch  // returns false and |state| is unchanged.
131e4256316f8b5e8d1ec0df1f7762771622a53fa63Ben Murdoch  bool GetPersistedHardlockState(
132e4256316f8b5e8d1ec0df1f7762771622a53fa63Ben Murdoch      EasyUnlockScreenlockStateHandler::HardlockState* state) const;
133e4256316f8b5e8d1ec0df1f7762771622a53fa63Ben Murdoch
134e4256316f8b5e8d1ec0df1f7762771622a53fa63Ben Murdoch  // Shows the hardlock or connecting state as initial UI before cryptohome
135e4256316f8b5e8d1ec0df1f7762771622a53fa63Ben Murdoch  // keys checking and state update from the app.
136e4256316f8b5e8d1ec0df1f7762771622a53fa63Ben Murdoch  void ShowInitialUserState();
13734680572440d7894ef8dafce81d8039ed80726a2Torne (Richard Coles)
1381320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Updates the user pod on the signin/lock screen for the user associated with
1391320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // the service to reflect the provided screenlock state.
1401320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  bool UpdateScreenlockState(EasyUnlockScreenlockStateHandler::State state);
1416e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
1421320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Starts an auth attempt for the user associated with the service. The
1431320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // attempt type (unlock vs. signin) will depend on the service type.
1441320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  void AttemptAuth(const std::string& user_id);
1456e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
1461320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Finalizes the previously started auth attempt for easy unlock. If called on
1471320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // signin profile service, it will cancel the current auth attempt if one
1481320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // exists.
1491320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  void FinalizeUnlock(bool success);
1506e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
1511320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Finalizes previously started auth attempt for easy signin. If called on
1521320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // regular profile service, it will cancel the current auth attempt if one
1531320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // exists.
1541320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  void FinalizeSignin(const std::string& secret);
1556e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
15634680572440d7894ef8dafce81d8039ed80726a2Torne (Richard Coles)  // Checks the consistency between pairing data and cryptohome keys. Set
15734680572440d7894ef8dafce81d8039ed80726a2Torne (Richard Coles)  // hardlock state if the two do not match.
15834680572440d7894ef8dafce81d8039ed80726a2Torne (Richard Coles)  void CheckCryptohomeKeysAndMaybeHardlock();
15934680572440d7894ef8dafce81d8039ed80726a2Torne (Richard Coles)
1605b892326406927b709cdaf6c384d4ababf456332Ben Murdoch  // Marks the Easy Unlock screen lock state as the one associated with the
1615b892326406927b709cdaf6c384d4ababf456332Ben Murdoch  // trial run initiated by Easy Unlock app.
1625b892326406927b709cdaf6c384d4ababf456332Ben Murdoch  void SetTrialRun();
1635b892326406927b709cdaf6c384d4ababf456332Ben Murdoch
1646e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  void AddObserver(EasyUnlockServiceObserver* observer);
1656e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  void RemoveObserver(EasyUnlockServiceObserver* observer);
1666e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
1671320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci protected:
1681320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  explicit EasyUnlockService(Profile* profile);
1691320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  virtual ~EasyUnlockService();
1706e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
1711320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Does a service type specific initialization.
1721320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  virtual void InitializeInternal() = 0;
17303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)
1741320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Does a service type specific shutdown. Called from |Shutdown|.
1751320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  virtual void ShutdownInternal() = 0;
17603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)
1771320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Service type specific tests for whether the service is allowed. Returns
1781320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // false if service is not allowed. If true is returned, the service may still
1791320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // not be allowed if common tests fail (e.g. if Bluetooth is not available).
1801320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  virtual bool IsAllowedInternal() = 0;
1811320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
1821320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // KeyedService override:
1831320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  virtual void Shutdown() OVERRIDE;
1841320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
1851320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Exposes the profile to which the service is attached to subclasses.
1861320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  Profile* profile() const { return profile_; }
1871320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
1881320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Installs the Easy unlock component app if it isn't installed and enables
1891320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // the app if it is disabled.
1905f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  void LoadApp();
19103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)
1921320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Disables the Easy unlock component app if it's loaded.
1931320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  void DisableAppIfLoaded();
1941320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
1951320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Unloads the Easy unlock component app if it's loaded.
1965f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  void UnloadApp();
19703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)
1981320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Reloads the Easy unlock component app if it's loaded.
1991320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  void ReloadApp();
2001320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
20103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  // Checks whether Easy unlock should be running and updates app state.
20203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  void UpdateAppState();
20303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)
2041320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Notifies the easy unlock app that the user state has been updated.
2051320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  void NotifyUserUpdated();
2065f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
2071320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Notifies observers that the turn off flow status changed.
2081320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  void NotifyTurnOffOperationStatusChanged();
20903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)
2101320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Resets the screenlock state set by this service.
2111320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  void ResetScreenlockState();
21203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)
21334680572440d7894ef8dafce81d8039ed80726a2Torne (Richard Coles)  // Updates |screenlock_state_handler_|'s hardlocked state.
21434680572440d7894ef8dafce81d8039ed80726a2Torne (Richard Coles)  void SetScreenlockHardlockedState(
21534680572440d7894ef8dafce81d8039ed80726a2Torne (Richard Coles)      EasyUnlockScreenlockStateHandler::HardlockState state);
21634680572440d7894ef8dafce81d8039ed80726a2Torne (Richard Coles)
217ab8f6f0bd665d3c1ff476eb06c58c42630e462d4Ben Murdoch  const EasyUnlockScreenlockStateHandler* screenlock_state_handler() const {
218ab8f6f0bd665d3c1ff476eb06c58c42630e462d4Ben Murdoch    return screenlock_state_handler_.get();
219ab8f6f0bd665d3c1ff476eb06c58c42630e462d4Ben Murdoch  }
220ab8f6f0bd665d3c1ff476eb06c58c42630e462d4Ben Murdoch
22129b820f8d84e3bc97d62552e54923c42407f2f29Ben Murdoch  // Saves hardlock state for the given user. Update UI if the currently
22229b820f8d84e3bc97d62552e54923c42407f2f29Ben Murdoch  // associated user is the same.
22329b820f8d84e3bc97d62552e54923c42407f2f29Ben Murdoch  void SetHardlockStateForUser(
22429b820f8d84e3bc97d62552e54923c42407f2f29Ben Murdoch      const std::string& user_id,
22529b820f8d84e3bc97d62552e54923c42407f2f29Ben Murdoch      EasyUnlockScreenlockStateHandler::HardlockState state);
22629b820f8d84e3bc97d62552e54923c42407f2f29Ben Murdoch
2271320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci private:
2281320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // A class to detect whether a bluetooth adapter is present.
2291320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  class BluetoothDetector;
2301320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
2311320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Initializes the service after ExtensionService is ready.
2321320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  void Initialize();
2331320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
2341320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Gets |screenlock_state_handler_|. Returns NULL if Easy Unlock is not
2351320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // allowed. Otherwise, if |screenlock_state_handler_| is not set, an instance
2361320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // is created. Do not cache the returned value, as it may go away if Easy
2371320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Unlock gets disabled.
2381320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  EasyUnlockScreenlockStateHandler* GetScreenlockStateHandler();
2391320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
2401320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Callback when Bluetooth adapter present state changes.
2411320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  void OnBluetoothAdapterPresentChanged();
2426e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
24334680572440d7894ef8dafce81d8039ed80726a2Torne (Richard Coles)#if defined(OS_CHROMEOS)
24434680572440d7894ef8dafce81d8039ed80726a2Torne (Richard Coles)  // Callback for get key operation from CheckCryptohomeKeysAndMaybeHardlock.
24534680572440d7894ef8dafce81d8039ed80726a2Torne (Richard Coles)  void OnCryptohomeKeysFetchedForChecking(
24634680572440d7894ef8dafce81d8039ed80726a2Torne (Richard Coles)      const std::string& user_id,
24734680572440d7894ef8dafce81d8039ed80726a2Torne (Richard Coles)      const std::set<std::string> paired_devices,
24834680572440d7894ef8dafce81d8039ed80726a2Torne (Richard Coles)      bool success,
24934680572440d7894ef8dafce81d8039ed80726a2Torne (Richard Coles)      const chromeos::EasyUnlockDeviceKeyDataList& key_data_list);
25034680572440d7894ef8dafce81d8039ed80726a2Torne (Richard Coles)#endif
25134680572440d7894ef8dafce81d8039ed80726a2Torne (Richard Coles)
2525b892326406927b709cdaf6c384d4ababf456332Ben Murdoch  // Updates the service to state for handling system suspend.
2535b892326406927b709cdaf6c384d4ababf456332Ben Murdoch  void PrepareForSuspend();
2545b892326406927b709cdaf6c384d4ababf456332Ben Murdoch
2555f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  Profile* profile_;
2561320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
2576e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // Created lazily in |GetScreenlockStateHandler|.
2586e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  scoped_ptr<EasyUnlockScreenlockStateHandler> screenlock_state_handler_;
2596e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
2601320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // The handler for the current auth attempt. Set iff an auth attempt is in
2611320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // progress.
2621320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  scoped_ptr<EasyUnlockAuthAttempt> auth_attempt_;
2631320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
2641320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  scoped_ptr<BluetoothDetector> bluetooth_detector_;
2651320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
2661320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#if defined(OS_CHROMEOS)
2671320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Monitors suspend and wake state of ChromeOS.
2681320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  class PowerMonitor;
2691320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  scoped_ptr<PowerMonitor> power_monitor_;
2701320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#endif
2711320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
2721320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Whether the service has been shut down.
2731320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  bool shut_down_;
2741320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
2756e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  ObserverList<EasyUnlockServiceObserver> observers_;
2766e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
2775f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  base::WeakPtrFactory<EasyUnlockService> weak_ptr_factory_;
2785f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
2795f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(EasyUnlockService);
2805f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)};
2815f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
2825f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#endif  // CHROME_BROWSER_SIGNIN_EASY_UNLOCK_SERVICE_H_
283