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

Side by Side Diff: Source/modules/serviceworkers/ServiceWorkerRegistration.cpp

Issue 1267703003: Service Worker: Make ServiceWorkerRegistration.update() return a promise. (Blink 1/3) (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Overload WebServiceWorkerRegistration::update() to land patch sets across the repos. 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "config.h" 5 #include "config.h"
6 #include "ServiceWorkerRegistration.h" 6 #include "ServiceWorkerRegistration.h"
7 7
8 #include "bindings/core/v8/CallbackPromiseAdapter.h" 8 #include "bindings/core/v8/CallbackPromiseAdapter.h"
9 #include "bindings/core/v8/ScriptPromise.h" 9 #include "bindings/core/v8/ScriptPromise.h"
10 #include "bindings/core/v8/ScriptPromiseResolver.h" 10 #include "bindings/core/v8/ScriptPromiseResolver.h"
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 { 79 {
80 if (registration && !registration->proxy()) 80 if (registration && !registration->proxy())
81 delete registration; 81 delete registration;
82 } 82 }
83 83
84 String ServiceWorkerRegistration::scope() const 84 String ServiceWorkerRegistration::scope() const
85 { 85 {
86 return m_outerRegistration->scope().string(); 86 return m_outerRegistration->scope().string();
87 } 87 }
88 88
89 void ServiceWorkerRegistration::update(ScriptState* scriptState, ExceptionState& exceptionState) 89 ScriptPromise ServiceWorkerRegistration::update(ScriptState* scriptState)
90 { 90 {
91 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver:: create(scriptState);
92 ScriptPromise promise = resolver->promise();
93
91 if (!m_provider) { 94 if (!m_provider) {
92 exceptionState.throwDOMException(InvalidStateError, "Failed to update a ServiceWorkerRegistration: No associated provider is available."); 95 resolver->reject(DOMException::create(InvalidStateError, "Failed to upda te a ServiceWorkerRegistration: No associated provider is available."));
93 return; 96 return promise;
94 } 97 }
95 m_outerRegistration->update(m_provider); 98
99 m_outerRegistration->update(m_provider, new CallbackPromiseAdapter<void, Ser viceWorkerError>(resolver));
100 return promise;
96 } 101 }
97 102
98 ScriptPromise ServiceWorkerRegistration::unregister(ScriptState* scriptState) 103 ScriptPromise ServiceWorkerRegistration::unregister(ScriptState* scriptState)
99 { 104 {
100 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver:: create(scriptState); 105 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver:: create(scriptState);
101 ScriptPromise promise = resolver->promise(); 106 ScriptPromise promise = resolver->promise();
102 107
103 if (!m_provider) { 108 if (!m_provider) {
104 resolver->reject(DOMException::create(InvalidStateError, "Failed to unre gister a ServiceWorkerRegistration: No associated provider is available.")); 109 resolver->reject(DOMException::create(InvalidStateError, "Failed to unre gister a ServiceWorkerRegistration: No associated provider is available."));
105 return promise; 110 return promise;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 166
162 void ServiceWorkerRegistration::stop() 167 void ServiceWorkerRegistration::stop()
163 { 168 {
164 if (m_stopped) 169 if (m_stopped)
165 return; 170 return;
166 m_stopped = true; 171 m_stopped = true;
167 m_outerRegistration->proxyStopped(); 172 m_outerRegistration->proxyStopped();
168 } 173 }
169 174
170 } // namespace blink 175 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698