| 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 <memory> | 8 #include <memory> |
| 9 #include <string> |
| 9 | 10 |
| 10 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 11 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 12 #include "base/single_thread_task_runner.h" | 13 #include "base/single_thread_task_runner.h" |
| 13 #include "base/threading/thread_checker.h" | 14 #include "base/threading/thread_checker.h" |
| 14 #include "mojo/public/cpp/bindings/callback.h" | 15 #include "mojo/public/cpp/bindings/callback.h" |
| 15 #include "mojo/public/cpp/bindings/lib/sync_handle_watcher.h" | 16 #include "mojo/public/cpp/bindings/lib/sync_handle_watcher.h" |
| 16 #include "mojo/public/cpp/bindings/message.h" | 17 #include "mojo/public/cpp/bindings/message.h" |
| 17 #include "mojo/public/cpp/system/core.h" | 18 #include "mojo/public/cpp/system/core.h" |
| 18 #include "mojo/public/cpp/system/watcher.h" | 19 #include "mojo/public/cpp/system/watcher.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 ~Connector() override; | 51 ~Connector() override; |
| 51 | 52 |
| 52 // Sets the receiver to handle messages read from the message pipe. The | 53 // Sets the receiver to handle messages read from the message pipe. The |
| 53 // Connector will read messages from the pipe regardless of whether or not an | 54 // Connector will read messages from the pipe regardless of whether or not an |
| 54 // incoming receiver has been set. | 55 // incoming receiver has been set. |
| 55 void set_incoming_receiver(MessageReceiver* receiver) { | 56 void set_incoming_receiver(MessageReceiver* receiver) { |
| 56 DCHECK(thread_checker_.CalledOnValidThread()); | 57 DCHECK(thread_checker_.CalledOnValidThread()); |
| 57 incoming_receiver_ = receiver; | 58 incoming_receiver_ = receiver; |
| 58 } | 59 } |
| 59 | 60 |
| 61 // Sets the interface name for this connector. Used only for debugging. |
| 62 void set_interface_name(const std::string& name) { interface_name_ = name; } |
| 63 |
| 60 // Errors from incoming receivers will force the connector into an error | 64 // Errors from incoming receivers will force the connector into an error |
| 61 // state, where no more messages will be processed. This method is used | 65 // state, where no more messages will be processed. This method is used |
| 62 // during testing to prevent that from happening. | 66 // during testing to prevent that from happening. |
| 63 void set_enforce_errors_from_incoming_receiver(bool enforce) { | 67 void set_enforce_errors_from_incoming_receiver(bool enforce) { |
| 64 DCHECK(thread_checker_.CalledOnValidThread()); | 68 DCHECK(thread_checker_.CalledOnValidThread()); |
| 65 enforce_errors_from_incoming_receiver_ = enforce; | 69 enforce_errors_from_incoming_receiver_ = enforce; |
| 66 } | 70 } |
| 67 | 71 |
| 68 // Sets the error handler to receive notifications when an error is | 72 // Sets the error handler to receive notifications when an error is |
| 69 // encountered while reading from the pipe or waiting to read from the pipe. | 73 // encountered while reading from the pipe or waiting to read from the pipe. |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 | 184 |
| 181 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 185 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 182 Watcher handle_watcher_; | 186 Watcher handle_watcher_; |
| 183 | 187 |
| 184 bool error_; | 188 bool error_; |
| 185 bool drop_writes_; | 189 bool drop_writes_; |
| 186 bool enforce_errors_from_incoming_receiver_; | 190 bool enforce_errors_from_incoming_receiver_; |
| 187 | 191 |
| 188 bool paused_; | 192 bool paused_; |
| 189 | 193 |
| 194 // The name of the interface bound to this connector. Used for debugging only. |
| 195 std::string interface_name_; |
| 196 |
| 190 // If sending messages is allowed from multiple threads, |lock_| is used to | 197 // If sending messages is allowed from multiple threads, |lock_| is used to |
| 191 // protect modifications to |message_pipe_| and |drop_writes_|. | 198 // protect modifications to |message_pipe_| and |drop_writes_|. |
| 192 std::unique_ptr<base::Lock> lock_; | 199 std::unique_ptr<base::Lock> lock_; |
| 193 | 200 |
| 194 std::unique_ptr<SyncHandleWatcher> sync_watcher_; | 201 std::unique_ptr<SyncHandleWatcher> sync_watcher_; |
| 195 bool allow_woken_up_by_others_; | 202 bool allow_woken_up_by_others_; |
| 196 // If non-zero, currently the control flow is inside the sync handle watcher | 203 // If non-zero, currently the control flow is inside the sync handle watcher |
| 197 // callback. | 204 // callback. |
| 198 size_t sync_handle_watcher_callback_count_; | 205 size_t sync_handle_watcher_callback_count_; |
| 199 | 206 |
| 200 base::ThreadChecker thread_checker_; | 207 base::ThreadChecker thread_checker_; |
| 201 | 208 |
| 202 // Create a single weak ptr and use it everywhere, to avoid the malloc/free | 209 // Create a single weak ptr and use it everywhere, to avoid the malloc/free |
| 203 // cost of creating a new weak ptr whenever it is needed. | 210 // cost of creating a new weak ptr whenever it is needed. |
| 204 base::WeakPtr<Connector> weak_self_; | 211 base::WeakPtr<Connector> weak_self_; |
| 205 base::WeakPtrFactory<Connector> weak_factory_; | 212 base::WeakPtrFactory<Connector> weak_factory_; |
| 206 | 213 |
| 207 DISALLOW_COPY_AND_ASSIGN(Connector); | 214 DISALLOW_COPY_AND_ASSIGN(Connector); |
| 208 }; | 215 }; |
| 209 | 216 |
| 210 } // namespace internal | 217 } // namespace internal |
| 211 } // namespace mojo | 218 } // namespace mojo |
| 212 | 219 |
| 213 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_CONNECTOR_H_ | 220 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_CONNECTOR_H_ |
| OLD | NEW |