1 // Copyright 2015 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/service/cloud_print/cloud_print_message_handler.h"
9 #include "chrome/common/service_messages.h"
10 #include "ipc/ipc_sender.h"
12 namespace cloud_print
{
14 CloudPrintMessageHandler::CloudPrintMessageHandler(
15 IPC::Sender
* ipc_sender
,
16 CloudPrintProxy::Provider
* proxy_provider
)
17 : ipc_sender_(ipc_sender
), proxy_provider_(proxy_provider
) {
19 DCHECK(proxy_provider
);
22 CloudPrintMessageHandler::~CloudPrintMessageHandler() {
25 bool CloudPrintMessageHandler::HandleMessage(const IPC::Message
& message
) {
27 IPC_BEGIN_MESSAGE_MAP(CloudPrintMessageHandler
, message
)
28 IPC_MESSAGE_HANDLER(ServiceMsg_EnableCloudPrintProxyWithRobot
,
29 OnEnableCloudPrintProxyWithRobot
)
30 IPC_MESSAGE_HANDLER(ServiceMsg_DisableCloudPrintProxy
,
31 OnDisableCloudPrintProxy
)
32 IPC_MESSAGE_HANDLER(ServiceMsg_GetCloudPrintProxyInfo
,
33 OnGetCloudPrintProxyInfo
)
34 IPC_MESSAGE_HANDLER(ServiceMsg_GetPrinters
, OnGetPrinters
)
35 IPC_MESSAGE_UNHANDLED(handled
= false)
40 void CloudPrintMessageHandler::OnEnableCloudPrintProxyWithRobot(
41 const std::string
& robot_auth_code
,
42 const std::string
& robot_email
,
43 const std::string
& user_email
,
44 const base::DictionaryValue
& user_settings
) {
45 proxy_provider_
->GetCloudPrintProxy()->EnableForUserWithRobot(
46 robot_auth_code
, robot_email
, user_email
, user_settings
);
49 void CloudPrintMessageHandler::OnGetCloudPrintProxyInfo() {
50 CloudPrintProxyInfo info
;
51 proxy_provider_
->GetCloudPrintProxy()->GetProxyInfo(&info
);
52 ipc_sender_
->Send(new ServiceHostMsg_CloudPrintProxy_Info(info
));
55 void CloudPrintMessageHandler::OnGetPrinters() {
56 std::vector
<std::string
> printers
;
57 proxy_provider_
->GetCloudPrintProxy()->GetPrinters(&printers
);
58 ipc_sender_
->Send(new ServiceHostMsg_Printers(printers
));
61 void CloudPrintMessageHandler::OnDisableCloudPrintProxy() {
62 proxy_provider_
->GetCloudPrintProxy()->UnregisterPrintersAndDisableForUser();
65 } // namespace cloud_print