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

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: rebase Created 3 years, 8 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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 std::unique_ptr<ServiceWorkerProviderHost> ServiceWorkerProviderHost::Create( 105 std::unique_ptr<ServiceWorkerProviderHost> ServiceWorkerProviderHost::Create(
103 int process_id, 106 int process_id,
104 ServiceWorkerProviderHostInfo info, 107 ServiceWorkerProviderHostInfo info,
105 base::WeakPtr<ServiceWorkerContextCore> context, 108 base::WeakPtr<ServiceWorkerContextCore> context,
106 ServiceWorkerDispatcherHost* dispatcher_host) { 109 ServiceWorkerDispatcherHost* dispatcher_host) {
107 return base::WrapUnique(new ServiceWorkerProviderHost( 110 return base::WrapUnique(new ServiceWorkerProviderHost(
108 process_id, info.route_id, info.provider_id, info.type, 111 process_id, info.route_id, info.provider_id, info.type,
109 info.is_parent_frame_secure, context, dispatcher_host)); 112 info.is_parent_frame_secure, context, dispatcher_host));
110 } 113 }
111 114
115 void ServiceWorkerProviderHost::BindWorkerFetchContext(
116 mojom::ServiceWorkerWorkerClientAssociatedPtrInfo client_ptr_info) {
117 DCHECK(base::FeatureList::IsEnabled(features::kOffMainThreadFetch));
118 mojom::ServiceWorkerWorkerClientAssociatedPtr client;
119 client.Bind(std::move(client_ptr_info));
120 client.set_connection_error_handler(
121 base::Bind(&ServiceWorkerProviderHost::UnregisterWorkerFetchContext,
122 base::Unretained(this), client.get()));
123
124 if (controlling_version_)
125 client->SetControllerServiceWorker(controlling_version_->version_id());
126
127 auto result = worker_clients_.insert(
128 std::make_pair<mojom::ServiceWorkerWorkerClient*,
129 mojom::ServiceWorkerWorkerClientAssociatedPtr>(
130 client.get(), std::move(client)));
131 DCHECK(result.second);
132 }
133
134 void ServiceWorkerProviderHost::UnregisterWorkerFetchContext(
135 mojom::ServiceWorkerWorkerClient* client) {
136 DCHECK(worker_clients_.count(client));
137 worker_clients_.erase(client);
138 }
139
112 ServiceWorkerProviderHost::ServiceWorkerProviderHost( 140 ServiceWorkerProviderHost::ServiceWorkerProviderHost(
113 int render_process_id, 141 int render_process_id,
114 int route_id, 142 int route_id,
115 int provider_id, 143 int provider_id,
116 ServiceWorkerProviderType provider_type, 144 ServiceWorkerProviderType provider_type,
117 bool is_parent_frame_secure, 145 bool is_parent_frame_secure,
118 base::WeakPtr<ServiceWorkerContextCore> context, 146 base::WeakPtr<ServiceWorkerContextCore> context,
119 ServiceWorkerDispatcherHost* dispatcher_host) 147 ServiceWorkerDispatcherHost* dispatcher_host)
120 : client_uuid_(base::GenerateGUID()), 148 : client_uuid_(base::GenerateGUID()),
121 render_process_id_(render_process_id), 149 render_process_id_(render_process_id),
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 265
238 void ServiceWorkerProviderHost::SetControllerVersionAttribute( 266 void ServiceWorkerProviderHost::SetControllerVersionAttribute(
239 ServiceWorkerVersion* version, 267 ServiceWorkerVersion* version,
240 bool notify_controllerchange) { 268 bool notify_controllerchange) {
241 CHECK(!version || IsContextSecureForServiceWorker()); 269 CHECK(!version || IsContextSecureForServiceWorker());
242 if (version == controlling_version_.get()) 270 if (version == controlling_version_.get())
243 return; 271 return;
244 272
245 scoped_refptr<ServiceWorkerVersion> previous_version = controlling_version_; 273 scoped_refptr<ServiceWorkerVersion> previous_version = controlling_version_;
246 controlling_version_ = version; 274 controlling_version_ = version;
247 if (version) 275 if (version) {
248 version->AddControllee(this); 276 version->AddControllee(this);
277 for (auto it = worker_clients_.begin(); it != worker_clients_.end(); it++) {
yhirano 2017/04/21 09:18:41 optional: for (const auto& pair : worker_clients_
horo 2017/04/21 09:42:32 Done.
278 it->second->SetControllerServiceWorker(version->version_id());
279 }
280 }
249 if (previous_version.get()) 281 if (previous_version.get())
250 previous_version->RemoveControllee(this); 282 previous_version->RemoveControllee(this);
251 283
252 if (!dispatcher_host_) 284 if (!dispatcher_host_)
253 return; // Could be NULL in some tests. 285 return; // Could be NULL in some tests.
254 286
255 // SetController message should be sent only for controllees. 287 // SetController message should be sent only for controllees.
256 DCHECK(IsProviderForClient()); 288 DCHECK(IsProviderForClient());
257 Send(new ServiceWorkerMsg_SetControllerServiceWorker( 289 Send(new ServiceWorkerMsg_SetControllerServiceWorker(
258 render_thread_id_, provider_id(), GetOrCreateServiceWorkerHandle(version), 290 render_thread_id_, provider_id(), GetOrCreateServiceWorkerHandle(version),
(...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after
751 render_thread_id_, provider_id(), 783 render_thread_id_, provider_id(),
752 GetOrCreateServiceWorkerHandle( 784 GetOrCreateServiceWorkerHandle(
753 associated_registration_->active_version()), 785 associated_registration_->active_version()),
754 false /* shouldNotifyControllerChange */, 786 false /* shouldNotifyControllerChange */,
755 associated_registration_->active_version()->used_features())); 787 associated_registration_->active_version()->used_features()));
756 } 788 }
757 } 789 }
758 } 790 }
759 791
760 } // namespace content 792 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698