| Index: chrome/browser/signin/easy_unlock_service.cc
|
| diff --git a/chrome/browser/signin/easy_unlock_service.cc b/chrome/browser/signin/easy_unlock_service.cc
|
| index 1afcbc9e128e45c78b357f083d75025b091eac08..954a1f11b8bfd04d2d63e54f6e40cf197f699d92 100644
|
| --- a/chrome/browser/signin/easy_unlock_service.cc
|
| +++ b/chrome/browser/signin/easy_unlock_service.cc
|
| @@ -9,11 +9,15 @@
|
| #include "base/logging.h"
|
| #include "base/metrics/field_trial.h"
|
| #include "base/prefs/pref_service.h"
|
| +#include "base/prefs/scoped_user_pref_update.h"
|
| #include "base/values.h"
|
| +#include "chrome/browser/extensions/api/easy_unlock_private/easy_unlock_private_api.h"
|
| #include "chrome/browser/extensions/component_loader.h"
|
| #include "chrome/browser/extensions/extension_service.h"
|
| #include "chrome/browser/profiles/profile.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_toggle_flow.h"
|
| #include "chrome/browser/ui/extensions/application_launch.h"
|
| #include "chrome/common/chrome_switches.h"
|
| #include "chrome/common/pref_names.h"
|
| @@ -29,6 +33,15 @@
|
|
|
| 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(
|
| content::BrowserContext* context) {
|
| extensions::ExtensionSystem* extension_system =
|
| @@ -45,7 +58,7 @@ EasyUnlockService* EasyUnlockService::Get(Profile* profile) {
|
| }
|
|
|
| EasyUnlockService::EasyUnlockService(Profile* profile)
|
| - : profile_(profile), weak_ptr_factory_(this) {
|
| + : profile_(profile), turn_off_flow_status_(IDLE), weak_ptr_factory_(this) {
|
| extensions::ExtensionSystem::Get(profile_)->ready().Post(
|
| FROM_HERE,
|
| base::Bind(&EasyUnlockService::Initialize,
|
| @@ -105,6 +118,95 @@ bool EasyUnlockService::IsAllowed() {
|
| #endif
|
| }
|
|
|
| +const base::DictionaryValue* EasyUnlockService::GetPermitAccess() const {
|
| + const base::DictionaryValue* pairing_dict =
|
| + profile_->GetPrefs()->GetDictionary(prefs::kEasyUnlockPairing);
|
| + const base::DictionaryValue* permit_dict;
|
| + 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;
|
| + 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) {
|
| + observers_.AddObserver(observer);
|
| +}
|
| +
|
| +void EasyUnlockService::RemoveObserver(EasyUnlockServiceObserver* observer) {
|
| + observers_.RemoveObserver(observer);
|
| +}
|
| +
|
| +void EasyUnlockService::RunTurnOffFlow() {
|
| + if (turn_off_flow_status_ == PENDING)
|
| + return;
|
| +
|
| + SetTurnOffFlowStatus(PENDING);
|
| +
|
| + const base::DictionaryValue* pairing_dict =
|
| + profile_->GetPrefs()->GetDictionary(prefs::kEasyUnlockPairing);
|
| + const base::ListValue* devices_list;
|
| + const base::DictionaryValue* first_device;
|
| + 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(
|
| @@ -148,3 +250,26 @@ void EasyUnlockService::OnPrefsChanged() {
|
| else
|
| UnloadApp();
|
| }
|
| +
|
| +void EasyUnlockService::SetTurnOffFlowStatus(TurnOffFlowStatus status) {
|
| + turn_off_flow_status_ = status;
|
| + FOR_EACH_OBSERVER(
|
| + EasyUnlockServiceObserver, observers_, OnTurnOffOperationStatusChanged());
|
| +}
|
| +
|
| +void EasyUnlockService::OnTurnOffFlowFinished(bool success) {
|
| + turn_off_flow_.reset();
|
| +
|
| + if (!success) {
|
| + SetTurnOffFlowStatus(FAIL);
|
| + return;
|
| + }
|
| +
|
| + ClearPermitAccess();
|
| + ClearRemoteDevices();
|
| +
|
| + extensions::BrowserContextKeyedAPIFactory<
|
| + extensions::api::EasyUnlockPrivateAPI>::Get(profile_)
|
| + ->SendTurnOffFlowFinished();
|
| + SetTurnOffFlowStatus(IDLE);
|
| +}
|
|
|