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

Side by Side Diff: content/browser/service_worker/service_worker_provider_host.cc

Issue 2804843005: Implement the infrastructure of creating WorkerFetchContext in worker global scope. (Closed)
Patch Set: s/WebScheduler.h/web_scheduler.h/ Created 3 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
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 <utility> 7 #include <utility>
8 8
9 #include "base/feature_list.h"
9 #include "base/guid.h" 10 #include "base/guid.h"
10 #include "base/memory/ptr_util.h" 11 #include "base/memory/ptr_util.h"
11 #include "base/stl_util.h" 12 #include "base/stl_util.h"
12 #include "base/time/time.h" 13 #include "base/time/time.h"
13 #include "content/browser/service_worker/embedded_worker_status.h" 14 #include "content/browser/service_worker/embedded_worker_status.h"
14 #include "content/browser/service_worker/service_worker_context_core.h" 15 #include "content/browser/service_worker/service_worker_context_core.h"
15 #include "content/browser/service_worker/service_worker_context_request_handler. h" 16 #include "content/browser/service_worker/service_worker_context_request_handler. h"
16 #include "content/browser/service_worker/service_worker_controllee_request_handl er.h" 17 #include "content/browser/service_worker/service_worker_controllee_request_handl er.h"
17 #include "content/browser/service_worker/service_worker_dispatcher_host.h" 18 #include "content/browser/service_worker/service_worker_dispatcher_host.h"
18 #include "content/browser/service_worker/service_worker_handle.h" 19 #include "content/browser/service_worker/service_worker_handle.h"
19 #include "content/browser/service_worker/service_worker_registration_handle.h" 20 #include "content/browser/service_worker/service_worker_registration_handle.h"
20 #include "content/browser/service_worker/service_worker_version.h" 21 #include "content/browser/service_worker/service_worker_version.h"
21 #include "content/common/resource_request_body_impl.h" 22 #include "content/common/resource_request_body_impl.h"
22 #include "content/common/service_worker/service_worker_messages.h" 23 #include "content/common/service_worker/service_worker_messages.h"
23 #include "content/common/service_worker/service_worker_types.h" 24 #include "content/common/service_worker/service_worker_types.h"
24 #include "content/common/service_worker/service_worker_utils.h" 25 #include "content/common/service_worker/service_worker_utils.h"
25 #include "content/public/browser/content_browser_client.h" 26 #include "content/public/browser/content_browser_client.h"
26 #include "content/public/common/browser_side_navigation_policy.h" 27 #include "content/public/common/browser_side_navigation_policy.h"
27 #include "content/public/common/child_process_host.h" 28 #include "content/public/common/child_process_host.h"
28 #include "content/public/common/content_client.h" 29 #include "content/public/common/content_client.h"
30 #include "content/public/common/content_features.h"
29 #include "content/public/common/origin_util.h" 31 #include "content/public/common/origin_util.h"
32 #include "mojo/public/cpp/bindings/strong_associated_binding.h"
30 #include "net/base/url_util.h" 33 #include "net/base/url_util.h"
31 34
32 namespace content { 35 namespace content {
33 36
34 namespace { 37 namespace {
35 38
36 // PlzNavigate 39 // PlzNavigate
37 // Next ServiceWorkerProviderHost ID for navigations, starts at -2 and keeps 40 // Next ServiceWorkerProviderHost ID for navigations, starts at -2 and keeps
38 // going down. 41 // going down.
39 int g_next_navigation_provider_id = -2; 42 int g_next_navigation_provider_id = -2;
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 std::unique_ptr<ServiceWorkerProviderHost> ServiceWorkerProviderHost::Create( 108 std::unique_ptr<ServiceWorkerProviderHost> ServiceWorkerProviderHost::Create(
106 int process_id, 109 int process_id,
107 ServiceWorkerProviderHostInfo info, 110 ServiceWorkerProviderHostInfo info,
108 base::WeakPtr<ServiceWorkerContextCore> context, 111 base::WeakPtr<ServiceWorkerContextCore> context,
109 ServiceWorkerDispatcherHost* dispatcher_host) { 112 ServiceWorkerDispatcherHost* dispatcher_host) {
110 return base::WrapUnique(new ServiceWorkerProviderHost( 113 return base::WrapUnique(new ServiceWorkerProviderHost(
111 process_id, info.route_id, info.provider_id, info.type, 114 process_id, info.route_id, info.provider_id, info.type,
112 info.is_parent_frame_secure, context, dispatcher_host)); 115 info.is_parent_frame_secure, context, dispatcher_host));
113 } 116 }
114 117
118 void ServiceWorkerProviderHost::BindWorkerFetchContext(
119 mojom::ServiceWorkerWorkerClientAssociatedPtrInfo client_ptr_info) {
120 DCHECK(base::FeatureList::IsEnabled(features::kOffMainThreadFetch));
121 mojom::ServiceWorkerWorkerClientAssociatedPtr client;
122 client.Bind(std::move(client_ptr_info));
123 client.set_connection_error_handler(
124 base::Bind(&ServiceWorkerProviderHost::UnregisterWorkerFetchContext,
125 base::Unretained(this), client.get()));
126
127 if (controlling_version_)
128 client->SetControllerServiceWorker(controlling_version_->version_id());
129
130 auto result = worker_clients_.insert(
131 std::make_pair<mojom::ServiceWorkerWorkerClient*,
132 mojom::ServiceWorkerWorkerClientAssociatedPtr>(
133 client.get(), std::move(client)));
134 DCHECK(result.second);
135 }
136
137 void ServiceWorkerProviderHost::UnregisterWorkerFetchContext(
138 mojom::ServiceWorkerWorkerClient* client) {
139 DCHECK(worker_clients_.count(client));
140 worker_clients_.erase(client);
141 }
142
115 ServiceWorkerProviderHost::ServiceWorkerProviderHost( 143 ServiceWorkerProviderHost::ServiceWorkerProviderHost(
116 int render_process_id, 144 int render_process_id,
117 int route_id, 145 int route_id,
118 int provider_id, 146 int provider_id,
119 ServiceWorkerProviderType provider_type, 147 ServiceWorkerProviderType provider_type,
120 bool is_parent_frame_secure, 148 bool is_parent_frame_secure,
121 base::WeakPtr<ServiceWorkerContextCore> context, 149 base::WeakPtr<ServiceWorkerContextCore> context,
122 ServiceWorkerDispatcherHost* dispatcher_host) 150 ServiceWorkerDispatcherHost* dispatcher_host)
123 : client_uuid_(base::GenerateGUID()), 151 : client_uuid_(base::GenerateGUID()),
124 render_process_id_(render_process_id), 152 render_process_id_(render_process_id),
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 268
241 void ServiceWorkerProviderHost::SetControllerVersionAttribute( 269 void ServiceWorkerProviderHost::SetControllerVersionAttribute(
242 ServiceWorkerVersion* version, 270 ServiceWorkerVersion* version,
243 bool notify_controllerchange) { 271 bool notify_controllerchange) {
244 CHECK(!version || IsContextSecureForServiceWorker()); 272 CHECK(!version || IsContextSecureForServiceWorker());
245 if (version == controlling_version_.get()) 273 if (version == controlling_version_.get())
246 return; 274 return;
247 275
248 scoped_refptr<ServiceWorkerVersion> previous_version = controlling_version_; 276 scoped_refptr<ServiceWorkerVersion> previous_version = controlling_version_;
249 controlling_version_ = version; 277 controlling_version_ = version;
250 if (version) 278 if (version) {
251 version->AddControllee(this); 279 version->AddControllee(this);
280 for (const auto& pair : worker_clients_) {
281 pair.second->SetControllerServiceWorker(version->version_id());
282 }
283 }
252 if (previous_version.get()) 284 if (previous_version.get())
253 previous_version->RemoveControllee(this); 285 previous_version->RemoveControllee(this);
254 286
255 if (!dispatcher_host_) 287 if (!dispatcher_host_)
256 return; // Could be NULL in some tests. 288 return; // Could be NULL in some tests.
257 289
258 // SetController message should be sent only for controllees. 290 // SetController message should be sent only for controllees.
259 DCHECK(IsProviderForClient()); 291 DCHECK(IsProviderForClient());
260 Send(new ServiceWorkerMsg_SetControllerServiceWorker( 292 Send(new ServiceWorkerMsg_SetControllerServiceWorker(
261 render_thread_id_, provider_id(), GetOrCreateServiceWorkerHandle(version), 293 render_thread_id_, provider_id(), GetOrCreateServiceWorkerHandle(version),
(...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after
754 render_thread_id_, provider_id(), 786 render_thread_id_, provider_id(),
755 GetOrCreateServiceWorkerHandle( 787 GetOrCreateServiceWorkerHandle(
756 associated_registration_->active_version()), 788 associated_registration_->active_version()),
757 false /* shouldNotifyControllerChange */, 789 false /* shouldNotifyControllerChange */,
758 associated_registration_->active_version()->used_features())); 790 associated_registration_->active_version()->used_features()));
759 } 791 }
760 } 792 }
761 } 793 }
762 794
763 } // namespace content 795 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/service_worker/service_worker_provider_host.h ('k') | content/child/resource_dispatcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698