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

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

Issue 309503014: Make ServiceWorkerDispatcher reuse existing WebServiceWorkerImpls. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Correct comment. Created 6 years, 6 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 18 matching lines...) Expand all
29 dispatcher->AddProviderContext(this); 29 dispatcher->AddProviderContext(this);
30 } 30 }
31 31
32 ServiceWorkerProviderContext::~ServiceWorkerProviderContext() { 32 ServiceWorkerProviderContext::~ServiceWorkerProviderContext() {
33 if (ServiceWorkerDispatcher* dispatcher = 33 if (ServiceWorkerDispatcher* dispatcher =
34 ServiceWorkerDispatcher::GetThreadSpecificInstance()) { 34 ServiceWorkerDispatcher::GetThreadSpecificInstance()) {
35 dispatcher->RemoveProviderContext(this); 35 dispatcher->RemoveProviderContext(this);
36 } 36 }
37 } 37 }
38 38
39 scoped_ptr<ServiceWorkerHandleReference> 39 ServiceWorkerHandleReference* ServiceWorkerProviderContext::current() {
40 ServiceWorkerProviderContext::GetCurrentServiceWorkerHandle() {
41 DCHECK(main_thread_loop_proxy_->RunsTasksOnCurrentThread()); 40 DCHECK(main_thread_loop_proxy_->RunsTasksOnCurrentThread());
42 if (!current_) 41 return current_.get();
43 return scoped_ptr<ServiceWorkerHandleReference>();
44 return ServiceWorkerHandleReference::Create(
45 current_->info(), thread_safe_sender_);
46 } 42 }
47 43
48 void ServiceWorkerProviderContext::OnServiceWorkerStateChanged( 44 void ServiceWorkerProviderContext::OnServiceWorkerStateChanged(
49 int handle_id, 45 int handle_id,
50 blink::WebServiceWorkerState state) { 46 blink::WebServiceWorkerState state) {
51 // Currently .current is the only ServiceWorker associated to this provider. 47 // Currently .current is the only ServiceWorker associated to this provider.
52 DCHECK_EQ(current_handle_id(), handle_id); 48 DCHECK_EQ(current_handle_id(), handle_id);
53 current_->set_state(state); 49 current_->set_state(state);
54 50
55 // TODO(kinuko): We can forward the message to other threads here 51 // TODO(kinuko): We can forward the message to other threads here
56 // when we support navigator.serviceWorker in dedicated workers. 52 // when we support navigator.serviceWorker in dedicated workers.
57 } 53 }
58 54
59 void ServiceWorkerProviderContext::OnSetCurrentServiceWorker( 55 void ServiceWorkerProviderContext::OnSetCurrentServiceWorker(
60 int provider_id, 56 int provider_id,
61 const ServiceWorkerObjectInfo& info) { 57 const ServiceWorkerObjectInfo& info) {
62 DCHECK_EQ(provider_id_, provider_id); 58 DCHECK_EQ(provider_id_, provider_id);
63 59
64 // This context is is the primary owner of this handle, keeps the 60 // This context is is the primary owner of this handle, keeps the
65 // initial reference until it goes away. 61 // initial reference until it goes away.
66 current_ = ServiceWorkerHandleReference::CreateForDeleter( 62 current_ = ServiceWorkerHandleReference::Adopt(info, thread_safe_sender_);
67 info, thread_safe_sender_);
68 63
69 // TODO(kinuko): We can forward the message to other threads here 64 // TODO(kinuko): We can forward the message to other threads here
70 // when we support navigator.serviceWorker in dedicated workers. 65 // when we support navigator.serviceWorker in dedicated workers.
71 } 66 }
72 67
73 int ServiceWorkerProviderContext::current_handle_id() const { 68 int ServiceWorkerProviderContext::current_handle_id() const {
74 DCHECK(main_thread_loop_proxy_->RunsTasksOnCurrentThread()); 69 DCHECK(main_thread_loop_proxy_->RunsTasksOnCurrentThread());
75 return current_ ? current_->info().handle_id : kInvalidServiceWorkerHandleId; 70 return current_ ? current_->info().handle_id : kInvalidServiceWorkerHandleId;
76 } 71 }
77 72
78 } // namespace content 73 } // namespace content
OLDNEW
« no previous file with comments | « content/child/service_worker/service_worker_provider_context.h ('k') | content/child/service_worker/web_service_worker_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698