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/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/memory/weak_ptr.h" |
9 #include "base/threading/thread_checker.h" | 10 #include "base/threading/thread_checker.h" |
10 #include "mojo/public/c/environment/async_waiter.h" | 11 #include "mojo/public/c/environment/async_waiter.h" |
11 #include "mojo/public/cpp/bindings/callback.h" | 12 #include "mojo/public/cpp/bindings/callback.h" |
12 #include "mojo/public/cpp/bindings/message.h" | 13 #include "mojo/public/cpp/bindings/message.h" |
13 #include "mojo/public/cpp/environment/environment.h" | 14 #include "mojo/public/cpp/environment/environment.h" |
14 #include "mojo/public/cpp/system/core.h" | 15 #include "mojo/public/cpp/system/core.h" |
15 | 16 |
16 namespace base { | 17 namespace base { |
17 class Lock; | 18 class Lock; |
18 } | 19 } |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 void ResumeIncomingMethodCallProcessing(); | 115 void ResumeIncomingMethodCallProcessing(); |
115 | 116 |
116 // MessageReceiver implementation: | 117 // MessageReceiver implementation: |
117 bool Accept(Message* message) override; | 118 bool Accept(Message* message) override; |
118 | 119 |
119 MessagePipeHandle handle() const { | 120 MessagePipeHandle handle() const { |
120 DCHECK(thread_checker_.CalledOnValidThread()); | 121 DCHECK(thread_checker_.CalledOnValidThread()); |
121 return message_pipe_.get(); | 122 return message_pipe_.get(); |
122 } | 123 } |
123 | 124 |
| 125 // Requests to register |message_pipe_| with SyncHandleWatcher whenever this |
| 126 // instance is expecting incoming messages. |
| 127 // |
| 128 // Please note that UnregisterSyncHandleWatch() needs to be called as many |
| 129 // times as successful RegisterSyncHandleWatch() calls in order to cancel the |
| 130 // effect. |
| 131 bool RegisterSyncHandleWatch(); |
| 132 void UnregisterSyncHandleWatch(); |
| 133 |
| 134 // Watches all handles registered with SyncHandleWatcher on the same thread. |
| 135 // The method returns true when |*should_stop| is set to true; returns false |
| 136 // when any failure occurs during the watch, including |message_pipe_| is |
| 137 // closed. |
| 138 bool RunSyncHandleWatch(const bool* should_stop); |
| 139 |
| 140 // Whether currently the control flow is inside the sync handle watcher |
| 141 // callback. |
| 142 bool during_sync_handle_watcher_callback() const { |
| 143 return sync_handle_watcher_callback_count_ > 0; |
| 144 } |
| 145 |
124 private: | 146 private: |
125 static void CallOnHandleReady(void* closure, MojoResult result); | 147 static void CallOnHandleReady(void* closure, MojoResult result); |
126 void OnHandleReady(MojoResult result); | 148 void OnSyncHandleWatcherHandleReady(MojoResult result); |
| 149 void OnHandleReadyInternal(MojoResult result); |
127 | 150 |
128 void WaitToReadMore(); | 151 void WaitToReadMore(); |
129 | 152 |
130 // Returns false if |this| was destroyed during message dispatch. | 153 // Returns false if |this| was destroyed during message dispatch. |
131 MOJO_WARN_UNUSED_RESULT bool ReadSingleMessage(MojoResult* read_result); | 154 MOJO_WARN_UNUSED_RESULT bool ReadSingleMessage(MojoResult* read_result); |
132 | 155 |
133 // |this| can be destroyed during message dispatch. | 156 // |this| can be destroyed during message dispatch. |
134 void ReadAllAvailableMessages(); | 157 void ReadAllAvailableMessages(); |
135 | 158 |
136 // If |force_pipe_reset| is true, this method replaces the existing | 159 // If |force_pipe_reset| is true, this method replaces the existing |
(...skipping 11 matching lines...) Expand all Loading... |
148 ScopedMessagePipeHandle message_pipe_; | 171 ScopedMessagePipeHandle message_pipe_; |
149 MessageReceiver* incoming_receiver_; | 172 MessageReceiver* incoming_receiver_; |
150 | 173 |
151 MojoAsyncWaitID async_wait_id_; | 174 MojoAsyncWaitID async_wait_id_; |
152 bool error_; | 175 bool error_; |
153 bool drop_writes_; | 176 bool drop_writes_; |
154 bool enforce_errors_from_incoming_receiver_; | 177 bool enforce_errors_from_incoming_receiver_; |
155 | 178 |
156 bool paused_; | 179 bool paused_; |
157 | 180 |
158 // If non-null, this will be set to true when the Connector is destroyed. We | |
159 // use this flag to allow for the Connector to be destroyed as a side-effect | |
160 // of dispatching an incoming message. | |
161 bool* destroyed_flag_; | |
162 | |
163 // If sending messages is allowed from multiple threads, |lock_| is used to | 181 // If sending messages is allowed from multiple threads, |lock_| is used to |
164 // protect modifications to |message_pipe_| and |drop_writes_|. | 182 // protect modifications to |message_pipe_| and |drop_writes_|. |
165 scoped_ptr<base::Lock> lock_; | 183 scoped_ptr<base::Lock> lock_; |
166 | 184 |
| 185 // If non-zero, |message_pipe_| should be registered with SyncHandleWatcher. |
| 186 size_t register_sync_handle_watch_count_; |
| 187 // Whether |message_pipe_| has been registered with SyncHandleWatcher. |
| 188 bool registered_with_sync_handle_watcher_; |
| 189 // If non-zero, currently the control flow is inside the sync handle watcher |
| 190 // callback. |
| 191 size_t sync_handle_watcher_callback_count_; |
| 192 |
167 base::ThreadChecker thread_checker_; | 193 base::ThreadChecker thread_checker_; |
168 | 194 |
| 195 base::WeakPtrFactory<Connector> weak_factory_; |
| 196 |
169 MOJO_DISALLOW_COPY_AND_ASSIGN(Connector); | 197 MOJO_DISALLOW_COPY_AND_ASSIGN(Connector); |
170 }; | 198 }; |
171 | 199 |
172 } // namespace internal | 200 } // namespace internal |
173 } // namespace mojo | 201 } // namespace mojo |
174 | 202 |
175 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_CONNECTOR_H_ | 203 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_CONNECTOR_H_ |
OLD | NEW |