Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6167)

Unified Diff: chrome/browser/ui/webui/options/easy_unlock_handler.cc

Issue 475483003: Wire easy unlock settings UI (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/webui/options/easy_unlock_handler.cc
diff --git a/chrome/browser/ui/webui/options/easy_unlock_handler.cc b/chrome/browser/ui/webui/options/easy_unlock_handler.cc
new file mode 100644
index 0000000000000000000000000000000000000000..493a6d788f799c4aacde4a2e74bf236d00d86654
--- /dev/null
+++ b/chrome/browser/ui/webui/options/easy_unlock_handler.cc
@@ -0,0 +1,107 @@
+// 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/ui/webui/options/easy_unlock_handler.h"
+
+#include "base/bind.h"
+#include "base/values.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/signin/easy_unlock_service.h"
+#include "content/public/browser/web_ui.h"
+#include "grit/generated_resources.h"
+
+namespace options {
+
+EasyUnlockHandler::EasyUnlockHandler() {
+}
+
+EasyUnlockHandler::~EasyUnlockHandler() {
+ EasyUnlockService::Get(Profile::FromWebUI(web_ui()))->RemoveObserver(this);
+}
+
+void EasyUnlockHandler::GetLocalizedValues(base::DictionaryValue* values) {
+ static OptionsStringResource resources[] = {
+ {"easyUnlockTurnOffButton", IDS_OPTIONS_EASY_UNLOCK_TURN_OFF_BUTTON},
+ {"easyUnlockTurnOffTitle", IDS_OPTIONS_EASY_UNLOCK_TURN_OFF_TITLE},
+ {"easyUnlockTurnOffDescription",
+ IDS_OPTIONS_EASY_UNLOCK_TURN_OFF_DESCRIPTION},
+ {"easyUnlockTurnOffOfflineTitle",
+ IDS_OPTIONS_EASY_UNLOCK_TURN_OFF_OFFLINE_TITLE},
+ {"easyUnlockTurnOffOfflineMessage",
+ IDS_OPTIONS_EASY_UNLOCK_TURN_OFF_OFFLINE_MESSAGE},
+ {"easyUnlockTurnOffErrorTitle",
+ IDS_OPTIONS_EASY_UNLOCK_TURN_OFF_ERROR_TITLE},
+ {"easyUnlockTurnOffErrorMessage",
+ IDS_OPTIONS_EASY_UNLOCK_TURN_OFF_ERROR_MESSAGE},
+ {"easyUnlockTurnOffRetryButton",
+ IDS_OPTIONS_EASY_UNLOCK_TURN_OFF_RETRY_BUTTON},
+ };
+
+ RegisterStrings(values, resources, arraysize(resources));
+}
+
+void EasyUnlockHandler::InitializeHandler() {
+ EasyUnlockService::Get(Profile::FromWebUI(web_ui()))->AddObserver(this);
+}
+
+void EasyUnlockHandler::RegisterMessages() {
+ web_ui()->RegisterMessageCallback(
+ "easyUnlockGetTurnOffFlowStatus",
+ base::Bind(&EasyUnlockHandler::HandleGetTurnOffFlowStatus,
+ base::Unretained(this)));
+ web_ui()->RegisterMessageCallback(
+ "easyUnlockRequestTurnOff",
+ base::Bind(&EasyUnlockHandler::HandleRequestTurnOff,
+ base::Unretained(this)));
+ web_ui()->RegisterMessageCallback(
+ "easyUnlockTurnOffOverlayDismissed",
+ base::Bind(&EasyUnlockHandler::HandlePageDismissed,
+ base::Unretained(this)));
+}
+
+void EasyUnlockHandler::OnTurnOffOperationStatusChanged() {
+ SendTurnOffOperationStatus();
+}
+
+void EasyUnlockHandler::SendTurnOffOperationStatus() {
+ EasyUnlockService::TurnOffFlowStatus status =
+ EasyUnlockService::Get(Profile::FromWebUI(web_ui()))
+ ->turn_off_flow_status();
+
+ // Translate status into JS UI state string. Note the translated string
+ // should match UIState defined in easy_unlock_turn_off_overlay.js.
+ std::string status_string;
+ switch (status) {
+ case EasyUnlockService::IDLE:
+ status_string = "idle";
+ break;
+ case EasyUnlockService::PENDING:
+ status_string = "pending";
+ break;
+ case EasyUnlockService::FAIL:
+ status_string = "server-error";
+ break;
+ default:
+ LOG(ERROR) << "Unknown Easy unlock turn-off operation status: " << status;
+ status_string = "idle";
+ break;
+ }
+ web_ui()->CallJavascriptFunction("EasyUnlockTurnOffOverlay.updateUIState",
+ base::StringValue(status_string));
+}
+
+void EasyUnlockHandler::HandleGetTurnOffFlowStatus(
+ const base::ListValue* args) {
+ SendTurnOffOperationStatus();
+}
+
+void EasyUnlockHandler::HandleRequestTurnOff(const base::ListValue* args) {
+ EasyUnlockService::Get(Profile::FromWebUI(web_ui()))->RunTurnOffFlow();
+}
+
+void EasyUnlockHandler::HandlePageDismissed(const base::ListValue* args) {
+ EasyUnlockService::Get(Profile::FromWebUI(web_ui()))->ResetTurnOffFlow();
+}
+
+} // namespace options
« no previous file with comments | « chrome/browser/ui/webui/options/easy_unlock_handler.h ('k') | chrome/browser/ui/webui/options/options_ui.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698