| 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/message_loop/message_loop.h" |
| 18 #include "base/single_thread_task_runner.h" | 19 #include "base/single_thread_task_runner.h" |
| 19 #include "base/threading/thread_checker.h" | 20 #include "base/threading/thread_checker.h" |
| 20 #include "mojo/public/cpp/bindings/connection_error_callback.h" | 21 #include "mojo/public/cpp/bindings/connection_error_callback.h" |
| 21 #include "mojo/public/cpp/bindings/filter_chain.h" | 22 #include "mojo/public/cpp/bindings/filter_chain.h" |
| 22 #include "mojo/public/cpp/bindings/lib/control_message_handler.h" | 23 #include "mojo/public/cpp/bindings/lib/control_message_handler.h" |
| 23 #include "mojo/public/cpp/bindings/lib/control_message_proxy.h" | 24 #include "mojo/public/cpp/bindings/lib/control_message_proxy.h" |
| 24 #include "mojo/public/cpp/bindings/message.h" | 25 #include "mojo/public/cpp/bindings/message.h" |
| 25 #include "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h" | 26 #include "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h" |
| 26 | 27 |
| 27 namespace mojo { | 28 namespace mojo { |
| 28 | 29 |
| 29 class AssociatedGroup; | 30 class AssociatedGroup; |
| 30 class AssociatedGroupController; | 31 class AssociatedGroupController; |
| 31 class InterfaceEndpointController; | 32 class InterfaceEndpointController; |
| 32 | 33 |
| 33 // InterfaceEndpointClient handles message sending and receiving of an interface | 34 // InterfaceEndpointClient handles message sending and receiving of an interface |
| 34 // endpoint, either the implementation side or the client side. | 35 // endpoint, either the implementation side or the client side. |
| 35 // It should only be accessed and destructed on the creating thread. | 36 // It should only be accessed and destructed on the creating thread. |
| 36 class InterfaceEndpointClient : public MessageReceiverWithResponder { | 37 class InterfaceEndpointClient : public MessageReceiverWithResponder, |
| 38 public base::MessageLoop::DestructionObserver { |
| 37 public: | 39 public: |
| 38 // |receiver| is okay to be null. If it is not null, it must outlive this | 40 // |receiver| is okay to be null. If it is not null, it must outlive this |
| 39 // object. | 41 // object. |
| 40 InterfaceEndpointClient(ScopedInterfaceEndpointHandle handle, | 42 InterfaceEndpointClient(ScopedInterfaceEndpointHandle handle, |
| 41 MessageReceiverWithResponderStatus* receiver, | 43 MessageReceiverWithResponderStatus* receiver, |
| 42 std::unique_ptr<MessageReceiver> payload_validator, | 44 std::unique_ptr<MessageReceiver> payload_validator, |
| 43 bool expect_sync_requests, | 45 bool expect_sync_requests, |
| 44 scoped_refptr<base::SingleThreadTaskRunner> runner, | 46 scoped_refptr<base::SingleThreadTaskRunner> runner, |
| 45 uint32_t interface_version); | 47 uint32_t interface_version); |
| 46 ~InterfaceEndpointClient() override; | 48 ~InterfaceEndpointClient() override; |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 // MessageReceiver implementation: | 139 // MessageReceiver implementation: |
| 138 bool Accept(Message* message) override; | 140 bool Accept(Message* message) override; |
| 139 | 141 |
| 140 private: | 142 private: |
| 141 InterfaceEndpointClient* const owner_; | 143 InterfaceEndpointClient* const owner_; |
| 142 | 144 |
| 143 DISALLOW_COPY_AND_ASSIGN(HandleIncomingMessageThunk); | 145 DISALLOW_COPY_AND_ASSIGN(HandleIncomingMessageThunk); |
| 144 }; | 146 }; |
| 145 | 147 |
| 146 bool HandleValidatedMessage(Message* message); | 148 bool HandleValidatedMessage(Message* message); |
| 149 void StopObservingIfNecessary(); |
| 150 |
| 151 // base::MessageLoop::DestructionObserver: |
| 152 void WillDestroyCurrentMessageLoop() override; |
| 147 | 153 |
| 148 ScopedInterfaceEndpointHandle handle_; | 154 ScopedInterfaceEndpointHandle handle_; |
| 149 std::unique_ptr<AssociatedGroup> associated_group_; | 155 std::unique_ptr<AssociatedGroup> associated_group_; |
| 150 InterfaceEndpointController* controller_; | 156 InterfaceEndpointController* controller_; |
| 151 | 157 |
| 152 MessageReceiverWithResponderStatus* const incoming_receiver_; | 158 MessageReceiverWithResponderStatus* const incoming_receiver_; |
| 153 HandleIncomingMessageThunk thunk_; | 159 HandleIncomingMessageThunk thunk_; |
| 154 FilterChain filters_; | 160 FilterChain filters_; |
| 155 | 161 |
| 156 AsyncResponderMap async_responders_; | 162 AsyncResponderMap async_responders_; |
| 157 SyncResponseMap sync_responses_; | 163 SyncResponseMap sync_responses_; |
| 158 | 164 |
| 159 uint64_t next_request_id_; | 165 uint64_t next_request_id_; |
| 160 | 166 |
| 161 base::Closure error_handler_; | 167 base::Closure error_handler_; |
| 162 ConnectionErrorWithReasonCallback error_with_reason_handler_; | 168 ConnectionErrorWithReasonCallback error_with_reason_handler_; |
| 163 bool encountered_error_; | 169 bool encountered_error_; |
| 164 | 170 |
| 165 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 171 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 166 | 172 |
| 167 internal::ControlMessageProxy control_message_proxy_; | 173 internal::ControlMessageProxy control_message_proxy_; |
| 168 internal::ControlMessageHandler control_message_handler_; | 174 internal::ControlMessageHandler control_message_handler_; |
| 169 | 175 |
| 176 bool observing_message_loop_destruction_ = true; |
| 177 |
| 170 base::ThreadChecker thread_checker_; | 178 base::ThreadChecker thread_checker_; |
| 171 | 179 |
| 172 base::WeakPtrFactory<InterfaceEndpointClient> weak_ptr_factory_; | 180 base::WeakPtrFactory<InterfaceEndpointClient> weak_ptr_factory_; |
| 173 | 181 |
| 174 DISALLOW_COPY_AND_ASSIGN(InterfaceEndpointClient); | 182 DISALLOW_COPY_AND_ASSIGN(InterfaceEndpointClient); |
| 175 }; | 183 }; |
| 176 | 184 |
| 177 } // namespace mojo | 185 } // namespace mojo |
| 178 | 186 |
| 179 #endif // MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_ENDPOINT_CLIENT_H_ | 187 #endif // MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_ENDPOINT_CLIENT_H_ |
| OLD | NEW |