| 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_CONNECTOR_H_ | 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_CONNECTOR_H_ |
| 6 #define MOJO_PUBLIC_CPP_BINDINGS_CONNECTOR_H_ | 6 #define MOJO_PUBLIC_CPP_BINDINGS_CONNECTOR_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <utility> |
| 9 | 10 |
| 10 #include "base/callback.h" | 11 #include "base/callback.h" |
| 11 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 12 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 13 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
| 14 #include "base/optional.h" | 15 #include "base/optional.h" |
| 15 #include "base/single_thread_task_runner.h" | 16 #include "base/single_thread_task_runner.h" |
| 16 #include "base/threading/thread_checker.h" | 17 #include "base/threading/thread_checker.h" |
| 17 #include "mojo/public/cpp/bindings/bindings_export.h" | 18 #include "mojo/public/cpp/bindings/bindings_export.h" |
| 18 #include "mojo/public/cpp/bindings/message.h" | 19 #include "mojo/public/cpp/bindings/message.h" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 // Errors from incoming receivers will force the connector into an error | 64 // Errors from incoming receivers will force the connector into an error |
| 64 // 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 |
| 65 // during testing to prevent that from happening. | 66 // during testing to prevent that from happening. |
| 66 void set_enforce_errors_from_incoming_receiver(bool enforce) { | 67 void set_enforce_errors_from_incoming_receiver(bool enforce) { |
| 67 DCHECK(thread_checker_.CalledOnValidThread()); | 68 DCHECK(thread_checker_.CalledOnValidThread()); |
| 68 enforce_errors_from_incoming_receiver_ = enforce; | 69 enforce_errors_from_incoming_receiver_ = enforce; |
| 69 } | 70 } |
| 70 | 71 |
| 71 // Sets the error handler to receive notifications when an error is | 72 // Sets the error handler to receive notifications when an error is |
| 72 // 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. |
| 73 void set_connection_error_handler(const base::Closure& error_handler) { | 74 void set_connection_error_handler(base::OnceClosure error_handler) { |
| 74 DCHECK(thread_checker_.CalledOnValidThread()); | 75 DCHECK(thread_checker_.CalledOnValidThread()); |
| 75 connection_error_handler_ = error_handler; | 76 connection_error_handler_ = std::move(error_handler); |
| 76 } | 77 } |
| 77 | 78 |
| 78 // Returns true if an error was encountered while reading from the pipe or | 79 // Returns true if an error was encountered while reading from the pipe or |
| 79 // waiting to read from the pipe. | 80 // waiting to read from the pipe. |
| 80 bool encountered_error() const { | 81 bool encountered_error() const { |
| 81 DCHECK(thread_checker_.CalledOnValidThread()); | 82 DCHECK(thread_checker_.CalledOnValidThread()); |
| 82 return error_; | 83 return error_; |
| 83 } | 84 } |
| 84 | 85 |
| 85 // Closes the pipe. The connector is put into a quiescent state. | 86 // Closes the pipe. The connector is put into a quiescent state. |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 // |message_pipe_| with a dummy message pipe handle (whose peer is closed). | 179 // |message_pipe_| with a dummy message pipe handle (whose peer is closed). |
| 179 // If |force_async_handler| is true, |connection_error_handler_| is called | 180 // If |force_async_handler| is true, |connection_error_handler_| is called |
| 180 // asynchronously. | 181 // asynchronously. |
| 181 void HandleError(bool force_pipe_reset, bool force_async_handler); | 182 void HandleError(bool force_pipe_reset, bool force_async_handler); |
| 182 | 183 |
| 183 // Cancels any calls made to |waiter_|. | 184 // Cancels any calls made to |waiter_|. |
| 184 void CancelWait(); | 185 void CancelWait(); |
| 185 | 186 |
| 186 void EnsureSyncWatcherExists(); | 187 void EnsureSyncWatcherExists(); |
| 187 | 188 |
| 188 base::Closure connection_error_handler_; | 189 base::OnceClosure connection_error_handler_; |
| 189 | 190 |
| 190 ScopedMessagePipeHandle message_pipe_; | 191 ScopedMessagePipeHandle message_pipe_; |
| 191 MessageReceiver* incoming_receiver_ = nullptr; | 192 MessageReceiver* incoming_receiver_ = nullptr; |
| 192 | 193 |
| 193 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 194 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 194 std::unique_ptr<SimpleWatcher> handle_watcher_; | 195 std::unique_ptr<SimpleWatcher> handle_watcher_; |
| 195 | 196 |
| 196 bool error_ = false; | 197 bool error_ = false; |
| 197 bool drop_writes_ = false; | 198 bool drop_writes_ = false; |
| 198 bool enforce_errors_from_incoming_receiver_ = true; | 199 bool enforce_errors_from_incoming_receiver_ = true; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 // transferred (i.e., when |connected_| is set to false). | 233 // transferred (i.e., when |connected_| is set to false). |
| 233 base::WeakPtr<Connector> weak_self_; | 234 base::WeakPtr<Connector> weak_self_; |
| 234 base::WeakPtrFactory<Connector> weak_factory_; | 235 base::WeakPtrFactory<Connector> weak_factory_; |
| 235 | 236 |
| 236 DISALLOW_COPY_AND_ASSIGN(Connector); | 237 DISALLOW_COPY_AND_ASSIGN(Connector); |
| 237 }; | 238 }; |
| 238 | 239 |
| 239 } // namespace mojo | 240 } // namespace mojo |
| 240 | 241 |
| 241 #endif // MOJO_PUBLIC_CPP_BINDINGS_CONNECTOR_H_ | 242 #endif // MOJO_PUBLIC_CPP_BINDINGS_CONNECTOR_H_ |
| OLD | NEW |