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> |
(...skipping 19 matching lines...) Expand all Loading... |
30 | 30 |
31 // Sets the receiver to handle messages read from the message pipe that do | 31 // Sets the receiver to handle messages read from the message pipe that do |
32 // not have the kMessageIsResponse flag set. | 32 // not have the kMessageIsResponse flag set. |
33 void set_incoming_receiver(MessageReceiverWithResponderStatus* receiver) { | 33 void set_incoming_receiver(MessageReceiverWithResponderStatus* receiver) { |
34 incoming_receiver_ = receiver; | 34 incoming_receiver_ = receiver; |
35 } | 35 } |
36 | 36 |
37 // Sets the error handler to receive notifications when an error is | 37 // Sets the error handler to receive notifications when an error is |
38 // encountered while reading from the pipe or waiting to read from the pipe. | 38 // encountered while reading from the pipe or waiting to read from the pipe. |
39 void set_connection_error_handler(const Closure& error_handler) { | 39 void set_connection_error_handler(const Closure& error_handler) { |
40 connector_.set_connection_error_handler(error_handler); | 40 error_handler_ = error_handler; |
41 } | 41 } |
42 | 42 |
43 // Returns true if an error was encountered while reading from the pipe or | 43 // Returns true if an error was encountered while reading from the pipe or |
44 // waiting to read from the pipe. | 44 // waiting to read from the pipe. |
45 bool encountered_error() const { | 45 bool encountered_error() const { |
46 DCHECK(thread_checker_.CalledOnValidThread()); | 46 DCHECK(thread_checker_.CalledOnValidThread()); |
47 return connector_.encountered_error(); | 47 return encountered_error_; |
48 } | 48 } |
49 | 49 |
50 // Is the router bound to a MessagePipe handle? | 50 // Is the router bound to a MessagePipe handle? |
51 bool is_valid() const { | 51 bool is_valid() const { |
52 DCHECK(thread_checker_.CalledOnValidThread()); | 52 DCHECK(thread_checker_.CalledOnValidThread()); |
53 return connector_.is_valid(); | 53 return connector_.is_valid(); |
54 } | 54 } |
55 | 55 |
56 // Please note that this method shouldn't be called unless it results from an | 56 // Please note that this method shouldn't be called unless it results from an |
57 // explicit request of the user of bindings (e.g., the user sets an | 57 // explicit request of the user of bindings (e.g., the user sets an |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 | 136 |
137 // MessageReceiver implementation: | 137 // MessageReceiver implementation: |
138 bool Accept(Message* message) override; | 138 bool Accept(Message* message) override; |
139 | 139 |
140 private: | 140 private: |
141 Router* router_; | 141 Router* router_; |
142 }; | 142 }; |
143 | 143 |
144 bool HandleIncomingMessage(Message* message); | 144 bool HandleIncomingMessage(Message* message); |
145 void HandleQueuedMessages(); | 145 void HandleQueuedMessages(); |
| 146 bool HandleMessageInternal(Message* message); |
146 | 147 |
147 bool HandleMessageInternal(Message* message); | 148 void OnConnectionError(); |
148 | 149 |
149 HandleIncomingMessageThunk thunk_; | 150 HandleIncomingMessageThunk thunk_; |
150 FilterChain filters_; | 151 FilterChain filters_; |
151 Connector connector_; | 152 Connector connector_; |
152 MessageReceiverWithResponderStatus* incoming_receiver_; | 153 MessageReceiverWithResponderStatus* incoming_receiver_; |
153 AsyncResponderMap async_responders_; | 154 AsyncResponderMap async_responders_; |
154 SyncResponseMap sync_responses_; | 155 SyncResponseMap sync_responses_; |
155 uint64_t next_request_id_; | 156 uint64_t next_request_id_; |
156 bool testing_mode_; | 157 bool testing_mode_; |
157 std::queue<scoped_ptr<Message>> pending_messages_; | 158 std::queue<scoped_ptr<Message>> pending_messages_; |
158 // Whether a task has been posted to trigger processing of | 159 // Whether a task has been posted to trigger processing of |
159 // |pending_messages_|. | 160 // |pending_messages_|. |
160 bool pending_task_for_messages_; | 161 bool pending_task_for_messages_; |
| 162 bool encountered_error_; |
| 163 Closure error_handler_; |
161 base::ThreadChecker thread_checker_; | 164 base::ThreadChecker thread_checker_; |
162 base::WeakPtrFactory<Router> weak_factory_; | 165 base::WeakPtrFactory<Router> weak_factory_; |
163 }; | 166 }; |
164 | 167 |
165 } // namespace internal | 168 } // namespace internal |
166 } // namespace mojo | 169 } // namespace mojo |
167 | 170 |
168 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_ROUTER_H_ | 171 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_ROUTER_H_ |
OLD | NEW |