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 "base/atomic_sequence_num.h"
8 #include "base/logging.h"
9 #include "content/child/child_thread.h"
10 #include "content/child/service_worker/service_worker_dispatcher.h"
11 #include "content/child/thread_safe_sender.h"
12 #include "content/common/service_worker/service_worker_messages.h"
13 #include "third_party/WebKit/public/platform/WebURL.h"
21 // Must be unique in the child process.
22 int GetNextProviderId() {
23 static base::StaticAtomicSequenceNumber sequence
;
24 return sequence
.GetNext() + 1; // We want to start at 1.
29 WebServiceWorkerProviderImpl::WebServiceWorkerProviderImpl(
30 ThreadSafeSender
* thread_safe_sender
,
31 scoped_ptr
<blink::WebServiceWorkerProviderClient
> client
)
32 : provider_id_(GetNextProviderId()),
33 thread_safe_sender_(thread_safe_sender
),
34 client_(client
.Pass()) {
35 thread_safe_sender_
->Send(
36 new ServiceWorkerHostMsg_ProviderCreated(provider_id_
));
39 WebServiceWorkerProviderImpl::~WebServiceWorkerProviderImpl() {
40 thread_safe_sender_
->Send(
41 new ServiceWorkerHostMsg_ProviderDestroyed(provider_id_
));
44 void WebServiceWorkerProviderImpl::registerServiceWorker(
45 const WebURL
& pattern
,
46 const WebURL
& script_url
,
47 WebServiceWorkerCallbacks
* callbacks
) {
48 ServiceWorkerDispatcher::ThreadSpecificInstance(thread_safe_sender_
)
49 ->RegisterServiceWorker(pattern
, script_url
, callbacks
);
52 void WebServiceWorkerProviderImpl::unregisterServiceWorker(
53 const WebURL
& pattern
,
54 WebServiceWorkerCallbacks
* callbacks
) {
55 ServiceWorkerDispatcher::ThreadSpecificInstance(thread_safe_sender_
)
56 ->UnregisterServiceWorker(pattern
, callbacks
);
59 } // namespace content