1 // Copyright 2016 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 #include "mojo/public/cpp/bindings/lib/binding_state.h" 6 7 namespace mojo { 8 namespace internal { 9 10 BindingStateBase::BindingStateBase() = default; 11 12 BindingStateBase::~BindingStateBase() = default; 13 14 void BindingStateBase::AddFilter(std::unique_ptr<MessageReceiver> filter) { 15 DCHECK(endpoint_client_); 16 endpoint_client_->AddFilter(std::move(filter)); 17 } 18 19 bool BindingStateBase::HasAssociatedInterfaces() const { 20 return router_ ? router_->HasAssociatedEndpoints() : false; 21 } 22 23 void BindingStateBase::PauseIncomingMethodCallProcessing() { 24 DCHECK(router_); 25 router_->PauseIncomingMethodCallProcessing(); 26 } 27 void BindingStateBase::ResumeIncomingMethodCallProcessing() { 28 DCHECK(router_); 29 router_->ResumeIncomingMethodCallProcessing(); 30 } 31 32 bool BindingStateBase::WaitForIncomingMethodCall(MojoDeadline deadline) { 33 DCHECK(router_); 34 return router_->WaitForIncomingMessage(deadline); 35 } 36 37 void BindingStateBase::Close() { 38 if (!router_) 39 return; 40 41 endpoint_client_.reset(); 42 router_->CloseMessagePipe(); 43 router_ = nullptr; 44 } 45 46 void BindingStateBase::CloseWithReason(uint32_t custom_reason, 47 const std::string& description) { 48 if (endpoint_client_) 49 endpoint_client_->CloseWithReason(custom_reason, description); 50 51 Close(); 52 } 53 54 void BindingStateBase::FlushForTesting() { 55 endpoint_client_->FlushForTesting(); 56 } 57 58 void BindingStateBase::EnableTestingMode() { 59 DCHECK(is_bound()); 60 router_->EnableTestingMode(); 61 } 62 63 void BindingStateBase::BindInternal( 64 ScopedMessagePipeHandle handle, 65 scoped_refptr<base::SingleThreadTaskRunner> runner, 66 const char* interface_name, 67 std::unique_ptr<MessageReceiver> request_validator, 68 bool passes_associated_kinds, 69 bool has_sync_methods, 70 MessageReceiverWithResponderStatus* stub, 71 uint32_t interface_version) { 72 DCHECK(!router_); 73 74 MultiplexRouter::Config config = 75 passes_associated_kinds 76 ? MultiplexRouter::MULTI_INTERFACE 77 : (has_sync_methods 78 ? MultiplexRouter::SINGLE_INTERFACE_WITH_SYNC_METHODS 79 : MultiplexRouter::SINGLE_INTERFACE); 80 router_ = new MultiplexRouter(std::move(handle), config, false, runner); 81 router_->SetMasterInterfaceName(interface_name); 82 83 endpoint_client_.reset(new InterfaceEndpointClient( 84 router_->CreateLocalEndpointHandle(kMasterInterfaceId), stub, 85 std::move(request_validator), has_sync_methods, std::move(runner), 86 interface_version)); 87 } 88 89 } // namesapce internal 90 } // namespace mojo 91