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

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

Issue 261533003: Populate .current when navigator.serviceWorker is accessed (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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 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" 7 #include "base/atomic_sequence_num.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "content/child/child_thread.h" 9 #include "content/child/child_thread.h"
10 #include "content/child/service_worker/service_worker_dispatcher.h" 10 #include "content/child/service_worker/service_worker_dispatcher.h"
11 #include "content/child/service_worker/service_worker_handle_reference.h"
12 #include "content/child/service_worker/service_worker_provider_context.h"
13 #include "content/child/service_worker/web_service_worker_impl.h"
11 #include "content/child/thread_safe_sender.h" 14 #include "content/child/thread_safe_sender.h"
15 #include "content/common/service_worker/service_worker_messages.h"
16 #include "third_party/WebKit/public/platform/WebServiceWorkerProviderClient.h"
12 #include "third_party/WebKit/public/platform/WebURL.h" 17 #include "third_party/WebKit/public/platform/WebURL.h"
13 18
14 using blink::WebURL; 19 using blink::WebURL;
15 20
16 namespace content { 21 namespace content {
17 22
18 WebServiceWorkerProviderImpl::WebServiceWorkerProviderImpl( 23 WebServiceWorkerProviderImpl::WebServiceWorkerProviderImpl(
19 ThreadSafeSender* thread_safe_sender, 24 ThreadSafeSender* thread_safe_sender,
20 int provider_id) 25 ServiceWorkerProviderContext* context)
21 : thread_safe_sender_(thread_safe_sender), 26 : thread_safe_sender_(thread_safe_sender),
22 provider_id_(provider_id) { 27 context_(context),
28 provider_id_(context->provider_id()) {
23 } 29 }
24 30
25 WebServiceWorkerProviderImpl::~WebServiceWorkerProviderImpl() { 31 WebServiceWorkerProviderImpl::~WebServiceWorkerProviderImpl() {
26 // Make sure the script client is removed. 32 // Make sure the script client is removed.
27 RemoveScriptClient(); 33 RemoveScriptClient();
28 } 34 }
29 35
30 void WebServiceWorkerProviderImpl::setClient( 36 void WebServiceWorkerProviderImpl::setClient(
31 blink::WebServiceWorkerProviderClient* client) { 37 blink::WebServiceWorkerProviderClient* client) {
32 if (client) 38 if (!client) {
33 GetDispatcher()->AddScriptClient(provider_id_, client);
34 else
35 RemoveScriptClient(); 39 RemoveScriptClient();
40 return;
41 }
42
43 // TODO(kinuko): Here we could also register the current thread ID
44 // on the provider context so that multiple WebServiceWorkerProviderImpl
45 // (e.g. on document and on dedicated workers) can properly share
46 // the single provider context across threads. (http://crbug.com/366538
47 // for more context)
48 scoped_ptr<ServiceWorkerHandleReference> current =
49 context_->GetCurrentServiceWorkerHandle();
50 GetDispatcher()->AddScriptClient(provider_id_, client);
51 if (!current)
52 return;
53
54 int handle_id = current->info().handle_id;
55 if (handle_id != kInvalidServiceWorkerHandleId) {
56 scoped_ptr<WebServiceWorkerImpl> worker(
57 new WebServiceWorkerImpl(current.Pass(), thread_safe_sender_));
58 client->setCurrentServiceWorker(worker.release());
59 }
36 } 60 }
37 61
38 void WebServiceWorkerProviderImpl::registerServiceWorker( 62 void WebServiceWorkerProviderImpl::registerServiceWorker(
39 const WebURL& pattern, 63 const WebURL& pattern,
40 const WebURL& script_url, 64 const WebURL& script_url,
41 WebServiceWorkerCallbacks* callbacks) { 65 WebServiceWorkerCallbacks* callbacks) {
42 GetDispatcher()->RegisterServiceWorker( 66 GetDispatcher()->RegisterServiceWorker(
43 provider_id_, pattern, script_url, callbacks); 67 provider_id_, pattern, script_url, callbacks);
44 } 68 }
45 69
(...skipping 12 matching lines...) Expand all
58 if (dispatcher) 82 if (dispatcher)
59 dispatcher->RemoveScriptClient(provider_id_); 83 dispatcher->RemoveScriptClient(provider_id_);
60 } 84 }
61 85
62 ServiceWorkerDispatcher* WebServiceWorkerProviderImpl::GetDispatcher() { 86 ServiceWorkerDispatcher* WebServiceWorkerProviderImpl::GetDispatcher() {
63 return ServiceWorkerDispatcher::GetOrCreateThreadSpecificInstance( 87 return ServiceWorkerDispatcher::GetOrCreateThreadSpecificInstance(
64 thread_safe_sender_); 88 thread_safe_sender_);
65 } 89 }
66 90
67 } // namespace content 91 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698