OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_ROUTER_H_ | 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_ROUTER_H_ |
6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_ROUTER_H_ | 6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_ROUTER_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <map> | 10 #include <map> |
11 #include <memory> | 11 #include <memory> |
12 #include <queue> | 12 #include <queue> |
13 | 13 |
14 #include "base/callback.h" | 14 #include "base/callback.h" |
15 #include "base/macros.h" | 15 #include "base/macros.h" |
16 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
17 #include "base/memory/weak_ptr.h" | 17 #include "base/memory/weak_ptr.h" |
18 #include "base/single_thread_task_runner.h" | 18 #include "base/single_thread_task_runner.h" |
19 #include "base/threading/thread_checker.h" | 19 #include "base/threading/thread_checker.h" |
| 20 #include "mojo/public/cpp/bindings/connection_error_callback.h" |
20 #include "mojo/public/cpp/bindings/connector.h" | 21 #include "mojo/public/cpp/bindings/connector.h" |
21 #include "mojo/public/cpp/bindings/filter_chain.h" | 22 #include "mojo/public/cpp/bindings/filter_chain.h" |
22 #include "mojo/public/cpp/bindings/lib/control_message_handler.h" | 23 #include "mojo/public/cpp/bindings/lib/control_message_handler.h" |
23 #include "mojo/public/cpp/bindings/lib/control_message_proxy.h" | 24 #include "mojo/public/cpp/bindings/lib/control_message_proxy.h" |
24 #include "mojo/public/cpp/bindings/message.h" | 25 #include "mojo/public/cpp/bindings/message.h" |
25 | 26 |
26 namespace mojo { | 27 namespace mojo { |
27 namespace internal { | 28 namespace internal { |
28 | 29 |
29 // TODO(yzshen): Consider removing this class and use MultiplexRouter in all | 30 // TODO(yzshen): Consider removing this class and use MultiplexRouter in all |
(...skipping 10 matching lines...) Expand all Loading... |
40 // Sets the receiver to handle messages read from the message pipe that do | 41 // Sets the receiver to handle messages read from the message pipe that do |
41 // not have the Message::kFlagIsResponse flag set. | 42 // not have the Message::kFlagIsResponse flag set. |
42 void set_incoming_receiver(MessageReceiverWithResponderStatus* receiver) { | 43 void set_incoming_receiver(MessageReceiverWithResponderStatus* receiver) { |
43 incoming_receiver_ = receiver; | 44 incoming_receiver_ = receiver; |
44 } | 45 } |
45 | 46 |
46 // Sets the error handler to receive notifications when an error is | 47 // Sets the error handler to receive notifications when an error is |
47 // encountered while reading from the pipe or waiting to read from the pipe. | 48 // encountered while reading from the pipe or waiting to read from the pipe. |
48 void set_connection_error_handler(const base::Closure& error_handler) { | 49 void set_connection_error_handler(const base::Closure& error_handler) { |
49 error_handler_ = error_handler; | 50 error_handler_ = error_handler; |
| 51 error_with_reason_handler_.Reset(); |
| 52 } |
| 53 void set_connection_error_with_reason_handler( |
| 54 const ConnectionErrorWithReasonCallback& error_handler) { |
| 55 error_with_reason_handler_ = error_handler; |
| 56 error_handler_.Reset(); |
50 } | 57 } |
51 | 58 |
52 // Returns true if an error was encountered while reading from the pipe or | 59 // Returns true if an error was encountered while reading from the pipe or |
53 // waiting to read from the pipe. | 60 // waiting to read from the pipe. |
54 bool encountered_error() const { | 61 bool encountered_error() const { |
55 DCHECK(thread_checker_.CalledOnValidThread()); | 62 DCHECK(thread_checker_.CalledOnValidThread()); |
56 return encountered_error_; | 63 return encountered_error_; |
57 } | 64 } |
58 | 65 |
59 // Is the router bound to a MessagePipe handle? | 66 // Is the router bound to a MessagePipe handle? |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 AsyncResponderMap async_responders_; | 179 AsyncResponderMap async_responders_; |
173 SyncResponseMap sync_responses_; | 180 SyncResponseMap sync_responses_; |
174 uint64_t next_request_id_; | 181 uint64_t next_request_id_; |
175 bool testing_mode_; | 182 bool testing_mode_; |
176 std::queue<Message> pending_messages_; | 183 std::queue<Message> pending_messages_; |
177 // Whether a task has been posted to trigger processing of | 184 // Whether a task has been posted to trigger processing of |
178 // |pending_messages_|. | 185 // |pending_messages_|. |
179 bool pending_task_for_messages_; | 186 bool pending_task_for_messages_; |
180 bool encountered_error_; | 187 bool encountered_error_; |
181 base::Closure error_handler_; | 188 base::Closure error_handler_; |
| 189 ConnectionErrorWithReasonCallback error_with_reason_handler_; |
182 ControlMessageProxy control_message_proxy_; | 190 ControlMessageProxy control_message_proxy_; |
183 ControlMessageHandler control_message_handler_; | 191 ControlMessageHandler control_message_handler_; |
184 base::ThreadChecker thread_checker_; | 192 base::ThreadChecker thread_checker_; |
185 base::WeakPtrFactory<Router> weak_factory_; | 193 base::WeakPtrFactory<Router> weak_factory_; |
186 }; | 194 }; |
187 | 195 |
188 } // namespace internal | 196 } // namespace internal |
189 } // namespace mojo | 197 } // namespace mojo |
190 | 198 |
191 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_ROUTER_H_ | 199 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_ROUTER_H_ |
OLD | NEW |