Commit 390ac978 authored by tbarzic's avatar tbarzic Committed by Commit bot

Introduce EasyUnlockService class for signin profile

This makes EasyUnlockService pure virtual base class and introduces
separate implementations for regular and signin profiles. Common code
for both service types is kept in EasyUnlockService class.

EasyunlockService for signin profile is left empty.

BUG=401634

Review URL: https://codereview.chromium.org/577683002

Cr-Commit-Position: refs/heads/master@{#295188}
parent 278b065b
...@@ -4,15 +4,11 @@ ...@@ -4,15 +4,11 @@
#include "chrome/browser/signin/easy_unlock_service.h" #include "chrome/browser/signin/easy_unlock_service.h"
#include <string>
#include "base/bind.h" #include "base/bind.h"
#include "base/command_line.h" #include "base/command_line.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/memory/ref_counted.h"
#include "base/metrics/field_trial.h" #include "base/metrics/field_trial.h"
#include "base/prefs/pref_service.h" #include "base/prefs/pref_service.h"
#include "base/prefs/scoped_user_pref_update.h"
#include "base/values.h" #include "base/values.h"
#include "chrome/browser/extensions/component_loader.h" #include "chrome/browser/extensions/component_loader.h"
#include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/extensions/extension_service.h"
...@@ -20,10 +16,9 @@ ...@@ -20,10 +16,9 @@
#include "chrome/browser/signin/easy_unlock_screenlock_state_handler.h" #include "chrome/browser/signin/easy_unlock_screenlock_state_handler.h"
#include "chrome/browser/signin/easy_unlock_service_factory.h" #include "chrome/browser/signin/easy_unlock_service_factory.h"
#include "chrome/browser/signin/easy_unlock_service_observer.h" #include "chrome/browser/signin/easy_unlock_service_observer.h"
#include "chrome/browser/signin/easy_unlock_toggle_flow.h"
#include "chrome/browser/signin/screenlock_bridge.h" #include "chrome/browser/signin/screenlock_bridge.h"
#include "chrome/browser/ui/extensions/application_launch.h"
#include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_switches.h"
#include "chrome/common/extensions/extension_constants.h"
#include "chrome/common/pref_names.h" #include "chrome/common/pref_names.h"
#include "components/pref_registry/pref_registry_syncable.h" #include "components/pref_registry/pref_registry_syncable.h"
#include "device/bluetooth/bluetooth_adapter.h" #include "device/bluetooth/bluetooth_adapter.h"
...@@ -34,23 +29,12 @@ ...@@ -34,23 +29,12 @@
#include "grit/browser_resources.h" #include "grit/browser_resources.h"
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
#include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chromeos/dbus/dbus_thread_manager.h" #include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/dbus/power_manager_client.h" #include "chromeos/dbus/power_manager_client.h"
#include "components/user_manager/user_manager.h"
#endif #endif
namespace { namespace {
// Key name of the local device permit record dictonary in kEasyUnlockPairing.
const char kKeyPermitAccess[] = "permitAccess";
// Key name of the remote device list in kEasyUnlockPairing.
const char kKeyDevices[] = "devices";
// Key name of the phone public key in a device dictionary.
const char kKeyPhoneId[] = "permitRecord.id";
extensions::ComponentLoader* GetComponentLoader( extensions::ComponentLoader* GetComponentLoader(
content::BrowserContext* context) { content::BrowserContext* context) {
extensions::ExtensionSystem* extension_system = extensions::ExtensionSystem* extension_system =
...@@ -129,7 +113,6 @@ class EasyUnlockService::PowerMonitor : ...@@ -129,7 +113,6 @@ class EasyUnlockService::PowerMonitor :
// chromeos::PowerManagerClient::Observer: // chromeos::PowerManagerClient::Observer:
virtual void SuspendImminent() OVERRIDE { virtual void SuspendImminent() OVERRIDE {
service_->DisableAppIfLoaded(); service_->DisableAppIfLoaded();
service_->screenlock_state_handler_.reset();
} }
virtual void SuspendDone(const base::TimeDelta& sleep_duration) OVERRIDE { virtual void SuspendDone(const base::TimeDelta& sleep_duration) OVERRIDE {
...@@ -145,7 +128,6 @@ class EasyUnlockService::PowerMonitor : ...@@ -145,7 +128,6 @@ class EasyUnlockService::PowerMonitor :
EasyUnlockService::EasyUnlockService(Profile* profile) EasyUnlockService::EasyUnlockService(Profile* profile)
: profile_(profile), : profile_(profile),
bluetooth_detector_(new BluetoothDetector(this)), bluetooth_detector_(new BluetoothDetector(this)),
turn_off_flow_status_(IDLE),
weak_ptr_factory_(this) { weak_ptr_factory_(this) {
extensions::ExtensionSystem::Get(profile_)->ready().Post( extensions::ExtensionSystem::Get(profile_)->ready().Post(
FROM_HERE, FROM_HERE,
...@@ -177,24 +159,11 @@ void EasyUnlockService::RegisterProfilePrefs( ...@@ -177,24 +159,11 @@ void EasyUnlockService::RegisterProfilePrefs(
user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
} }
void EasyUnlockService::LaunchSetup() {
ExtensionService* service =
extensions::ExtensionSystem::Get(profile_)->extension_service();
const extensions::Extension* extension =
service->GetExtensionById(extension_misc::kEasyUnlockAppId, false);
OpenApplication(AppLaunchParams(
profile_, extension, extensions::LAUNCH_CONTAINER_WINDOW, NEW_WINDOW));
}
bool EasyUnlockService::IsAllowed() { bool EasyUnlockService::IsAllowed() {
#if defined(OS_CHROMEOS) if (!IsAllowedInternal())
if (!user_manager::UserManager::Get()->IsLoggedInAsRegularUser())
return false;
if (!chromeos::ProfileHelper::IsPrimaryProfile(profile_))
return false; return false;
#if defined(OS_CHROMEOS)
if (!profile_->GetPrefs()->GetBoolean(prefs::kEasyUnlockAllowed)) if (!profile_->GetPrefs()->GetBoolean(prefs::kEasyUnlockAllowed))
return false; return false;
...@@ -221,60 +190,13 @@ EasyUnlockScreenlockStateHandler* ...@@ -221,60 +190,13 @@ EasyUnlockScreenlockStateHandler*
return NULL; return NULL;
if (!screenlock_state_handler_) { if (!screenlock_state_handler_) {
screenlock_state_handler_.reset(new EasyUnlockScreenlockStateHandler( screenlock_state_handler_.reset(new EasyUnlockScreenlockStateHandler(
ScreenlockBridge::GetAuthenticatedUserEmail(profile_), GetUserEmail(),
profile_->GetPrefs(), GetType() == TYPE_REGULAR ? profile_->GetPrefs() : NULL,
ScreenlockBridge::Get())); ScreenlockBridge::Get()));
} }
return screenlock_state_handler_.get(); return screenlock_state_handler_.get();
} }
const base::DictionaryValue* EasyUnlockService::GetPermitAccess() const {
const base::DictionaryValue* pairing_dict =
profile_->GetPrefs()->GetDictionary(prefs::kEasyUnlockPairing);
const base::DictionaryValue* permit_dict = NULL;
if (pairing_dict &&
pairing_dict->GetDictionary(kKeyPermitAccess, &permit_dict)) {
return permit_dict;
}
return NULL;
}
void EasyUnlockService::SetPermitAccess(const base::DictionaryValue& permit) {
DictionaryPrefUpdate pairing_update(profile_->GetPrefs(),
prefs::kEasyUnlockPairing);
pairing_update->SetWithoutPathExpansion(kKeyPermitAccess, permit.DeepCopy());
}
void EasyUnlockService::ClearPermitAccess() {
DictionaryPrefUpdate pairing_update(profile_->GetPrefs(),
prefs::kEasyUnlockPairing);
pairing_update->RemoveWithoutPathExpansion(kKeyPermitAccess, NULL);
}
const base::ListValue* EasyUnlockService::GetRemoteDevices() const {
const base::DictionaryValue* pairing_dict =
profile_->GetPrefs()->GetDictionary(prefs::kEasyUnlockPairing);
const base::ListValue* devices = NULL;
if (pairing_dict && pairing_dict->GetList(kKeyDevices, &devices)) {
return devices;
}
return NULL;
}
void EasyUnlockService::SetRemoteDevices(const base::ListValue& devices) {
DictionaryPrefUpdate pairing_update(profile_->GetPrefs(),
prefs::kEasyUnlockPairing);
pairing_update->SetWithoutPathExpansion(kKeyDevices, devices.DeepCopy());
}
void EasyUnlockService::ClearRemoteDevices() {
DictionaryPrefUpdate pairing_update(profile_->GetPrefs(),
prefs::kEasyUnlockPairing);
pairing_update->RemoveWithoutPathExpansion(kKeyDevices, NULL);
}
void EasyUnlockService::AddObserver(EasyUnlockServiceObserver* observer) { void EasyUnlockService::AddObserver(EasyUnlockServiceObserver* observer) {
observers_.AddObserver(observer); observers_.AddObserver(observer);
} }
...@@ -283,61 +205,6 @@ void EasyUnlockService::RemoveObserver(EasyUnlockServiceObserver* observer) { ...@@ -283,61 +205,6 @@ void EasyUnlockService::RemoveObserver(EasyUnlockServiceObserver* observer) {
observers_.RemoveObserver(observer); observers_.RemoveObserver(observer);
} }
void EasyUnlockService::RunTurnOffFlow() {
if (turn_off_flow_status_ == PENDING)
return;
SetTurnOffFlowStatus(PENDING);
// Currently there should only be one registered phone.
// TODO(xiyuan): Revisit this when server supports toggle for all or
// there are multiple phones.
const base::DictionaryValue* pairing_dict =
profile_->GetPrefs()->GetDictionary(prefs::kEasyUnlockPairing);
const base::ListValue* devices_list = NULL;
const base::DictionaryValue* first_device = NULL;
std::string phone_public_key;
if (!pairing_dict || !pairing_dict->GetList(kKeyDevices, &devices_list) ||
!devices_list || !devices_list->GetDictionary(0, &first_device) ||
!first_device ||
!first_device->GetString(kKeyPhoneId, &phone_public_key)) {
LOG(WARNING) << "Bad easy unlock pairing data, wiping out local data";
OnTurnOffFlowFinished(true);
return;
}
turn_off_flow_.reset(new EasyUnlockToggleFlow(
profile_,
phone_public_key,
false,
base::Bind(&EasyUnlockService::OnTurnOffFlowFinished,
base::Unretained(this))));
turn_off_flow_->Start();
}
void EasyUnlockService::ResetTurnOffFlow() {
turn_off_flow_.reset();
SetTurnOffFlowStatus(IDLE);
}
void EasyUnlockService::Initialize() {
registrar_.Init(profile_->GetPrefs());
registrar_.Add(
prefs::kEasyUnlockAllowed,
base::Bind(&EasyUnlockService::OnPrefsChanged, base::Unretained(this)));
OnPrefsChanged();
#if defined(OS_CHROMEOS)
// Only start Bluetooth detection for ChromeOS since the feature is
// only offered on ChromeOS. Enabling this on non-ChromeOS platforms
// previously introduced a performance regression: http://crbug.com/404482
// Make sure not to reintroduce a performance regression if re-enabling on
// additional platforms.
// TODO(xiyuan): Revisit when non-chromeos platforms are supported.
bluetooth_detector_->Initialize();
#endif // defined(OS_CHROMEOS)
}
void EasyUnlockService::LoadApp() { void EasyUnlockService::LoadApp() {
DCHECK(IsAllowed()); DCHECK(IsAllowed());
...@@ -358,9 +225,9 @@ void EasyUnlockService::LoadApp() { ...@@ -358,9 +225,9 @@ void EasyUnlockService::LoadApp() {
if (!easy_unlock_path.empty()) { if (!easy_unlock_path.empty()) {
extensions::ComponentLoader* loader = GetComponentLoader(profile_); extensions::ComponentLoader* loader = GetComponentLoader(profile_);
if (!loader->Exists(extension_misc::kEasyUnlockAppId)) { if (!loader->Exists(extension_misc::kEasyUnlockAppId))
loader->Add(IDR_EASY_UNLOCK_MANIFEST, easy_unlock_path); loader->Add(IDR_EASY_UNLOCK_MANIFEST, easy_unlock_path);
}
ExtensionService* extension_service = ExtensionService* extension_service =
extensions::ExtensionSystem::Get(profile_)->extension_service(); extensions::ExtensionSystem::Get(profile_)->extension_service();
extension_service->EnableExtension(extension_misc::kEasyUnlockAppId); extension_service->EnableExtension(extension_misc::kEasyUnlockAppId);
...@@ -369,6 +236,9 @@ void EasyUnlockService::LoadApp() { ...@@ -369,6 +236,9 @@ void EasyUnlockService::LoadApp() {
} }
void EasyUnlockService::DisableAppIfLoaded() { void EasyUnlockService::DisableAppIfLoaded() {
// Make sure lock screen state set by the extension gets reset.
screenlock_state_handler_.reset();
extensions::ComponentLoader* loader = GetComponentLoader(profile_); extensions::ComponentLoader* loader = GetComponentLoader(profile_);
if (!loader->Exists(extension_misc::kEasyUnlockAppId)) if (!loader->Exists(extension_misc::kEasyUnlockAppId))
return; return;
...@@ -379,6 +249,18 @@ void EasyUnlockService::DisableAppIfLoaded() { ...@@ -379,6 +249,18 @@ void EasyUnlockService::DisableAppIfLoaded() {
extensions::Extension::DISABLE_RELOAD); extensions::Extension::DISABLE_RELOAD);
} }
void EasyUnlockService::ReloadApp() {
// Make sure lock screen state set by the extension gets reset.
screenlock_state_handler_.reset();
if (GetComponentLoader(profile_)->Exists(extension_misc::kEasyUnlockAppId)) {
extensions::ExtensionSystem* extension_system =
extensions::ExtensionSystem::Get(profile_);
extension_system->extension_service()->ReloadExtension(
extension_misc::kEasyUnlockAppId);
}
}
void EasyUnlockService::UpdateAppState() { void EasyUnlockService::UpdateAppState() {
if (IsAllowed()) { if (IsAllowed()) {
LoadApp(); LoadApp();
...@@ -389,48 +271,32 @@ void EasyUnlockService::UpdateAppState() { ...@@ -389,48 +271,32 @@ void EasyUnlockService::UpdateAppState() {
#endif #endif
} else { } else {
DisableAppIfLoaded(); DisableAppIfLoaded();
// Reset the screenlock state handler to make sure Screenlock state set
// by Easy Unlock app is reset.
screenlock_state_handler_.reset();
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
power_monitor_.reset(); power_monitor_.reset();
#endif #endif
} }
} }
void EasyUnlockService::OnPrefsChanged() { void EasyUnlockService::NotifyTurnOffOperationStatusChanged() {
UpdateAppState();
}
void EasyUnlockService::OnBluetoothAdapterPresentChanged() {
UpdateAppState();
}
void EasyUnlockService::SetTurnOffFlowStatus(TurnOffFlowStatus status) {
turn_off_flow_status_ = status;
FOR_EACH_OBSERVER( FOR_EACH_OBSERVER(
EasyUnlockServiceObserver, observers_, OnTurnOffOperationStatusChanged()); EasyUnlockServiceObserver, observers_, OnTurnOffOperationStatusChanged());
} }
void EasyUnlockService::OnTurnOffFlowFinished(bool success) { void EasyUnlockService::Initialize() {
turn_off_flow_.reset(); InitializeInternal();
if (!success) {
SetTurnOffFlowStatus(FAIL);
return;
}
ClearRemoteDevices();
SetTurnOffFlowStatus(IDLE);
// Make sure lock screen state set by the extension gets reset. #if defined(OS_CHROMEOS)
screenlock_state_handler_.reset(); // Only start Bluetooth detection for ChromeOS since the feature is
// only offered on ChromeOS. Enabling this on non-ChromeOS platforms
// previously introduced a performance regression: http://crbug.com/404482
// Make sure not to reintroduce a performance regression if re-enabling on
// additional platforms.
// TODO(xiyuan): Revisit when non-chromeos platforms are supported.
bluetooth_detector_->Initialize();
#endif // defined(OS_CHROMEOS)
}
if (GetComponentLoader(profile_)->Exists(extension_misc::kEasyUnlockAppId)) { void EasyUnlockService::OnBluetoothAdapterPresentChanged() {
extensions::ExtensionSystem* extension_system = UpdateAppState();
extensions::ExtensionSystem::Get(profile_);
extension_system->extension_service()->ReloadExtension(
extension_misc::kEasyUnlockAppId);
}
} }
...@@ -5,11 +5,12 @@ ...@@ -5,11 +5,12 @@
#ifndef CHROME_BROWSER_SIGNIN_EASY_UNLOCK_SERVICE_H_ #ifndef CHROME_BROWSER_SIGNIN_EASY_UNLOCK_SERVICE_H_
#define CHROME_BROWSER_SIGNIN_EASY_UNLOCK_SERVICE_H_ #define CHROME_BROWSER_SIGNIN_EASY_UNLOCK_SERVICE_H_
#include <string>
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/observer_list.h" #include "base/observer_list.h"
#include "base/prefs/pref_change_registrar.h"
#include "components/keyed_service/core/keyed_service.h" #include "components/keyed_service/core/keyed_service.h"
namespace base { namespace base {
...@@ -23,7 +24,6 @@ class PrefRegistrySyncable; ...@@ -23,7 +24,6 @@ class PrefRegistrySyncable;
class EasyUnlockScreenlockStateHandler; class EasyUnlockScreenlockStateHandler;
class EasyUnlockServiceObserver; class EasyUnlockServiceObserver;
class EasyUnlockToggleFlow;
class Profile; class Profile;
class EasyUnlockService : public KeyedService { class EasyUnlockService : public KeyedService {
...@@ -34,8 +34,10 @@ class EasyUnlockService : public KeyedService { ...@@ -34,8 +34,10 @@ class EasyUnlockService : public KeyedService {
FAIL, FAIL,
}; };
explicit EasyUnlockService(Profile* profile); enum Type {
virtual ~EasyUnlockService(); TYPE_REGULAR,
TYPE_SIGNIN
};
// Gets EasyUnlockService instance. // Gets EasyUnlockService instance.
static EasyUnlockService* Get(Profile* profile); static EasyUnlockService* Get(Profile* profile);
...@@ -43,13 +45,33 @@ class EasyUnlockService : public KeyedService { ...@@ -43,13 +45,33 @@ class EasyUnlockService : public KeyedService {
// Registers Easy Unlock profile preferences. // Registers Easy Unlock profile preferences.
static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); 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. // Launches Easy Unlock Setup app.
void LaunchSetup(); virtual void LaunchSetup() = 0;
// Whether easy unlock is allowed to be used. If the controlling preference // Gets/Sets/Clears the permit access for the local device.
// is set (from policy), this returns the preference value. Otherwise, it is virtual const base::DictionaryValue* GetPermitAccess() const = 0;
// permitted either the flag is enabled or its field trial is enabled. virtual void SetPermitAccess(const base::DictionaryValue& permit) = 0;
bool IsAllowed(); 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 // Gets |screenlock_state_handler_|. Returns NULL if Easy Unlock is not
// allowed. Otherwise, if |screenlock_state_handler_| is not set, an instance // allowed. Otherwise, if |screenlock_state_handler_| is not set, an instance
...@@ -57,32 +79,28 @@ class EasyUnlockService : public KeyedService { ...@@ -57,32 +79,28 @@ class EasyUnlockService : public KeyedService {
// Unlock gets disabled. // Unlock gets disabled.
EasyUnlockScreenlockStateHandler* GetScreenlockStateHandler(); EasyUnlockScreenlockStateHandler* GetScreenlockStateHandler();
// Gets/Sets/Clears the permit access for the local device. // Whether easy unlock is allowed to be used. If the controlling preference
const base::DictionaryValue* GetPermitAccess() const; // is set (from policy), this returns the preference value. Otherwise, it is
void SetPermitAccess(const base::DictionaryValue& permit); // permitted either the flag is enabled or its field trial is enabled.
void ClearPermitAccess(); bool IsAllowed();
// Gets/Sets/Clears the remote devices list.
const base::ListValue* GetRemoteDevices() const;
void SetRemoteDevices(const base::ListValue& devices);
void ClearRemoteDevices();
void RunTurnOffFlow();
void ResetTurnOffFlow();
void AddObserver(EasyUnlockServiceObserver* observer); void AddObserver(EasyUnlockServiceObserver* observer);
void RemoveObserver(EasyUnlockServiceObserver* observer); void RemoveObserver(EasyUnlockServiceObserver* observer);
TurnOffFlowStatus turn_off_flow_status() const { protected:
return turn_off_flow_status_; explicit EasyUnlockService(Profile* profile);
} virtual ~EasyUnlockService();
private: // Does service type specific initialization.
// A class to detect whether a bluetooth adapter is present. virtual void InitializeInternal() = 0;
class BluetoothDetector;
// Initializes the service after ExtensionService is ready. // Service type specific tests for whether the service is allowed. Returns
void Initialize(); // 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 // Installs the Easy unlock component app if it isn't installed or enables
// the app if it is installed but disabled. // the app if it is installed but disabled.
...@@ -91,30 +109,31 @@ class EasyUnlockService : public KeyedService { ...@@ -91,30 +109,31 @@ class EasyUnlockService : public KeyedService {
// Disables the Easy unlock component app if it's loaded. // Disables the Easy unlock component app if it's loaded.
void DisableAppIfLoaded(); 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. // Checks whether Easy unlock should be running and updates app state.
void UpdateAppState(); void UpdateAppState();
// Callback when the controlling pref changes. // Notifies observers that the turn off flow status changed.
void OnPrefsChanged(); void NotifyTurnOffOperationStatusChanged();
// Callback when Bluetooth adapter present state changes. private:
void OnBluetoothAdapterPresentChanged(); // A class to detect whether a bluetooth adapter is present.
class BluetoothDetector;
// Sets the new turn-off flow status. // Initializes the service after ExtensionService is ready.
void SetTurnOffFlowStatus(TurnOffFlowStatus status); void Initialize();
// Callback invoked when turn off flow has finished. // Callback when Bluetooth adapter present state changes.
void OnTurnOffFlowFinished(bool success); void OnBluetoothAdapterPresentChanged();
Profile* profile_; Profile* profile_;
PrefChangeRegistrar registrar_;
scoped_ptr<BluetoothDetector> bluetooth_detector_;
// Created lazily in |GetScreenlockStateHandler|. // Created lazily in |GetScreenlockStateHandler|.
scoped_ptr<EasyUnlockScreenlockStateHandler> screenlock_state_handler_; scoped_ptr<EasyUnlockScreenlockStateHandler> screenlock_state_handler_;
TurnOffFlowStatus turn_off_flow_status_; scoped_ptr<BluetoothDetector> bluetooth_detector_;
scoped_ptr<EasyUnlockToggleFlow> turn_off_flow_;
ObserverList<EasyUnlockServiceObserver> observers_;
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
// Monitors suspend and wake state of ChromeOS. // Monitors suspend and wake state of ChromeOS.
...@@ -122,6 +141,8 @@ class EasyUnlockService : public KeyedService { ...@@ -122,6 +141,8 @@ class EasyUnlockService : public KeyedService {
scoped_ptr<PowerMonitor> power_monitor_; scoped_ptr<PowerMonitor> power_monitor_;
#endif #endif
ObserverList<EasyUnlockServiceObserver> observers_;
base::WeakPtrFactory<EasyUnlockService> weak_ptr_factory_; base::WeakPtrFactory<EasyUnlockService> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(EasyUnlockService); DISALLOW_COPY_AND_ASSIGN(EasyUnlockService);
......
...@@ -8,12 +8,14 @@ ...@@ -8,12 +8,14 @@
#include "chrome/browser/profiles/incognito_helpers.h" #include "chrome/browser/profiles/incognito_helpers.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/signin/easy_unlock_service.h" #include "chrome/browser/signin/easy_unlock_service.h"
#include "chrome/browser/signin/easy_unlock_service_regular.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h" #include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "extensions/browser/extension_system_provider.h" #include "extensions/browser/extension_system_provider.h"
#include "extensions/browser/extensions_browser_client.h" #include "extensions/browser/extensions_browser_client.h"
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
#include "chrome/browser/chromeos/profiles/profile_helper.h" #include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chrome/browser/signin/easy_unlock_service_signin_chromeos.h"
#endif #endif
// static // static
...@@ -41,17 +43,17 @@ EasyUnlockServiceFactory::~EasyUnlockServiceFactory() { ...@@ -41,17 +43,17 @@ EasyUnlockServiceFactory::~EasyUnlockServiceFactory() {
KeyedService* EasyUnlockServiceFactory::BuildServiceInstanceFor( KeyedService* EasyUnlockServiceFactory::BuildServiceInstanceFor(
content::BrowserContext* context) const { content::BrowserContext* context) const {
return new EasyUnlockService(Profile::FromBrowserContext(context));
}
content::BrowserContext* EasyUnlockServiceFactory::GetBrowserContextToUse(
content::BrowserContext* context) const {
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
if (chromeos::ProfileHelper::IsSigninProfile( if (chromeos::ProfileHelper::IsSigninProfile(
Profile::FromBrowserContext(context))) { Profile::FromBrowserContext(context))) {
return NULL; return new EasyUnlockServiceSignin(Profile::FromBrowserContext(context));
} }
#endif #endif
return new EasyUnlockServiceRegular(Profile::FromBrowserContext(context));
}
content::BrowserContext* EasyUnlockServiceFactory::GetBrowserContextToUse(
content::BrowserContext* context) const {
return chrome::GetBrowserContextRedirectedInIncognito(context); return chrome::GetBrowserContextRedirectedInIncognito(context);
} }
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/signin/easy_unlock_service_regular.h"
#include "base/bind.h"
#include "base/logging.h"
#include "base/prefs/pref_service.h"
#include "base/prefs/scoped_user_pref_update.h"
#include "base/values.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/signin/easy_unlock_toggle_flow.h"
#include "chrome/browser/signin/screenlock_bridge.h"
#include "chrome/browser/ui/extensions/application_launch.h"
#include "chrome/common/extensions/extension_constants.h"
#include "chrome/common/pref_names.h"
#include "components/pref_registry/pref_registry_syncable.h"
#include "extensions/browser/extension_system.h"
#if defined(OS_CHROMEOS)
#include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "components/user_manager/user_manager.h"
#endif
namespace {
// Key name of the local device permit record dictonary in kEasyUnlockPairing.
const char kKeyPermitAccess[] = "permitAccess";
// Key name of the remote device list in kEasyUnlockPairing.
const char kKeyDevices[] = "devices";
// Key name of the phone public key in a device dictionary.
const char kKeyPhoneId[] = "permitRecord.id";
} // namespace
EasyUnlockServiceRegular::EasyUnlockServiceRegular(Profile* profile)
: EasyUnlockService(profile),
turn_off_flow_status_(EasyUnlockService::IDLE) {
}
EasyUnlockServiceRegular::~EasyUnlockServiceRegular() {
}
EasyUnlockService::Type EasyUnlockServiceRegular::GetType() const {
return EasyUnlockService::TYPE_REGULAR;
}
std::string EasyUnlockServiceRegular::GetUserEmail() const {
return ScreenlockBridge::GetAuthenticatedUserEmail(profile());
}
void EasyUnlockServiceRegular::LaunchSetup() {
ExtensionService* service =
extensions::ExtensionSystem::Get(profile())->extension_service();
const extensions::Extension* extension =
service->GetExtensionById(extension_misc::kEasyUnlockAppId, false);
OpenApplication(AppLaunchParams(
profile(), extension, extensions::LAUNCH_CONTAINER_WINDOW, NEW_WINDOW));
}
const base::DictionaryValue* EasyUnlockServiceRegular::GetPermitAccess() const {
const base::DictionaryValue* pairing_dict =
profile()->GetPrefs()->GetDictionary(prefs::kEasyUnlockPairing);
const base::DictionaryValue* permit_dict = NULL;
if (pairing_dict &&
pairing_dict->GetDictionary(kKeyPermitAccess, &permit_dict))
return permit_dict;
return NULL;
}
void EasyUnlockServiceRegular::SetPermitAccess(
const base::DictionaryValue& permit) {
DictionaryPrefUpdate pairing_update(profile()->GetPrefs(),
prefs::kEasyUnlockPairing);
pairing_update->SetWithoutPathExpansion(kKeyPermitAccess, permit.DeepCopy());
}
void EasyUnlockServiceRegular::ClearPermitAccess() {
DictionaryPrefUpdate pairing_update(profile()->GetPrefs(),
prefs::kEasyUnlockPairing);
pairing_update->RemoveWithoutPathExpansion(kKeyPermitAccess, NULL);
}
const base::ListValue* EasyUnlockServiceRegular::GetRemoteDevices() const {
const base::DictionaryValue* pairing_dict =
profile()->GetPrefs()->GetDictionary(prefs::kEasyUnlockPairing);
const base::ListValue* devices = NULL;
if (pairing_dict && pairing_dict->GetList(kKeyDevices, &devices))
return devices;
return NULL;
}
void EasyUnlockServiceRegular::SetRemoteDevices(
const base::ListValue& devices) {
DictionaryPrefUpdate pairing_update(profile()->GetPrefs(),
prefs::kEasyUnlockPairing);
pairing_update->SetWithoutPathExpansion(kKeyDevices, devices.DeepCopy());
}
void EasyUnlockServiceRegular::ClearRemoteDevices() {
DictionaryPrefUpdate pairing_update(profile()->GetPrefs(),
prefs::kEasyUnlockPairing);
pairing_update->RemoveWithoutPathExpansion(kKeyDevices, NULL);
}
void EasyUnlockServiceRegular::RunTurnOffFlow() {
if (turn_off_flow_status_ == PENDING)
return;
SetTurnOffFlowStatus(PENDING);
// Currently there should only be one registered phone.
// TODO(xiyuan): Revisit this when server supports toggle for all or
// there are multiple phones.
const base::DictionaryValue* pairing_dict =
profile()->GetPrefs()->GetDictionary(prefs::kEasyUnlockPairing);
const base::ListValue* devices_list = NULL;
const base::DictionaryValue* first_device = NULL;
std::string phone_public_key;
if (!pairing_dict || !pairing_dict->GetList(kKeyDevices, &devices_list) ||
!devices_list || !devices_list->GetDictionary(0, &first_device) ||
!first_device ||
!first_device->GetString(kKeyPhoneId, &phone_public_key)) {
LOG(WARNING) << "Bad easy unlock pairing data, wiping out local data";
OnTurnOffFlowFinished(true);
return;
}
turn_off_flow_.reset(new EasyUnlockToggleFlow(
profile(),
phone_public_key,
false,
base::Bind(&EasyUnlockServiceRegular::OnTurnOffFlowFinished,
base::Unretained(this))));
turn_off_flow_->Start();
}
void EasyUnlockServiceRegular::ResetTurnOffFlow() {
turn_off_flow_.reset();
SetTurnOffFlowStatus(IDLE);
}
EasyUnlockService::TurnOffFlowStatus
EasyUnlockServiceRegular::GetTurnOffFlowStatus() const {
return turn_off_flow_status_;
}
void EasyUnlockServiceRegular::InitializeInternal() {
registrar_.Init(profile()->GetPrefs());
registrar_.Add(
prefs::kEasyUnlockAllowed,
base::Bind(&EasyUnlockServiceRegular::OnPrefsChanged,
base::Unretained(this)));
OnPrefsChanged();
}
bool EasyUnlockServiceRegular::IsAllowedInternal() {
#if defined(OS_CHROMEOS)
if (!user_manager::UserManager::Get()->IsLoggedInAsRegularUser())
return false;
if (!chromeos::ProfileHelper::IsPrimaryProfile(profile()))
return false;
return true;
#else
// TODO(xiyuan): Revisit when non-chromeos platforms are supported.
return false;
#endif
}
void EasyUnlockServiceRegular::OnPrefsChanged() {
UpdateAppState();
}
void EasyUnlockServiceRegular::SetTurnOffFlowStatus(TurnOffFlowStatus status) {
turn_off_flow_status_ = status;
NotifyTurnOffOperationStatusChanged();
}
void EasyUnlockServiceRegular::OnTurnOffFlowFinished(bool success) {
turn_off_flow_.reset();
if (!success) {
SetTurnOffFlowStatus(FAIL);
return;
}
ClearRemoteDevices();
SetTurnOffFlowStatus(IDLE);
ReloadApp();
}
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_SIGNIN_EASY_UNLOCK_SERVICE_REGULAR_H_
#define CHROME_BROWSER_SIGNIN_EASY_UNLOCK_SERVICE_REGULAR_H_
#include <string>
#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
#include "base/prefs/pref_change_registrar.h"
#include "chrome/browser/signin/easy_unlock_service.h"
namespace base {
class DictionaryValue;
class ListValue;
}
class EasyUnlockToggleFlow;
class Profile;
// EasyUnlockService instance that should be used for regular, non-signin
// profiles.
class EasyUnlockServiceRegular : public EasyUnlockService {
public:
explicit EasyUnlockServiceRegular(Profile* profile);
virtual ~EasyUnlockServiceRegular();
private:
// EasyUnlockService implementation.
virtual EasyUnlockService::Type GetType() const OVERRIDE;
virtual std::string GetUserEmail() const OVERRIDE;
virtual void LaunchSetup() OVERRIDE;
virtual const base::DictionaryValue* GetPermitAccess() const OVERRIDE;
virtual void SetPermitAccess(const base::DictionaryValue& permit) OVERRIDE;
virtual void ClearPermitAccess() OVERRIDE;
virtual const base::ListValue* GetRemoteDevices() const OVERRIDE;
virtual void SetRemoteDevices(const base::ListValue& devices) OVERRIDE;
virtual void ClearRemoteDevices() OVERRIDE;
virtual void RunTurnOffFlow() OVERRIDE;
virtual void ResetTurnOffFlow() OVERRIDE;
virtual TurnOffFlowStatus GetTurnOffFlowStatus() const OVERRIDE;
virtual void InitializeInternal() OVERRIDE;
virtual bool IsAllowedInternal() OVERRIDE;
// Callback when the controlling pref changes.
void OnPrefsChanged();
// Sets the new turn-off flow status.
void SetTurnOffFlowStatus(TurnOffFlowStatus status);
// Callback invoked when turn off flow has finished.
void OnTurnOffFlowFinished(bool success);
PrefChangeRegistrar registrar_;
TurnOffFlowStatus turn_off_flow_status_;
scoped_ptr<EasyUnlockToggleFlow> turn_off_flow_;
DISALLOW_COPY_AND_ASSIGN(EasyUnlockServiceRegular);
};
#endif // CHROME_BROWSER_SIGNIN_EASY_UNLOCK_SERVICE_REGULAR_H_
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/signin/easy_unlock_service_signin_chromeos.h"
EasyUnlockServiceSignin::EasyUnlockServiceSignin(Profile* profile)
: EasyUnlockService(profile) {
}
EasyUnlockServiceSignin::~EasyUnlockServiceSignin() {
}
EasyUnlockService::Type EasyUnlockServiceSignin::GetType() const {
return EasyUnlockService::TYPE_SIGNIN;
}
std::string EasyUnlockServiceSignin::GetUserEmail() const {
// TODO(tbarzic): Implement this (http://crbug.com/401634).
return "";
}
void EasyUnlockServiceSignin::LaunchSetup() {
NOTREACHED();
}
const base::DictionaryValue* EasyUnlockServiceSignin::GetPermitAccess() const {
// TODO(tbarzic): Implement this (http://crbug.com/401634).
return NULL;
}
void EasyUnlockServiceSignin::SetPermitAccess(
const base::DictionaryValue& permit) {
NOTREACHED();
}
void EasyUnlockServiceSignin::ClearPermitAccess() {
NOTREACHED();
}
const base::ListValue* EasyUnlockServiceSignin::GetRemoteDevices() const {
// TODO(tbarzic): Implement this (http://crbug.com/401634).
return NULL;
}
void EasyUnlockServiceSignin::SetRemoteDevices(
const base::ListValue& devices) {
NOTREACHED();
}
void EasyUnlockServiceSignin::ClearRemoteDevices() {
NOTREACHED();
}
void EasyUnlockServiceSignin::RunTurnOffFlow() {
NOTREACHED();
}
void EasyUnlockServiceSignin::ResetTurnOffFlow() {
NOTREACHED();
}
EasyUnlockService::TurnOffFlowStatus
EasyUnlockServiceSignin::GetTurnOffFlowStatus() const {
return EasyUnlockService::IDLE;
}
void EasyUnlockServiceSignin::InitializeInternal() {
}
bool EasyUnlockServiceSignin::IsAllowedInternal() {
// TODO(tbarzic): Implement this (http://crbug.com/401634).
return false;
}
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_SIGNIN_EASY_UNLOCK_SERVICE_SIGNIN_CHROMEOS_H_
#define CHROME_BROWSER_SIGNIN_EASY_UNLOCK_SERVICE_SIGNIN_CHROMEOS_H_
#include <string>
#include "base/macros.h"
#include "chrome/browser/signin/easy_unlock_service.h"
// EasyUnlockService instance that should be used for signin profile.
class EasyUnlockServiceSignin : public EasyUnlockService {
public:
explicit EasyUnlockServiceSignin(Profile* profile);
virtual ~EasyUnlockServiceSignin();
private:
// EasyUnlockService implementation:
virtual EasyUnlockService::Type GetType() const OVERRIDE;
virtual std::string GetUserEmail() const OVERRIDE;
virtual void LaunchSetup() OVERRIDE;
virtual const base::DictionaryValue* GetPermitAccess() const OVERRIDE;
virtual void SetPermitAccess(const base::DictionaryValue& permit) OVERRIDE;
virtual void ClearPermitAccess() OVERRIDE;
virtual const base::ListValue* GetRemoteDevices() const OVERRIDE;
virtual void SetRemoteDevices(const base::ListValue& devices) OVERRIDE;
virtual void ClearRemoteDevices() OVERRIDE;
virtual void RunTurnOffFlow() OVERRIDE;
virtual void ResetTurnOffFlow() OVERRIDE;
virtual TurnOffFlowStatus GetTurnOffFlowStatus() const OVERRIDE;
virtual bool IsAllowedInternal() OVERRIDE;
virtual void InitializeInternal() OVERRIDE;
DISALLOW_COPY_AND_ASSIGN(EasyUnlockServiceSignin);
};
#endif // CHROME_BROWSER_SIGNIN_EASY_UNLOCK_SERVICE_SIGNIN_CHROMEOS_H_
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#include "chrome/browser/ui/webui/options/easy_unlock_handler.h" #include "chrome/browser/ui/webui/options/easy_unlock_handler.h"
#include <string>
#include "base/bind.h" #include "base/bind.h"
#include "base/values.h" #include "base/values.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
...@@ -67,7 +69,7 @@ void EasyUnlockHandler::OnTurnOffOperationStatusChanged() { ...@@ -67,7 +69,7 @@ void EasyUnlockHandler::OnTurnOffOperationStatusChanged() {
void EasyUnlockHandler::SendTurnOffOperationStatus() { void EasyUnlockHandler::SendTurnOffOperationStatus() {
EasyUnlockService::TurnOffFlowStatus status = EasyUnlockService::TurnOffFlowStatus status =
EasyUnlockService::Get(Profile::FromWebUI(web_ui())) EasyUnlockService::Get(Profile::FromWebUI(web_ui()))
->turn_off_flow_status(); ->GetTurnOffFlowStatus();
// Translate status into JS UI state string. Note the translated string // Translate status into JS UI state string. Note the translated string
// should match UIState defined in easy_unlock_turn_off_overlay.js. // should match UIState defined in easy_unlock_turn_off_overlay.js.
......
...@@ -1458,6 +1458,10 @@ ...@@ -1458,6 +1458,10 @@
'browser/signin/easy_unlock_service.h', 'browser/signin/easy_unlock_service.h',
'browser/signin/easy_unlock_service_factory.cc', 'browser/signin/easy_unlock_service_factory.cc',
'browser/signin/easy_unlock_service_factory.h', 'browser/signin/easy_unlock_service_factory.h',
'browser/signin/easy_unlock_service_regular.cc',
'browser/signin/easy_unlock_service_regular.h',
'browser/signin/easy_unlock_service_signin_chromeos.cc',
'browser/signin/easy_unlock_service_signin_chromeos.h',
'browser/signin/easy_unlock_toggle_flow.cc', 'browser/signin/easy_unlock_toggle_flow.cc',
'browser/signin/easy_unlock_toggle_flow.h', 'browser/signin/easy_unlock_toggle_flow.h',
'browser/speech/extension_api/tts_engine_extension_api.cc', 'browser/speech/extension_api/tts_engine_extension_api.cc',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment