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

Side by Side Diff: content/child/service_worker/web_service_worker_registration_impl.cc

Issue 516873002: ServiceWorker: Queue tasks until the registration proxy becomes ready (Closed) Base URL: http://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix compile errors Created 6 years, 3 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
« no previous file with comments | « content/child/service_worker/web_service_worker_registration_impl.h ('k') | 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 // 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 "content/child/service_worker/web_service_worker_registration_impl.h" 5 #include "content/child/service_worker/web_service_worker_registration_impl.h"
6 6
7 #include "content/child/service_worker/service_worker_dispatcher.h" 7 #include "content/child/service_worker/service_worker_dispatcher.h"
8 #include "content/child/service_worker/service_worker_registration_handle_refere nce.h" 8 #include "content/child/service_worker/service_worker_registration_handle_refere nce.h"
9 #include "content/child/service_worker/web_service_worker_impl.h"
9 #include "content/common/service_worker/service_worker_types.h" 10 #include "content/common/service_worker/service_worker_types.h"
10 #include "third_party/WebKit/public/platform/WebServiceWorkerRegistrationProxy.h " 11 #include "third_party/WebKit/public/platform/WebServiceWorkerRegistrationProxy.h "
11 12
12 namespace content { 13 namespace content {
13 14
15 WebServiceWorkerRegistrationImpl::QueuedTask::QueuedTask(
16 QueuedTaskType type,
17 blink::WebServiceWorker* worker)
18 : type(type),
19 worker(worker) {
20 }
21
14 WebServiceWorkerRegistrationImpl::WebServiceWorkerRegistrationImpl( 22 WebServiceWorkerRegistrationImpl::WebServiceWorkerRegistrationImpl(
15 scoped_ptr<ServiceWorkerRegistrationHandleReference> handle_ref) 23 scoped_ptr<ServiceWorkerRegistrationHandleReference> handle_ref)
16 : handle_ref_(handle_ref.Pass()), 24 : handle_ref_(handle_ref.Pass()),
17 proxy_(NULL) { 25 proxy_(NULL) {
18 DCHECK(handle_ref_); 26 DCHECK(handle_ref_);
19 DCHECK_NE(kInvalidServiceWorkerRegistrationHandleId, 27 DCHECK_NE(kInvalidServiceWorkerRegistrationHandleId,
20 handle_ref_->handle_id()); 28 handle_ref_->handle_id());
21 ServiceWorkerDispatcher* dispatcher = 29 ServiceWorkerDispatcher* dispatcher =
22 ServiceWorkerDispatcher::GetThreadSpecificInstance(); 30 ServiceWorkerDispatcher::GetThreadSpecificInstance();
23 DCHECK(dispatcher); 31 DCHECK(dispatcher);
24 dispatcher->AddServiceWorkerRegistration(handle_ref_->handle_id(), this); 32 dispatcher->AddServiceWorkerRegistration(handle_ref_->handle_id(), this);
25 } 33 }
26 34
27 WebServiceWorkerRegistrationImpl::~WebServiceWorkerRegistrationImpl() { 35 WebServiceWorkerRegistrationImpl::~WebServiceWorkerRegistrationImpl() {
28 ServiceWorkerDispatcher* dispatcher = 36 ServiceWorkerDispatcher* dispatcher =
29 ServiceWorkerDispatcher::GetThreadSpecificInstance(); 37 ServiceWorkerDispatcher::GetThreadSpecificInstance();
30 if (dispatcher) 38 if (dispatcher)
31 dispatcher->RemoveServiceWorkerRegistration(handle_ref_->handle_id()); 39 dispatcher->RemoveServiceWorkerRegistration(handle_ref_->handle_id());
40 ClearQueuedTasks();
32 } 41 }
33 42
34 void WebServiceWorkerRegistrationImpl::SetInstalling( 43 void WebServiceWorkerRegistrationImpl::SetInstalling(
35 blink::WebServiceWorker* service_worker) { 44 blink::WebServiceWorker* service_worker) {
36 DCHECK(proxy_); 45 if (proxy_)
37 proxy_->setInstalling(service_worker); 46 proxy_->setInstalling(service_worker);
47 else
48 queued_tasks_.push_back(QueuedTask(INSTALLING, service_worker));
38 } 49 }
39 50
40 void WebServiceWorkerRegistrationImpl::SetWaiting( 51 void WebServiceWorkerRegistrationImpl::SetWaiting(
41 blink::WebServiceWorker* service_worker) { 52 blink::WebServiceWorker* service_worker) {
42 DCHECK(proxy_); 53 if (proxy_)
43 proxy_->setWaiting(service_worker); 54 proxy_->setWaiting(service_worker);
55 else
56 queued_tasks_.push_back(QueuedTask(WAITING, service_worker));
44 } 57 }
45 58
46 void WebServiceWorkerRegistrationImpl::SetActive( 59 void WebServiceWorkerRegistrationImpl::SetActive(
47 blink::WebServiceWorker* service_worker) { 60 blink::WebServiceWorker* service_worker) {
48 DCHECK(proxy_); 61 if (proxy_)
49 proxy_->setActive(service_worker); 62 proxy_->setActive(service_worker);
63 else
64 queued_tasks_.push_back(QueuedTask(ACTIVE, service_worker));
50 } 65 }
51 66
52 void WebServiceWorkerRegistrationImpl::OnUpdateFound() { 67 void WebServiceWorkerRegistrationImpl::OnUpdateFound() {
53 DCHECK(proxy_); 68 if (proxy_)
54 proxy_->dispatchUpdateFoundEvent(); 69 proxy_->dispatchUpdateFoundEvent();
70 else
71 queued_tasks_.push_back(QueuedTask(UPDATE_FOUND, NULL));
55 } 72 }
56 73
57 void WebServiceWorkerRegistrationImpl::setProxy( 74 void WebServiceWorkerRegistrationImpl::setProxy(
58 blink::WebServiceWorkerRegistrationProxy* proxy) { 75 blink::WebServiceWorkerRegistrationProxy* proxy) {
59 proxy_ = proxy; 76 proxy_ = proxy;
77 RunQueuedTasks();
78 }
79
80 void WebServiceWorkerRegistrationImpl::RunQueuedTasks() {
81 DCHECK(proxy_);
82 for (std::vector<QueuedTask>::const_iterator it = queued_tasks_.begin();
83 it != queued_tasks_.end(); ++it) {
84 if (it->type == INSTALLING)
85 proxy_->setInstalling(it->worker);
86 else if (it->type == WAITING)
87 proxy_->setWaiting(it->worker);
88 else if (it->type == ACTIVE)
89 proxy_->setActive(it->worker);
90 else if (it->type == UPDATE_FOUND)
91 proxy_->dispatchUpdateFoundEvent();
92 }
93 queued_tasks_.clear();
94 }
95
96 void WebServiceWorkerRegistrationImpl::ClearQueuedTasks() {
97 for (std::vector<QueuedTask>::const_iterator it = queued_tasks_.begin();
98 it != queued_tasks_.end(); ++it) {
99 // If the owner of the WebServiceWorker does not exist, delete it.
100 if (it->worker && !it->worker->proxy())
101 delete it->worker;
102 }
103 queued_tasks_.clear();
60 } 104 }
61 105
62 blink::WebServiceWorkerRegistrationProxy* 106 blink::WebServiceWorkerRegistrationProxy*
63 WebServiceWorkerRegistrationImpl::proxy() { 107 WebServiceWorkerRegistrationImpl::proxy() {
64 return proxy_; 108 return proxy_;
65 } 109 }
66 110
67 blink::WebURL WebServiceWorkerRegistrationImpl::scope() const { 111 blink::WebURL WebServiceWorkerRegistrationImpl::scope() const {
68 return handle_ref_->scope(); 112 return handle_ref_->scope();
69 } 113 }
70 114
71 } // namespace content 115 } // namespace content
OLDNEW
« no previous file with comments | « content/child/service_worker/web_service_worker_registration_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698