Avoid crashing when going back/forward to debug URLs on a sad WebUI tab.
[chromium-blink-merge.git] / chrome / service / cloud_print / cloud_print_message_handler.cc
blobbabcad71957c6abe868cb558127a7ad60afba9ce
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"
7 #include <vector>
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) {
18 DCHECK(ipc_sender);
19 DCHECK(proxy_provider);
22 CloudPrintMessageHandler::~CloudPrintMessageHandler() {
25 bool CloudPrintMessageHandler::HandleMessage(const IPC::Message& message) {
26 bool handled = true;
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)
36 IPC_END_MESSAGE_MAP()
37 return handled;
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