Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_INTERFACE_ENDPOINT_CLIENT_H_ | |
| 6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_INTERFACE_ENDPOINT_CLIENT_H_ | |
| 7 | |
| 8 #include <map> | |
| 9 | |
| 10 #include "base/logging.h" | |
| 11 #include "base/macros.h" | |
| 12 #include "base/memory/scoped_ptr.h" | |
| 13 #include "base/memory/weak_ptr.h" | |
| 14 #include "base/threading/thread_checker.h" | |
| 15 #include "mojo/public/cpp/bindings/callback.h" | |
| 16 #include "mojo/public/cpp/bindings/lib/scoped_interface_endpoint_handle.h" | |
| 17 #include "mojo/public/cpp/bindings/message.h" | |
| 18 #include "mojo/public/cpp/bindings/message_filter.h" | |
| 19 | |
| 20 namespace mojo { | |
| 21 namespace internal { | |
| 22 | |
| 23 // InterfaceEndpointClient handles message sending and receiving of an interface | |
| 24 // endpoint, either the implementation side or the client side. | |
| 25 // It should only be accessed and destructed on the creating thread. | |
| 26 class InterfaceEndpointClient : public MessageReceiverWithResponder { | |
| 27 public: | |
| 28 // |receiver| is okay to be null. If it is not null, it must outlive this | |
| 29 // object. | |
| 30 InterfaceEndpointClient(ScopedInterfaceEndpointHandle handle, | |
| 31 MessageReceiverWithResponderStatus* receiver, | |
| 32 scoped_ptr<MessageFilter> payload_validator); | |
| 33 ~InterfaceEndpointClient() override; | |
| 34 | |
| 35 // Sets the error handler to receive notifications when an error is | |
| 36 // encountered. | |
| 37 void set_connection_error_handler(const Closure& error_handler) { | |
| 38 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 39 error_handler_ = error_handler; | |
| 40 } | |
| 41 | |
| 42 // Returns true if an error was encountered. | |
| 43 bool encountered_error() const { | |
| 44 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 45 return encountered_error_; | |
| 46 } | |
| 47 | |
| 48 // Returns true if this endpoint has any pending callbacks. | |
| 49 bool has_pending_responders() const { | |
| 50 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 51 return !responders_.empty(); | |
| 52 } | |
| 53 | |
| 54 MultiplexRouter* router() const { return handle_.router(); } | |
| 55 | |
| 56 // After this call the object is in an invalid state and shouldn't be reused. | |
| 57 ScopedInterfaceEndpointHandle PassHandle(); | |
| 58 | |
| 59 // Raises an error on the underlying message pipe. It disconnects the pipe | |
| 60 // and notifies all interfaces running on this pipe. | |
| 61 void RaiseError(); | |
| 62 | |
| 63 // MessageReceiverWithResponder implementation: | |
| 64 bool Accept(Message* message) override; | |
| 65 bool AcceptWithResponder(Message* message, | |
| 66 MessageReceiver* responder) override; | |
| 67 | |
| 68 // The following methods are called by the router. They must be called | |
| 69 // outside of the router's lock. | |
| 70 | |
| 71 // NOTE: |message| must have passed message header validation. | |
| 72 bool HandleIncomingMessage(Message* message); | |
| 73 void NotifyError(); | |
| 74 | |
| 75 private: | |
| 76 typedef std::map<uint64_t, MessageReceiver*> ResponderMap; | |
|
sky
2015/11/19 17:16:27
using
yzshen1
2015/11/19 22:00:40
Done.
| |
| 77 | |
| 78 class HandleIncomingMessageThunk : public MessageReceiver { | |
| 79 public: | |
| 80 explicit HandleIncomingMessageThunk(InterfaceEndpointClient* owner); | |
| 81 ~HandleIncomingMessageThunk() override; | |
| 82 | |
| 83 // MessageReceiver implementation: | |
| 84 bool Accept(Message* message) override; | |
| 85 | |
| 86 private: | |
| 87 InterfaceEndpointClient* const owner_; | |
| 88 }; | |
|
sky
2015/11/19 17:16:27
DISALLOW...
yzshen1
2015/11/19 22:00:40
Done.
| |
| 89 | |
| 90 bool HandleValidatedMessage(Message* message); | |
| 91 | |
| 92 ScopedInterfaceEndpointHandle handle_; | |
| 93 | |
| 94 MessageReceiverWithResponderStatus* const incoming_receiver_; | |
| 95 scoped_ptr<MessageFilter> payload_validator_; | |
| 96 HandleIncomingMessageThunk thunk_; | |
| 97 | |
| 98 // Maps from the ID of a response to the MessageReceiver that handles the | |
| 99 // response. | |
| 100 ResponderMap responders_; | |
| 101 uint64_t next_request_id_; | |
| 102 | |
| 103 Closure error_handler_; | |
| 104 bool encountered_error_; | |
| 105 | |
| 106 base::ThreadChecker thread_checker_; | |
| 107 | |
| 108 base::WeakPtrFactory<InterfaceEndpointClient> weak_ptr_factory_; | |
| 109 | |
| 110 DISALLOW_COPY_AND_ASSIGN(InterfaceEndpointClient); | |
| 111 }; | |
| 112 | |
| 113 } // namespace internal | |
| 114 } // namespace mojo | |
| 115 | |
| 116 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_INTERFACE_ENDPOINT_CLIENT_H_ | |
| OLD | NEW |