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

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

Issue 1023613002: ServiceWorker: Clean up WebServiceWorkerProviderImpl (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 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_provider_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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_provider_impl.h" 5 #include "content/child/service_worker/web_service_worker_provider_impl.h"
6 6
7 #include "base/atomic_sequence_num.h"
8 #include "base/logging.h"
9 #include "content/child/service_worker/service_worker_dispatcher.h" 7 #include "content/child/service_worker/service_worker_dispatcher.h"
10 #include "content/child/service_worker/service_worker_handle_reference.h" 8 #include "content/child/service_worker/service_worker_handle_reference.h"
11 #include "content/child/service_worker/service_worker_provider_context.h" 9 #include "content/child/service_worker/service_worker_provider_context.h"
12 #include "content/child/service_worker/service_worker_registration_handle_refere nce.h"
13 #include "content/child/service_worker/web_service_worker_impl.h" 10 #include "content/child/service_worker/web_service_worker_impl.h"
14 #include "content/child/service_worker/web_service_worker_registration_impl.h"
15 #include "content/child/thread_safe_sender.h" 11 #include "content/child/thread_safe_sender.h"
16 #include "content/common/service_worker/service_worker_messages.h"
17 #include "third_party/WebKit/public/platform/WebServiceWorkerProviderClient.h" 12 #include "third_party/WebKit/public/platform/WebServiceWorkerProviderClient.h"
18 #include "third_party/WebKit/public/platform/WebURL.h" 13 #include "third_party/WebKit/public/platform/WebURL.h"
19 14
20 using blink::WebURL; 15 using blink::WebURL;
21 16
22 namespace content { 17 namespace content {
23 18
24 WebServiceWorkerProviderImpl::WebServiceWorkerProviderImpl( 19 WebServiceWorkerProviderImpl::WebServiceWorkerProviderImpl(
25 ThreadSafeSender* thread_safe_sender, 20 ThreadSafeSender* thread_safe_sender,
26 ServiceWorkerProviderContext* context) 21 ServiceWorkerProviderContext* context)
27 : thread_safe_sender_(thread_safe_sender), 22 : thread_safe_sender_(thread_safe_sender),
28 context_(context), 23 context_(context) {
29 provider_id_(context->provider_id()) {
30 } 24 }
31 25
32 WebServiceWorkerProviderImpl::~WebServiceWorkerProviderImpl() { 26 WebServiceWorkerProviderImpl::~WebServiceWorkerProviderImpl() {
33 // Make sure the provider client is removed. 27 // Make sure the provider client is removed.
34 RemoveProviderClient(); 28 RemoveProviderClient();
35 } 29 }
36 30
37 void WebServiceWorkerProviderImpl::setClient( 31 void WebServiceWorkerProviderImpl::setClient(
38 blink::WebServiceWorkerProviderClient* client) { 32 blink::WebServiceWorkerProviderClient* client) {
39 if (!client) { 33 if (!client) {
40 RemoveProviderClient(); 34 RemoveProviderClient();
41 return; 35 return;
42 } 36 }
43 37
44 // TODO(kinuko): Here we could also register the current thread ID 38 // TODO(kinuko): Here we could also register the current thread ID
45 // on the provider context so that multiple WebServiceWorkerProviderImpl 39 // on the provider context so that multiple WebServiceWorkerProviderImpl
46 // (e.g. on document and on dedicated workers) can properly share 40 // (e.g. on document and on dedicated workers) can properly share
47 // the single provider context across threads. (http://crbug.com/366538 41 // the single provider context across threads. (http://crbug.com/366538
48 // for more context) 42 // for more context)
49 GetDispatcher()->AddProviderClient(provider_id_, client); 43 GetDispatcher()->AddProviderClient(context_->provider_id(), client);
50 44
51 ServiceWorkerRegistrationObjectInfo info; 45 if (!context_->controller())
52 ServiceWorkerVersionAttributes attrs;
53 if (!context_->GetRegistrationInfoAndVersionAttributes(&info, &attrs)) {
54 // This provider is not associated with any registration.
55 return; 46 return;
56 } 47 client->setController(
57 if (context_->controller_handle_id() != kInvalidServiceWorkerHandleId) { 48 GetDispatcher()->GetServiceWorker(context_->controller()->info(), false),
58 client->setController(GetDispatcher()->GetServiceWorker( 49 false /* shouldNotifyControllerChange */);
59 context_->controller()->info(), false),
60 false /* shouldNotifyControllerChange */);
61 }
62 } 50 }
63 51
64 void WebServiceWorkerProviderImpl::registerServiceWorker( 52 void WebServiceWorkerProviderImpl::registerServiceWorker(
65 const WebURL& pattern, 53 const WebURL& pattern,
66 const WebURL& script_url, 54 const WebURL& script_url,
67 WebServiceWorkerRegistrationCallbacks* callbacks) { 55 WebServiceWorkerRegistrationCallbacks* callbacks) {
68 GetDispatcher()->RegisterServiceWorker( 56 GetDispatcher()->RegisterServiceWorker(
69 provider_id_, pattern, script_url, callbacks); 57 context_->provider_id(), pattern, script_url, callbacks);
70 } 58 }
71 59
72 void WebServiceWorkerProviderImpl::unregisterServiceWorker( 60 void WebServiceWorkerProviderImpl::unregisterServiceWorker(
73 const WebURL& pattern, 61 const WebURL& pattern,
74 WebServiceWorkerUnregistrationCallbacks* callbacks) { 62 WebServiceWorkerUnregistrationCallbacks* callbacks) {
75 GetDispatcher()->UnregisterServiceWorker( 63 GetDispatcher()->UnregisterServiceWorker(
76 provider_id_, pattern, callbacks); 64 context_->provider_id(), pattern, callbacks);
77 } 65 }
78 66
79 void WebServiceWorkerProviderImpl::getRegistration( 67 void WebServiceWorkerProviderImpl::getRegistration(
80 const blink::WebURL& document_url, 68 const blink::WebURL& document_url,
81 WebServiceWorkerRegistrationCallbacks* callbacks) { 69 WebServiceWorkerRegistrationCallbacks* callbacks) {
82 GetDispatcher()->GetRegistration(provider_id_, document_url, callbacks); 70 GetDispatcher()->GetRegistration(
71 context_->provider_id(), document_url, callbacks);
83 } 72 }
84 73
85 void WebServiceWorkerProviderImpl::getRegistrationForReady( 74 void WebServiceWorkerProviderImpl::getRegistrationForReady(
86 WebServiceWorkerGetRegistrationForReadyCallbacks* callbacks) { 75 WebServiceWorkerGetRegistrationForReadyCallbacks* callbacks) {
87 GetDispatcher()->GetRegistrationForReady(provider_id_, callbacks); 76 GetDispatcher()->GetRegistrationForReady(context_->provider_id(), callbacks);
88 } 77 }
89 78
90 void WebServiceWorkerProviderImpl::RemoveProviderClient() { 79 void WebServiceWorkerProviderImpl::RemoveProviderClient() {
91 // Remove the provider client, but only if the dispatcher is still there. 80 // Remove the provider client, but only if the dispatcher is still there.
92 // (For cleanup path we don't need to bother creating a new dispatcher) 81 // (For cleanup path we don't need to bother creating a new dispatcher)
93 ServiceWorkerDispatcher* dispatcher = 82 ServiceWorkerDispatcher* dispatcher =
94 ServiceWorkerDispatcher::GetThreadSpecificInstance(); 83 ServiceWorkerDispatcher::GetThreadSpecificInstance();
95 if (dispatcher) 84 if (dispatcher)
96 dispatcher->RemoveProviderClient(provider_id_); 85 dispatcher->RemoveProviderClient(context_->provider_id());
97 } 86 }
98 87
99 ServiceWorkerDispatcher* WebServiceWorkerProviderImpl::GetDispatcher() { 88 ServiceWorkerDispatcher* WebServiceWorkerProviderImpl::GetDispatcher() {
100 return ServiceWorkerDispatcher::GetOrCreateThreadSpecificInstance( 89 return ServiceWorkerDispatcher::GetOrCreateThreadSpecificInstance(
101 thread_safe_sender_.get()); 90 thread_safe_sender_.get());
102 } 91 }
103 92
104 } // namespace content 93 } // namespace content
OLDNEW
« no previous file with comments | « content/child/service_worker/web_service_worker_provider_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698