Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / browser / ui / webui / options / easy_unlock_handler.cc
blobccde01bf5315f57652b7318a854c8c489a14d11c
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/webui/options/easy_unlock_handler.h"
7 #include <string>
9 #include "base/bind.h"
10 #include "base/values.h"
11 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/signin/easy_unlock_service.h"
13 #include "chrome/grit/generated_resources.h"
14 #include "content/public/browser/web_ui.h"
16 namespace options {
18 EasyUnlockHandler::EasyUnlockHandler() {
21 EasyUnlockHandler::~EasyUnlockHandler() {
22 EasyUnlockService::Get(Profile::FromWebUI(web_ui()))->RemoveObserver(this);
25 void EasyUnlockHandler::GetLocalizedValues(base::DictionaryValue* values) {
26 static OptionsStringResource resources[] = {
27 {"easyUnlockTurnOffButton", IDS_OPTIONS_EASY_UNLOCK_TURN_OFF_BUTTON},
28 {"easyUnlockTurnOffTitle", IDS_OPTIONS_EASY_UNLOCK_TURN_OFF_TITLE},
29 {"easyUnlockTurnOffDescription",
30 IDS_OPTIONS_EASY_UNLOCK_TURN_OFF_DESCRIPTION},
31 {"easyUnlockTurnOffOfflineTitle",
32 IDS_OPTIONS_EASY_UNLOCK_TURN_OFF_OFFLINE_TITLE},
33 {"easyUnlockTurnOffOfflineMessage",
34 IDS_OPTIONS_EASY_UNLOCK_TURN_OFF_OFFLINE_MESSAGE},
35 {"easyUnlockTurnOffErrorTitle",
36 IDS_OPTIONS_EASY_UNLOCK_TURN_OFF_ERROR_TITLE},
37 {"easyUnlockTurnOffErrorMessage",
38 IDS_OPTIONS_EASY_UNLOCK_TURN_OFF_ERROR_MESSAGE},
39 {"easyUnlockTurnOffRetryButton",
40 IDS_OPTIONS_EASY_UNLOCK_TURN_OFF_RETRY_BUTTON},
43 RegisterStrings(values, resources, arraysize(resources));
46 void EasyUnlockHandler::InitializeHandler() {
47 EasyUnlockService::Get(Profile::FromWebUI(web_ui()))->AddObserver(this);
50 void EasyUnlockHandler::RegisterMessages() {
51 web_ui()->RegisterMessageCallback(
52 "easyUnlockGetTurnOffFlowStatus",
53 base::Bind(&EasyUnlockHandler::HandleGetTurnOffFlowStatus,
54 base::Unretained(this)));
55 web_ui()->RegisterMessageCallback(
56 "easyUnlockRequestTurnOff",
57 base::Bind(&EasyUnlockHandler::HandleRequestTurnOff,
58 base::Unretained(this)));
59 web_ui()->RegisterMessageCallback(
60 "easyUnlockTurnOffOverlayDismissed",
61 base::Bind(&EasyUnlockHandler::HandlePageDismissed,
62 base::Unretained(this)));
65 void EasyUnlockHandler::OnTurnOffOperationStatusChanged() {
66 SendTurnOffOperationStatus();
69 void EasyUnlockHandler::SendTurnOffOperationStatus() {
70 EasyUnlockService::TurnOffFlowStatus status =
71 EasyUnlockService::Get(Profile::FromWebUI(web_ui()))
72 ->GetTurnOffFlowStatus();
74 // Translate status into JS UI state string. Note the translated string
75 // should match UIState defined in easy_unlock_turn_off_overlay.js.
76 std::string status_string;
77 switch (status) {
78 case EasyUnlockService::IDLE:
79 status_string = "idle";
80 break;
81 case EasyUnlockService::PENDING:
82 status_string = "pending";
83 break;
84 case EasyUnlockService::FAIL:
85 status_string = "server-error";
86 break;
87 default:
88 LOG(ERROR) << "Unknown Easy unlock turn-off operation status: " << status;
89 status_string = "idle";
90 break;
92 web_ui()->CallJavascriptFunction("EasyUnlockTurnOffOverlay.updateUIState",
93 base::StringValue(status_string));
96 void EasyUnlockHandler::HandleGetTurnOffFlowStatus(
97 const base::ListValue* args) {
98 SendTurnOffOperationStatus();
101 void EasyUnlockHandler::HandleRequestTurnOff(const base::ListValue* args) {
102 EasyUnlockService::Get(Profile::FromWebUI(web_ui()))->RunTurnOffFlow();
105 void EasyUnlockHandler::HandlePageDismissed(const base::ListValue* args) {
106 EasyUnlockService::Get(Profile::FromWebUI(web_ui()))->ResetTurnOffFlow();
109 } // namespace options