OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 IPC_IPC_CHANNEL_MOJO_H_ | 5 #ifndef IPC_IPC_CHANNEL_MOJO_H_ |
6 #define IPC_IPC_CHANNEL_MOJO_H_ | 6 #define IPC_IPC_CHANNEL_MOJO_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 // | 47 // |
48 class IPC_MOJO_EXPORT ChannelMojo | 48 class IPC_MOJO_EXPORT ChannelMojo |
49 : public Channel, | 49 : public Channel, |
50 public MojoBootstrap::Delegate, | 50 public MojoBootstrap::Delegate, |
51 public NON_EXPORTED_BASE(internal::MessagePipeReader::Delegate) { | 51 public NON_EXPORTED_BASE(internal::MessagePipeReader::Delegate) { |
52 public: | 52 public: |
53 class Delegate { | 53 class Delegate { |
54 public: | 54 public: |
55 virtual ~Delegate() {} | 55 virtual ~Delegate() {} |
56 virtual base::WeakPtr<Delegate> ToWeakPtr() = 0; | 56 virtual base::WeakPtr<Delegate> ToWeakPtr() = 0; |
57 virtual scoped_refptr<base::TaskRunner> GetIOTaskRunner() = 0; | |
58 virtual void OnChannelCreated(base::WeakPtr<ChannelMojo> channel) = 0; | 57 virtual void OnChannelCreated(base::WeakPtr<ChannelMojo> channel) = 0; |
59 }; | 58 }; |
60 | 59 |
61 // True if ChannelMojo should be used regardless of the flag. | 60 // True if ChannelMojo should be used regardless of the flag. |
62 static bool ShouldBeUsed(); | 61 static bool ShouldBeUsed(); |
63 | 62 |
64 // Create ChannelMojo. A bootstrap channel is created as well. | 63 // Create ChannelMojo. A bootstrap channel is created as well. |
65 // |host| must not be null for server channels. | 64 // |host| must not be null for server channels. |
66 static scoped_ptr<ChannelMojo> Create(Delegate* delegate, | 65 static scoped_ptr<ChannelMojo> Create( |
67 const ChannelHandle& channel_handle, | 66 Delegate* delegate, |
68 Mode mode, | 67 scoped_refptr<base::TaskRunner> io_runner, |
69 Listener* listener); | 68 const ChannelHandle& channel_handle, |
| 69 Mode mode, |
| 70 Listener* listener); |
70 | 71 |
71 // Create a factory object for ChannelMojo. | 72 // Create a factory object for ChannelMojo. |
72 // The factory is used to create Mojo-based ChannelProxy family. | 73 // The factory is used to create Mojo-based ChannelProxy family. |
73 // |host| must not be null. | 74 // |host| must not be null. |
74 static scoped_ptr<ChannelFactory> CreateServerFactory( | 75 static scoped_ptr<ChannelFactory> CreateServerFactory( |
75 Delegate* delegate, | 76 Delegate* delegate, |
| 77 scoped_refptr<base::TaskRunner> io_runner, |
76 const ChannelHandle& channel_handle); | 78 const ChannelHandle& channel_handle); |
77 | 79 |
78 static scoped_ptr<ChannelFactory> CreateClientFactory( | 80 static scoped_ptr<ChannelFactory> CreateClientFactory( |
79 Delegate* delegate, | 81 Delegate* delegate, |
| 82 scoped_refptr<base::TaskRunner> io_runner, |
80 const ChannelHandle& channel_handle); | 83 const ChannelHandle& channel_handle); |
81 | 84 |
82 ~ChannelMojo() override; | 85 ~ChannelMojo() override; |
83 | 86 |
84 // ChannelMojoHost tells the client handle using this API. | 87 // ChannelMojoHost tells the client handle using this API. |
85 void OnClientLaunched(base::ProcessHandle handle); | 88 void OnClientLaunched(base::ProcessHandle handle); |
86 | 89 |
87 // Channel implementation | 90 // Channel implementation |
88 bool Connect() override; | 91 bool Connect() override; |
89 void Close() override; | 92 void Close() override; |
(...skipping 18 matching lines...) Expand all Loading... |
108 // MojoBootstrapDelegate implementation | 111 // MojoBootstrapDelegate implementation |
109 void OnBootstrapError() override; | 112 void OnBootstrapError() override; |
110 | 113 |
111 // MessagePipeReader::Delegate | 114 // MessagePipeReader::Delegate |
112 void OnMessageReceived(Message& message) override; | 115 void OnMessageReceived(Message& message) override; |
113 void OnPipeClosed(internal::MessagePipeReader* reader) override; | 116 void OnPipeClosed(internal::MessagePipeReader* reader) override; |
114 void OnPipeError(internal::MessagePipeReader* reader) override; | 117 void OnPipeError(internal::MessagePipeReader* reader) override; |
115 | 118 |
116 protected: | 119 protected: |
117 ChannelMojo(Delegate* delegate, | 120 ChannelMojo(Delegate* delegate, |
| 121 scoped_refptr<base::TaskRunner> io_runner, |
118 const ChannelHandle& channel_handle, | 122 const ChannelHandle& channel_handle, |
119 Mode mode, | 123 Mode mode, |
120 Listener* listener); | 124 Listener* listener); |
121 | 125 |
122 mojo::ScopedMessagePipeHandle CreateMessagingPipe( | 126 mojo::ScopedMessagePipeHandle CreateMessagingPipe( |
123 mojo::embedder::ScopedPlatformHandle handle); | 127 mojo::embedder::ScopedPlatformHandle handle); |
124 void InitMessageReader(mojo::ScopedMessagePipeHandle pipe, int32_t peer_pid); | 128 void InitMessageReader(mojo::ScopedMessagePipeHandle pipe, int32_t peer_pid); |
125 | 129 |
126 Listener* listener() const { return listener_; } | 130 Listener* listener() const { return listener_; } |
127 void set_peer_pid(base::ProcessId pid) { peer_pid_ = pid; } | 131 void set_peer_pid(base::ProcessId pid) { peer_pid_ = pid; } |
128 | 132 |
129 private: | 133 private: |
130 struct ChannelInfoDeleter { | 134 struct ChannelInfoDeleter { |
131 void operator()(mojo::embedder::ChannelInfo* ptr) const; | 135 void operator()(mojo::embedder::ChannelInfo* ptr) const; |
132 }; | 136 }; |
133 | 137 |
134 // ChannelMojo needs to kill its MessagePipeReader in delayed manner | 138 // ChannelMojo needs to kill its MessagePipeReader in delayed manner |
135 // because the channel wants to kill these readers during the | 139 // because the channel wants to kill these readers during the |
136 // notifications invoked by them. | 140 // notifications invoked by them. |
137 typedef internal::MessagePipeReader::DelayedDeleter ReaderDeleter; | 141 typedef internal::MessagePipeReader::DelayedDeleter ReaderDeleter; |
138 | 142 |
139 void InitDelegate(ChannelMojo::Delegate* delegate); | 143 void InitOnIOThread(ChannelMojo::Delegate* delegate); |
140 | 144 |
141 scoped_ptr<MojoBootstrap> bootstrap_; | 145 scoped_ptr<MojoBootstrap> bootstrap_; |
142 base::WeakPtr<Delegate> delegate_; | 146 base::WeakPtr<Delegate> delegate_; |
143 Mode mode_; | 147 Mode mode_; |
144 Listener* listener_; | 148 Listener* listener_; |
145 base::ProcessId peer_pid_; | 149 base::ProcessId peer_pid_; |
146 scoped_ptr<mojo::embedder::ChannelInfo, | 150 scoped_ptr<mojo::embedder::ChannelInfo, |
147 ChannelInfoDeleter> channel_info_; | 151 ChannelInfoDeleter> channel_info_; |
148 | 152 |
149 scoped_ptr<internal::MessagePipeReader, ReaderDeleter> message_reader_; | 153 scoped_ptr<internal::MessagePipeReader, ReaderDeleter> message_reader_; |
150 ScopedVector<Message> pending_messages_; | 154 ScopedVector<Message> pending_messages_; |
151 | 155 |
152 scoped_ptr<ScopedIPCSupport> ipc_support_; | 156 scoped_ptr<ScopedIPCSupport> ipc_support_; |
153 | 157 |
154 base::WeakPtrFactory<ChannelMojo> weak_factory_; | 158 base::WeakPtrFactory<ChannelMojo> weak_factory_; |
155 | 159 |
156 DISALLOW_COPY_AND_ASSIGN(ChannelMojo); | 160 DISALLOW_COPY_AND_ASSIGN(ChannelMojo); |
157 }; | 161 }; |
158 | 162 |
159 } // namespace IPC | 163 } // namespace IPC |
160 | 164 |
161 #endif // IPC_IPC_CHANNEL_MOJO_H_ | 165 #endif // IPC_IPC_CHANNEL_MOJO_H_ |
OLD | NEW |