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

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

Issue 2403533003: Mojo C++ Bindings: Support custom impl ref types (Closed)
Patch Set: nit, move Created 4 years, 2 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
« no previous file with comments | « mojo/public/cpp/bindings/binding.h ('k') | mojo/public/cpp/bindings/raw_ptr_impl_ref_traits.h » ('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 98eccb7186b0ecfb13db6800e8a592c935724341..1842509288c24d6fcd40f0b44a47fe1dc53cf325 100644
--- a/mojo/public/cpp/bindings/lib/binding_state.h
+++ b/mojo/public/cpp/bindings/lib/binding_state.h
@@ -92,18 +92,21 @@ class MOJO_CPP_BINDINGS_EXPORT SimpleBindingState {
internal::Router* router_ = nullptr;
};
-template <typename Interface, bool use_multiplex_router>
+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>
-class BindingState<Interface, false> : public SimpleBindingState {
+template <typename Interface, typename ImplRefTraits>
+class BindingState<Interface, false, ImplRefTraits>
+ : public SimpleBindingState {
public:
- explicit BindingState(Interface* impl) : impl_(impl) {
- stub_.set_sink(impl_);
+ using ImplPointerType = typename ImplRefTraits::PointerType;
+
+ explicit BindingState(ImplPointerType impl) {
+ stub_.set_sink(std::move(impl));
}
~BindingState() { Close(); }
@@ -124,11 +127,10 @@ class BindingState<Interface, false> : public SimpleBindingState {
return std::move(request);
}
- Interface* impl() { return impl_; }
+ Interface* impl() { return ImplRefTraits::GetRawPointer(&stub_.sink()); }
private:
- typename Interface::Stub_ stub_;
- Interface* impl_;
+ typename Interface::template Stub_<ImplRefTraits> stub_;
DISALLOW_COPY_AND_ASSIGN(BindingState);
};
@@ -195,11 +197,14 @@ class MOJO_CPP_BINDINGS_EXPORT MultiplexedBindingState {
// Uses a multiplexing router. If |Interface| has methods to pass associated
// interface pointers or requests, this specialization should be used.
-template <typename Interface>
-class BindingState<Interface, true> : public MultiplexedBindingState {
+template <typename Interface, typename ImplRefTraits>
+class BindingState<Interface, true, ImplRefTraits>
+ : public MultiplexedBindingState {
public:
- explicit BindingState(Interface* impl) : impl_(impl) {
- stub_.set_sink(impl_);
+ using ImplPointerType = typename ImplRefTraits::PointerType;
+
+ explicit BindingState(ImplPointerType impl) {
+ stub_.set_sink(std::move(impl));
}
~BindingState() { Close(); }
@@ -222,11 +227,10 @@ class BindingState<Interface, true> : public MultiplexedBindingState {
return request;
}
- Interface* impl() { return impl_; }
+ Interface* impl() { return ImplRefTraits::GetRawPointer(&stub_.sink()); }
private:
- typename Interface::Stub_ stub_;
- Interface* impl_;
+ typename Interface::template Stub_<ImplRefTraits> stub_;
DISALLOW_COPY_AND_ASSIGN(BindingState);
};
« no previous file with comments | « mojo/public/cpp/bindings/binding.h ('k') | mojo/public/cpp/bindings/raw_ptr_impl_ref_traits.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698