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" | |
15 #include "base/macros.h" | 14 #include "base/macros.h" |
16 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
17 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
18 #include "base/single_thread_task_runner.h" | 17 #include "base/single_thread_task_runner.h" |
19 #include "base/threading/thread_checker.h" | 18 #include "base/threading/thread_checker.h" |
| 19 #include "mojo/public/cpp/bindings/callback.h" |
20 #include "mojo/public/cpp/bindings/lib/connector.h" | 20 #include "mojo/public/cpp/bindings/lib/connector.h" |
21 #include "mojo/public/cpp/bindings/lib/filter_chain.h" | 21 #include "mojo/public/cpp/bindings/lib/filter_chain.h" |
22 | 22 |
23 namespace mojo { | 23 namespace mojo { |
24 namespace internal { | 24 namespace internal { |
25 | 25 |
26 // TODO(yzshen): Consider removing this class and use MultiplexRouter in all | 26 // TODO(yzshen): Consider removing this class and use MultiplexRouter in all |
27 // cases. crbug.com/594244 | 27 // cases. crbug.com/594244 |
28 class Router : public MessageReceiverWithResponder { | 28 class Router : public MessageReceiverWithResponder { |
29 public: | 29 public: |
30 Router(ScopedMessagePipeHandle message_pipe, | 30 Router(ScopedMessagePipeHandle message_pipe, |
31 FilterChain filters, | 31 FilterChain filters, |
32 bool expects_sync_requests, | 32 bool expects_sync_requests, |
33 scoped_refptr<base::SingleThreadTaskRunner> runner); | 33 scoped_refptr<base::SingleThreadTaskRunner> runner); |
34 ~Router() override; | 34 ~Router() override; |
35 | 35 |
36 // Sets the receiver to handle messages read from the message pipe that do | 36 // Sets the receiver to handle messages read from the message pipe that do |
37 // not have the kMessageIsResponse flag set. | 37 // not have the kMessageIsResponse flag set. |
38 void set_incoming_receiver(MessageReceiverWithResponderStatus* receiver) { | 38 void set_incoming_receiver(MessageReceiverWithResponderStatus* receiver) { |
39 incoming_receiver_ = receiver; | 39 incoming_receiver_ = receiver; |
40 } | 40 } |
41 | 41 |
42 // Sets the error handler to receive notifications when an error is | 42 // Sets the error handler to receive notifications when an error is |
43 // encountered while reading from the pipe or waiting to read from the pipe. | 43 // encountered while reading from the pipe or waiting to read from the pipe. |
44 void set_connection_error_handler(const base::Closure& error_handler) { | 44 void set_connection_error_handler(const Closure& error_handler) { |
45 error_handler_ = error_handler; | 45 error_handler_ = error_handler; |
46 } | 46 } |
47 | 47 |
48 // Returns true if an error was encountered while reading from the pipe or | 48 // Returns true if an error was encountered while reading from the pipe or |
49 // waiting to read from the pipe. | 49 // waiting to read from the pipe. |
50 bool encountered_error() const { | 50 bool encountered_error() const { |
51 DCHECK(thread_checker_.CalledOnValidThread()); | 51 DCHECK(thread_checker_.CalledOnValidThread()); |
52 return encountered_error_; | 52 return encountered_error_; |
53 } | 53 } |
54 | 54 |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 MessageReceiverWithResponderStatus* incoming_receiver_; | 159 MessageReceiverWithResponderStatus* incoming_receiver_; |
160 AsyncResponderMap async_responders_; | 160 AsyncResponderMap async_responders_; |
161 SyncResponseMap sync_responses_; | 161 SyncResponseMap sync_responses_; |
162 uint64_t next_request_id_; | 162 uint64_t next_request_id_; |
163 bool testing_mode_; | 163 bool testing_mode_; |
164 std::queue<std::unique_ptr<Message>> pending_messages_; | 164 std::queue<std::unique_ptr<Message>> pending_messages_; |
165 // Whether a task has been posted to trigger processing of | 165 // Whether a task has been posted to trigger processing of |
166 // |pending_messages_|. | 166 // |pending_messages_|. |
167 bool pending_task_for_messages_; | 167 bool pending_task_for_messages_; |
168 bool encountered_error_; | 168 bool encountered_error_; |
169 base::Closure error_handler_; | 169 Closure error_handler_; |
170 base::ThreadChecker thread_checker_; | 170 base::ThreadChecker thread_checker_; |
171 base::WeakPtrFactory<Router> weak_factory_; | 171 base::WeakPtrFactory<Router> weak_factory_; |
172 }; | 172 }; |
173 | 173 |
174 } // namespace internal | 174 } // namespace internal |
175 } // namespace mojo | 175 } // namespace mojo |
176 | 176 |
177 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_ROUTER_H_ | 177 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_ROUTER_H_ |
OLD | NEW |