OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_IMPL_H_ | 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_IMPL_H_ |
6 #define MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_IMPL_H_ | 6 #define MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_IMPL_H_ |
7 | 7 |
8 #include "mojo/public/cpp/bindings/interface_request.h" | 8 #include "mojo/public/cpp/bindings/interface_request.h" |
9 #include "mojo/public/cpp/bindings/lib/interface_impl_internal.h" | 9 #include "mojo/public/cpp/bindings/lib/interface_impl_internal.h" |
10 #include "mojo/public/cpp/environment/environment.h" | 10 #include "mojo/public/cpp/environment/environment.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
48 // DO NOT USE. Exposed only for internal use and for testing. | 48 // DO NOT USE. Exposed only for internal use and for testing. |
49 internal::InterfaceImplState<Interface>* internal_state() { | 49 internal::InterfaceImplState<Interface>* internal_state() { |
50 return &internal_state_; | 50 return &internal_state_; |
51 } | 51 } |
52 | 52 |
53 private: | 53 private: |
54 internal::InterfaceImplState<Interface> internal_state_; | 54 internal::InterfaceImplState<Interface> internal_state_; |
55 MOJO_DISALLOW_COPY_AND_ASSIGN(InterfaceImpl); | 55 MOJO_DISALLOW_COPY_AND_ASSIGN(InterfaceImpl); |
56 }; | 56 }; |
57 | 57 |
58 // Use InterfaceImplDeleteOnError if your interface implementation should delete | |
59 // itself when detecting a connection error. | |
60 template <typename Interface> | |
61 class InterfaceImplDeleteOnError : public InterfaceImpl<Interface> { | |
62 public: | |
63 virtual ~InterfaceImplDeleteOnError() {} | |
64 virtual void OnConnectionError() { delete this; } | |
tim (not reviewing)
2014/07/11 01:33:41
I might be missing something, but I think one thin
darin (slow to review)
2014/07/11 03:52:35
A template arg to InterfaceImpl<> would help solve
| |
65 }; | |
66 | |
58 // Takes an instance of an InterfaceImpl<..> subclass and binds it to the given | 67 // Takes an instance of an InterfaceImpl<..> subclass and binds it to the given |
59 // MessagePipe. The instance is returned for convenience in member initializer | 68 // MessagePipe. The instance is returned for convenience in member initializer |
60 // lists, etc. If the pipe is closed, the instance's OnConnectionError method | 69 // lists, etc. If the pipe is closed, the instance's OnConnectionError method |
61 // will be called. | 70 // will be called. |
62 // | 71 // |
63 // The instance is also bound to the current thread. Its methods will only be | 72 // The instance is also bound to the current thread. Its methods will only be |
64 // called on the current thread, and if the current thread exits, then it will | 73 // called on the current thread, and if the current thread exits, then it will |
65 // also be deleted, and along with it, its end point of the pipe will be closed. | 74 // also be deleted, and along with it, its end point of the pipe will be closed. |
66 // | 75 // |
67 // Before returning, the instance's OnConnectionEstablished method is called. | 76 // Before returning, the instance's OnConnectionEstablished method is called. |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
108 Impl* BindToRequest( | 117 Impl* BindToRequest( |
109 Impl* instance, | 118 Impl* instance, |
110 InterfaceRequest<Interface>* request, | 119 InterfaceRequest<Interface>* request, |
111 const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter()) { | 120 const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter()) { |
112 return BindToPipe(instance, request->PassMessagePipe(), waiter); | 121 return BindToPipe(instance, request->PassMessagePipe(), waiter); |
113 } | 122 } |
114 | 123 |
115 } // namespace mojo | 124 } // namespace mojo |
116 | 125 |
117 #endif // MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_IMPL_H_ | 126 #endif // MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_IMPL_H_ |
OLD | NEW |