Home | History | Annotate | Download | only in lib
      1 // Copyright 2017 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/associated_binding.h"
      6 
      7 #include "base/single_thread_task_runner.h"
      8 #include "mojo/public/cpp/bindings/lib/task_runner_helper.h"
      9 
     10 namespace mojo {
     11 
     12 AssociatedBindingBase::AssociatedBindingBase() {}
     13 
     14 AssociatedBindingBase::~AssociatedBindingBase() {}
     15 
     16 void AssociatedBindingBase::AddFilter(std::unique_ptr<MessageReceiver> filter) {
     17   DCHECK(endpoint_client_);
     18   endpoint_client_->AddFilter(std::move(filter));
     19 }
     20 
     21 void AssociatedBindingBase::Close() {
     22   endpoint_client_.reset();
     23 }
     24 
     25 void AssociatedBindingBase::CloseWithReason(uint32_t custom_reason,
     26                                             const std::string& description) {
     27   if (endpoint_client_)
     28     endpoint_client_->CloseWithReason(custom_reason, description);
     29   Close();
     30 }
     31 
     32 void AssociatedBindingBase::set_connection_error_handler(
     33     base::OnceClosure error_handler) {
     34   DCHECK(is_bound());
     35   endpoint_client_->set_connection_error_handler(std::move(error_handler));
     36 }
     37 
     38 void AssociatedBindingBase::set_connection_error_with_reason_handler(
     39     ConnectionErrorWithReasonCallback error_handler) {
     40   DCHECK(is_bound());
     41   endpoint_client_->set_connection_error_with_reason_handler(
     42       std::move(error_handler));
     43 }
     44 
     45 void AssociatedBindingBase::FlushForTesting() {
     46   endpoint_client_->FlushForTesting();
     47 }
     48 
     49 void AssociatedBindingBase::BindImpl(
     50     ScopedInterfaceEndpointHandle handle,
     51     MessageReceiverWithResponderStatus* receiver,
     52     std::unique_ptr<MessageReceiver> payload_validator,
     53     bool expect_sync_requests,
     54     scoped_refptr<base::SingleThreadTaskRunner> runner,
     55     uint32_t interface_version) {
     56   if (!handle.is_valid()) {
     57     endpoint_client_.reset();
     58     return;
     59   }
     60 
     61   endpoint_client_.reset(new InterfaceEndpointClient(
     62       std::move(handle), receiver, std::move(payload_validator),
     63       expect_sync_requests,
     64       internal::GetTaskRunnerToUseFromUserProvidedTaskRunner(std::move(runner)),
     65       interface_version));
     66 }
     67 
     68 }  // namespace mojo
     69