Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / content / child / service_worker / web_service_worker_provider_impl.cc
blob154dfe0281aae8a717387ef8bd2dd79bc7e73ee0
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
3 // found in the LICENSE file.
5 #include "content/child/service_worker/web_service_worker_provider_impl.h"
7 #include "content/child/service_worker/service_worker_dispatcher.h"
8 #include "content/child/service_worker/service_worker_handle_reference.h"
9 #include "content/child/service_worker/service_worker_provider_context.h"
10 #include "content/child/service_worker/web_service_worker_impl.h"
11 #include "content/child/thread_safe_sender.h"
12 #include "third_party/WebKit/public/platform/WebServiceWorkerProviderClient.h"
13 #include "third_party/WebKit/public/platform/WebURL.h"
15 using blink::WebURL;
17 namespace content {
19 WebServiceWorkerProviderImpl::WebServiceWorkerProviderImpl(
20 ThreadSafeSender* thread_safe_sender,
21 ServiceWorkerProviderContext* context)
22 : thread_safe_sender_(thread_safe_sender),
23 context_(context) {
24 DCHECK(context_);
27 WebServiceWorkerProviderImpl::~WebServiceWorkerProviderImpl() {
28 // Make sure the provider client is removed.
29 RemoveProviderClient();
32 void WebServiceWorkerProviderImpl::setClient(
33 blink::WebServiceWorkerProviderClient* client) {
34 if (!client) {
35 RemoveProviderClient();
36 return;
39 // TODO(kinuko): Here we could also register the current thread ID
40 // on the provider context so that multiple WebServiceWorkerProviderImpl
41 // (e.g. on document and on dedicated workers) can properly share
42 // the single provider context across threads. (http://crbug.com/366538
43 // for more context)
44 GetDispatcher()->AddProviderClient(context_->provider_id(), client);
46 if (!context_->controller())
47 return;
48 client->setController(
49 GetDispatcher()->GetServiceWorker(context_->controller()->info(), false),
50 false /* shouldNotifyControllerChange */);
53 void WebServiceWorkerProviderImpl::registerServiceWorker(
54 const WebURL& pattern,
55 const WebURL& script_url,
56 WebServiceWorkerRegistrationCallbacks* callbacks) {
57 GetDispatcher()->RegisterServiceWorker(
58 context_->provider_id(), pattern, script_url, callbacks);
61 void WebServiceWorkerProviderImpl::getRegistration(
62 const blink::WebURL& document_url,
63 WebServiceWorkerRegistrationCallbacks* callbacks) {
64 GetDispatcher()->GetRegistration(
65 context_->provider_id(), document_url, callbacks);
68 void WebServiceWorkerProviderImpl::getRegistrations(
69 WebServiceWorkerGetRegistrationsCallbacks* callbacks) {
70 GetDispatcher()->GetRegistrations(
71 context_->provider_id(), callbacks);
74 void WebServiceWorkerProviderImpl::getRegistrationForReady(
75 WebServiceWorkerGetRegistrationForReadyCallbacks* callbacks) {
76 GetDispatcher()->GetRegistrationForReady(context_->provider_id(), callbacks);
79 int WebServiceWorkerProviderImpl::provider_id() const {
80 return context_->provider_id();
83 void WebServiceWorkerProviderImpl::RemoveProviderClient() {
84 // Remove the provider client, but only if the dispatcher is still there.
85 // (For cleanup path we don't need to bother creating a new dispatcher)
86 ServiceWorkerDispatcher* dispatcher =
87 ServiceWorkerDispatcher::GetThreadSpecificInstance();
88 if (dispatcher)
89 dispatcher->RemoveProviderClient(context_->provider_id());
92 ServiceWorkerDispatcher* WebServiceWorkerProviderImpl::GetDispatcher() {
93 return ServiceWorkerDispatcher::GetThreadSpecificInstance();
96 } // namespace content