Update V8 to version 4.6.22.
[chromium-blink-merge.git] / chrome / service / service_ipc_server.h
blob878020c8728e89b74ff9a1c358a81eaa1ec60a1a
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_
8 #include <string>
9 #include <vector>
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"
17 namespace base {
19 class DictionaryValue;
20 class HistogramDeltaSerialization;
21 class WaitableEvent;
23 } // namespace base
25 // This class handles IPC commands for the service process.
26 class ServiceIPCServer : public IPC::Listener, public IPC::Sender {
27 public:
28 class Client {
29 public:
30 virtual ~Client() {}
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;
43 ServiceIPCServer(
44 Client* client,
45 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner,
46 const IPC::ChannelHandle& handle,
47 base::WaitableEvent* shutdown_event);
48 ~ServiceIPCServer() override;
50 bool Init();
52 // IPC::Sender implementation.
53 bool Send(IPC::Message* msg) override;
55 bool is_ipc_client_connected() const { return ipc_client_connected_; }
57 private:
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();
73 void OnGetPrinters();
74 void OnDisableCloudPrintProxy();
76 void OnShutdown();
77 void OnUpdateAvailable();
79 // Helper method to create the sync channel.
80 void CreateChannel();
82 Client* client_;
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_