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_INTERFACE_ENDPOINT_CLIENT_H_ | 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_ENDPOINT_CLIENT_H_ |
6 #define MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_ENDPOINT_CLIENT_H_ | 6 #define MOJO_PUBLIC_CPP_BINDINGS_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" | 13 #include "base/callback.h" |
14 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
15 #include "base/logging.h" | 15 #include "base/logging.h" |
16 #include "base/macros.h" | 16 #include "base/macros.h" |
17 #include "base/memory/ref_counted.h" | 17 #include "base/memory/ref_counted.h" |
18 #include "base/memory/weak_ptr.h" | 18 #include "base/memory/weak_ptr.h" |
19 #include "base/optional.h" | 19 #include "base/optional.h" |
20 #include "base/single_thread_task_runner.h" | 20 #include "base/sequence_checker.h" |
21 #include "base/threading/thread_checker.h" | 21 #include "base/sequenced_task_runner.h" |
22 #include "mojo/public/cpp/bindings/bindings_export.h" | 22 #include "mojo/public/cpp/bindings/bindings_export.h" |
23 #include "mojo/public/cpp/bindings/connection_error_callback.h" | 23 #include "mojo/public/cpp/bindings/connection_error_callback.h" |
24 #include "mojo/public/cpp/bindings/disconnect_reason.h" | 24 #include "mojo/public/cpp/bindings/disconnect_reason.h" |
25 #include "mojo/public/cpp/bindings/filter_chain.h" | 25 #include "mojo/public/cpp/bindings/filter_chain.h" |
26 #include "mojo/public/cpp/bindings/lib/control_message_handler.h" | 26 #include "mojo/public/cpp/bindings/lib/control_message_handler.h" |
27 #include "mojo/public/cpp/bindings/lib/control_message_proxy.h" | 27 #include "mojo/public/cpp/bindings/lib/control_message_proxy.h" |
28 #include "mojo/public/cpp/bindings/message.h" | 28 #include "mojo/public/cpp/bindings/message.h" |
29 #include "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h" | 29 #include "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h" |
30 | 30 |
31 namespace mojo { | 31 namespace mojo { |
32 | 32 |
33 class AssociatedGroup; | 33 class AssociatedGroup; |
34 class AssociatedGroupController; | 34 class AssociatedGroupController; |
35 class InterfaceEndpointController; | 35 class InterfaceEndpointController; |
36 | 36 |
37 // InterfaceEndpointClient handles message sending and receiving of an interface | 37 // InterfaceEndpointClient handles message sending and receiving of an interface |
38 // endpoint, either the implementation side or the client side. | 38 // endpoint, either the implementation side or the client side. |
39 // It should only be accessed and destructed on the creating thread. | 39 // It should only be accessed and destructed on the creating thread. |
40 class MOJO_CPP_BINDINGS_EXPORT InterfaceEndpointClient | 40 class MOJO_CPP_BINDINGS_EXPORT InterfaceEndpointClient |
41 : NON_EXPORTED_BASE(public MessageReceiverWithResponder) { | 41 : NON_EXPORTED_BASE(public MessageReceiverWithResponder) { |
42 public: | 42 public: |
43 // |receiver| is okay to be null. If it is not null, it must outlive this | 43 // |receiver| is okay to be null. If it is not null, it must outlive this |
44 // object. | 44 // object. |
45 InterfaceEndpointClient(ScopedInterfaceEndpointHandle handle, | 45 InterfaceEndpointClient(ScopedInterfaceEndpointHandle handle, |
46 MessageReceiverWithResponderStatus* receiver, | 46 MessageReceiverWithResponderStatus* receiver, |
47 std::unique_ptr<MessageReceiver> payload_validator, | 47 std::unique_ptr<MessageReceiver> payload_validator, |
48 bool expect_sync_requests, | 48 bool expect_sync_requests, |
49 scoped_refptr<base::SingleThreadTaskRunner> runner, | 49 scoped_refptr<base::SequencedTaskRunner> runner, |
50 uint32_t interface_version); | 50 uint32_t interface_version); |
51 ~InterfaceEndpointClient() override; | 51 ~InterfaceEndpointClient() override; |
52 | 52 |
53 // Sets the error handler to receive notifications when an error is | 53 // Sets the error handler to receive notifications when an error is |
54 // encountered. | 54 // encountered. |
55 void set_connection_error_handler(const base::Closure& error_handler) { | 55 void set_connection_error_handler(const base::Closure& error_handler) { |
56 DCHECK(thread_checker_.CalledOnValidThread()); | 56 DCHECK(sequence_checker_.CalledOnValidSequence()); |
57 error_handler_ = error_handler; | 57 error_handler_ = error_handler; |
58 error_with_reason_handler_.Reset(); | 58 error_with_reason_handler_.Reset(); |
59 } | 59 } |
60 | 60 |
61 void set_connection_error_with_reason_handler( | 61 void set_connection_error_with_reason_handler( |
62 const ConnectionErrorWithReasonCallback& error_handler) { | 62 const ConnectionErrorWithReasonCallback& error_handler) { |
63 DCHECK(thread_checker_.CalledOnValidThread()); | 63 DCHECK(sequence_checker_.CalledOnValidSequence()); |
64 error_with_reason_handler_ = error_handler; | 64 error_with_reason_handler_ = error_handler; |
65 error_handler_.Reset(); | 65 error_handler_.Reset(); |
66 } | 66 } |
67 | 67 |
68 // Returns true if an error was encountered. | 68 // Returns true if an error was encountered. |
69 bool encountered_error() const { | 69 bool encountered_error() const { |
70 DCHECK(thread_checker_.CalledOnValidThread()); | 70 DCHECK(sequence_checker_.CalledOnValidSequence()); |
71 return encountered_error_; | 71 return encountered_error_; |
72 } | 72 } |
73 | 73 |
74 // Returns true if this endpoint has any pending callbacks. | 74 // Returns true if this endpoint has any pending callbacks. |
75 bool has_pending_responders() const { | 75 bool has_pending_responders() const { |
76 DCHECK(thread_checker_.CalledOnValidThread()); | 76 DCHECK(sequence_checker_.CalledOnValidSequence()); |
77 return !async_responders_.empty() || !sync_responses_.empty(); | 77 return !async_responders_.empty() || !sync_responses_.empty(); |
78 } | 78 } |
79 | 79 |
80 AssociatedGroupController* group_controller() const { | 80 AssociatedGroupController* group_controller() const { |
81 return handle_.group_controller(); | 81 return handle_.group_controller(); |
82 } | 82 } |
83 AssociatedGroup* associated_group(); | 83 AssociatedGroup* associated_group(); |
84 uint32_t interface_id() const; | 84 uint32_t interface_id() const; |
85 | 85 |
86 // Adds a MessageReceiver which can filter a message after validation but | 86 // Adds a MessageReceiver which can filter a message after validation but |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 | 162 |
163 AsyncResponderMap async_responders_; | 163 AsyncResponderMap async_responders_; |
164 SyncResponseMap sync_responses_; | 164 SyncResponseMap sync_responses_; |
165 | 165 |
166 uint64_t next_request_id_; | 166 uint64_t next_request_id_; |
167 | 167 |
168 base::Closure error_handler_; | 168 base::Closure error_handler_; |
169 ConnectionErrorWithReasonCallback error_with_reason_handler_; | 169 ConnectionErrorWithReasonCallback error_with_reason_handler_; |
170 bool encountered_error_; | 170 bool encountered_error_; |
171 | 171 |
172 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 172 scoped_refptr<base::SequencedTaskRunner> task_runner_; |
173 | 173 |
174 internal::ControlMessageProxy control_message_proxy_; | 174 internal::ControlMessageProxy control_message_proxy_; |
175 internal::ControlMessageHandler control_message_handler_; | 175 internal::ControlMessageHandler control_message_handler_; |
176 | 176 |
177 base::ThreadChecker thread_checker_; | 177 base::SequenceChecker sequence_checker_; |
178 | 178 |
179 base::WeakPtrFactory<InterfaceEndpointClient> weak_ptr_factory_; | 179 base::WeakPtrFactory<InterfaceEndpointClient> weak_ptr_factory_; |
180 | 180 |
181 DISALLOW_COPY_AND_ASSIGN(InterfaceEndpointClient); | 181 DISALLOW_COPY_AND_ASSIGN(InterfaceEndpointClient); |
182 }; | 182 }; |
183 | 183 |
184 } // namespace mojo | 184 } // namespace mojo |
185 | 185 |
186 #endif // MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_ENDPOINT_CLIENT_H_ | 186 #endif // MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_ENDPOINT_CLIENT_H_ |
OLD | NEW |