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

Side by Side Diff: content/browser/service_worker/service_worker_provider_host.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/browser/service_worker/service_worker_provider_host.h" 5 #include "content/browser/service_worker/service_worker_provider_host.h"
6 6
7 #include "base/stl_util.h" 7 #include "base/stl_util.h"
8 #include "content/browser/service_worker/service_worker_context_core.h" 8 #include "content/browser/service_worker/service_worker_context_core.h"
9 #include "content/browser/service_worker/service_worker_context_request_handler. h" 9 #include "content/browser/service_worker/service_worker_context_request_handler. h"
10 #include "content/browser/service_worker/service_worker_controllee_request_handl er.h" 10 #include "content/browser/service_worker/service_worker_controllee_request_handl er.h"
11 #include "content/browser/service_worker/service_worker_dispatcher_host.h" 11 #include "content/browser/service_worker/service_worker_dispatcher_host.h"
12 #include "content/browser/service_worker/service_worker_handle.h" 12 #include "content/browser/service_worker/service_worker_handle.h"
13 #include "content/browser/service_worker/service_worker_utils.h" 13 #include "content/browser/service_worker/service_worker_utils.h"
14 #include "content/browser/service_worker/service_worker_version.h" 14 #include "content/browser/service_worker/service_worker_version.h"
15 #include "content/common/service_worker/service_worker_messages.h" 15 #include "content/common/service_worker/service_worker_messages.h"
16 16
17 namespace content { 17 namespace content {
18 18
19 static const int kDocumentMainThreadId = 0;
20
19 ServiceWorkerProviderHost::ServiceWorkerProviderHost( 21 ServiceWorkerProviderHost::ServiceWorkerProviderHost(
20 int process_id, int provider_id, 22 int process_id, int provider_id,
21 base::WeakPtr<ServiceWorkerContextCore> context, 23 base::WeakPtr<ServiceWorkerContextCore> context,
22 ServiceWorkerDispatcherHost* dispatcher_host) 24 ServiceWorkerDispatcherHost* dispatcher_host)
23 : process_id_(process_id), 25 : process_id_(process_id),
24 provider_id_(provider_id), 26 provider_id_(provider_id),
25 context_(context), 27 context_(context),
26 dispatcher_host_(dispatcher_host) { 28 dispatcher_host_(dispatcher_host) {
27 } 29 }
28 30
29 ServiceWorkerProviderHost::~ServiceWorkerProviderHost() { 31 ServiceWorkerProviderHost::~ServiceWorkerProviderHost() {
30 if (active_version_) 32 if (active_version_)
31 active_version_->RemoveControllee(this); 33 active_version_->RemoveControllee(this);
32 if (pending_version_) 34 if (pending_version_)
33 pending_version_->RemovePendingControllee(this); 35 pending_version_->RemovePendingControllee(this);
34 } 36 }
35 37
36 void ServiceWorkerProviderHost::AddScriptClient(int thread_id) {
37 DCHECK(!ContainsKey(script_client_thread_ids_, thread_id));
38 script_client_thread_ids_.insert(thread_id);
39 }
40
41 void ServiceWorkerProviderHost::RemoveScriptClient(int thread_id) {
42 DCHECK(ContainsKey(script_client_thread_ids_, thread_id));
43 script_client_thread_ids_.erase(thread_id);
44 }
45
46 void ServiceWorkerProviderHost::SetActiveVersion( 38 void ServiceWorkerProviderHost::SetActiveVersion(
47 ServiceWorkerVersion* version) { 39 ServiceWorkerVersion* version) {
48 if (version == active_version_) 40 if (version == active_version_)
49 return; 41 return;
50 scoped_refptr<ServiceWorkerVersion> previous_version = active_version_; 42 scoped_refptr<ServiceWorkerVersion> previous_version = active_version_;
51 active_version_ = version; 43 active_version_ = version;
52 if (version) 44 if (version)
53 version->AddControllee(this); 45 version->AddControllee(this);
54 if (previous_version) 46 if (previous_version)
55 previous_version->RemoveControllee(this); 47 previous_version->RemoveControllee(this);
56 48
57 if (!dispatcher_host_) 49 if (!dispatcher_host_)
58 return; // Could be NULL in some tests. 50 return; // Could be NULL in some tests.
59 51
60 for (std::set<int>::iterator it = script_client_thread_ids_.begin(); 52 ServiceWorkerObjectInfo info;
61 it != script_client_thread_ids_.end(); 53 if (context_ && version) {
62 ++it) { 54 scoped_ptr<ServiceWorkerHandle> handle =
63 ServiceWorkerObjectInfo info; 55 ServiceWorkerHandle::Create(context_, dispatcher_host_,
64 if (context_ && version) { 56 kDocumentMainThreadId, version);
65 scoped_ptr<ServiceWorkerHandle> handle = 57 info = handle->GetObjectInfo();
66 ServiceWorkerHandle::Create(context_, dispatcher_host_, *it, version); 58 dispatcher_host_->RegisterServiceWorkerHandle(handle.Pass());
67 info = handle->GetObjectInfo();
68 dispatcher_host_->RegisterServiceWorkerHandle(handle.Pass());
69 }
70 dispatcher_host_->Send(
71 new ServiceWorkerMsg_SetCurrentServiceWorker(*it, provider_id(), info));
72 } 59 }
60 dispatcher_host_->Send(
61 new ServiceWorkerMsg_SetCurrentServiceWorker(
62 kDocumentMainThreadId, provider_id(), info));
73 } 63 }
74 64
75 void ServiceWorkerProviderHost::SetPendingVersion( 65 void ServiceWorkerProviderHost::SetPendingVersion(
76 ServiceWorkerVersion* version) { 66 ServiceWorkerVersion* version) {
77 if (version == pending_version_) 67 if (version == pending_version_)
78 return; 68 return;
79 scoped_refptr<ServiceWorkerVersion> previous_version = pending_version_; 69 scoped_refptr<ServiceWorkerVersion> previous_version = pending_version_;
80 pending_version_ = version; 70 pending_version_ = version;
81 if (version) 71 if (version)
82 version->AddPendingControllee(this); 72 version->AddPendingControllee(this);
83 if (previous_version) 73 if (previous_version)
84 previous_version->RemovePendingControllee(this); 74 previous_version->RemovePendingControllee(this);
85 75
86 if (!dispatcher_host_) 76 if (!dispatcher_host_)
87 return; // Could be NULL in some tests. 77 return; // Could be NULL in some tests.
88 78
89 for (std::set<int>::iterator it = script_client_thread_ids_.begin(); 79 // TODO(kinuko): dispatch pendingchange event to the document.
90 it != script_client_thread_ids_.end();
91 ++it) {
92 // TODO(kinuko): dispatch pendingchange event to the script clients.
93 }
94 } 80 }
95 81
96 bool ServiceWorkerProviderHost::SetHostedVersionId(int64 version_id) { 82 bool ServiceWorkerProviderHost::SetHostedVersionId(int64 version_id) {
97 if (!context_) 83 if (!context_)
98 return true; // System is shutting down. 84 return true; // System is shutting down.
99 if (active_version_) 85 if (active_version_)
100 return false; // Unexpected bad message. 86 return false; // Unexpected bad message.
101 87
102 ServiceWorkerVersion* live_version = context_->GetLiveVersion(version_id); 88 ServiceWorkerVersion* live_version = context_->GetLiveVersion(version_id);
103 if (!live_version) 89 if (!live_version)
(...skipping 22 matching lines...) Expand all
126 if (ServiceWorkerUtils::IsMainResourceType(resource_type) || 112 if (ServiceWorkerUtils::IsMainResourceType(resource_type) ||
127 active_version()) { 113 active_version()) {
128 return scoped_ptr<ServiceWorkerRequestHandler>( 114 return scoped_ptr<ServiceWorkerRequestHandler>(
129 new ServiceWorkerControlleeRequestHandler( 115 new ServiceWorkerControlleeRequestHandler(
130 context_, AsWeakPtr(), resource_type)); 116 context_, AsWeakPtr(), resource_type));
131 } 117 }
132 return scoped_ptr<ServiceWorkerRequestHandler>(); 118 return scoped_ptr<ServiceWorkerRequestHandler>();
133 } 119 }
134 120
135 } // namespace content 121 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698