OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_INTERFACE_ENDPOINT_CLIENT_H_ | 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_INTERFACE_ENDPOINT_CLIENT_H_ |
6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_INTERFACE_ENDPOINT_CLIENT_H_ | 6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_INTERFACE_ENDPOINT_CLIENT_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 | 12 |
13 #include "base/callback.h" | |
14 #include "base/logging.h" | 13 #include "base/logging.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/message.h" | 20 #include "mojo/public/cpp/bindings/message.h" |
21 #include "mojo/public/cpp/bindings/message_filter.h" | 21 #include "mojo/public/cpp/bindings/message_filter.h" |
22 #include "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h" | 22 #include "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h" |
23 | 23 |
24 namespace mojo { | 24 namespace mojo { |
25 | 25 |
26 class AssociatedGroup; | 26 class AssociatedGroup; |
27 | 27 |
28 namespace internal { | 28 namespace internal { |
29 | 29 |
30 class MultiplexRouter; | 30 class MultiplexRouter; |
31 class InterfaceEndpointController; | 31 class InterfaceEndpointController; |
32 | 32 |
33 // InterfaceEndpointClient handles message sending and receiving of an interface | 33 // InterfaceEndpointClient handles message sending and receiving of an interface |
34 // endpoint, either the implementation side or the client side. | 34 // endpoint, either the implementation side or the client side. |
35 // It should only be accessed and destructed on the creating thread. | 35 // It should only be accessed and destructed on the creating thread. |
36 class InterfaceEndpointClient : public MessageReceiverWithResponder { | 36 class InterfaceEndpointClient : public MessageReceiverWithResponder { |
37 public: | 37 public: |
38 // |receiver| is okay to be null. If it is not null, it must outlive this | 38 // |receiver| is okay to be null. If it is not null, it must outlive this |
39 // object. | 39 // object. |
40 InterfaceEndpointClient(ScopedInterfaceEndpointHandle handle, | 40 InterfaceEndpointClient(ScopedInterfaceEndpointHandle handle, |
41 MessageReceiverWithResponderStatus* receiver, | 41 MessageReceiverWithResponderStatus* receiver, |
42 std::unique_ptr<MessageFilter> payload_validator, | 42 std::unique_ptr<MessageFilter> payload_validator, |
43 bool expect_sync_requests, | 43 bool expect_sync_requests, |
44 scoped_refptr<base::SingleThreadTaskRunner> runner); | 44 scoped_refptr<base::SingleThreadTaskRunner> runner); |
45 ~InterfaceEndpointClient() override; | 45 ~InterfaceEndpointClient() override; |
46 | 46 |
47 // Sets the error handler to receive notifications when an error is | 47 // Sets the error handler to receive notifications when an error is |
48 // encountered. | 48 // encountered. |
49 void set_connection_error_handler(const base::Closure& error_handler) { | 49 void set_connection_error_handler(const Closure& error_handler) { |
50 DCHECK(thread_checker_.CalledOnValidThread()); | 50 DCHECK(thread_checker_.CalledOnValidThread()); |
51 error_handler_ = error_handler; | 51 error_handler_ = error_handler; |
52 } | 52 } |
53 | 53 |
54 // Returns true if an error was encountered. | 54 // Returns true if an error was encountered. |
55 bool encountered_error() const { | 55 bool encountered_error() const { |
56 DCHECK(thread_checker_.CalledOnValidThread()); | 56 DCHECK(thread_checker_.CalledOnValidThread()); |
57 return encountered_error_; | 57 return encountered_error_; |
58 } | 58 } |
59 | 59 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 | 132 |
133 MessageReceiverWithResponderStatus* const incoming_receiver_; | 133 MessageReceiverWithResponderStatus* const incoming_receiver_; |
134 std::unique_ptr<MessageFilter> payload_validator_; | 134 std::unique_ptr<MessageFilter> payload_validator_; |
135 HandleIncomingMessageThunk thunk_; | 135 HandleIncomingMessageThunk thunk_; |
136 | 136 |
137 AsyncResponderMap async_responders_; | 137 AsyncResponderMap async_responders_; |
138 SyncResponseMap sync_responses_; | 138 SyncResponseMap sync_responses_; |
139 | 139 |
140 uint64_t next_request_id_; | 140 uint64_t next_request_id_; |
141 | 141 |
142 base::Closure error_handler_; | 142 Closure error_handler_; |
143 bool encountered_error_; | 143 bool encountered_error_; |
144 | 144 |
145 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 145 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
146 | 146 |
147 base::ThreadChecker thread_checker_; | 147 base::ThreadChecker thread_checker_; |
148 | 148 |
149 base::WeakPtrFactory<InterfaceEndpointClient> weak_ptr_factory_; | 149 base::WeakPtrFactory<InterfaceEndpointClient> weak_ptr_factory_; |
150 | 150 |
151 DISALLOW_COPY_AND_ASSIGN(InterfaceEndpointClient); | 151 DISALLOW_COPY_AND_ASSIGN(InterfaceEndpointClient); |
152 }; | 152 }; |
153 | 153 |
154 } // namespace internal | 154 } // namespace internal |
155 } // namespace mojo | 155 } // namespace mojo |
156 | 156 |
157 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_INTERFACE_ENDPOINT_CLIENT_H_ | 157 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_INTERFACE_ENDPOINT_CLIENT_H_ |
OLD | NEW |