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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 // | 71 // |
72 // // call signature: callSomeMethod(WebCallbacks<MyClass, MyClass>* callback
s) | 72 // // call signature: callSomeMethod(WebCallbacks<MyClass, MyClass>* callback
s) |
73 // webObject->callSomeMethod(new CallbackPromiseAdapter<MyClass, MyClass>(res
olver, scriptExecutionContext)); | 73 // webObject->callSomeMethod(new CallbackPromiseAdapter<MyClass, MyClass>(res
olver, scriptExecutionContext)); |
74 // | 74 // |
75 // Note that this class does not manage its own lifetime. In this | 75 // Note that this class does not manage its own lifetime. In this |
76 // example that ownership of the WebCallbacks instance is being passed | 76 // example that ownership of the WebCallbacks instance is being passed |
77 // in and it is up to the callee to free the WebCallbacks instace. | 77 // in and it is up to the callee to free the WebCallbacks instace. |
78 template<typename S, typename T> | 78 template<typename S, typename T> |
79 class CallbackPromiseAdapter final : public blink::WebCallbacks<typename S::WebT
ype, typename T::WebType> { | 79 class CallbackPromiseAdapter final : public blink::WebCallbacks<typename S::WebT
ype, typename T::WebType> { |
80 public: | 80 public: |
81 explicit CallbackPromiseAdapter(PassRefPtr<ScriptPromiseResolver> resolver) | 81 explicit CallbackPromiseAdapter(PassRefPtrWillBeRawPtr<ScriptPromiseResolver
> resolver) |
82 : m_resolver(resolver) | 82 : m_resolver(resolver) |
83 { | 83 { |
84 ASSERT(m_resolver); | 84 ASSERT(m_resolver); |
85 } | 85 } |
86 virtual ~CallbackPromiseAdapter() { } | 86 virtual ~CallbackPromiseAdapter() { } |
87 | 87 |
88 virtual void onSuccess(typename S::WebType* result) override | 88 virtual void onSuccess(typename S::WebType* result) override |
89 { | 89 { |
90 if (!m_resolver->executionContext() || m_resolver->executionContext()->a
ctiveDOMObjectsAreStopped()) { | 90 if (!m_resolver->executionContext() || m_resolver->executionContext()->a
ctiveDOMObjectsAreStopped()) { |
91 S::dispose(result); | 91 S::dispose(result); |
92 return; | 92 return; |
93 } | 93 } |
94 m_resolver->resolve(S::take(m_resolver.get(), result)); | 94 m_resolver->resolve(S::take(m_resolver.get(), result)); |
95 } | 95 } |
96 | 96 |
97 virtual void onError(typename T::WebType* error) override | 97 virtual void onError(typename T::WebType* error) override |
98 { | 98 { |
99 if (!m_resolver->executionContext() || m_resolver->executionContext()->a
ctiveDOMObjectsAreStopped()) { | 99 if (!m_resolver->executionContext() || m_resolver->executionContext()->a
ctiveDOMObjectsAreStopped()) { |
100 T::dispose(error); | 100 T::dispose(error); |
101 return; | 101 return; |
102 } | 102 } |
103 m_resolver->reject(T::take(m_resolver.get(), error)); | 103 m_resolver->reject(T::take(m_resolver.get(), error)); |
104 } | 104 } |
105 | 105 |
106 private: | 106 private: |
107 RefPtr<ScriptPromiseResolver> m_resolver; | 107 RefPtrWillBePersistent<ScriptPromiseResolver> m_resolver; |
108 WTF_MAKE_NONCOPYABLE(CallbackPromiseAdapter); | 108 WTF_MAKE_NONCOPYABLE(CallbackPromiseAdapter); |
109 }; | 109 }; |
110 | 110 |
111 template<typename T> | 111 template<typename T> |
112 class CallbackPromiseAdapter<void, T> final : public blink::WebCallbacks<void, t
ypename T::WebType> { | 112 class CallbackPromiseAdapter<void, T> final : public blink::WebCallbacks<void, t
ypename T::WebType> { |
113 public: | 113 public: |
114 explicit CallbackPromiseAdapter(PassRefPtr<ScriptPromiseResolver> resolver) | 114 explicit CallbackPromiseAdapter(PassRefPtr<ScriptPromiseResolver> resolver) |
115 : m_resolver(resolver) | 115 : m_resolver(resolver) |
116 { | 116 { |
117 ASSERT(m_resolver); | 117 ASSERT(m_resolver); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 } | 166 } |
167 | 167 |
168 private: | 168 private: |
169 RefPtr<ScriptPromiseResolver> m_resolver; | 169 RefPtr<ScriptPromiseResolver> m_resolver; |
170 WTF_MAKE_NONCOPYABLE(CallbackPromiseAdapter); | 170 WTF_MAKE_NONCOPYABLE(CallbackPromiseAdapter); |
171 }; | 171 }; |
172 | 172 |
173 } // namespace blink | 173 } // namespace blink |
174 | 174 |
175 #endif | 175 #endif |
OLD | NEW |