easy_unlock_service.h revision 6e8cce623b6e4fe0c9e4af605d675dd9d0338c38
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.
4
5#ifndef CHROME_BROWSER_SIGNIN_EASY_UNLOCK_SERVICE_H_
6#define CHROME_BROWSER_SIGNIN_EASY_UNLOCK_SERVICE_H_
7
8#include "base/macros.h"
9#include "base/memory/scoped_ptr.h"
10#include "base/memory/weak_ptr.h"
11#include "base/observer_list.h"
12#include "base/prefs/pref_change_registrar.h"
13#include "components/keyed_service/core/keyed_service.h"
14
15namespace base {
16class DictionaryValue;
17class ListValue;
18}
19
20namespace user_prefs {
21class PrefRegistrySyncable;
22}
23
24class EasyUnlockScreenlockStateHandler;
25class EasyUnlockServiceObserver;
26class EasyUnlockToggleFlow;
27class Profile;
28
29class EasyUnlockService : public KeyedService {
30 public:
31  enum TurnOffFlowStatus {
32    IDLE,
33    PENDING,
34    FAIL,
35  };
36
37  explicit EasyUnlockService(Profile* profile);
38  virtual ~EasyUnlockService();
39
40  // Gets EasyUnlockService instance.
41  static EasyUnlockService* Get(Profile* profile);
42
43  // Registers Easy Unlock profile preferences.
44  static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
45
46  // Launches Easy Unlock Setup app.
47  void LaunchSetup();
48
49  // Whether easy unlock is allowed to be used. If the controlling preference
50  // is set (from policy), this returns the preference value. Otherwise, it is
51  // permitted either the flag is enabled or its field trial is enabled.
52  bool IsAllowed();
53
54  // Gets |screenlock_state_handler_|. Returns NULL if Easy Unlock is not
55  // allowed. Otherwise, if |screenlock_state_handler_| is not set, an instance
56  // is created. Do not cache the returned value, as it may go away if Easy
57  // Unlock gets disabled.
58  EasyUnlockScreenlockStateHandler* GetScreenlockStateHandler();
59
60  // Gets/Sets/Clears the permit access for the local device.
61  const base::DictionaryValue* GetPermitAccess() const;
62  void SetPermitAccess(const base::DictionaryValue& permit);
63  void ClearPermitAccess();
64
65  // Gets/Sets/Clears the remote devices list.
66  const base::ListValue* GetRemoteDevices() const;
67  void SetRemoteDevices(const base::ListValue& devices);
68  void ClearRemoteDevices();
69
70  void RunTurnOffFlow();
71  void ResetTurnOffFlow();
72
73  void AddObserver(EasyUnlockServiceObserver* observer);
74  void RemoveObserver(EasyUnlockServiceObserver* observer);
75
76  TurnOffFlowStatus turn_off_flow_status() const {
77    return turn_off_flow_status_;
78  }
79
80 private:
81  void Initialize();
82  void LoadApp();
83  void UnloadApp();
84  void OnPrefsChanged();
85
86  void SetTurnOffFlowStatus(TurnOffFlowStatus status);
87  void OnTurnOffFlowFinished(bool success);
88
89  Profile* profile_;
90  PrefChangeRegistrar registrar_;
91  // Created lazily in |GetScreenlockStateHandler|.
92  scoped_ptr<EasyUnlockScreenlockStateHandler> screenlock_state_handler_;
93
94  TurnOffFlowStatus turn_off_flow_status_;
95  scoped_ptr<EasyUnlockToggleFlow> turn_off_flow_;
96  ObserverList<EasyUnlockServiceObserver> observers_;
97
98  base::WeakPtrFactory<EasyUnlockService> weak_ptr_factory_;
99
100  DISALLOW_COPY_AND_ASSIGN(EasyUnlockService);
101};
102
103#endif  // CHROME_BROWSER_SIGNIN_EASY_UNLOCK_SERVICE_H_
104