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

Side by Side Diff: third_party/WebKit/Source/bindings/core/v8/CallbackPromiseAdapter.h

Issue 1865913005: Nuke WebPassOwnPtr<T> and replace it with std::unique_ptr<T>. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 8 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
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 15 matching lines...) Expand all
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 CallbackPromiseAdapter_h 31 #ifndef CallbackPromiseAdapter_h
32 #define CallbackPromiseAdapter_h 32 #define CallbackPromiseAdapter_h
33 33
34 #include "bindings/core/v8/ScriptPromiseResolver.h" 34 #include "bindings/core/v8/ScriptPromiseResolver.h"
35 #include "public/platform/WebCallbacks.h" 35 #include "public/platform/WebCallbacks.h"
36 #include "public/platform/WebPassOwnPtr.h"
37 #include "wtf/OwnPtr.h" 36 #include "wtf/OwnPtr.h"
38 #include "wtf/PassOwnPtr.h" 37 #include "wtf/PassOwnPtr.h"
39 #include "wtf/TypeTraits.h" 38 #include "wtf/TypeTraits.h"
40 39
40 #include <memory>
41
41 namespace blink { 42 namespace blink {
42 43
43 // CallbackPromiseAdapter is a WebCallbacks subclass and resolves / rejects the 44 // CallbackPromiseAdapter is a WebCallbacks subclass and resolves / rejects the
44 // stored resolver when onSuccess / onError is called, respectively. 45 // stored resolver when onSuccess / onError is called, respectively.
45 // 46 //
46 // Basically CallbackPromiseAdapter<S, T> is a subclass of 47 // Basically CallbackPromiseAdapter<S, T> is a subclass of
47 // WebCallbacks<S::WebType, T::WebType>. There are some exceptions: 48 // WebCallbacks<S::WebType, T::WebType>. There are some exceptions:
48 // - If S or T don't have WebType (e.g. S = bool), a default WebType holder 49 // - If S or T don't have WebType (e.g. S = bool), a default WebType holder
49 // called trivial WebType holder is used. For example, 50 // called trivial WebType holder is used. For example,
50 // CallbackPromiseAdapter<bool, void> is a subclass of 51 // CallbackPromiseAdapter<bool, void> is a subclass of
51 // WebCallbacks<bool, void>. 52 // WebCallbacks<bool, void>.
52 // - If a WebType is OwnPtr<T>, its corresponding type parameter on 53 // - If a WebType is OwnPtr<T>, its corresponding type parameter on
53 // WebCallbacks is WebPassOwnPtr<T>, because WebCallbacks must be exposed to 54 // WebCallbacks is std::unique_ptr<T>, because WebCallbacks must be exposed t o
54 // Chromium. 55 // Chromium.
55 // 56 //
56 // When onSuccess is called with a S::WebType value, the value is passed to 57 // When onSuccess is called with a S::WebType value, the value is passed to
57 // S::take and the resolver is resolved with its return value. Ditto for 58 // S::take and the resolver is resolved with its return value. Ditto for
58 // onError. 59 // onError.
59 // 60 //
60 // ScriptPromiseResolver::resolve / reject will not be called when the execution 61 // ScriptPromiseResolver::resolve / reject will not be called when the execution
61 // context is stopped. 62 // context is stopped.
62 // 63 //
63 // Example: 64 // Example:
(...skipping 10 matching lines...) Expand all
74 // class MyErrorClass { 75 // class MyErrorClass {
75 // public: 76 // public:
76 // using WebType = const WebMyErrorClass&; 77 // using WebType = const WebMyErrorClass&;
77 // static MyErrorClass take(ScriptPromiseResolver* resolver, 78 // static MyErrorClass take(ScriptPromiseResolver* resolver,
78 // const WebErrorClass& webError) 79 // const WebErrorClass& webError)
79 // { 80 // {
80 // return MyErrorClass(webError); 81 // return MyErrorClass(webError);
81 // } 82 // }
82 // ... 83 // ...
83 // }; 84 // };
84 // OwnPtr<WebCallbacks<WebPassOwnPtr<WebMyClass>, const WebMyErrorClass&>> 85 // OwnPtr<WebCallbacks<std::unique_ptr<WebMyClass>, const WebMyErrorClass&>>
85 // callbacks = adoptPtr(new CallbackPromiseAdapter<MyClass, MyErrorClass>( 86 // callbacks = adoptPtr(new CallbackPromiseAdapter<MyClass, MyErrorClass>(
86 // resolver)); 87 // resolver));
87 // ... 88 // ...
88 // 89 //
89 // OwnPtr<WebCallbacks<bool, const WebMyErrorClass&>> callbacks2 = 90 // OwnPtr<WebCallbacks<bool, const WebMyErrorClass&>> callbacks2 =
90 // adoptPtr(new CallbackPromiseAdapter<bool, MyErrorClass>(resolver)); 91 // adoptPtr(new CallbackPromiseAdapter<bool, MyErrorClass>(resolver));
91 // ... 92 // ...
92 // 93 //
93 // 94 //
94 // In order to implement the above exceptions, we have template classes below. 95 // In order to implement the above exceptions, we have template classes below.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 template <typename T> 127 template <typename T>
127 struct PassTypeImpl<OwnPtr<T>> { 128 struct PassTypeImpl<OwnPtr<T>> {
128 using Type = PassOwnPtr<T>; 129 using Type = PassOwnPtr<T>;
129 }; 130 };
130 template <typename T> 131 template <typename T>
131 struct WebPassTypeImpl { 132 struct WebPassTypeImpl {
132 using Type = T; 133 using Type = T;
133 }; 134 };
134 template <typename T> 135 template <typename T>
135 struct WebPassTypeImpl<OwnPtr<T>> { 136 struct WebPassTypeImpl<OwnPtr<T>> {
136 using Type = WebPassOwnPtr<T>; 137 using Type = std::unique_ptr<T>;
137 }; 138 };
138 template <typename T> using PassType = typename PassTypeImpl<T>::Type; 139 template <typename T> using PassType = typename PassTypeImpl<T>::Type;
139 template <typename T> using WebPassType = typename WebPassTypeImpl<T>::Type; 140 template <typename T> using WebPassType = typename WebPassTypeImpl<T>::Type;
140 template <typename T> static T& adopt(T& x) { return x; } 141 template <typename T> static T& adopt(T& x) { return x; }
141 template <typename T> static PassOwnPtr<T> adopt(WebPassOwnPtr<T>& x) { retu rn x.release(); } 142 template <typename T>
143 static PassOwnPtr<T> adopt(std::unique_ptr<T>& x) { return adoptPtr(x.releas e()); }
142 template <typename T> static PassType<T> pass(T& x) { return x; } 144 template <typename T> static PassType<T> pass(T& x) { return x; }
143 template <typename T> static PassOwnPtr<T> pass(OwnPtr<T>& x) { return x.rel ease(); } 145 template <typename T> static PassOwnPtr<T> pass(OwnPtr<T>& x) { return x.rel ease(); }
144 146
145 template <typename S, typename T> 147 template <typename S, typename T>
146 class Base : public WebCallbacks<WebPassType<typename S::WebType>, WebPassTy pe<typename T::WebType>> { 148 class Base : public WebCallbacks<WebPassType<typename S::WebType>, WebPassTy pe<typename T::WebType>> {
147 public: 149 public:
148 explicit Base(ScriptPromiseResolver* resolver) : m_resolver(resolver) {} 150 explicit Base(ScriptPromiseResolver* resolver) : m_resolver(resolver) {}
149 ScriptPromiseResolver* resolver() { return m_resolver; } 151 ScriptPromiseResolver* resolver() { return m_resolver; }
150 152
151 private: 153 private:
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 }; 215 };
214 216
215 } // namespace internal 217 } // namespace internal
216 218
217 template <typename S, typename T> 219 template <typename S, typename T>
218 using CallbackPromiseAdapter = internal::CallbackPromiseAdapterInternal::Callbac kPromiseAdapter<S, T>; 220 using CallbackPromiseAdapter = internal::CallbackPromiseAdapterInternal::Callbac kPromiseAdapter<S, T>;
219 221
220 } // namespace blink 222 } // namespace blink
221 223
222 #endif 224 #endif
OLDNEW
« no previous file with comments | « content/renderer/usb/web_usb_device_impl.cc ('k') | third_party/WebKit/Source/modules/background_sync/SyncCallbacks.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698