1 // Copyright (c) 2012 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 #ifndef CHROME_SERVICE_SERVICE_IPC_SERVER_H_
6 #define CHROME_SERVICE_SERVICE_IPC_SERVER_H_
11 #include "base/memory/scoped_ptr.h"
12 #include "ipc/ipc_channel_handle.h"
13 #include "ipc/ipc_listener.h"
14 #include "ipc/ipc_sync_channel.h"
15 #include "ipc/ipc_sender.h"
19 class DictionaryValue
;
20 class HistogramDeltaSerialization
;
25 // This class handles IPC commands for the service process.
26 class ServiceIPCServer
: public IPC::Listener
, public IPC::Sender
{
32 // Called when the service process must shut down.
33 virtual void OnShutdown() = 0;
35 // Called when a product update is available.
36 virtual void OnUpdateAvailable() = 0;
38 // Called when the IPC channel is closed. A return value of true indicates
39 // that the IPC server should continue listening for new connections.
40 virtual bool OnIPCClientDisconnect() = 0;
45 const scoped_refptr
<base::SingleThreadTaskRunner
>& io_task_runner
,
46 const IPC::ChannelHandle
& handle
,
47 base::WaitableEvent
* shutdown_event
);
48 ~ServiceIPCServer() override
;
52 // IPC::Sender implementation.
53 bool Send(IPC::Message
* msg
) override
;
55 bool is_ipc_client_connected() const { return ipc_client_connected_
; }
58 friend class MockServiceIPCServer
;
60 // IPC::Listener implementation.
61 bool OnMessageReceived(const IPC::Message
& msg
) override
;
62 void OnChannelConnected(int32 peer_pid
) override
;
63 void OnChannelError() override
;
65 // IPC message handlers.
66 void OnEnableCloudPrintProxyWithRobot(
67 const std::string
& robot_auth_code
,
68 const std::string
& robot_email
,
69 const std::string
& user_email
,
70 const base::DictionaryValue
& user_settings
);
71 void OnGetCloudPrintProxyInfo();
72 void OnGetHistograms();
74 void OnDisableCloudPrintProxy();
77 void OnUpdateAvailable();
79 // Helper method to create the sync channel.
83 scoped_refptr
<base::SingleThreadTaskRunner
> io_task_runner_
;
84 IPC::ChannelHandle channel_handle_
;
85 scoped_ptr
<IPC::SyncChannel
> channel_
;
86 base::WaitableEvent
* shutdown_event_
;
88 // Indicates whether an IPC client is currently connected to the channel.
89 bool ipc_client_connected_
;
91 // Calculates histograms deltas.
92 scoped_ptr
<base::HistogramDeltaSerialization
> histogram_delta_serializer_
;
94 DISALLOW_COPY_AND_ASSIGN(ServiceIPCServer
);
97 #endif // CHROME_SERVICE_SERVICE_IPC_SERVER_H_