| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #ifndef WebCallbacks_h | 31 #ifndef WebCallbacks_h |
| 32 #define WebCallbacks_h | 32 #define WebCallbacks_h |
| 33 | 33 |
| 34 #include "public/platform/WebPrivateOwnPtr.h" |
| 35 |
| 34 namespace blink { | 36 namespace blink { |
| 35 | 37 |
| 36 template<typename S, typename T> | 38 template<typename S, typename T> |
| 37 class WebCallbacks { | 39 class WebCallbacks { |
| 38 public: | 40 public: |
| 39 virtual ~WebCallbacks() { } | 41 virtual ~WebCallbacks() {} |
| 40 virtual void onSuccess(S) { } | 42 virtual void onSuccess(S) {} |
| 41 virtual void onError(T) { } | 43 virtual void onError(T) {} |
| 42 }; | 44 }; |
| 43 | 45 |
| 44 template<typename T> | 46 template<typename T> |
| 45 class WebCallbacks<void, T> { | 47 class WebCallbacks<void, T> { |
| 46 public: | 48 public: |
| 47 virtual ~WebCallbacks() { } | 49 virtual ~WebCallbacks() {} |
| 48 virtual void onSuccess() { } | 50 virtual void onSuccess() {} |
| 49 virtual void onError(T) { } | 51 virtual void onError(T) {} |
| 50 }; | 52 }; |
| 51 | 53 |
| 52 template<typename S> | 54 template<typename S> |
| 53 class WebCallbacks<S, void> { | 55 class WebCallbacks<S, void> { |
| 54 public: | 56 public: |
| 55 virtual ~WebCallbacks() { } | 57 virtual ~WebCallbacks() {} |
| 56 virtual void onSuccess(S) { } | 58 virtual void onSuccess(S) {} |
| 57 virtual void onError() { } | 59 virtual void onError() {} |
| 58 }; | 60 }; |
| 59 | 61 |
| 60 template<> | 62 template<> |
| 61 class WebCallbacks<void, void> { | 63 class WebCallbacks<void, void> { |
| 62 public: | 64 public: |
| 63 virtual ~WebCallbacks() { } | 65 virtual ~WebCallbacks() {} |
| 64 virtual void onSuccess() { } | 66 virtual void onSuccess() {} |
| 65 virtual void onError() { } | 67 virtual void onError() {} |
| 68 }; |
| 69 |
| 70 // WebPrivateOwnPtr<T>&& adapter: defined for migration purpose and should |
| 71 // be deleted in the future. |
| 72 |
| 73 template <typename S, typename T> |
| 74 class WebCallbacks<WebPrivateOwnPtr<S>&&, WebPrivateOwnPtr<T>&&> { |
| 75 public: |
| 76 virtual ~WebCallbacks() {} |
| 77 virtual void onSuccess(WebPrivateOwnPtr<S>&&) {} |
| 78 void onSuccess(const S& r) { onSuccess(WebPrivateOwnPtr<S>(new S(r))); } |
| 79 virtual void onError(WebPrivateOwnPtr<T>&&) {} |
| 80 void onError(const T& e) { onError(WebPrivateOwnPtr<T>(new T(e))); } |
| 81 |
| 82 void onSuccess(S* r) { onSuccess(WebPrivateOwnPtr<S>(r)); } |
| 83 void onError(T* e) { onError(WebPrivateOwnPtr<T>(e)); } |
| 84 }; |
| 85 |
| 86 template <typename S> |
| 87 class WebCallbacks<WebPrivateOwnPtr<S>&&, void> { |
| 88 public: |
| 89 virtual ~WebCallbacks() {} |
| 90 virtual void onSuccess(WebPrivateOwnPtr<S>&&) {} |
| 91 virtual void onSuccess(const S& r) { onSuccess(WebPrivateOwnPtr<S>(new S(r))
); } |
| 92 virtual void onError() {} |
| 93 |
| 94 void onSuccess(S* r) { onSuccess(WebPrivateOwnPtr<S>(r)); } |
| 95 }; |
| 96 |
| 97 template <typename T> |
| 98 class WebCallbacks<void, WebPrivateOwnPtr<T>&&> { |
| 99 public: |
| 100 virtual ~WebCallbacks() {} |
| 101 virtual void onSuccess() {} |
| 102 virtual void onError(WebPrivateOwnPtr<T>&&) {} |
| 103 void onError(const T& e) { onError(WebPrivateOwnPtr<T>(new T(e))); } |
| 104 |
| 105 void onError(T* e) { onError(WebPrivateOwnPtr<T>(e)); } |
| 106 }; |
| 107 |
| 108 template <typename T> |
| 109 class WebCallbacks<bool*, WebPrivateOwnPtr<T>&&> { |
| 110 public: |
| 111 virtual ~WebCallbacks() {} |
| 112 void onSuccess(bool b) { onSuccess(&b); } |
| 113 virtual void onError(WebPrivateOwnPtr<T>&&) {} |
| 114 void onError(const T& e) { onError(WebPrivateOwnPtr<T>(new T(e))); } |
| 115 |
| 116 virtual void onSuccess(bool* b) {} |
| 117 void onError(T* e) { onError(WebPrivateOwnPtr<T>(e)); } |
| 118 }; |
| 119 |
| 120 template <> |
| 121 class WebCallbacks<bool*, void> { |
| 122 public: |
| 123 virtual ~WebCallbacks<bool*, void>() {} |
| 124 void onSuccess(bool b) { onSuccess(&b); } |
| 125 virtual void onError() {} |
| 126 |
| 127 virtual void onSuccess(bool *b) {} |
| 66 }; | 128 }; |
| 67 | 129 |
| 68 } // namespace blink | 130 } // namespace blink |
| 69 | 131 |
| 70 #endif | 132 #endif |
| OLD | NEW |