Chromium Code Reviews| Index: chrome/browser/ui/webui/settings/chromeos/easy_unlock_settings_handler.cc |
| diff --git a/chrome/browser/ui/webui/settings/chromeos/easy_unlock_settings_handler.cc b/chrome/browser/ui/webui/settings/chromeos/easy_unlock_settings_handler.cc |
| index 686a85a2f5fc3b9f1a41c67a2c24868bcd0b7dea..ef5b16604eb05d475c658d3e658f92588e168af4 100644 |
| --- a/chrome/browser/ui/webui/settings/chromeos/easy_unlock_settings_handler.cc |
| +++ b/chrome/browser/ui/webui/settings/chromeos/easy_unlock_settings_handler.cc |
| @@ -12,6 +12,7 @@ |
| #include "base/values.h" |
| #include "chrome/browser/profiles/profile.h" |
| #include "chrome/browser/signin/easy_unlock_service.h" |
| +#include "chrome/common/pref_names.h" |
| #include "chrome/common/url_constants.h" |
| #include "chrome/grit/generated_resources.h" |
| #include "components/proximity_auth/switches.h" |
| @@ -24,6 +25,12 @@ namespace settings { |
| EasyUnlockSettingsHandler::EasyUnlockSettingsHandler(Profile* profile) |
| : profile_(profile) { |
| EasyUnlockService::Get(profile)->AddObserver(this); |
| + |
| + profile_pref_registrar_.Init(profile->GetPrefs()); |
| + profile_pref_registrar_.Add( |
|
dpapad
2016/03/15 17:49:40
Based on our WebUI initialization pitfalls discuss
tommycli
2016/03/15 18:58:27
Done.
|
| + prefs::kEasyUnlockPairing, |
| + base::Bind(&EasyUnlockSettingsHandler::SendEnabledStatus, |
| + base::Unretained(this))); |
| } |
| EasyUnlockSettingsHandler::~EasyUnlockSettingsHandler() { |
| @@ -33,11 +40,14 @@ EasyUnlockSettingsHandler::~EasyUnlockSettingsHandler() { |
| EasyUnlockSettingsHandler* EasyUnlockSettingsHandler::Create( |
| content::WebUIDataSource* html_source, |
| Profile* profile) { |
| - bool allowed = EasyUnlockService::Get(profile)->IsAllowed(); |
| + EasyUnlockService* easy_unlock_service = EasyUnlockService::Get(profile); |
| + bool allowed = easy_unlock_service->IsAllowed(); |
| html_source->AddBoolean("easyUnlockAllowed", allowed); |
| if (!allowed) |
| return nullptr; |
| + html_source->AddBoolean("easyUnlockEnabled", |
| + easy_unlock_service->IsEnabled()); |
| html_source->AddString("easyUnlockLearnMoreURL", |
|
dpapad
2016/03/15 17:49:40
Can we move "easyUnlockLearnMoreURL" registration
tommycli
2016/03/15 18:58:27
Done.
|
| chrome::kEasyUnlockLearnMoreUrl); |
| html_source->AddBoolean( |
| @@ -50,6 +60,10 @@ EasyUnlockSettingsHandler* EasyUnlockSettingsHandler::Create( |
| void EasyUnlockSettingsHandler::RegisterMessages() { |
| web_ui()->RegisterMessageCallback( |
| + "easyUnlockGetEnabledStatus", |
| + base::Bind(&EasyUnlockSettingsHandler::HandleGetEnabledStatus, |
| + base::Unretained(this))); |
| + web_ui()->RegisterMessageCallback( |
| "easyUnlockGetTurnOffFlowStatus", |
| base::Bind(&EasyUnlockSettingsHandler::HandleGetTurnOffFlowStatus, |
| base::Unretained(this))); |
| @@ -67,6 +81,13 @@ void EasyUnlockSettingsHandler::OnTurnOffOperationStatusChanged() { |
| SendTurnOffOperationStatus(); |
| } |
| +void EasyUnlockSettingsHandler::SendEnabledStatus() { |
| + web_ui()->CallJavascriptFunction( |
| + "cr.webUIListenerCallback", |
| + base::StringValue("easy-unlock-enabled-status"), |
| + base::FundamentalValue(EasyUnlockService::Get(profile_)->IsEnabled())); |
| +} |
| + |
| void EasyUnlockSettingsHandler::SendTurnOffOperationStatus() { |
| EasyUnlockService::TurnOffFlowStatus status = |
| EasyUnlockService::Get(profile_)->GetTurnOffFlowStatus(); |
| @@ -96,6 +117,16 @@ void EasyUnlockSettingsHandler::SendTurnOffOperationStatus() { |
| base::StringValue(status_string)); |
| } |
| +void EasyUnlockSettingsHandler::HandleGetEnabledStatus( |
| + const base::ListValue* args) { |
| + CHECK_EQ(1U, args->GetSize()); |
| + const base::Value* callback_id; |
| + CHECK(args->Get(0, &callback_id)); |
| + ResolveJavascriptCallback( |
| + *callback_id, |
| + base::FundamentalValue(EasyUnlockService::Get(profile_)->IsEnabled())); |
| +} |
| + |
| void EasyUnlockSettingsHandler::HandleGetTurnOffFlowStatus( |
| const base::ListValue* args) { |
| SendTurnOffOperationStatus(); |