| 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/logging.h" | 14 #include "base/logging.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/filter_chain.h" |
| 20 #include "mojo/public/cpp/bindings/message.h" | 21 #include "mojo/public/cpp/bindings/message.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 class AssociatedGroupController; | 27 class AssociatedGroupController; |
| 28 class InterfaceEndpointController; | 28 class InterfaceEndpointController; |
| 29 | 29 |
| 30 // InterfaceEndpointClient handles message sending and receiving of an interface | 30 // InterfaceEndpointClient handles message sending and receiving of an interface |
| 31 // endpoint, either the implementation side or the client side. | 31 // endpoint, either the implementation side or the client side. |
| 32 // It should only be accessed and destructed on the creating thread. | 32 // It should only be accessed and destructed on the creating thread. |
| 33 class InterfaceEndpointClient : public MessageReceiverWithResponder { | 33 class InterfaceEndpointClient : public MessageReceiverWithResponder { |
| 34 public: | 34 public: |
| 35 // |receiver| is okay to be null. If it is not null, it must outlive this | 35 // |receiver| is okay to be null. If it is not null, it must outlive this |
| 36 // object. | 36 // object. |
| 37 InterfaceEndpointClient(ScopedInterfaceEndpointHandle handle, | 37 InterfaceEndpointClient(ScopedInterfaceEndpointHandle handle, |
| 38 MessageReceiverWithResponderStatus* receiver, | 38 MessageReceiverWithResponderStatus* receiver, |
| 39 std::unique_ptr<MessageFilter> payload_validator, | 39 std::unique_ptr<MessageReceiver> payload_validator, |
| 40 bool expect_sync_requests, | 40 bool expect_sync_requests, |
| 41 scoped_refptr<base::SingleThreadTaskRunner> runner); | 41 scoped_refptr<base::SingleThreadTaskRunner> runner); |
| 42 ~InterfaceEndpointClient() override; | 42 ~InterfaceEndpointClient() override; |
| 43 | 43 |
| 44 // Sets the error handler to receive notifications when an error is | 44 // Sets the error handler to receive notifications when an error is |
| 45 // encountered. | 45 // encountered. |
| 46 void set_connection_error_handler(const base::Closure& error_handler) { | 46 void set_connection_error_handler(const base::Closure& error_handler) { |
| 47 DCHECK(thread_checker_.CalledOnValidThread()); | 47 DCHECK(thread_checker_.CalledOnValidThread()); |
| 48 error_handler_ = error_handler; | 48 error_handler_ = error_handler; |
| 49 } | 49 } |
| 50 | 50 |
| 51 // Returns true if an error was encountered. | 51 // Returns true if an error was encountered. |
| 52 bool encountered_error() const { | 52 bool encountered_error() const { |
| 53 DCHECK(thread_checker_.CalledOnValidThread()); | 53 DCHECK(thread_checker_.CalledOnValidThread()); |
| 54 return encountered_error_; | 54 return encountered_error_; |
| 55 } | 55 } |
| 56 | 56 |
| 57 // Returns true if this endpoint has any pending callbacks. | 57 // Returns true if this endpoint has any pending callbacks. |
| 58 bool has_pending_responders() const { | 58 bool has_pending_responders() const { |
| 59 DCHECK(thread_checker_.CalledOnValidThread()); | 59 DCHECK(thread_checker_.CalledOnValidThread()); |
| 60 return !async_responders_.empty() || !sync_responses_.empty(); | 60 return !async_responders_.empty() || !sync_responses_.empty(); |
| 61 } | 61 } |
| 62 | 62 |
| 63 AssociatedGroupController* group_controller() const { | 63 AssociatedGroupController* group_controller() const { |
| 64 return handle_.group_controller(); | 64 return handle_.group_controller(); |
| 65 } | 65 } |
| 66 AssociatedGroup* associated_group(); | 66 AssociatedGroup* associated_group(); |
| 67 uint32_t interface_id() const; | 67 uint32_t interface_id() const; |
| 68 | 68 |
| 69 // Adds a MessageReceiver which can filter a message after validation but |
| 70 // before dispatch. |
| 71 void AddFilter(std::unique_ptr<MessageReceiver> filter); |
| 72 |
| 69 // After this call the object is in an invalid state and shouldn't be reused. | 73 // After this call the object is in an invalid state and shouldn't be reused. |
| 70 ScopedInterfaceEndpointHandle PassHandle(); | 74 ScopedInterfaceEndpointHandle PassHandle(); |
| 71 | 75 |
| 72 // Raises an error on the underlying message pipe. It disconnects the pipe | 76 // Raises an error on the underlying message pipe. It disconnects the pipe |
| 73 // and notifies all interfaces running on this pipe. | 77 // and notifies all interfaces running on this pipe. |
| 74 void RaiseError(); | 78 void RaiseError(); |
| 75 | 79 |
| 76 // MessageReceiverWithResponder implementation: | 80 // MessageReceiverWithResponder implementation: |
| 77 bool Accept(Message* message) override; | 81 bool Accept(Message* message) override; |
| 78 bool AcceptWithResponder(Message* message, | 82 bool AcceptWithResponder(Message* message, |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 DISALLOW_COPY_AND_ASSIGN(HandleIncomingMessageThunk); | 127 DISALLOW_COPY_AND_ASSIGN(HandleIncomingMessageThunk); |
| 124 }; | 128 }; |
| 125 | 129 |
| 126 bool HandleValidatedMessage(Message* message); | 130 bool HandleValidatedMessage(Message* message); |
| 127 | 131 |
| 128 ScopedInterfaceEndpointHandle handle_; | 132 ScopedInterfaceEndpointHandle handle_; |
| 129 std::unique_ptr<AssociatedGroup> associated_group_; | 133 std::unique_ptr<AssociatedGroup> associated_group_; |
| 130 InterfaceEndpointController* controller_; | 134 InterfaceEndpointController* controller_; |
| 131 | 135 |
| 132 MessageReceiverWithResponderStatus* const incoming_receiver_; | 136 MessageReceiverWithResponderStatus* const incoming_receiver_; |
| 133 std::unique_ptr<MessageFilter> payload_validator_; | |
| 134 HandleIncomingMessageThunk thunk_; | 137 HandleIncomingMessageThunk thunk_; |
| 138 FilterChain filters_; |
| 135 | 139 |
| 136 AsyncResponderMap async_responders_; | 140 AsyncResponderMap async_responders_; |
| 137 SyncResponseMap sync_responses_; | 141 SyncResponseMap sync_responses_; |
| 138 | 142 |
| 139 uint64_t next_request_id_; | 143 uint64_t next_request_id_; |
| 140 | 144 |
| 141 base::Closure error_handler_; | 145 base::Closure error_handler_; |
| 142 bool encountered_error_; | 146 bool encountered_error_; |
| 143 | 147 |
| 144 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 148 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 145 | 149 |
| 146 base::ThreadChecker thread_checker_; | 150 base::ThreadChecker thread_checker_; |
| 147 | 151 |
| 148 base::WeakPtrFactory<InterfaceEndpointClient> weak_ptr_factory_; | 152 base::WeakPtrFactory<InterfaceEndpointClient> weak_ptr_factory_; |
| 149 | 153 |
| 150 DISALLOW_COPY_AND_ASSIGN(InterfaceEndpointClient); | 154 DISALLOW_COPY_AND_ASSIGN(InterfaceEndpointClient); |
| 151 }; | 155 }; |
| 152 | 156 |
| 153 } // namespace mojo | 157 } // namespace mojo |
| 154 | 158 |
| 155 #endif // MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_ENDPOINT_CLIENT_H_ | 159 #endif // MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_ENDPOINT_CLIENT_H_ |
| OLD | NEW |