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

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

Issue 2570193002: Rename OnError to OnErrorAdapter and OnSuccess to OnSucessAdapter. (Closed)
Patch Set: Created 4 years 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 // new CallbackPromiseAdapter<MyClass, MyErrorClass>(resolver)); 87 // new CallbackPromiseAdapter<MyClass, MyErrorClass>(resolver));
88 // ... 88 // ...
89 // 89 //
90 // std::unique_ptr<WebCallbacks<bool, const WebMyErrorClass&>> callbacks2 = 90 // std::unique_ptr<WebCallbacks<bool, const WebMyErrorClass&>> callbacks2 =
91 // WTF::wrapUnique( 91 // WTF::wrapUnique(
92 // new CallbackPromiseAdapter<bool, MyErrorClass>(resolver)); 92 // new CallbackPromiseAdapter<bool, MyErrorClass>(resolver));
93 // ... 93 // ...
94 // 94 //
95 // 95 //
96 // In order to implement the above exceptions, we have template classes below. 96 // In order to implement the above exceptions, we have template classes below.
97 // OnSuccess and OnError provide onSuccess and onError implementation, and there 97 // OnSuccessAdapter and OnErrorAdapter provide onSuccess and onError
98 // are utility templates that provide the trivial WebType holder. 98 // implementation, and there are utility templates that provide the trivial
99 // WebType holder.
99 100
100 namespace internal { 101 namespace internal {
101 102
102 // This template is placed outside of CallbackPromiseAdapterInternal because 103 // This template is placed outside of CallbackPromiseAdapterInternal because
103 // explicit specialization is forbidden in a class scope. 104 // explicit specialization is forbidden in a class scope.
104 template <typename T> 105 template <typename T>
105 struct CallbackPromiseAdapterTrivialWebTypeHolder { 106 struct CallbackPromiseAdapterTrivialWebTypeHolder {
106 using WebType = T; 107 using WebType = T;
107 static T take(ScriptPromiseResolver*, const T& x) { return x; } 108 static T take(ScriptPromiseResolver*, const T& x) { return x; }
108 }; 109 };
(...skipping 17 matching lines...) Expand all
126 class Base : public WebCallbacks<typename S::WebType, typename T::WebType> { 127 class Base : public WebCallbacks<typename S::WebType, typename T::WebType> {
127 public: 128 public:
128 explicit Base(ScriptPromiseResolver* resolver) : m_resolver(resolver) {} 129 explicit Base(ScriptPromiseResolver* resolver) : m_resolver(resolver) {}
129 ScriptPromiseResolver* resolver() { return m_resolver; } 130 ScriptPromiseResolver* resolver() { return m_resolver; }
130 131
131 private: 132 private:
132 Persistent<ScriptPromiseResolver> m_resolver; 133 Persistent<ScriptPromiseResolver> m_resolver;
133 }; 134 };
134 135
135 template <typename S, typename T> 136 template <typename S, typename T>
136 class OnSuccess : public Base<S, T> { 137 class OnSuccessAdapter : public Base<S, T> {
137 public: 138 public:
138 explicit OnSuccess(ScriptPromiseResolver* resolver) 139 explicit OnSuccessAdapter(ScriptPromiseResolver* resolver)
139 : Base<S, T>(resolver) {} 140 : Base<S, T>(resolver) {}
140 void onSuccess(typename S::WebType result) override { 141 void onSuccess(typename S::WebType result) override {
141 ScriptPromiseResolver* resolver = this->resolver(); 142 ScriptPromiseResolver* resolver = this->resolver();
142 if (!resolver->getExecutionContext() || 143 if (!resolver->getExecutionContext() ||
143 resolver->getExecutionContext()->isContextDestroyed()) 144 resolver->getExecutionContext()->isContextDestroyed())
144 return; 145 return;
145 resolver->resolve(S::take(resolver, std::move(result))); 146 resolver->resolve(S::take(resolver, std::move(result)));
146 } 147 }
147 }; 148 };
148 template <typename T> 149 template <typename T>
149 class OnSuccess<CallbackPromiseAdapterTrivialWebTypeHolder<void>, T> 150 class OnSuccessAdapter<CallbackPromiseAdapterTrivialWebTypeHolder<void>, T>
150 : public Base<CallbackPromiseAdapterTrivialWebTypeHolder<void>, T> { 151 : public Base<CallbackPromiseAdapterTrivialWebTypeHolder<void>, T> {
151 public: 152 public:
152 explicit OnSuccess(ScriptPromiseResolver* resolver) 153 explicit OnSuccessAdapter(ScriptPromiseResolver* resolver)
153 : Base<CallbackPromiseAdapterTrivialWebTypeHolder<void>, T>(resolver) {} 154 : Base<CallbackPromiseAdapterTrivialWebTypeHolder<void>, T>(resolver) {}
154 void onSuccess() override { 155 void onSuccess() override {
155 ScriptPromiseResolver* resolver = this->resolver(); 156 ScriptPromiseResolver* resolver = this->resolver();
156 if (!resolver->getExecutionContext() || 157 if (!resolver->getExecutionContext() ||
157 resolver->getExecutionContext()->isContextDestroyed()) 158 resolver->getExecutionContext()->isContextDestroyed())
158 return; 159 return;
159 resolver->resolve(); 160 resolver->resolve();
160 } 161 }
161 }; 162 };
162 template <typename S, typename T> 163 template <typename S, typename T>
163 class OnError : public OnSuccess<S, T> { 164 class OnErrorAdapter : public OnSuccessAdapter<S, T> {
164 public: 165 public:
165 explicit OnError(ScriptPromiseResolver* resolver) 166 explicit OnErrorAdapter(ScriptPromiseResolver* resolver)
166 : OnSuccess<S, T>(resolver) {} 167 : OnSuccessAdapter<S, T>(resolver) {}
167 void onError(typename T::WebType e) override { 168 void onError(typename T::WebType e) override {
168 ScriptPromiseResolver* resolver = this->resolver(); 169 ScriptPromiseResolver* resolver = this->resolver();
169 if (!resolver->getExecutionContext() || 170 if (!resolver->getExecutionContext() ||
170 resolver->getExecutionContext()->isContextDestroyed()) 171 resolver->getExecutionContext()->isContextDestroyed())
171 return; 172 return;
172 ScriptState::Scope scope(resolver->getScriptState()); 173 ScriptState::Scope scope(resolver->getScriptState());
173 resolver->reject(T::take(resolver, std::move(e))); 174 resolver->reject(T::take(resolver, std::move(e)));
174 } 175 }
175 }; 176 };
176 template <typename S> 177 template <typename S>
177 class OnError<S, CallbackPromiseAdapterTrivialWebTypeHolder<void>> 178 class OnErrorAdapter<S, CallbackPromiseAdapterTrivialWebTypeHolder<void>>
178 : public OnSuccess<S, CallbackPromiseAdapterTrivialWebTypeHolder<void>> { 179 : public OnSuccessAdapter<
180 S,
181 CallbackPromiseAdapterTrivialWebTypeHolder<void>> {
179 public: 182 public:
180 explicit OnError(ScriptPromiseResolver* resolver) 183 explicit OnErrorAdapter(ScriptPromiseResolver* resolver)
181 : OnSuccess<S, CallbackPromiseAdapterTrivialWebTypeHolder<void>>( 184 : OnSuccessAdapter<S, CallbackPromiseAdapterTrivialWebTypeHolder<void>>(
182 resolver) {} 185 resolver) {}
183 void onError() override { 186 void onError() override {
184 ScriptPromiseResolver* resolver = this->resolver(); 187 ScriptPromiseResolver* resolver = this->resolver();
185 if (!resolver->getExecutionContext() || 188 if (!resolver->getExecutionContext() ||
186 resolver->getExecutionContext()->isContextDestroyed()) 189 resolver->getExecutionContext()->isContextDestroyed())
187 return; 190 return;
188 resolver->reject(); 191 resolver->reject();
189 } 192 }
190 }; 193 };
191 194
192 public: 195 public:
193 template <typename S, typename T> 196 template <typename S, typename T>
194 class CallbackPromiseAdapter final 197 class CallbackPromiseAdapter final
195 : public OnError<WebTypeHolder<S>, WebTypeHolder<T>> { 198 : public OnErrorAdapter<WebTypeHolder<S>, WebTypeHolder<T>> {
196 WTF_MAKE_NONCOPYABLE(CallbackPromiseAdapter); 199 WTF_MAKE_NONCOPYABLE(CallbackPromiseAdapter);
197 200
198 public: 201 public:
199 explicit CallbackPromiseAdapter(ScriptPromiseResolver* resolver) 202 explicit CallbackPromiseAdapter(ScriptPromiseResolver* resolver)
200 : OnError<WebTypeHolder<S>, WebTypeHolder<T>>(resolver) {} 203 : OnErrorAdapter<WebTypeHolder<S>, WebTypeHolder<T>>(resolver) {}
201 }; 204 };
202 }; 205 };
203 206
204 } // namespace internal 207 } // namespace internal
205 208
206 template <typename S, typename T> 209 template <typename S, typename T>
207 using CallbackPromiseAdapter = 210 using CallbackPromiseAdapter =
208 internal::CallbackPromiseAdapterInternal::CallbackPromiseAdapter<S, T>; 211 internal::CallbackPromiseAdapterInternal::CallbackPromiseAdapter<S, T>;
209 212
210 } // namespace blink 213 } // namespace blink
211 214
212 #endif 215 #endif
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698