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