OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 MOJO_PUBLIC_CPP_BINDINGS_LIB_CONNECTOR_H_ | 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_CONNECTOR_H_ |
6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_CONNECTOR_H_ | 6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_CONNECTOR_H_ |
7 | 7 |
8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
11 #include "base/threading/thread_checker.h" | 11 #include "base/threading/thread_checker.h" |
| 12 #include "mojo/message_pump/handle_watcher.h" |
12 #include "mojo/public/cpp/bindings/callback.h" | 13 #include "mojo/public/cpp/bindings/callback.h" |
13 #include "mojo/public/cpp/bindings/message.h" | 14 #include "mojo/public/cpp/bindings/message.h" |
14 #include "mojo/public/cpp/system/core.h" | 15 #include "mojo/public/cpp/system/core.h" |
15 #include "mojo/public/cpp/system/watcher.h" | |
16 | 16 |
17 namespace base { | 17 namespace base { |
18 class Lock; | 18 class Lock; |
19 } | 19 } |
20 | 20 |
21 namespace mojo { | 21 namespace mojo { |
22 namespace internal { | 22 namespace internal { |
23 | 23 |
24 // The Connector class is responsible for performing read/write operations on a | 24 // The Connector class is responsible for performing read/write operations on a |
25 // MessagePipe. It writes messages it receives through the MessageReceiver | 25 // MessagePipe. It writes messages it receives through the MessageReceiver |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 // closed. | 134 // closed. |
135 bool RunSyncHandleWatch(const bool* should_stop); | 135 bool RunSyncHandleWatch(const bool* should_stop); |
136 | 136 |
137 // Whether currently the control flow is inside the sync handle watcher | 137 // Whether currently the control flow is inside the sync handle watcher |
138 // callback. | 138 // callback. |
139 bool during_sync_handle_watcher_callback() const { | 139 bool during_sync_handle_watcher_callback() const { |
140 return sync_handle_watcher_callback_count_ > 0; | 140 return sync_handle_watcher_callback_count_ > 0; |
141 } | 141 } |
142 | 142 |
143 private: | 143 private: |
144 // Callback of mojo::Watcher. | 144 // Callback of mojo::common::HandleWatcher. |
145 void OnWatcherHandleReady(MojoResult result); | 145 void OnHandleWatcherHandleReady(MojoResult result); |
146 // Callback of SyncHandleWatcher. | 146 // Callback of SyncHandleWatcher. |
147 void OnSyncHandleWatcherHandleReady(MojoResult result); | 147 void OnSyncHandleWatcherHandleReady(MojoResult result); |
148 void OnHandleReadyInternal(MojoResult result); | 148 void OnHandleReadyInternal(MojoResult result); |
149 | 149 |
150 void WaitToReadMore(); | 150 void WaitToReadMore(); |
151 | 151 |
152 // Returns false if |this| was destroyed during message dispatch. | 152 // Returns false if |this| was destroyed during message dispatch. |
153 WARN_UNUSED_RESULT bool ReadSingleMessage(MojoResult* read_result); | 153 WARN_UNUSED_RESULT bool ReadSingleMessage(MojoResult* read_result); |
154 | 154 |
155 // |this| can be destroyed during message dispatch. | 155 // |this| can be destroyed during message dispatch. |
156 void ReadAllAvailableMessages(); | 156 void ReadAllAvailableMessages(); |
157 | 157 |
158 // If |force_pipe_reset| is true, this method replaces the existing | 158 // If |force_pipe_reset| is true, this method replaces the existing |
159 // |message_pipe_| with a dummy message pipe handle (whose peer is closed). | 159 // |message_pipe_| with a dummy message pipe handle (whose peer is closed). |
160 // If |force_async_handler| is true, |connection_error_handler_| is called | 160 // If |force_async_handler| is true, |connection_error_handler_| is called |
161 // asynchronously. | 161 // asynchronously. |
162 void HandleError(bool force_pipe_reset, bool force_async_handler); | 162 void HandleError(bool force_pipe_reset, bool force_async_handler); |
163 | 163 |
164 // Cancels any calls made to |waiter_|. | 164 // Cancels any calls made to |waiter_|. |
165 void CancelWait(); | 165 void CancelWait(); |
166 | 166 |
167 Closure connection_error_handler_; | 167 Closure connection_error_handler_; |
168 | 168 |
169 ScopedMessagePipeHandle message_pipe_; | 169 ScopedMessagePipeHandle message_pipe_; |
170 MessageReceiver* incoming_receiver_; | 170 MessageReceiver* incoming_receiver_; |
171 | 171 |
172 Watcher handle_watcher_; | 172 common::HandleWatcher handle_watcher_; |
173 | 173 |
174 bool error_; | 174 bool error_; |
175 bool drop_writes_; | 175 bool drop_writes_; |
176 bool enforce_errors_from_incoming_receiver_; | 176 bool enforce_errors_from_incoming_receiver_; |
177 | 177 |
178 bool paused_; | 178 bool paused_; |
179 | 179 |
180 // If sending messages is allowed from multiple threads, |lock_| is used to | 180 // If sending messages is allowed from multiple threads, |lock_| is used to |
181 // protect modifications to |message_pipe_| and |drop_writes_|. | 181 // protect modifications to |message_pipe_| and |drop_writes_|. |
182 scoped_ptr<base::Lock> lock_; | 182 scoped_ptr<base::Lock> lock_; |
(...skipping 11 matching lines...) Expand all Loading... |
194 | 194 |
195 base::WeakPtrFactory<Connector> weak_factory_; | 195 base::WeakPtrFactory<Connector> weak_factory_; |
196 | 196 |
197 DISALLOW_COPY_AND_ASSIGN(Connector); | 197 DISALLOW_COPY_AND_ASSIGN(Connector); |
198 }; | 198 }; |
199 | 199 |
200 } // namespace internal | 200 } // namespace internal |
201 } // namespace mojo | 201 } // namespace mojo |
202 | 202 |
203 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_CONNECTOR_H_ | 203 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_CONNECTOR_H_ |
OLD | NEW |