| 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 | 9 |
| 10 #include "base/callback.h" | |
| 11 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| 12 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
| 13 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
| 14 #include "base/threading/thread_checker.h" | 13 #include "base/threading/thread_checker.h" |
| 14 #include "mojo/public/cpp/bindings/callback.h" |
| 15 #include "mojo/public/cpp/bindings/lib/sync_handle_watcher.h" | 15 #include "mojo/public/cpp/bindings/lib/sync_handle_watcher.h" |
| 16 #include "mojo/public/cpp/bindings/message.h" | 16 #include "mojo/public/cpp/bindings/message.h" |
| 17 #include "mojo/public/cpp/system/core.h" | 17 #include "mojo/public/cpp/system/core.h" |
| 18 #include "mojo/public/cpp/system/watcher.h" | 18 #include "mojo/public/cpp/system/watcher.h" |
| 19 | 19 |
| 20 namespace base { | 20 namespace base { |
| 21 class Lock; | 21 class Lock; |
| 22 } | 22 } |
| 23 | 23 |
| 24 namespace mojo { | 24 namespace mojo { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 // Errors from incoming receivers will force the connector into an error | 60 // Errors from incoming receivers will force the connector into an error |
| 61 // state, where no more messages will be processed. This method is used | 61 // state, where no more messages will be processed. This method is used |
| 62 // during testing to prevent that from happening. | 62 // during testing to prevent that from happening. |
| 63 void set_enforce_errors_from_incoming_receiver(bool enforce) { | 63 void set_enforce_errors_from_incoming_receiver(bool enforce) { |
| 64 DCHECK(thread_checker_.CalledOnValidThread()); | 64 DCHECK(thread_checker_.CalledOnValidThread()); |
| 65 enforce_errors_from_incoming_receiver_ = enforce; | 65 enforce_errors_from_incoming_receiver_ = enforce; |
| 66 } | 66 } |
| 67 | 67 |
| 68 // Sets the error handler to receive notifications when an error is | 68 // 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. | 69 // encountered while reading from the pipe or waiting to read from the pipe. |
| 70 void set_connection_error_handler(const base::Closure& error_handler) { | 70 void set_connection_error_handler(const Closure& error_handler) { |
| 71 DCHECK(thread_checker_.CalledOnValidThread()); | 71 DCHECK(thread_checker_.CalledOnValidThread()); |
| 72 connection_error_handler_ = error_handler; | 72 connection_error_handler_ = error_handler; |
| 73 } | 73 } |
| 74 | 74 |
| 75 // Returns true if an error was encountered while reading from the pipe or | 75 // Returns true if an error was encountered while reading from the pipe or |
| 76 // waiting to read from the pipe. | 76 // waiting to read from the pipe. |
| 77 bool encountered_error() const { | 77 bool encountered_error() const { |
| 78 DCHECK(thread_checker_.CalledOnValidThread()); | 78 DCHECK(thread_checker_.CalledOnValidThread()); |
| 79 return error_; | 79 return error_; |
| 80 } | 80 } |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 // |message_pipe_| with a dummy message pipe handle (whose peer is closed). | 166 // |message_pipe_| with a dummy message pipe handle (whose peer is closed). |
| 167 // If |force_async_handler| is true, |connection_error_handler_| is called | 167 // If |force_async_handler| is true, |connection_error_handler_| is called |
| 168 // asynchronously. | 168 // asynchronously. |
| 169 void HandleError(bool force_pipe_reset, bool force_async_handler); | 169 void HandleError(bool force_pipe_reset, bool force_async_handler); |
| 170 | 170 |
| 171 // Cancels any calls made to |waiter_|. | 171 // Cancels any calls made to |waiter_|. |
| 172 void CancelWait(); | 172 void CancelWait(); |
| 173 | 173 |
| 174 void EnsureSyncWatcherExists(); | 174 void EnsureSyncWatcherExists(); |
| 175 | 175 |
| 176 base::Closure connection_error_handler_; | 176 Closure connection_error_handler_; |
| 177 | 177 |
| 178 ScopedMessagePipeHandle message_pipe_; | 178 ScopedMessagePipeHandle message_pipe_; |
| 179 MessageReceiver* incoming_receiver_; | 179 MessageReceiver* incoming_receiver_; |
| 180 | 180 |
| 181 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 181 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 182 Watcher handle_watcher_; | 182 Watcher handle_watcher_; |
| 183 | 183 |
| 184 bool error_; | 184 bool error_; |
| 185 bool drop_writes_; | 185 bool drop_writes_; |
| 186 bool enforce_errors_from_incoming_receiver_; | 186 bool enforce_errors_from_incoming_receiver_; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 204 base::WeakPtr<Connector> weak_self_; | 204 base::WeakPtr<Connector> weak_self_; |
| 205 base::WeakPtrFactory<Connector> weak_factory_; | 205 base::WeakPtrFactory<Connector> weak_factory_; |
| 206 | 206 |
| 207 DISALLOW_COPY_AND_ASSIGN(Connector); | 207 DISALLOW_COPY_AND_ASSIGN(Connector); |
| 208 }; | 208 }; |
| 209 | 209 |
| 210 } // namespace internal | 210 } // namespace internal |
| 211 } // namespace mojo | 211 } // namespace mojo |
| 212 | 212 |
| 213 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_CONNECTOR_H_ | 213 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_CONNECTOR_H_ |
| OLD | NEW |