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

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

Issue 354643003: ServiceWorker: Support navigator.serviceWorker.active (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 28 matching lines...) Expand all
39 ServiceWorkerHandleReference* ServiceWorkerProviderContext::installing() { 39 ServiceWorkerHandleReference* ServiceWorkerProviderContext::installing() {
40 DCHECK(main_thread_loop_proxy_->RunsTasksOnCurrentThread()); 40 DCHECK(main_thread_loop_proxy_->RunsTasksOnCurrentThread());
41 return installing_.get(); 41 return installing_.get();
42 } 42 }
43 43
44 ServiceWorkerHandleReference* ServiceWorkerProviderContext::waiting() { 44 ServiceWorkerHandleReference* ServiceWorkerProviderContext::waiting() {
45 DCHECK(main_thread_loop_proxy_->RunsTasksOnCurrentThread()); 45 DCHECK(main_thread_loop_proxy_->RunsTasksOnCurrentThread());
46 return waiting_.get(); 46 return waiting_.get();
47 } 47 }
48 48
49 ServiceWorkerHandleReference* ServiceWorkerProviderContext::active() {
50 DCHECK(main_thread_loop_proxy_->RunsTasksOnCurrentThread());
51 return active_.get();
52 }
53
49 ServiceWorkerHandleReference* ServiceWorkerProviderContext::controller() { 54 ServiceWorkerHandleReference* ServiceWorkerProviderContext::controller() {
50 DCHECK(main_thread_loop_proxy_->RunsTasksOnCurrentThread()); 55 DCHECK(main_thread_loop_proxy_->RunsTasksOnCurrentThread());
51 return controller_.get(); 56 return controller_.get();
52 } 57 }
53 58
54 void ServiceWorkerProviderContext::OnServiceWorkerStateChanged( 59 void ServiceWorkerProviderContext::OnServiceWorkerStateChanged(
55 int handle_id, 60 int handle_id,
56 blink::WebServiceWorkerState state) { 61 blink::WebServiceWorkerState state) {
57 ServiceWorkerHandleReference* which = NULL; 62 ServiceWorkerHandleReference* which = NULL;
58 if (handle_id == controller_handle_id()) { 63 if (handle_id == controller_handle_id()) {
59 which = controller_.get(); 64 which = controller_.get();
65 } else if (handle_id == active_handle_id()) {
66 which = active_.get();
michaeln 2014/07/09 02:07:05 style nit: these one line blocks don't need {}'s
nhiroki 2014/07/09 06:14:27 Done.
60 } else if (handle_id == waiting_handle_id()) { 67 } else if (handle_id == waiting_handle_id()) {
61 which = waiting_.get(); 68 which = waiting_.get();
62 } else if (handle_id == installing_handle_id()) { 69 } else if (handle_id == installing_handle_id()) {
63 which = installing_.get(); 70 which = installing_.get();
64 } 71 }
65 72
66 // We should only get messages for ServiceWorkers associated with 73 // We should only get messages for ServiceWorkers associated with
67 // this provider. 74 // this provider.
68 DCHECK(which); 75 DCHECK(which);
69 76
(...skipping 10 matching lines...) Expand all
80 installing_ = ServiceWorkerHandleReference::Adopt(info, thread_safe_sender_); 87 installing_ = ServiceWorkerHandleReference::Adopt(info, thread_safe_sender_);
81 } 88 }
82 89
83 void ServiceWorkerProviderContext::OnSetWaitingServiceWorker( 90 void ServiceWorkerProviderContext::OnSetWaitingServiceWorker(
84 int provider_id, 91 int provider_id,
85 const ServiceWorkerObjectInfo& info) { 92 const ServiceWorkerObjectInfo& info) {
86 DCHECK_EQ(provider_id_, provider_id); 93 DCHECK_EQ(provider_id_, provider_id);
87 waiting_ = ServiceWorkerHandleReference::Adopt(info, thread_safe_sender_); 94 waiting_ = ServiceWorkerHandleReference::Adopt(info, thread_safe_sender_);
88 } 95 }
89 96
97 void ServiceWorkerProviderContext::OnSetActiveServiceWorker(
98 int provider_id,
99 const ServiceWorkerObjectInfo& info) {
100 DCHECK_EQ(provider_id_, provider_id);
101 active_ = ServiceWorkerHandleReference::Adopt(info, thread_safe_sender_);
102 }
103
90 void ServiceWorkerProviderContext::OnSetControllerServiceWorker( 104 void ServiceWorkerProviderContext::OnSetControllerServiceWorker(
91 int provider_id, 105 int provider_id,
92 const ServiceWorkerObjectInfo& info) { 106 const ServiceWorkerObjectInfo& info) {
93 DCHECK_EQ(provider_id_, provider_id); 107 DCHECK_EQ(provider_id_, provider_id);
94 108
95 // This context is is the primary owner of this handle, keeps the 109 // This context is is the primary owner of this handle, keeps the
96 // initial reference until it goes away. 110 // initial reference until it goes away.
97 controller_ = ServiceWorkerHandleReference::Adopt(info, thread_safe_sender_); 111 controller_ = ServiceWorkerHandleReference::Adopt(info, thread_safe_sender_);
98 112
99 // TODO(kinuko): We can forward the message to other threads here 113 // TODO(kinuko): We can forward the message to other threads here
100 // when we support navigator.serviceWorker in dedicated workers. 114 // when we support navigator.serviceWorker in dedicated workers.
101 } 115 }
102 116
103 int ServiceWorkerProviderContext::installing_handle_id() const { 117 int ServiceWorkerProviderContext::installing_handle_id() const {
104 DCHECK(main_thread_loop_proxy_->RunsTasksOnCurrentThread()); 118 DCHECK(main_thread_loop_proxy_->RunsTasksOnCurrentThread());
105 return installing_ ? installing_->info().handle_id 119 return installing_ ? installing_->info().handle_id
106 : kInvalidServiceWorkerHandleId; 120 : kInvalidServiceWorkerHandleId;
107 } 121 }
108 122
109 int ServiceWorkerProviderContext::waiting_handle_id() const { 123 int ServiceWorkerProviderContext::waiting_handle_id() const {
110 DCHECK(main_thread_loop_proxy_->RunsTasksOnCurrentThread()); 124 DCHECK(main_thread_loop_proxy_->RunsTasksOnCurrentThread());
111 return waiting_ ? waiting_->info().handle_id 125 return waiting_ ? waiting_->info().handle_id
112 : kInvalidServiceWorkerHandleId; 126 : kInvalidServiceWorkerHandleId;
113 } 127 }
114 128
129 int ServiceWorkerProviderContext::active_handle_id() const {
130 DCHECK(main_thread_loop_proxy_->RunsTasksOnCurrentThread());
131 return active_ ? active_->info().handle_id
132 : kInvalidServiceWorkerHandleId;
133 }
134
115 int ServiceWorkerProviderContext::controller_handle_id() const { 135 int ServiceWorkerProviderContext::controller_handle_id() const {
116 DCHECK(main_thread_loop_proxy_->RunsTasksOnCurrentThread()); 136 DCHECK(main_thread_loop_proxy_->RunsTasksOnCurrentThread());
117 return controller_ ? controller_->info().handle_id 137 return controller_ ? controller_->info().handle_id
118 : kInvalidServiceWorkerHandleId; 138 : kInvalidServiceWorkerHandleId;
119 } 139 }
120 140
121 } // namespace content 141 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698