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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: mojo/public/cpp/bindings/lib/binding_state.cc
diff --git a/mojo/public/cpp/bindings/lib/binding_state.cc b/mojo/public/cpp/bindings/lib/binding_state.cc
new file mode 100644
index 0000000000000000000000000000000000000000..4d5da79cb353af9c054130391bc6d5340a74ceef
--- /dev/null
+++ b/mojo/public/cpp/bindings/lib/binding_state.cc
@@ -0,0 +1,139 @@
+// Copyright 2016 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/lib/binding_state.h"
+
+namespace mojo {
+namespace internal {
+
+SimpleBindingStateBase::SimpleBindingStateBase() = default;
+
+SimpleBindingStateBase::~SimpleBindingStateBase() = default;
+
+void SimpleBindingStateBase::Bind(
+ ScopedMessagePipeHandle handle,
+ scoped_refptr<base::SingleThreadTaskRunner> runner,
+ const char* interface_name,
+ MessageFilter* request_validator,
+ bool has_sync_methods,
+ MessageReceiverWithResponderStatus* stub) {
+ internal::FilterChain filters;
+ filters.Append<MessageHeaderValidator>(interface_name);
+ filters.Append(request_validator);
+
+ router_ = new internal::Router(std::move(handle), std::move(filters),
+ has_sync_methods, std::move(runner));
+ router_->set_incoming_receiver(stub);
+ router_->set_connection_error_handler(
+ base::Bind(&SimpleBindingStateBase::RunConnectionErrorHandler,
+ base::Unretained(this)));
+}
+
+void SimpleBindingStateBase::PauseIncomingMethodCallProcessing() {
+ DCHECK(router_);
+ router_->PauseIncomingMethodCallProcessing();
+}
+void SimpleBindingStateBase::ResumeIncomingMethodCallProcessing() {
+ DCHECK(router_);
+ router_->ResumeIncomingMethodCallProcessing();
+}
+
+bool SimpleBindingStateBase::WaitForIncomingMethodCall(MojoDeadline deadline) {
+ DCHECK(router_);
+ return router_->WaitForIncomingMessage(deadline);
+}
+
+void SimpleBindingStateBase::Close() {
+ if (!router_)
+ return;
+
+ router_->CloseMessagePipe();
+ DestroyRouter();
+}
+
+void SimpleBindingStateBase::EnableTestingMode() {
+ DCHECK(is_bound());
+ router_->EnableTestingMode();
+}
+
+void SimpleBindingStateBase::DestroyRouter() {
+ router_->set_connection_error_handler(base::Closure());
+ delete router_;
+ router_ = nullptr;
+ connection_error_handler_.Reset();
+}
+
+void SimpleBindingStateBase::RunConnectionErrorHandler() {
+ if (!connection_error_handler_.is_null())
+ connection_error_handler_.Run();
+}
+
+// -----------------------------------------------------------------------------
+
+MultiplexedBindingStateBase::MultiplexedBindingStateBase() = default;
+
+MultiplexedBindingStateBase::~MultiplexedBindingStateBase() = default;
+
+void MultiplexedBindingStateBase::Bind(
+ ScopedMessagePipeHandle handle,
+ scoped_refptr<base::SingleThreadTaskRunner> runner,
+ const char* interface_name,
+ std::unique_ptr<MessageFilter> request_validator,
+ bool has_sync_methods,
+ MessageReceiverWithResponderStatus* stub) {
+ DCHECK(!router_);
+
+ router_ = new internal::MultiplexRouter(false, std::move(handle), runner);
+ router_->SetMasterInterfaceName(interface_name);
+
tibell 2016/08/03 01:02:15 I moved the line stub_.serialization_context(
+ endpoint_client_.reset(new InterfaceEndpointClient(
+ router_->CreateLocalEndpointHandle(kMasterInterfaceId), stub,
+ std::move(request_validator), has_sync_methods, std::move(runner)));
+
+ endpoint_client_->set_connection_error_handler(
+ base::Bind(&MultiplexedBindingStateBase::RunConnectionErrorHandler,
+ base::Unretained(this)));
+}
+
+bool MultiplexedBindingStateBase::HasAssociatedInterfaces() const {
+ return router_ ? router_->HasAssociatedEndpoints() : false;
+}
+
+void MultiplexedBindingStateBase::PauseIncomingMethodCallProcessing() {
+ DCHECK(router_);
+ router_->PauseIncomingMethodCallProcessing();
+}
+void MultiplexedBindingStateBase::ResumeIncomingMethodCallProcessing() {
+ DCHECK(router_);
+ router_->ResumeIncomingMethodCallProcessing();
+}
+
+bool MultiplexedBindingStateBase::WaitForIncomingMethodCall(
+ MojoDeadline deadline) {
+ DCHECK(router_);
+ return router_->WaitForIncomingMessage(deadline);
+}
+
+void MultiplexedBindingStateBase::Close() {
+ if (!router_)
+ return;
+
+ endpoint_client_.reset();
+ router_->CloseMessagePipe();
+ router_ = nullptr;
+ connection_error_handler_.Reset();
+}
+
+void MultiplexedBindingStateBase::EnableTestingMode() {
+ DCHECK(is_bound());
+ router_->EnableTestingMode();
+}
+
+void MultiplexedBindingStateBase::RunConnectionErrorHandler() {
+ if (!connection_error_handler_.is_null())
+ connection_error_handler_.Run();
+}
+
+} // namesapce internal
+} // namespace mojo

Powered by Google App Engine
This is Rietveld 408576698