| 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; |
| 72 |
| 73 // Returns the cirernt turn off flow status. |
| 74 virtual TurnOffFlowStatus GetTurnOffFlowStatus() const = 0; |
| 53 | 75 |
| 54 // Gets |screenlock_state_handler_|. Returns NULL if Easy Unlock is not | 76 // Gets |screenlock_state_handler_|. Returns NULL if Easy Unlock is not |
| 55 // allowed. Otherwise, if |screenlock_state_handler_| is not set, an instance | 77 // 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 | 78 // is created. Do not cache the returned value, as it may go away if Easy |
| 57 // Unlock gets disabled. | 79 // Unlock gets disabled. |
| 58 EasyUnlockScreenlockStateHandler* GetScreenlockStateHandler(); | 80 EasyUnlockScreenlockStateHandler* GetScreenlockStateHandler(); |
| 59 | 81 |
| 60 // Gets/Sets/Clears the permit access for the local device. | 82 // Whether easy unlock is allowed to be used. If the controlling preference |
| 61 const base::DictionaryValue* GetPermitAccess() const; | 83 // is set (from policy), this returns the preference value. Otherwise, it is |
| 62 void SetPermitAccess(const base::DictionaryValue& permit); | 84 // permitted either the flag is enabled or its field trial is enabled. |
| 63 void ClearPermitAccess(); | 85 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 | 86 |
| 73 void AddObserver(EasyUnlockServiceObserver* observer); | 87 void AddObserver(EasyUnlockServiceObserver* observer); |
| 74 void RemoveObserver(EasyUnlockServiceObserver* observer); | 88 void RemoveObserver(EasyUnlockServiceObserver* observer); |
| 75 | 89 |
| 76 TurnOffFlowStatus turn_off_flow_status() const { | 90 protected: |
| 77 return turn_off_flow_status_; | 91 explicit EasyUnlockService(Profile* profile); |
| 78 } | 92 virtual ~EasyUnlockService(); |
| 79 | 93 |
| 80 private: | 94 // Does service type specific initialization. |
| 81 // A class to detect whether a bluetooth adapter is present. | 95 virtual void InitializeInternal() = 0; |
| 82 class BluetoothDetector; | |
| 83 | 96 |
| 84 // Initializes the service after ExtensionService is ready. | 97 // Service type specific tests for whether the service is allowed. Returns |
| 85 void Initialize(); | 98 // false if service is not allowed. If true is returned, the service may still |
| 99 // not be allowed if common tests fail (e.g. if Bluetooth is not available). |
| 100 virtual bool IsAllowedInternal() = 0; |
| 101 |
| 102 // Exposes the profile to which the service is attached to subclasses. |
| 103 Profile* profile() const { return profile_; } |
| 86 | 104 |
| 87 // Installs the Easy unlock component app if it isn't installed or enables | 105 // Installs the Easy unlock component app if it isn't installed or enables |
| 88 // the app if it is installed but disabled. | 106 // the app if it is installed but disabled. |
| 89 void LoadApp(); | 107 void LoadApp(); |
| 90 | 108 |
| 91 // Disables the Easy unlock component app if it's loaded. | 109 // Disables the Easy unlock component app if it's loaded. |
| 92 void DisableAppIfLoaded(); | 110 void DisableAppIfLoaded(); |
| 93 | 111 |
| 112 // Reloads the Easy unlock component app if it's loaded. |
| 113 void ReloadApp(); |
| 114 |
| 94 // Checks whether Easy unlock should be running and updates app state. | 115 // Checks whether Easy unlock should be running and updates app state. |
| 95 void UpdateAppState(); | 116 void UpdateAppState(); |
| 96 | 117 |
| 97 // Callback when the controlling pref changes. | 118 // Notifies observers that the turn off flow status changed. |
| 98 void OnPrefsChanged(); | 119 void NotifyTurnOffOperationStatusChanged(); |
| 120 |
| 121 private: |
| 122 // A class to detect whether a bluetooth adapter is present. |
| 123 class BluetoothDetector; |
| 124 |
| 125 // Initializes the service after ExtensionService is ready. |
| 126 void Initialize(); |
| 99 | 127 |
| 100 // Callback when Bluetooth adapter present state changes. | 128 // Callback when Bluetooth adapter present state changes. |
| 101 void OnBluetoothAdapterPresentChanged(); | 129 void OnBluetoothAdapterPresentChanged(); |
| 102 | 130 |
| 103 // Sets the new turn-off flow status. | 131 Profile* profile_; |
| 104 void SetTurnOffFlowStatus(TurnOffFlowStatus status); | |
| 105 | 132 |
| 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|. | 133 // Created lazily in |GetScreenlockStateHandler|. |
| 113 scoped_ptr<EasyUnlockScreenlockStateHandler> screenlock_state_handler_; | 134 scoped_ptr<EasyUnlockScreenlockStateHandler> screenlock_state_handler_; |
| 114 | 135 |
| 115 TurnOffFlowStatus turn_off_flow_status_; | 136 scoped_ptr<BluetoothDetector> bluetooth_detector_; |
| 116 scoped_ptr<EasyUnlockToggleFlow> turn_off_flow_; | |
| 117 ObserverList<EasyUnlockServiceObserver> observers_; | |
| 118 | 137 |
| 119 #if defined(OS_CHROMEOS) | 138 #if defined(OS_CHROMEOS) |
| 120 // Monitors suspend and wake state of ChromeOS. | 139 // Monitors suspend and wake state of ChromeOS. |
| 121 class PowerMonitor; | 140 class PowerMonitor; |
| 122 scoped_ptr<PowerMonitor> power_monitor_; | 141 scoped_ptr<PowerMonitor> power_monitor_; |
| 123 #endif | 142 #endif |
| 124 | 143 |
| 144 ObserverList<EasyUnlockServiceObserver> observers_; |
| 145 |
| 125 base::WeakPtrFactory<EasyUnlockService> weak_ptr_factory_; | 146 base::WeakPtrFactory<EasyUnlockService> weak_ptr_factory_; |
| 126 | 147 |
| 127 DISALLOW_COPY_AND_ASSIGN(EasyUnlockService); | 148 DISALLOW_COPY_AND_ASSIGN(EasyUnlockService); |
| 128 }; | 149 }; |
| 129 | 150 |
| 130 #endif // CHROME_BROWSER_SIGNIN_EASY_UNLOCK_SERVICE_H_ | 151 #endif // CHROME_BROWSER_SIGNIN_EASY_UNLOCK_SERVICE_H_ |
| OLD | NEW |