| 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 <map> | 8 #include <map> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 14 #include "base/threading/thread_checker.h" | 14 #include "base/threading/thread_checker.h" |
| 15 #include "mojo/public/cpp/bindings/callback.h" | 15 #include "mojo/public/cpp/bindings/callback.h" |
| 16 #include "mojo/public/cpp/bindings/lib/scoped_interface_endpoint_handle.h" | 16 #include "mojo/public/cpp/bindings/lib/scoped_interface_endpoint_handle.h" |
| 17 #include "mojo/public/cpp/bindings/message.h" | 17 #include "mojo/public/cpp/bindings/message.h" |
| 18 #include "mojo/public/cpp/bindings/message_filter.h" | 18 #include "mojo/public/cpp/bindings/message_filter.h" |
| 19 | 19 |
| 20 namespace mojo { | 20 namespace mojo { |
| 21 |
| 22 class AssociatedGroup; |
| 23 |
| 21 namespace internal { | 24 namespace internal { |
| 22 | 25 |
| 26 class MultiplexRouter; |
| 27 |
| 23 // InterfaceEndpointClient handles message sending and receiving of an interface | 28 // InterfaceEndpointClient handles message sending and receiving of an interface |
| 24 // endpoint, either the implementation side or the client side. | 29 // endpoint, either the implementation side or the client side. |
| 25 // It should only be accessed and destructed on the creating thread. | 30 // It should only be accessed and destructed on the creating thread. |
| 26 class InterfaceEndpointClient : public MessageReceiverWithResponder { | 31 class InterfaceEndpointClient : public MessageReceiverWithResponder { |
| 27 public: | 32 public: |
| 28 // |receiver| is okay to be null. If it is not null, it must outlive this | 33 // |receiver| is okay to be null. If it is not null, it must outlive this |
| 29 // object. | 34 // object. |
| 30 InterfaceEndpointClient(ScopedInterfaceEndpointHandle handle, | 35 InterfaceEndpointClient(ScopedInterfaceEndpointHandle handle, |
| 31 MessageReceiverWithResponderStatus* receiver, | 36 MessageReceiverWithResponderStatus* receiver, |
| 32 scoped_ptr<MessageFilter> payload_validator); | 37 scoped_ptr<MessageFilter> payload_validator); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 45 return encountered_error_; | 50 return encountered_error_; |
| 46 } | 51 } |
| 47 | 52 |
| 48 // Returns true if this endpoint has any pending callbacks. | 53 // Returns true if this endpoint has any pending callbacks. |
| 49 bool has_pending_responders() const { | 54 bool has_pending_responders() const { |
| 50 DCHECK(thread_checker_.CalledOnValidThread()); | 55 DCHECK(thread_checker_.CalledOnValidThread()); |
| 51 return !responders_.empty(); | 56 return !responders_.empty(); |
| 52 } | 57 } |
| 53 | 58 |
| 54 MultiplexRouter* router() const { return handle_.router(); } | 59 MultiplexRouter* router() const { return handle_.router(); } |
| 60 AssociatedGroup* associated_group(); |
| 55 | 61 |
| 56 // After this call the object is in an invalid state and shouldn't be reused. | 62 // After this call the object is in an invalid state and shouldn't be reused. |
| 57 ScopedInterfaceEndpointHandle PassHandle(); | 63 ScopedInterfaceEndpointHandle PassHandle(); |
| 58 | 64 |
| 59 // Raises an error on the underlying message pipe. It disconnects the pipe | 65 // Raises an error on the underlying message pipe. It disconnects the pipe |
| 60 // and notifies all interfaces running on this pipe. | 66 // and notifies all interfaces running on this pipe. |
| 61 void RaiseError(); | 67 void RaiseError(); |
| 62 | 68 |
| 63 // MessageReceiverWithResponder implementation: | 69 // MessageReceiverWithResponder implementation: |
| 64 bool Accept(Message* message) override; | 70 bool Accept(Message* message) override; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 87 | 93 |
| 88 private: | 94 private: |
| 89 InterfaceEndpointClient* const owner_; | 95 InterfaceEndpointClient* const owner_; |
| 90 | 96 |
| 91 DISALLOW_COPY_AND_ASSIGN(HandleIncomingMessageThunk); | 97 DISALLOW_COPY_AND_ASSIGN(HandleIncomingMessageThunk); |
| 92 }; | 98 }; |
| 93 | 99 |
| 94 bool HandleValidatedMessage(Message* message); | 100 bool HandleValidatedMessage(Message* message); |
| 95 | 101 |
| 96 ScopedInterfaceEndpointHandle handle_; | 102 ScopedInterfaceEndpointHandle handle_; |
| 103 scoped_ptr<AssociatedGroup> associated_group_; |
| 97 | 104 |
| 98 MessageReceiverWithResponderStatus* const incoming_receiver_; | 105 MessageReceiverWithResponderStatus* const incoming_receiver_; |
| 99 scoped_ptr<MessageFilter> payload_validator_; | 106 scoped_ptr<MessageFilter> payload_validator_; |
| 100 HandleIncomingMessageThunk thunk_; | 107 HandleIncomingMessageThunk thunk_; |
| 101 | 108 |
| 102 // Maps from the ID of a response to the MessageReceiver that handles the | 109 // Maps from the ID of a response to the MessageReceiver that handles the |
| 103 // response. | 110 // response. |
| 104 ResponderMap responders_; | 111 ResponderMap responders_; |
| 105 uint64_t next_request_id_; | 112 uint64_t next_request_id_; |
| 106 | 113 |
| 107 Closure error_handler_; | 114 Closure error_handler_; |
| 108 bool encountered_error_; | 115 bool encountered_error_; |
| 109 | 116 |
| 110 base::ThreadChecker thread_checker_; | 117 base::ThreadChecker thread_checker_; |
| 111 | 118 |
| 112 base::WeakPtrFactory<InterfaceEndpointClient> weak_ptr_factory_; | 119 base::WeakPtrFactory<InterfaceEndpointClient> weak_ptr_factory_; |
| 113 | 120 |
| 114 DISALLOW_COPY_AND_ASSIGN(InterfaceEndpointClient); | 121 DISALLOW_COPY_AND_ASSIGN(InterfaceEndpointClient); |
| 115 }; | 122 }; |
| 116 | 123 |
| 117 } // namespace internal | 124 } // namespace internal |
| 118 } // namespace mojo | 125 } // namespace mojo |
| 119 | 126 |
| 120 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_INTERFACE_ENDPOINT_CLIENT_H_ | 127 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_INTERFACE_ENDPOINT_CLIENT_H_ |
| OLD | NEW |