| 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 17 matching lines...) Expand all Loading... |
| 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/WebPassOwnPtr.h" | 34 #include "public/platform/WebPassOwnPtr.h" |
| 35 | 35 |
| 36 namespace blink { | 36 namespace blink { |
| 37 | 37 |
| 38 // A WebCallbacks<S, T> represents a callback object. Typically it is created |
| 39 // in Blink and passed to Chromium, and onSuccess or onError will be called |
| 40 // from Chromium. |
| 41 // When transferring ownership, use |WebPrivatePassOwnPtr<X>| as a type |
| 42 // parameter. Otherwise, |const X&| or |X| for a type parameter. It is |
| 43 // generally not preferred to use |X*| because the object ownership is not well |
| 44 // specified. |
| 45 |
| 38 template<typename S, typename T> | 46 template<typename S, typename T> |
| 39 class WebCallbacks { | 47 class WebCallbacks { |
| 40 public: | 48 public: |
| 41 virtual ~WebCallbacks() {} | 49 virtual ~WebCallbacks() {} |
| 42 virtual void onSuccess(S) {} | 50 virtual void onSuccess(S) {} |
| 43 virtual void onError(T) {} | 51 virtual void onError(T) {} |
| 44 }; | 52 }; |
| 45 | 53 |
| 46 template<typename T> | 54 template<typename T> |
| 47 class WebCallbacks<void, T> { | 55 class WebCallbacks<void, T> { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 60 }; | 68 }; |
| 61 | 69 |
| 62 template<> | 70 template<> |
| 63 class WebCallbacks<void, void> { | 71 class WebCallbacks<void, void> { |
| 64 public: | 72 public: |
| 65 virtual ~WebCallbacks() {} | 73 virtual ~WebCallbacks() {} |
| 66 virtual void onSuccess() {} | 74 virtual void onSuccess() {} |
| 67 virtual void onError() {} | 75 virtual void onError() {} |
| 68 }; | 76 }; |
| 69 | 77 |
| 70 // WebPassOwnPtr<T> adapter: defined for migration purpose and should | |
| 71 // be deleted in the future. | |
| 72 | |
| 73 template <typename S, typename T> | |
| 74 class WebCallbacks<WebPassOwnPtr<S>, WebPassOwnPtr<T>> { | |
| 75 public: | |
| 76 virtual ~WebCallbacks() {} | |
| 77 virtual void onSuccess(WebPassOwnPtr<S>) {} | |
| 78 void onSuccess(const S& r) { onSuccess(adoptWebPtr(new S(r))); } | |
| 79 virtual void onError(WebPassOwnPtr<T>) {} | |
| 80 void onError(const T& e) { onError(adoptWebPtr(new T(e))); } | |
| 81 | |
| 82 void onSuccess(S* r) { onSuccess(adoptWebPtr(r)); } | |
| 83 void onError(T* e) { onError(adoptWebPtr(e)); } | |
| 84 }; | |
| 85 | |
| 86 template <typename S> | |
| 87 class WebCallbacks<WebPassOwnPtr<S>, void> { | |
| 88 public: | |
| 89 virtual ~WebCallbacks() {} | |
| 90 virtual void onSuccess(WebPassOwnPtr<S>) {} | |
| 91 virtual void onSuccess(const S& r) { onSuccess(adoptWebPtr(new S(r))); } | |
| 92 virtual void onError() {} | |
| 93 | |
| 94 void onSuccess(S* r) { onSuccess(adoptWebPtr(r)); } | |
| 95 }; | |
| 96 | |
| 97 template <typename T> | |
| 98 class WebCallbacks<void, WebPassOwnPtr<T>> { | |
| 99 public: | |
| 100 virtual ~WebCallbacks() {} | |
| 101 virtual void onSuccess() {} | |
| 102 virtual void onError(WebPassOwnPtr<T>) {} | |
| 103 void onError(const T& e) { onError(adoptWebPtr(new T(e))); } | |
| 104 | |
| 105 void onError(T* e) { onError(adoptWebPtr(e)); } | |
| 106 }; | |
| 107 | |
| 108 template <typename T> | |
| 109 class WebCallbacks<bool*, WebPassOwnPtr<T>> { | |
| 110 public: | |
| 111 virtual ~WebCallbacks() {} | |
| 112 void onSuccess(bool b) { onSuccess(&b); } | |
| 113 virtual void onError(WebPassOwnPtr<T>) {} | |
| 114 void onError(const T& e) { onError(adoptWebPtr(new T(e))); } | |
| 115 | |
| 116 virtual void onSuccess(bool* b) {} | |
| 117 void onError(T* e) { onError(adoptWebPtr(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) {} | |
| 128 }; | |
| 129 | |
| 130 } // namespace blink | 78 } // namespace blink |
| 131 | 79 |
| 132 #endif | 80 #endif |
| OLD | NEW |