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

Unified Diff: mojo/public/cpp/bindings/interface_impl.h

Issue 380413003: Mojo: Use InterfaceFactory<Interface> for service registration (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix network_service_loader Created 6 years, 5 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/interface_impl.h
diff --git a/mojo/public/cpp/bindings/interface_impl.h b/mojo/public/cpp/bindings/interface_impl.h
index 4a78cb4b05a1f11b4380a001aab45fa76e91a8e2..da1055de535bb71445541320ab274be536bd5fe1 100644
--- a/mojo/public/cpp/bindings/interface_impl.h
+++ b/mojo/public/cpp/bindings/interface_impl.h
@@ -19,6 +19,7 @@ template <typename Interface>
class InterfaceImpl : public internal::InterfaceImplBase<Interface> {
public:
typedef typename Interface::Client Client;
+ typedef Interface ImplementedInterface;
InterfaceImpl() : internal_state_(this) {}
virtual ~InterfaceImpl() {}
@@ -57,12 +58,15 @@ class InterfaceImpl : public internal::InterfaceImplBase<Interface> {
// Takes an instance of an InterfaceImpl<..> subclass and binds it to the given
// MessagePipe. The instance is returned for convenience in member initializer
-// lists, etc. If the pipe is closed, the instance's OnConnectionError method
-// will be called.
+// lists, etc.
+//
+// If the pipe is closed, the instance's OnConnectionError method will be called
+// and then the instance will be deleted.
//
// The instance is also bound to the current thread. Its methods will only be
-// called on the current thread, and if the current thread exits, then it will
-// also be deleted, and along with it, its end point of the pipe will be closed.
+// called on the current thread, and if the current thread exits, then the end
+// point of the pipe will be closed and the error handler's OnConnectionError
+// method will be called.
//
// Before returning, the instance's OnConnectionEstablished method is called.
template <typename Impl>
@@ -70,14 +74,25 @@ Impl* BindToPipe(
Impl* instance,
ScopedMessagePipeHandle handle,
const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter()) {
- instance->internal_state()->Bind(handle.Pass(), waiter);
+ instance->internal_state()->Bind(handle.Pass(), true, waiter);
+ return instance;
+}
+
+// Like BindToPipe but does not delete the instance after a channel error.
+template <typename Impl>
+Impl* WeakBindToPipe(
+ Impl* instance,
+ ScopedMessagePipeHandle handle,
+ const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter()) {
+ instance->internal_state()->Bind(handle.Pass(), false, waiter);
return instance;
}
// Takes an instance of an InterfaceImpl<..> subclass and binds it to the given
// InterfacePtr<..>. The instance is returned for convenience in member
// initializer lists, etc. If the pipe is closed, the instance's
-// OnConnectionError method will be called.
+// OnConnectionError method will be called and then the instance will be
+// deleted.
//
// The instance is also bound to the current thread. Its methods will only be
// called on the current thread, and if the current thread exits, then it will
@@ -89,14 +104,25 @@ Impl* BindToProxy(
Impl* instance,
InterfacePtr<Interface>* ptr,
const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter()) {
- instance->internal_state()->BindProxy(ptr, waiter);
+ instance->internal_state()->BindProxy(ptr, true, waiter);
+ return instance;
+}
+
+// Like BindToProxy but does not delete the instance after a channel error.
+template <typename Impl, typename Interface>
+Impl* WeakBindToProxy(
+ Impl* instance,
+ InterfacePtr<Interface>* ptr,
+ const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter()) {
+ instance->internal_state()->BindProxy(ptr, false, waiter);
return instance;
}
// Takes an instance of an InterfaceImpl<..> subclass and binds it to the given
// InterfaceRequest<..>. The instance is returned for convenience in member
// initializer lists, etc. If the pipe is closed, the instance's
-// OnConnectionError method will be called.
+// OnConnectionError method will be called and then the instance will be
+// deleted.
//
// The instance is also bound to the current thread. Its methods will only be
// called on the current thread, and if the current thread exits, then it will
@@ -112,6 +138,15 @@ Impl* BindToRequest(
return BindToPipe(instance, request->PassMessagePipe(), waiter);
}
+// Like BindToRequest but does not delete the instance after a channel error.
+template <typename Impl, typename Interface>
+Impl* WeakBindToRequest(
+ Impl* instance,
+ InterfaceRequest<Interface>* request,
+ const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter()) {
+ return WeakBindToPipe(instance, request->PassMessagePipe(), waiter);
+}
+
} // namespace mojo
#endif // MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_IMPL_H_
« no previous file with comments | « mojo/public/cpp/application/lib/service_connector.h ('k') | mojo/public/cpp/bindings/lib/interface_impl_internal.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698