summaryrefslogtreecommitdiff
path: root/mojo/public/cpp/bindings/lib/associated_binding.cc
blob: 6788e68e071b3b893e674d5f67e58c1066b2a079 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "mojo/public/cpp/bindings/associated_binding.h"

namespace mojo {

AssociatedBindingBase::AssociatedBindingBase() {}

AssociatedBindingBase::~AssociatedBindingBase() {}

void AssociatedBindingBase::AddFilter(std::unique_ptr<MessageReceiver> filter) {
  DCHECK(endpoint_client_);
  endpoint_client_->AddFilter(std::move(filter));
}

void AssociatedBindingBase::Close() {
  endpoint_client_.reset();
}

void AssociatedBindingBase::CloseWithReason(uint32_t custom_reason,
                                            const std::string& description) {
  if (endpoint_client_)
    endpoint_client_->CloseWithReason(custom_reason, description);
  Close();
}

void AssociatedBindingBase::set_connection_error_handler(
    const base::Closure& error_handler) {
  DCHECK(is_bound());
  endpoint_client_->set_connection_error_handler(error_handler);
}

void AssociatedBindingBase::set_connection_error_with_reason_handler(
    const ConnectionErrorWithReasonCallback& error_handler) {
  DCHECK(is_bound());
  endpoint_client_->set_connection_error_with_reason_handler(error_handler);
}

void AssociatedBindingBase::FlushForTesting() {
  endpoint_client_->FlushForTesting();
}

void AssociatedBindingBase::BindImpl(
    ScopedInterfaceEndpointHandle handle,
    MessageReceiverWithResponderStatus* receiver,
    std::unique_ptr<MessageReceiver> payload_validator,
    bool expect_sync_requests,
    scoped_refptr<base::SingleThreadTaskRunner> runner,
    uint32_t interface_version) {
  if (!handle.is_valid()) {
    endpoint_client_.reset();
    return;
  }

  endpoint_client_.reset(new InterfaceEndpointClient(
      std::move(handle), receiver, std::move(payload_validator),
      expect_sync_requests, std::move(runner), interface_version));
}

}  // namespace mojo