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_sync_message_filter.h"
16 #include "ipc/ipc_sender.h"
20 class DictionaryValue
;
21 class HistogramDeltaSerialization
;
25 // This class handles IPC commands for the service process.
26 class ServiceIPCServer
: public IPC::Listener
, public IPC::Sender
{
28 explicit ServiceIPCServer(const IPC::ChannelHandle
& handle
);
29 virtual ~ServiceIPCServer();
33 // IPC::Sender implementation.
34 virtual bool Send(IPC::Message
* msg
) OVERRIDE
;
36 IPC::SyncChannel
* channel() { return channel_
.get(); }
38 // Safe to call on any thread, as long as it's guaranteed that the thread's
39 // lifetime is less than the main thread.
40 IPC::SyncMessageFilter
* sync_message_filter() {
41 return sync_message_filter_
.get();
44 bool is_client_connected() const { return client_connected_
; }
48 friend class MockServiceIPCServer
;
50 // IPC::Listener implementation.
51 virtual bool OnMessageReceived(const IPC::Message
& msg
) OVERRIDE
;
52 virtual void OnChannelConnected(int32 peer_pid
) OVERRIDE
;
53 virtual void OnChannelError() OVERRIDE
;
55 // IPC message handlers.
56 void OnEnableCloudPrintProxyWithRobot(
57 const std::string
& robot_auth_code
,
58 const std::string
& robot_email
,
59 const std::string
& user_email
,
60 const base::DictionaryValue
& user_settings
);
61 void OnGetCloudPrintProxyInfo();
62 void OnGetHistograms();
64 void OnDisableCloudPrintProxy();
67 void OnUpdateAvailable();
69 // Helper method to create the sync channel.
72 IPC::ChannelHandle channel_handle_
;
73 scoped_ptr
<IPC::SyncChannel
> channel_
;
74 // Indicates whether a client is currently connected to the channel.
75 bool client_connected_
;
77 // Allows threads other than the main thread to send sync messages.
78 scoped_refptr
<IPC::SyncMessageFilter
> sync_message_filter_
;
80 // Calculates histograms deltas.
81 scoped_ptr
<base::HistogramDeltaSerialization
> histogram_delta_serializer_
;
83 DISALLOW_COPY_AND_ASSIGN(ServiceIPCServer
);
86 #endif // CHROME_SERVICE_SERVICE_IPC_SERVER_H_