Chromium Code Reviews| Index: chrome/browser/signin/easy_unlock_service.h |
| diff --git a/chrome/browser/signin/easy_unlock_service.h b/chrome/browser/signin/easy_unlock_service.h |
| index ab4f50ad277b6b8a63486f0499a40b25ed43d0a2..bd3ae064772e432fdf4d403e92608401fb26696d 100644 |
| --- a/chrome/browser/signin/easy_unlock_service.h |
| +++ b/chrome/browser/signin/easy_unlock_service.h |
| @@ -5,11 +5,12 @@ |
| #ifndef CHROME_BROWSER_SIGNIN_EASY_UNLOCK_SERVICE_H_ |
| #define CHROME_BROWSER_SIGNIN_EASY_UNLOCK_SERVICE_H_ |
| +#include <string> |
| + |
| #include "base/macros.h" |
| #include "base/memory/scoped_ptr.h" |
| #include "base/memory/weak_ptr.h" |
| #include "base/observer_list.h" |
| -#include "base/prefs/pref_change_registrar.h" |
| #include "components/keyed_service/core/keyed_service.h" |
| namespace base { |
| @@ -23,7 +24,6 @@ class PrefRegistrySyncable; |
| class EasyUnlockScreenlockStateHandler; |
| class EasyUnlockServiceObserver; |
| -class EasyUnlockToggleFlow; |
| class Profile; |
| class EasyUnlockService : public KeyedService { |
| @@ -34,8 +34,10 @@ class EasyUnlockService : public KeyedService { |
| FAIL, |
| }; |
| - explicit EasyUnlockService(Profile* profile); |
| - virtual ~EasyUnlockService(); |
| + enum Type { |
| + TYPE_REGULAR, |
| + TYPE_SIGNIN |
| + }; |
| // Gets EasyUnlockService instance. |
| static EasyUnlockService* Get(Profile* profile); |
| @@ -43,13 +45,30 @@ class EasyUnlockService : public KeyedService { |
| // Registers Easy Unlock profile preferences. |
| static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); |
| + // Returns the EasyUnlockService type. |
| + virtual Type GetType() const = 0; |
| + |
| + // Returns the user currently associated with the service. |
| + virtual std::string GetUserEmail() const = 0; |
| + |
| // Launches Easy Unlock Setup app. |
| - void LaunchSetup(); |
| + virtual void LaunchSetup() = 0; |
| - // Whether easy unlock is allowed to be used. If the controlling preference |
| - // is set (from policy), this returns the preference value. Otherwise, it is |
| - // permitted either the flag is enabled or its field trial is enabled. |
| - bool IsAllowed(); |
| + // Gets/Sets/Clears the permit access for the local device. |
| + virtual const base::DictionaryValue* GetPermitAccess() const = 0; |
| + virtual void SetPermitAccess(const base::DictionaryValue& permit) = 0; |
| + virtual void ClearPermitAccess() = 0; |
| + |
| + // Gets/Sets/Clears the remote devices list. |
| + virtual const base::ListValue* GetRemoteDevices() const = 0; |
| + virtual void SetRemoteDevices(const base::ListValue& devices) = 0; |
| + virtual void ClearRemoteDevices() = 0; |
| + |
| + // Runs the flow for turning Easy unlock off. |
| + virtual void RunTurnOffFlow() = 0; |
| + |
| + // Resets the turn off flow if one is in progress. |
| + virtual void ResetTurnOffFlow() = 0; |
| // Gets |screenlock_state_handler_|. Returns NULL if Easy Unlock is not |
| // allowed. Otherwise, if |screenlock_state_handler_| is not set, an instance |
| @@ -57,18 +76,10 @@ class EasyUnlockService : public KeyedService { |
| // Unlock gets disabled. |
| EasyUnlockScreenlockStateHandler* GetScreenlockStateHandler(); |
| - // Gets/Sets/Clears the permit access for the local device. |
| - const base::DictionaryValue* GetPermitAccess() const; |
| - void SetPermitAccess(const base::DictionaryValue& permit); |
| - void ClearPermitAccess(); |
| - |
| - // Gets/Sets/Clears the remote devices list. |
| - const base::ListValue* GetRemoteDevices() const; |
| - void SetRemoteDevices(const base::ListValue& devices); |
| - void ClearRemoteDevices(); |
| - |
| - void RunTurnOffFlow(); |
| - void ResetTurnOffFlow(); |
| + // Whether easy unlock is allowed to be used. If the controlling preference |
| + // is set (from policy), this returns the preference value. Otherwise, it is |
| + // permitted either the flag is enabled or its field trial is enabled. |
| + bool IsAllowed(); |
| void AddObserver(EasyUnlockServiceObserver* observer); |
| void RemoveObserver(EasyUnlockServiceObserver* observer); |
| @@ -77,12 +88,17 @@ class EasyUnlockService : public KeyedService { |
| return turn_off_flow_status_; |
| } |
| - private: |
| - // A class to detect whether a bluetooth adapter is present. |
| - class BluetoothDetector; |
| + protected: |
| + explicit EasyUnlockService(Profile* profile); |
| + virtual ~EasyUnlockService(); |
| - // Initializes the service after ExtensionService is ready. |
| - void Initialize(); |
| + // Does service type specific initialization. |
| + virtual void InitializeInternal() = 0; |
| + |
| + // Service type specific tests for whether the service is allowed. Returns |
| + // false if service is not allowed. If true is returned, the service may still |
| + // not be allowed if common tests fail (e.g. if Bluetooth is not available). |
| + virtual bool IsAllowedInternal() = 0; |
| // Installs the Easy unlock component app if it isn't installed or enables |
| // the app if it is installed but disabled. |
| @@ -91,30 +107,35 @@ class EasyUnlockService : public KeyedService { |
| // Disables the Easy unlock component app if it's loaded. |
| void DisableAppIfLoaded(); |
| + // Reloads the Easy unlock component app if it's loaded. |
| + void ReloadApp(); |
| + |
| // Checks whether Easy unlock should be running and updates app state. |
| void UpdateAppState(); |
| - // Callback when the controlling pref changes. |
| - void OnPrefsChanged(); |
| + // Notifies observers that the turn off flow status changed. |
| + void NotifyTurnOffOperationStatusChanged(); |
| - // Callback when Bluetooth adapter present state changes. |
| - void OnBluetoothAdapterPresentChanged(); |
| + private: |
| + // Initializes the service after ExtensionService is ready. |
| + void Initialize(); |
| - // Sets the new turn-off flow status. |
| - void SetTurnOffFlowStatus(TurnOffFlowStatus status); |
| + // A class to detect whether a bluetooth adapter is present. |
| + class BluetoothDetector; |
|
xiyuan
2014/09/16 21:59:59
nit: class declaration before function declaration
tbarzic
2014/09/16 22:30:58
Done.
|
| - // Callback invoked when turn off flow has finished. |
| - void OnTurnOffFlowFinished(bool success); |
| + // Callback when Bluetooth adapter present state changes. |
| + void OnBluetoothAdapterPresentChanged(); |
| + protected: |
| 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.
|
| - PrefChangeRegistrar registrar_; |
| - scoped_ptr<BluetoothDetector> bluetooth_detector_; |
| + |
| // Created lazily in |GetScreenlockStateHandler|. |
| 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.
|
| 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.
|
| - scoped_ptr<EasyUnlockToggleFlow> turn_off_flow_; |
| - ObserverList<EasyUnlockServiceObserver> observers_; |
| + |
| + private: |
| + scoped_ptr<BluetoothDetector> bluetooth_detector_; |
| #if defined(OS_CHROMEOS) |
| // Monitors suspend and wake state of ChromeOS. |
| @@ -122,6 +143,8 @@ class EasyUnlockService : public KeyedService { |
| scoped_ptr<PowerMonitor> power_monitor_; |
| #endif |
| + ObserverList<EasyUnlockServiceObserver> observers_; |
| + |
| base::WeakPtrFactory<EasyUnlockService> weak_ptr_factory_; |
| DISALLOW_COPY_AND_ASSIGN(EasyUnlockService); |