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

Unified Diff: mojo/public/cpp/bindings/lib/binding_state.h

Issue 2532053004: Mojo C++ bindings: remove the single-threaded Router. (Closed)
Patch Set: . Created 4 years, 1 month 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
« no previous file with comments | « mojo/public/cpp/bindings/interface_ptr.h ('k') | mojo/public/cpp/bindings/lib/binding_state.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/public/cpp/bindings/lib/binding_state.h
diff --git a/mojo/public/cpp/bindings/lib/binding_state.h b/mojo/public/cpp/bindings/lib/binding_state.h
index a947cf73c57c9d13b7a80370b33983e8c197863c..a57d904041dada28943cedc780cff9d6cde5b9b1 100644
--- a/mojo/public/cpp/bindings/lib/binding_state.h
+++ b/mojo/public/cpp/bindings/lib/binding_state.h
@@ -26,7 +26,6 @@
#include "mojo/public/cpp/bindings/interface_ptr_info.h"
#include "mojo/public/cpp/bindings/interface_request.h"
#include "mojo/public/cpp/bindings/lib/multiplex_router.h"
-#include "mojo/public/cpp/bindings/lib/router.h"
#include "mojo/public/cpp/bindings/message_header_validator.h"
#include "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h"
#include "mojo/public/cpp/system/core.h"
@@ -34,113 +33,10 @@
namespace mojo {
namespace internal {
-// Base class used for templated binding primitives which bind a pipe
-// exclusively to a single interface.
-class MOJO_CPP_BINDINGS_EXPORT SimpleBindingState {
+class MOJO_CPP_BINDINGS_EXPORT BindingStateBase {
public:
- SimpleBindingState();
- ~SimpleBindingState();
-
- void AddFilter(std::unique_ptr<MessageReceiver> filter);
-
- bool HasAssociatedInterfaces() const { return false; }
-
- void PauseIncomingMethodCallProcessing();
- void ResumeIncomingMethodCallProcessing();
-
- bool WaitForIncomingMethodCall(
- MojoDeadline deadline = MOJO_DEADLINE_INDEFINITE);
-
- void Close();
- void CloseWithReason(uint32_t custom_reason, const std::string& description);
-
- void set_connection_error_handler(const base::Closure& error_handler) {
- DCHECK(is_bound());
- router_->set_connection_error_handler(error_handler);
- }
-
- void set_connection_error_with_reason_handler(
- const ConnectionErrorWithReasonCallback& error_handler) {
- DCHECK(is_bound());
- router_->set_connection_error_with_reason_handler(error_handler);
- }
-
- bool is_bound() const { return !!router_; }
-
- MessagePipeHandle handle() const {
- DCHECK(is_bound());
- return router_->handle();
- }
-
- AssociatedGroup* associated_group() { return nullptr; }
-
- void FlushForTesting();
-
- void EnableTestingMode();
-
- protected:
- void BindInternal(ScopedMessagePipeHandle handle,
- scoped_refptr<base::SingleThreadTaskRunner> runner,
- const char* interface_name,
- std::unique_ptr<MessageReceiver> request_validator,
- bool has_sync_methods,
- MessageReceiverWithResponderStatus* stub,
- uint32_t interface_version);
-
- void DestroyRouter();
-
- internal::Router* router_ = nullptr;
-};
-
-template <typename Interface, bool use_multiplex_router, typename ImplRefTraits>
-class BindingState;
-
-// Uses a single-threaded, dedicated router. If |Interface| doesn't have any
-// methods to pass associated interface pointers or requests, there won't be
-// multiple interfaces running on the underlying message pipe. In that case, we
-// can use this specialization to reduce cost.
-template <typename Interface, typename ImplRefTraits>
-class BindingState<Interface, false, ImplRefTraits>
- : public SimpleBindingState {
- public:
- using ImplPointerType = typename ImplRefTraits::PointerType;
-
- explicit BindingState(ImplPointerType impl) {
- stub_.set_sink(std::move(impl));
- }
-
- ~BindingState() { Close(); }
-
- void Bind(ScopedMessagePipeHandle handle,
- scoped_refptr<base::SingleThreadTaskRunner> runner) {
- DCHECK(!router_);
- SimpleBindingState::BindInternal(
- std::move(handle), runner, Interface::Name_,
- base::MakeUnique<typename Interface::RequestValidator_>(),
- Interface::HasSyncMethods_, &stub_, Interface::Version_);
- }
-
- InterfaceRequest<Interface> Unbind() {
- InterfaceRequest<Interface> request =
- MakeRequest<Interface>(router_->PassMessagePipe());
- DestroyRouter();
- return std::move(request);
- }
-
- Interface* impl() { return ImplRefTraits::GetRawPointer(&stub_.sink()); }
-
- private:
- typename Interface::template Stub_<ImplRefTraits> stub_;
-
- DISALLOW_COPY_AND_ASSIGN(BindingState);
-};
-
-// Base class used for templated binding primitives which may bind a pipe to
-// multiple interfaces.
-class MOJO_CPP_BINDINGS_EXPORT MultiplexedBindingState {
- public:
- MultiplexedBindingState();
- ~MultiplexedBindingState();
+ BindingStateBase();
+ ~BindingStateBase();
void AddFilter(std::unique_ptr<MessageReceiver> filter);
@@ -195,11 +91,8 @@ class MOJO_CPP_BINDINGS_EXPORT MultiplexedBindingState {
std::unique_ptr<InterfaceEndpointClient> endpoint_client_;
};
-// Uses a multiplexing router. If |Interface| has methods to pass associated
-// interface pointers or requests, this specialization should be used.
template <typename Interface, typename ImplRefTraits>
-class BindingState<Interface, true, ImplRefTraits>
- : public MultiplexedBindingState {
+class BindingState : public BindingStateBase {
public:
using ImplPointerType = typename ImplRefTraits::PointerType;
@@ -211,7 +104,7 @@ class BindingState<Interface, true, ImplRefTraits>
void Bind(ScopedMessagePipeHandle handle,
scoped_refptr<base::SingleThreadTaskRunner> runner) {
- MultiplexedBindingState::BindInternal(
+ BindingStateBase::BindInternal(
std::move(handle), runner, Interface::Name_,
base::MakeUnique<typename Interface::RequestValidator_>(),
Interface::PassesAssociatedKinds_, Interface::HasSyncMethods_, &stub_,
« no previous file with comments | « mojo/public/cpp/bindings/interface_ptr.h ('k') | mojo/public/cpp/bindings/lib/binding_state.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698