| 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_STRONG_BINDING_H_ | 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_STRONG_BINDING_H_ |
| 6 #define MOJO_PUBLIC_CPP_BINDINGS_STRONG_BINDING_H_ | 6 #define MOJO_PUBLIC_CPP_BINDINGS_STRONG_BINDING_H_ |
| 7 | 7 |
| 8 #include <assert.h> | 8 #include <assert.h> |
| 9 | 9 |
| 10 #include "mojo/public/c/environment/async_waiter.h" | 10 #include "mojo/public/c/environment/async_waiter.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 // class StronglyBound : public Foo { | 35 // class StronglyBound : public Foo { |
| 36 // public: | 36 // public: |
| 37 // explicit StronglyBound(InterfaceRequest<Foo> request) | 37 // explicit StronglyBound(InterfaceRequest<Foo> request) |
| 38 // : binding_(this, request.Pass()) {} | 38 // : binding_(this, request.Pass()) {} |
| 39 // | 39 // |
| 40 // // Foo implementation here | 40 // // Foo implementation here |
| 41 // | 41 // |
| 42 // private: | 42 // private: |
| 43 // StrongBinding<Foo> binding_; | 43 // StrongBinding<Foo> binding_; |
| 44 // }; | 44 // }; |
| 45 // | |
| 46 // class MyFooFactory : public InterfaceFactory<Foo> { | |
| 47 // public: | |
| 48 // void Create(..., InterfaceRequest<Foo> request) override { | |
| 49 // new StronglyBound(request.Pass()); // The binding now owns the | |
| 50 // // instance of StronglyBound. | |
| 51 // } | |
| 52 // }; | |
| 53 template <typename Interface> | 45 template <typename Interface> |
| 54 class StrongBinding { | 46 class StrongBinding { |
| 55 public: | 47 public: |
| 56 // Constructs an incomplete binding that will use the implementation |impl|. | 48 // Constructs an incomplete binding that will use the implementation |impl|. |
| 57 // The binding may be completed with a subsequent call to the |Bind| method. | 49 // The binding may be completed with a subsequent call to the |Bind| method. |
| 58 // Does not take ownership of |impl|, which must outlive the binding. | 50 // Does not take ownership of |impl|, which must outlive the binding. |
| 59 explicit StrongBinding(Interface* impl) : binding_(impl) { | 51 explicit StrongBinding(Interface* impl) : binding_(impl) { |
| 60 binding_.set_connection_error_handler([this]() { OnConnectionError(); }); | 52 binding_.set_connection_error_handler([this]() { OnConnectionError(); }); |
| 61 } | 53 } |
| 62 | 54 |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 private: | 178 private: |
| 187 Closure connection_error_handler_; | 179 Closure connection_error_handler_; |
| 188 Binding<Interface> binding_; | 180 Binding<Interface> binding_; |
| 189 | 181 |
| 190 MOJO_DISALLOW_COPY_AND_ASSIGN(StrongBinding); | 182 MOJO_DISALLOW_COPY_AND_ASSIGN(StrongBinding); |
| 191 }; | 183 }; |
| 192 | 184 |
| 193 } // namespace mojo | 185 } // namespace mojo |
| 194 | 186 |
| 195 #endif // MOJO_PUBLIC_CPP_BINDINGS_STRONG_BINDING_H_ | 187 #endif // MOJO_PUBLIC_CPP_BINDINGS_STRONG_BINDING_H_ |
| OLD | NEW |