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

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

Issue 369013002: ServiceWorker: Support navigator.serviceWorker.installing (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 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 | Annotate | Revision Log
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/service_worker_provider_context.h" 5 #include "content/child/service_worker/service_worker_provider_context.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/message_loop/message_loop_proxy.h" 8 #include "base/message_loop/message_loop_proxy.h"
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "content/child/child_thread.h" 10 #include "content/child/child_thread.h"
(...skipping 18 matching lines...) Expand all
29 dispatcher->AddProviderContext(this); 29 dispatcher->AddProviderContext(this);
30 } 30 }
31 31
32 ServiceWorkerProviderContext::~ServiceWorkerProviderContext() { 32 ServiceWorkerProviderContext::~ServiceWorkerProviderContext() {
33 if (ServiceWorkerDispatcher* dispatcher = 33 if (ServiceWorkerDispatcher* dispatcher =
34 ServiceWorkerDispatcher::GetThreadSpecificInstance()) { 34 ServiceWorkerDispatcher::GetThreadSpecificInstance()) {
35 dispatcher->RemoveProviderContext(this); 35 dispatcher->RemoveProviderContext(this);
36 } 36 }
37 } 37 }
38 38
39 ServiceWorkerHandleReference* ServiceWorkerProviderContext::installing() {
40 DCHECK(main_thread_loop_proxy_->RunsTasksOnCurrentThread());
41 return installing_.get();
42 }
43
39 ServiceWorkerHandleReference* ServiceWorkerProviderContext::waiting() { 44 ServiceWorkerHandleReference* ServiceWorkerProviderContext::waiting() {
40 DCHECK(main_thread_loop_proxy_->RunsTasksOnCurrentThread()); 45 DCHECK(main_thread_loop_proxy_->RunsTasksOnCurrentThread());
41 return waiting_.get(); 46 return waiting_.get();
42 } 47 }
43 48
44 ServiceWorkerHandleReference* ServiceWorkerProviderContext::controller() { 49 ServiceWorkerHandleReference* ServiceWorkerProviderContext::controller() {
45 DCHECK(main_thread_loop_proxy_->RunsTasksOnCurrentThread()); 50 DCHECK(main_thread_loop_proxy_->RunsTasksOnCurrentThread());
46 return controller_.get(); 51 return controller_.get();
47 } 52 }
48 53
49 void ServiceWorkerProviderContext::OnServiceWorkerStateChanged( 54 void ServiceWorkerProviderContext::OnServiceWorkerStateChanged(
50 int handle_id, 55 int handle_id,
51 blink::WebServiceWorkerState state) { 56 blink::WebServiceWorkerState state) {
52 ServiceWorkerHandleReference* which = NULL; 57 ServiceWorkerHandleReference* which = NULL;
53 if (handle_id == controller_handle_id()) { 58 if (handle_id == controller_handle_id()) {
54 which = controller_.get(); 59 which = controller_.get();
55 } else if (handle_id == waiting_handle_id()) { 60 } else if (handle_id == waiting_handle_id()) {
56 which = waiting_.get(); 61 which = waiting_.get();
62 } else if (handle_id == installing_handle_id()) {
63 which = installing_.get();
57 } 64 }
58 65
59 // We should only get messages for ServiceWorkers associated with 66 // We should only get messages for ServiceWorkers associated with
60 // this provider. 67 // this provider.
61 DCHECK(which); 68 DCHECK(which);
62 69
63 which->set_state(state); 70 which->set_state(state);
64 71
65 // TODO(kinuko): We can forward the message to other threads here 72 // TODO(kinuko): We can forward the message to other threads here
66 // when we support navigator.serviceWorker in dedicated workers. 73 // when we support navigator.serviceWorker in dedicated workers.
67 } 74 }
68 75
76 void ServiceWorkerProviderContext::OnSetInstallingServiceWorker(
77 int provider_id,
78 const ServiceWorkerObjectInfo& info) {
79 DCHECK_EQ(provider_id_, provider_id);
80 installing_ = ServiceWorkerHandleReference::Adopt(info, thread_safe_sender_);
81 }
82
69 void ServiceWorkerProviderContext::OnSetWaitingServiceWorker( 83 void ServiceWorkerProviderContext::OnSetWaitingServiceWorker(
70 int provider_id, 84 int provider_id,
71 const ServiceWorkerObjectInfo& info) { 85 const ServiceWorkerObjectInfo& info) {
72 DCHECK_EQ(provider_id_, provider_id); 86 DCHECK_EQ(provider_id_, provider_id);
73 waiting_ = ServiceWorkerHandleReference::Adopt(info, thread_safe_sender_); 87 waiting_ = ServiceWorkerHandleReference::Adopt(info, thread_safe_sender_);
74 } 88 }
75 89
76 void ServiceWorkerProviderContext::OnSetControllerServiceWorker( 90 void ServiceWorkerProviderContext::OnSetControllerServiceWorker(
77 int provider_id, 91 int provider_id,
78 const ServiceWorkerObjectInfo& info) { 92 const ServiceWorkerObjectInfo& info) {
79 DCHECK_EQ(provider_id_, provider_id); 93 DCHECK_EQ(provider_id_, provider_id);
80 94
81 // This context is is the primary owner of this handle, keeps the 95 // This context is is the primary owner of this handle, keeps the
82 // initial reference until it goes away. 96 // initial reference until it goes away.
83 controller_ = ServiceWorkerHandleReference::Adopt(info, thread_safe_sender_); 97 controller_ = ServiceWorkerHandleReference::Adopt(info, thread_safe_sender_);
84 98
85 // TODO(kinuko): We can forward the message to other threads here 99 // TODO(kinuko): We can forward the message to other threads here
86 // when we support navigator.serviceWorker in dedicated workers. 100 // when we support navigator.serviceWorker in dedicated workers.
87 } 101 }
88 102
103 int ServiceWorkerProviderContext::installing_handle_id() const {
104 DCHECK(main_thread_loop_proxy_->RunsTasksOnCurrentThread());
105 return installing_ ? installing_->info().handle_id
106 : kInvalidServiceWorkerHandleId;
107 }
108
109 int ServiceWorkerProviderContext::waiting_handle_id() const {
110 DCHECK(main_thread_loop_proxy_->RunsTasksOnCurrentThread());
111 return waiting_ ? waiting_->info().handle_id
112 : kInvalidServiceWorkerHandleId;
113 }
114
89 int ServiceWorkerProviderContext::controller_handle_id() const { 115 int ServiceWorkerProviderContext::controller_handle_id() const {
90 DCHECK(main_thread_loop_proxy_->RunsTasksOnCurrentThread()); 116 DCHECK(main_thread_loop_proxy_->RunsTasksOnCurrentThread());
91 return controller_ ? controller_->info().handle_id 117 return controller_ ? controller_->info().handle_id
92 : kInvalidServiceWorkerHandleId; 118 : kInvalidServiceWorkerHandleId;
93 } 119 }
94 120
95 int ServiceWorkerProviderContext::waiting_handle_id() const {
96 DCHECK(main_thread_loop_proxy_->RunsTasksOnCurrentThread());
97 return waiting_ ? waiting_->info().handle_id : kInvalidServiceWorkerHandleId;
98 }
99
100 } // namespace content 121 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698