| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_SERVICE_SERVICE_IPC_SERVER_H_ | 5 #ifndef CHROME_SERVICE_SERVICE_IPC_SERVER_H_ |
| 6 #define CHROME_SERVICE_SERVICE_IPC_SERVER_H_ | 6 #define CHROME_SERVICE_SERVICE_IPC_SERVER_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/memory/scoped_vector.h" | 14 #include "base/memory/scoped_vector.h" |
| 15 #include "base/single_thread_task_runner.h" |
| 15 #include "ipc/ipc_channel_handle.h" | 16 #include "ipc/ipc_channel_handle.h" |
| 16 #include "ipc/ipc_listener.h" | 17 #include "ipc/ipc_listener.h" |
| 17 #include "ipc/ipc_sender.h" | 18 #include "ipc/ipc_sender.h" |
| 18 #include "ipc/ipc_sync_channel.h" | 19 #include "ipc/ipc_sync_channel.h" |
| 20 #include "mojo/public/cpp/system/message_pipe.h" |
| 19 | 21 |
| 20 namespace base { | 22 namespace base { |
| 21 | 23 |
| 22 class HistogramDeltaSerialization; | 24 class HistogramDeltaSerialization; |
| 23 class WaitableEvent; | 25 class WaitableEvent; |
| 24 | 26 |
| 25 } // namespace base | 27 } // namespace base |
| 26 | 28 |
| 27 // This class handles IPC commands for the service process. | 29 // This class handles IPC commands for the service process. |
| 28 class ServiceIPCServer : public IPC::Listener, public IPC::Sender { | 30 class ServiceIPCServer : public IPC::Listener, public IPC::Sender { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 40 | 42 |
| 41 // Called when the service process must shut down. | 43 // Called when the service process must shut down. |
| 42 virtual void OnShutdown() = 0; | 44 virtual void OnShutdown() = 0; |
| 43 | 45 |
| 44 // Called when a product update is available. | 46 // Called when a product update is available. |
| 45 virtual void OnUpdateAvailable() = 0; | 47 virtual void OnUpdateAvailable() = 0; |
| 46 | 48 |
| 47 // Called when the IPC channel is closed. A return value of true indicates | 49 // Called when the IPC channel is closed. A return value of true indicates |
| 48 // that the IPC server should continue listening for new connections. | 50 // that the IPC server should continue listening for new connections. |
| 49 virtual bool OnIPCClientDisconnect() = 0; | 51 virtual bool OnIPCClientDisconnect() = 0; |
| 52 |
| 53 // Called to create a message pipe to use for an IPC Channel connection. |
| 54 virtual mojo::ScopedMessagePipeHandle CreateChannelMessagePipe() = 0; |
| 50 }; | 55 }; |
| 51 | 56 |
| 52 ServiceIPCServer( | 57 ServiceIPCServer( |
| 53 Client* client, | 58 Client* client, |
| 54 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner, | 59 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner, |
| 55 const IPC::ChannelHandle& handle, | |
| 56 base::WaitableEvent* shutdown_event); | 60 base::WaitableEvent* shutdown_event); |
| 57 ~ServiceIPCServer() override; | 61 ~ServiceIPCServer() override; |
| 58 | 62 |
| 59 bool Init(); | 63 bool Init(); |
| 60 | 64 |
| 61 // IPC::Sender implementation. | 65 // IPC::Sender implementation. |
| 62 bool Send(IPC::Message* msg) override; | 66 bool Send(IPC::Message* msg) override; |
| 63 | 67 |
| 64 // Registers a MessageHandler with the ServiceIPCServer. When an IPC message | 68 // Registers a MessageHandler with the ServiceIPCServer. When an IPC message |
| 65 // is received that is not handled by the ServiceIPCServer itself, the | 69 // is received that is not handled by the ServiceIPCServer itself, the |
| (...skipping 15 matching lines...) Expand all Loading... |
| 81 // IPC message handlers. | 85 // IPC message handlers. |
| 82 void OnGetHistograms(); | 86 void OnGetHistograms(); |
| 83 void OnShutdown(); | 87 void OnShutdown(); |
| 84 void OnUpdateAvailable(); | 88 void OnUpdateAvailable(); |
| 85 | 89 |
| 86 // Helper method to create the sync channel. | 90 // Helper method to create the sync channel. |
| 87 void CreateChannel(); | 91 void CreateChannel(); |
| 88 | 92 |
| 89 Client* client_; | 93 Client* client_; |
| 90 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; | 94 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; |
| 91 IPC::ChannelHandle channel_handle_; | |
| 92 std::unique_ptr<IPC::SyncChannel> channel_; | 95 std::unique_ptr<IPC::SyncChannel> channel_; |
| 93 base::WaitableEvent* shutdown_event_; | 96 base::WaitableEvent* shutdown_event_; |
| 94 ScopedVector<MessageHandler> message_handlers_; | 97 ScopedVector<MessageHandler> message_handlers_; |
| 95 | 98 |
| 96 // Indicates whether an IPC client is currently connected to the channel. | 99 // Indicates whether an IPC client is currently connected to the channel. |
| 97 bool ipc_client_connected_; | 100 bool ipc_client_connected_ = false; |
| 98 | 101 |
| 99 // Calculates histograms deltas. | 102 // Calculates histograms deltas. |
| 100 std::unique_ptr<base::HistogramDeltaSerialization> | 103 std::unique_ptr<base::HistogramDeltaSerialization> |
| 101 histogram_delta_serializer_; | 104 histogram_delta_serializer_; |
| 102 | 105 |
| 103 DISALLOW_COPY_AND_ASSIGN(ServiceIPCServer); | 106 DISALLOW_COPY_AND_ASSIGN(ServiceIPCServer); |
| 104 }; | 107 }; |
| 105 | 108 |
| 106 #endif // CHROME_SERVICE_SERVICE_IPC_SERVER_H_ | 109 #endif // CHROME_SERVICE_SERVICE_IPC_SERVER_H_ |
| OLD | NEW |