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

Side by Side Diff: public/platform/WebCallbacks.h

Issue 1234603003: CallbackPromiseAdapter types should be more compatible with WebCallbacks (1/3). (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: retry! Created 5 years, 4 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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/WebPassOwnPtr.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 // 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) {}
66 }; 128 };
67 129
68 } // namespace blink 130 } // namespace blink
69 131
70 #endif 132 #endif
OLDNEW
« no previous file with comments | « Source/modules/serviceworkers/ServiceWorkerWindowClient.cpp ('k') | public/platform/WebGeofencingProvider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698