Implemented consumer management unenrollment.
[chromium-blink-merge.git] / chrome / browser / ui / webui / options / chromeos / consumer_management_handler.cc
blob61495627d6e5f93ffdca5c9b51e52ab5896467e8
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/chromeos/consumer_management_handler.h"
7 #include "base/bind.h"
8 #include "base/bind_helpers.h"
9 #include "base/logging.h"
10 #include "base/values.h"
11 #include "chrome/browser/chromeos/policy/consumer_management_service.h"
12 #include "chrome/browser/chromeos/policy/consumer_management_stage.h"
13 #include "chrome/browser/chromeos/policy/consumer_unenrollment_handler.h"
14 #include "chrome/browser/chromeos/policy/consumer_unenrollment_handler_factory.h"
15 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/grit/generated_resources.h"
17 #include "chromeos/dbus/dbus_thread_manager.h"
18 #include "chromeos/dbus/power_manager_client.h"
19 #include "components/user_manager/user_manager.h"
20 #include "content/public/browser/web_ui.h"
21 #include "ui/base/l10n/l10n_util.h"
23 namespace chromeos {
24 namespace options {
26 ConsumerManagementHandler::ConsumerManagementHandler(
27 policy::ConsumerManagementService* management_service)
28 : management_service_(management_service) {
31 ConsumerManagementHandler::~ConsumerManagementHandler() {
34 void ConsumerManagementHandler::GetLocalizedValues(
35 base::DictionaryValue* localized_strings) {
36 DCHECK(localized_strings);
38 RegisterTitle(localized_strings, "consumerManagementOverlay",
39 IDS_OPTIONS_CONSUMER_MANAGEMENT_OVERLAY);
41 // Enroll.
42 localized_strings->SetString(
43 "consumerManagementOverlayEnrollTitle",
44 l10n_util::GetStringUTF16(
45 IDS_OPTIONS_CONSUMER_MANAGEMENT_OVERLAY_ENROLL_TITLE));
46 localized_strings->SetString(
47 "consumerManagementOverlayEnrollMessage",
48 l10n_util::GetStringUTF16(
49 IDS_OPTIONS_CONSUMER_MANAGEMENT_OVERLAY_ENROLL_MESSAGE));
50 localized_strings->SetString(
51 "consumerManagementOverlayEnroll",
52 l10n_util::GetStringUTF16(
53 IDS_OPTIONS_CONSUMER_MANAGEMENT_OVERLAY_ENROLL));
55 // Unenroll.
56 localized_strings->SetString(
57 "consumerManagementOverlayUnenrollTitle",
58 l10n_util::GetStringUTF16(
59 IDS_OPTIONS_CONSUMER_MANAGEMENT_OVERLAY_UNENROLL_TITLE));
60 localized_strings->SetString(
61 "consumerManagementOverlayUnenrollMessage",
62 l10n_util::GetStringUTF16(
63 IDS_OPTIONS_CONSUMER_MANAGEMENT_OVERLAY_UNENROLL_MESSAGE));
64 localized_strings->SetString(
65 "consumerManagementOverlayUnenroll",
66 l10n_util::GetStringUTF16(
67 IDS_OPTIONS_CONSUMER_MANAGEMENT_OVERLAY_UNENROLL));
70 void ConsumerManagementHandler::RegisterMessages() {
71 web_ui()->RegisterMessageCallback(
72 "enrollConsumerManagement",
73 base::Bind(&ConsumerManagementHandler::HandleEnrollConsumerManagement,
74 base::Unretained(this)));
75 web_ui()->RegisterMessageCallback(
76 "unenrollConsumerManagement",
77 base::Bind(&ConsumerManagementHandler::HandleUnenrollConsumerManagement,
78 base::Unretained(this)));
81 void ConsumerManagementHandler::HandleEnrollConsumerManagement(
82 const base::ListValue* args) {
83 if (!user_manager::UserManager::Get()->IsCurrentUserOwner()) {
84 LOG(ERROR) << "Received enrollConsumerManagement, but the current user is "
85 << "not the owner.";
86 return;
89 CHECK(management_service_);
90 management_service_->SetStage(
91 policy::ConsumerManagementStage::EnrollmentRequested());
92 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->RequestRestart();
95 void ConsumerManagementHandler::HandleUnenrollConsumerManagement(
96 const base::ListValue* args) {
97 if (!user_manager::UserManager::Get()->IsCurrentUserOwner()) {
98 LOG(ERROR) << "Received unenrollConsumerManagement, but the current user "
99 << "is not the owner.";
100 return;
103 CHECK(management_service_);
104 management_service_->SetStage(
105 policy::ConsumerManagementStage::UnenrollmentRequested());
106 policy::ConsumerUnenrollmentHandlerFactory::GetForBrowserContext(
107 Profile::FromWebUI(web_ui()))->Start();
110 } // namespace options
111 } // namespace chromeos