Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(168)

Side by Side Diff: mojo/public/cpp/bindings/lib/binding_state.cc

Issue 2203243002: Reduce code size of BindingState (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@before-sharing
Patch Set: --similarity=10 Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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 SimpleBindingStateBase::SimpleBindingStateBase() = default;
11
12 SimpleBindingStateBase::~SimpleBindingStateBase() = default;
13
14 void SimpleBindingStateBase::Bind(
15 ScopedMessagePipeHandle handle,
16 scoped_refptr<base::SingleThreadTaskRunner> runner,
17 const char* interface_name,
18 MessageFilter* request_validator,
19 bool has_sync_methods,
20 MessageReceiverWithResponderStatus* stub) {
21 internal::FilterChain filters;
22 filters.Append<MessageHeaderValidator>(interface_name);
23 filters.Append(request_validator);
24
25 router_ = new internal::Router(std::move(handle), std::move(filters),
26 has_sync_methods, std::move(runner));
27 router_->set_incoming_receiver(stub);
28 router_->set_connection_error_handler(
29 base::Bind(&SimpleBindingStateBase::RunConnectionErrorHandler,
30 base::Unretained(this)));
31 }
32
33 void SimpleBindingStateBase::PauseIncomingMethodCallProcessing() {
34 DCHECK(router_);
35 router_->PauseIncomingMethodCallProcessing();
36 }
37 void SimpleBindingStateBase::ResumeIncomingMethodCallProcessing() {
38 DCHECK(router_);
39 router_->ResumeIncomingMethodCallProcessing();
40 }
41
42 bool SimpleBindingStateBase::WaitForIncomingMethodCall(MojoDeadline deadline) {
43 DCHECK(router_);
44 return router_->WaitForIncomingMessage(deadline);
45 }
46
47 void SimpleBindingStateBase::Close() {
48 if (!router_)
49 return;
50
51 router_->CloseMessagePipe();
52 DestroyRouter();
53 }
54
55 void SimpleBindingStateBase::EnableTestingMode() {
56 DCHECK(is_bound());
57 router_->EnableTestingMode();
58 }
59
60 void SimpleBindingStateBase::DestroyRouter() {
61 router_->set_connection_error_handler(base::Closure());
62 delete router_;
63 router_ = nullptr;
64 connection_error_handler_.Reset();
65 }
66
67 void SimpleBindingStateBase::RunConnectionErrorHandler() {
68 if (!connection_error_handler_.is_null())
69 connection_error_handler_.Run();
70 }
71
72 // -----------------------------------------------------------------------------
73
74 MultiplexedBindingStateBase::MultiplexedBindingStateBase() = default;
75
76 MultiplexedBindingStateBase::~MultiplexedBindingStateBase() = default;
77
78 void MultiplexedBindingStateBase::Bind(
79 ScopedMessagePipeHandle handle,
80 scoped_refptr<base::SingleThreadTaskRunner> runner,
81 const char* interface_name,
82 std::unique_ptr<MessageFilter> request_validator,
83 bool has_sync_methods,
84 MessageReceiverWithResponderStatus* stub) {
85 DCHECK(!router_);
86
87 router_ = new internal::MultiplexRouter(false, std::move(handle), runner);
88 router_->SetMasterInterfaceName(interface_name);
89
tibell 2016/08/03 01:02:15 I moved the line stub_.serialization_context(
90 endpoint_client_.reset(new InterfaceEndpointClient(
91 router_->CreateLocalEndpointHandle(kMasterInterfaceId), stub,
92 std::move(request_validator), has_sync_methods, std::move(runner)));
93
94 endpoint_client_->set_connection_error_handler(
95 base::Bind(&MultiplexedBindingStateBase::RunConnectionErrorHandler,
96 base::Unretained(this)));
97 }
98
99 bool MultiplexedBindingStateBase::HasAssociatedInterfaces() const {
100 return router_ ? router_->HasAssociatedEndpoints() : false;
101 }
102
103 void MultiplexedBindingStateBase::PauseIncomingMethodCallProcessing() {
104 DCHECK(router_);
105 router_->PauseIncomingMethodCallProcessing();
106 }
107 void MultiplexedBindingStateBase::ResumeIncomingMethodCallProcessing() {
108 DCHECK(router_);
109 router_->ResumeIncomingMethodCallProcessing();
110 }
111
112 bool MultiplexedBindingStateBase::WaitForIncomingMethodCall(
113 MojoDeadline deadline) {
114 DCHECK(router_);
115 return router_->WaitForIncomingMessage(deadline);
116 }
117
118 void MultiplexedBindingStateBase::Close() {
119 if (!router_)
120 return;
121
122 endpoint_client_.reset();
123 router_->CloseMessagePipe();
124 router_ = nullptr;
125 connection_error_handler_.Reset();
126 }
127
128 void MultiplexedBindingStateBase::EnableTestingMode() {
129 DCHECK(is_bound());
130 router_->EnableTestingMode();
131 }
132
133 void MultiplexedBindingStateBase::RunConnectionErrorHandler() {
134 if (!connection_error_handler_.is_null())
135 connection_error_handler_.Run();
136 }
137
138 } // namesapce internal
139 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698