Chromium Code Reviews| 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 <string> | |
| 9 | |
| 8 #include "base/macros.h" | 10 #include "base/macros.h" |
| 9 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 11 #include "base/observer_list.h" | 13 #include "base/observer_list.h" |
| 12 #include "base/prefs/pref_change_registrar.h" | |
| 13 #include "components/keyed_service/core/keyed_service.h" | 14 #include "components/keyed_service/core/keyed_service.h" |
| 14 | 15 |
| 15 namespace base { | 16 namespace base { |
| 16 class DictionaryValue; | 17 class DictionaryValue; |
| 17 class ListValue; | 18 class ListValue; |
| 18 } | 19 } |
| 19 | 20 |
| 20 namespace user_prefs { | 21 namespace user_prefs { |
| 21 class PrefRegistrySyncable; | 22 class PrefRegistrySyncable; |
| 22 } | 23 } |
| 23 | 24 |
| 24 class EasyUnlockScreenlockStateHandler; | 25 class EasyUnlockScreenlockStateHandler; |
| 25 class EasyUnlockServiceObserver; | 26 class EasyUnlockServiceObserver; |
| 26 class EasyUnlockToggleFlow; | |
| 27 class Profile; | 27 class Profile; |
| 28 | 28 |
| 29 class EasyUnlockService : public KeyedService { | 29 class EasyUnlockService : public KeyedService { |
| 30 public: | 30 public: |
| 31 enum TurnOffFlowStatus { | 31 enum TurnOffFlowStatus { |
| 32 IDLE, | 32 IDLE, |
| 33 PENDING, | 33 PENDING, |
| 34 FAIL, | 34 FAIL, |
| 35 }; | 35 }; |
| 36 | 36 |
| 37 explicit EasyUnlockService(Profile* profile); | 37 enum Type { |
| 38 virtual ~EasyUnlockService(); | 38 TYPE_REGULAR, |
| 39 TYPE_SIGNIN | |
| 40 }; | |
| 39 | 41 |
| 40 // Gets EasyUnlockService instance. | 42 // Gets EasyUnlockService instance. |
| 41 static EasyUnlockService* Get(Profile* profile); | 43 static EasyUnlockService* Get(Profile* profile); |
| 42 | 44 |
| 43 // Registers Easy Unlock profile preferences. | 45 // Registers Easy Unlock profile preferences. |
| 44 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); | 46 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); |
| 45 | 47 |
| 48 // Returns the EasyUnlockService type. | |
| 49 virtual Type GetType() const = 0; | |
| 50 | |
| 51 // Returns the user currently associated with the service. | |
| 52 virtual std::string GetUserEmail() const = 0; | |
| 53 | |
| 46 // Launches Easy Unlock Setup app. | 54 // Launches Easy Unlock Setup app. |
| 47 void LaunchSetup(); | 55 virtual void LaunchSetup() = 0; |
| 48 | 56 |
| 49 // Whether easy unlock is allowed to be used. If the controlling preference | 57 // Gets/Sets/Clears the permit access for the local device. |
| 50 // is set (from policy), this returns the preference value. Otherwise, it is | 58 virtual const base::DictionaryValue* GetPermitAccess() const = 0; |
| 51 // permitted either the flag is enabled or its field trial is enabled. | 59 virtual void SetPermitAccess(const base::DictionaryValue& permit) = 0; |
| 52 bool IsAllowed(); | 60 virtual void ClearPermitAccess() = 0; |
| 61 | |
| 62 // Gets/Sets/Clears the remote devices list. | |
| 63 virtual const base::ListValue* GetRemoteDevices() const = 0; | |
| 64 virtual void SetRemoteDevices(const base::ListValue& devices) = 0; | |
| 65 virtual void ClearRemoteDevices() = 0; | |
| 66 | |
| 67 // Runs the flow for turning Easy unlock off. | |
| 68 virtual void RunTurnOffFlow() = 0; | |
| 69 | |
| 70 // Resets the turn off flow if one is in progress. | |
| 71 virtual void ResetTurnOffFlow() = 0; | |
| 53 | 72 |
| 54 // Gets |screenlock_state_handler_|. Returns NULL if Easy Unlock is not | 73 // Gets |screenlock_state_handler_|. Returns NULL if Easy Unlock is not |
| 55 // allowed. Otherwise, if |screenlock_state_handler_| is not set, an instance | 74 // 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 | 75 // is created. Do not cache the returned value, as it may go away if Easy |
| 57 // Unlock gets disabled. | 76 // Unlock gets disabled. |
| 58 EasyUnlockScreenlockStateHandler* GetScreenlockStateHandler(); | 77 EasyUnlockScreenlockStateHandler* GetScreenlockStateHandler(); |
| 59 | 78 |
| 60 // Gets/Sets/Clears the permit access for the local device. | 79 // Whether easy unlock is allowed to be used. If the controlling preference |
| 61 const base::DictionaryValue* GetPermitAccess() const; | 80 // is set (from policy), this returns the preference value. Otherwise, it is |
| 62 void SetPermitAccess(const base::DictionaryValue& permit); | 81 // permitted either the flag is enabled or its field trial is enabled. |
| 63 void ClearPermitAccess(); | 82 bool IsAllowed(); |
| 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 | 83 |
| 73 void AddObserver(EasyUnlockServiceObserver* observer); | 84 void AddObserver(EasyUnlockServiceObserver* observer); |
| 74 void RemoveObserver(EasyUnlockServiceObserver* observer); | 85 void RemoveObserver(EasyUnlockServiceObserver* observer); |
| 75 | 86 |
| 76 TurnOffFlowStatus turn_off_flow_status() const { | 87 TurnOffFlowStatus turn_off_flow_status() const { |
| 77 return turn_off_flow_status_; | 88 return turn_off_flow_status_; |
| 78 } | 89 } |
| 79 | 90 |
| 80 private: | 91 protected: |
| 81 // A class to detect whether a bluetooth adapter is present. | 92 explicit EasyUnlockService(Profile* profile); |
| 82 class BluetoothDetector; | 93 virtual ~EasyUnlockService(); |
| 83 | 94 |
| 84 // Initializes the service after ExtensionService is ready. | 95 // Does service type specific initialization. |
| 85 void Initialize(); | 96 virtual void InitializeInternal() = 0; |
| 97 | |
| 98 // Service type specific tests for whether the service is allowed. Returns | |
| 99 // false if service is not allowed. If true is returned, the service may still | |
| 100 // not be allowed if common tests fail (e.g. if Bluetooth is not available). | |
| 101 virtual bool IsAllowedInternal() = 0; | |
| 86 | 102 |
| 87 // Installs the Easy unlock component app if it isn't installed or enables | 103 // Installs the Easy unlock component app if it isn't installed or enables |
| 88 // the app if it is installed but disabled. | 104 // the app if it is installed but disabled. |
| 89 void LoadApp(); | 105 void LoadApp(); |
| 90 | 106 |
| 91 // Disables the Easy unlock component app if it's loaded. | 107 // Disables the Easy unlock component app if it's loaded. |
| 92 void DisableAppIfLoaded(); | 108 void DisableAppIfLoaded(); |
| 93 | 109 |
| 110 // Reloads the Easy unlock component app if it's loaded. | |
| 111 void ReloadApp(); | |
| 112 | |
| 94 // Checks whether Easy unlock should be running and updates app state. | 113 // Checks whether Easy unlock should be running and updates app state. |
| 95 void UpdateAppState(); | 114 void UpdateAppState(); |
| 96 | 115 |
| 97 // Callback when the controlling pref changes. | 116 // Notifies observers that the turn off flow status changed. |
| 98 void OnPrefsChanged(); | 117 void NotifyTurnOffOperationStatusChanged(); |
| 118 | |
| 119 private: | |
| 120 // Initializes the service after ExtensionService is ready. | |
| 121 void Initialize(); | |
| 122 | |
| 123 // A class to detect whether a bluetooth adapter is present. | |
| 124 class BluetoothDetector; | |
|
xiyuan
2014/09/16 21:59:59
nit: class declaration before function declaration
tbarzic
2014/09/16 22:30:58
Done.
| |
| 99 | 125 |
| 100 // Callback when Bluetooth adapter present state changes. | 126 // Callback when Bluetooth adapter present state changes. |
| 101 void OnBluetoothAdapterPresentChanged(); | 127 void OnBluetoothAdapterPresentChanged(); |
| 102 | 128 |
| 103 // Sets the new turn-off flow status. | 129 protected: |
| 104 void SetTurnOffFlowStatus(TurnOffFlowStatus status); | 130 Profile* profile_; |
|
xiyuan
2014/09/16 21:59:59
Can we keep this in private and expose to sub clas
tbarzic
2014/09/16 22:30:58
Done.
| |
| 105 | 131 |
| 106 // Callback invoked when turn off flow has finished. | |
| 107 void OnTurnOffFlowFinished(bool success); | |
| 108 | |
| 109 Profile* profile_; | |
| 110 PrefChangeRegistrar registrar_; | |
| 111 scoped_ptr<BluetoothDetector> bluetooth_detector_; | |
| 112 // Created lazily in |GetScreenlockStateHandler|. | 132 // Created lazily in |GetScreenlockStateHandler|. |
| 113 scoped_ptr<EasyUnlockScreenlockStateHandler> screenlock_state_handler_; | 133 scoped_ptr<EasyUnlockScreenlockStateHandler> screenlock_state_handler_; |
|
xiyuan
2014/09/16 21:59:59
sub class seems not accessing it. Let's keep it pr
tbarzic
2014/09/16 22:30:58
Done.
| |
| 114 | 134 |
| 115 TurnOffFlowStatus turn_off_flow_status_; | 135 TurnOffFlowStatus turn_off_flow_status_; |
|
xiyuan
2014/09/16 21:59:59
Think we want to get rid of this here and change t
tbarzic
2014/09/16 22:30:58
Done.
| |
| 116 scoped_ptr<EasyUnlockToggleFlow> turn_off_flow_; | 136 |
| 117 ObserverList<EasyUnlockServiceObserver> observers_; | 137 private: |
| 138 scoped_ptr<BluetoothDetector> bluetooth_detector_; | |
| 118 | 139 |
| 119 #if defined(OS_CHROMEOS) | 140 #if defined(OS_CHROMEOS) |
| 120 // Monitors suspend and wake state of ChromeOS. | 141 // Monitors suspend and wake state of ChromeOS. |
| 121 class PowerMonitor; | 142 class PowerMonitor; |
| 122 scoped_ptr<PowerMonitor> power_monitor_; | 143 scoped_ptr<PowerMonitor> power_monitor_; |
| 123 #endif | 144 #endif |
| 124 | 145 |
| 146 ObserverList<EasyUnlockServiceObserver> observers_; | |
| 147 | |
| 125 base::WeakPtrFactory<EasyUnlockService> weak_ptr_factory_; | 148 base::WeakPtrFactory<EasyUnlockService> weak_ptr_factory_; |
| 126 | 149 |
| 127 DISALLOW_COPY_AND_ASSIGN(EasyUnlockService); | 150 DISALLOW_COPY_AND_ASSIGN(EasyUnlockService); |
| 128 }; | 151 }; |
| 129 | 152 |
| 130 #endif // CHROME_BROWSER_SIGNIN_EASY_UNLOCK_SERVICE_H_ | 153 #endif // CHROME_BROWSER_SIGNIN_EASY_UNLOCK_SERVICE_H_ |
| OLD | NEW |