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 "ash/system/chromeos/devicetype_utils.h"
9 #include "base/bind_helpers.h"
10 #include "base/logging.h"
11 #include "base/values.h"
12 #include "chrome/browser/chromeos/policy/consumer_management_service.h"
13 #include "chrome/browser/chromeos/policy/consumer_management_stage.h"
14 #include "chrome/browser/chromeos/policy/consumer_unenrollment_handler.h"
15 #include "chrome/browser/chromeos/policy/consumer_unenrollment_handler_factory.h"
16 #include "chrome/browser/profiles/profile.h"
17 #include "chrome/grit/generated_resources.h"
18 #include "chromeos/dbus/dbus_thread_manager.h"
19 #include "chromeos/dbus/power_manager_client.h"
20 #include "components/user_manager/user_manager.h"
21 #include "content/public/browser/web_ui.h"
22 #include "ui/base/l10n/l10n_util.h"
27 ConsumerManagementHandler::ConsumerManagementHandler(
28 policy::ConsumerManagementService
* management_service
)
29 : management_service_(management_service
) {
32 ConsumerManagementHandler::~ConsumerManagementHandler() {
35 void ConsumerManagementHandler::GetLocalizedValues(
36 base::DictionaryValue
* localized_strings
) {
37 DCHECK(localized_strings
);
39 RegisterTitle(localized_strings
, "consumerManagementOverlay",
40 IDS_OPTIONS_CONSUMER_MANAGEMENT_OVERLAY
);
43 localized_strings
->SetString(
44 "consumerManagementOverlayEnrollTitle",
45 ash::SubstituteChromeOSDeviceType(
46 IDS_OPTIONS_CONSUMER_MANAGEMENT_OVERLAY_ENROLL_TITLE
));
47 localized_strings
->SetString(
48 "consumerManagementOverlayEnrollMessage",
49 ash::SubstituteChromeOSDeviceType(
50 IDS_OPTIONS_CONSUMER_MANAGEMENT_OVERLAY_ENROLL_MESSAGE
));
51 localized_strings
->SetString(
52 "consumerManagementOverlayEnroll",
53 l10n_util::GetStringUTF16(
54 IDS_OPTIONS_CONSUMER_MANAGEMENT_OVERLAY_ENROLL
));
57 localized_strings
->SetString(
58 "consumerManagementOverlayUnenrollTitle",
59 ash::SubstituteChromeOSDeviceType(
60 IDS_OPTIONS_CONSUMER_MANAGEMENT_OVERLAY_UNENROLL_TITLE
));
61 localized_strings
->SetString(
62 "consumerManagementOverlayUnenrollMessage",
63 ash::SubstituteChromeOSDeviceType(
64 IDS_OPTIONS_CONSUMER_MANAGEMENT_OVERLAY_UNENROLL_MESSAGE
));
65 localized_strings
->SetString(
66 "consumerManagementOverlayUnenroll",
67 l10n_util::GetStringUTF16(
68 IDS_OPTIONS_CONSUMER_MANAGEMENT_OVERLAY_UNENROLL
));
71 void ConsumerManagementHandler::RegisterMessages() {
72 web_ui()->RegisterMessageCallback(
73 "enrollConsumerManagement",
74 base::Bind(&ConsumerManagementHandler::HandleEnrollConsumerManagement
,
75 base::Unretained(this)));
76 web_ui()->RegisterMessageCallback(
77 "unenrollConsumerManagement",
78 base::Bind(&ConsumerManagementHandler::HandleUnenrollConsumerManagement
,
79 base::Unretained(this)));
82 void ConsumerManagementHandler::HandleEnrollConsumerManagement(
83 const base::ListValue
* args
) {
84 if (!user_manager::UserManager::Get()->IsCurrentUserOwner()) {
85 LOG(ERROR
) << "Received enrollConsumerManagement, but the current user is "
90 CHECK(management_service_
);
91 management_service_
->SetStage(
92 policy::ConsumerManagementStage::EnrollmentRequested());
93 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->RequestRestart();
96 void ConsumerManagementHandler::HandleUnenrollConsumerManagement(
97 const base::ListValue
* args
) {
98 if (!user_manager::UserManager::Get()->IsCurrentUserOwner()) {
99 LOG(ERROR
) << "Received unenrollConsumerManagement, but the current user "
100 << "is not the owner.";
104 CHECK(management_service_
);
105 management_service_
->SetStage(
106 policy::ConsumerManagementStage::UnenrollmentRequested());
107 policy::ConsumerUnenrollmentHandlerFactory::GetForBrowserContext(
108 Profile::FromWebUI(web_ui()))->Start();
111 } // namespace options
112 } // namespace chromeos