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..ee1cd06ce41962c15ee02e78c9731fc47f1887a7 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,33 @@ 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; |
+ |
+ // Returns the cirernt turn off flow status. |
+ virtual TurnOffFlowStatus GetTurnOffFlowStatus() const = 0; |
// Gets |screenlock_state_handler_|. Returns NULL if Easy Unlock is not |
// allowed. Otherwise, if |screenlock_state_handler_| is not set, an instance |
@@ -57,32 +79,28 @@ 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); |
- TurnOffFlowStatus turn_off_flow_status() const { |
- return turn_off_flow_status_; |
- } |
+ protected: |
+ explicit EasyUnlockService(Profile* profile); |
+ virtual ~EasyUnlockService(); |
- private: |
- // A class to detect whether a bluetooth adapter is present. |
- class BluetoothDetector; |
+ // Does service type specific initialization. |
+ virtual void InitializeInternal() = 0; |
- // Initializes the service after ExtensionService is ready. |
- void Initialize(); |
+ // 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; |
+ |
+ // Exposes the profile to which the service is attached to subclasses. |
+ Profile* profile() const { return profile_; } |
// Installs the Easy unlock component app if it isn't installed or enables |
// the app if it is installed but disabled. |
@@ -91,30 +109,31 @@ 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: |
+ // A class to detect whether a bluetooth adapter is present. |
+ class BluetoothDetector; |
- // Sets the new turn-off flow status. |
- void SetTurnOffFlowStatus(TurnOffFlowStatus status); |
+ // Initializes the service after ExtensionService is ready. |
+ void Initialize(); |
- // Callback invoked when turn off flow has finished. |
- void OnTurnOffFlowFinished(bool success); |
+ // Callback when Bluetooth adapter present state changes. |
+ void OnBluetoothAdapterPresentChanged(); |
Profile* profile_; |
- PrefChangeRegistrar registrar_; |
- scoped_ptr<BluetoothDetector> bluetooth_detector_; |
+ |
// Created lazily in |GetScreenlockStateHandler|. |
scoped_ptr<EasyUnlockScreenlockStateHandler> screenlock_state_handler_; |
- TurnOffFlowStatus turn_off_flow_status_; |
- scoped_ptr<EasyUnlockToggleFlow> turn_off_flow_; |
- ObserverList<EasyUnlockServiceObserver> observers_; |
+ scoped_ptr<BluetoothDetector> bluetooth_detector_; |
#if defined(OS_CHROMEOS) |
// Monitors suspend and wake state of ChromeOS. |
@@ -122,6 +141,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); |