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

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

Issue 2886843006: servificied service worker interception
Patch Set: 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 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/browser/service_worker/service_worker_controllee_request_handl er.h" 5 #include "content/browser/service_worker/service_worker_controllee_request_handl er.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 10
11 #include "base/trace_event/trace_event.h" 11 #include "base/trace_event/trace_event.h"
12 #include "content/browser/service_worker/service_worker_context_core.h" 12 #include "content/browser/service_worker/service_worker_context_core.h"
13 #include "content/browser/service_worker/service_worker_metrics.h" 13 #include "content/browser/service_worker/service_worker_metrics.h"
14 #include "content/browser/service_worker/service_worker_provider_host.h" 14 #include "content/browser/service_worker/service_worker_provider_host.h"
15 #include "content/browser/service_worker/service_worker_registration.h" 15 #include "content/browser/service_worker/service_worker_registration.h"
16 #include "content/browser/service_worker/service_worker_response_info.h" 16 #include "content/browser/service_worker/service_worker_response_info.h"
17 #include "content/browser/service_worker/service_worker_url_request_job.h" 17 #include "content/browser/service_worker/service_worker_url_request_job.h"
18 #include "content/common/resource_request_body_impl.h" 18 #include "content/common/resource_request_body_impl.h"
19 #include "content/common/service_worker/service_worker_types.h" 19 #include "content/common/service_worker/service_worker_types.h"
20 #include "content/common/service_worker/service_worker_utils.h" 20 #include "content/common/service_worker/service_worker_utils.h"
21 #include "content/public/browser/content_browser_client.h" 21 #include "content/public/browser/content_browser_client.h"
22 #include "content/public/browser/render_frame_host.h" 22 #include "content/public/browser/render_frame_host.h"
23 #include "content/public/browser/resource_request_info.h" 23 #include "content/public/browser/resource_request_info.h"
24 #include "content/public/browser/web_contents.h" 24 #include "content/public/browser/web_contents.h"
25 #include "content/public/common/browser_side_navigation_policy.h" 25 #include "content/public/common/browser_side_navigation_policy.h"
26 #include "content/public/common/content_client.h" 26 #include "content/public/common/content_client.h"
27 #include "content/public/common/resource_response_info.h" 27 #include "content/public/common/resource_response_info.h"
28 #include "mojo/public/cpp/bindings/strong_binding.h"
28 #include "net/base/load_flags.h" 29 #include "net/base/load_flags.h"
29 #include "net/base/url_util.h" 30 #include "net/base/url_util.h"
30 #include "net/url_request/url_request.h" 31 #include "net/url_request/url_request.h"
31 #include "ui/base/page_transition_types.h" 32 #include "ui/base/page_transition_types.h"
32 33
33 namespace content { 34 namespace content {
34 35
36 // Helper to support both a URLRequestJob and a URLLoaderFactory to support
37 // running with and without --enable-network-service.
38 class ServiceWorkerControlleeRequestHandler::JobWrapper {
39 public:
40 explicit JobWrapper(base::WeakPtr<ServiceWorkerURLRequestJob> url_request_job)
41 : url_request_job_(std::move(url_request_job)), factory_(nullptr) {}
42
43 // --enable-network-service.
44 explicit JobWrapper(ServiceWorkerControlleeURLLoaderFactory* factory)
45 : factory_(factory) {}
46
47 void FallbackToNetwork() {
48 if (factory_) {
49 factory_->FallbackToNetwork();
50 } else {
51 url_request_job_->FallbackToNetwork();
52 }
53 }
54
55 bool ShouldFallbackToNetwork() {
56 if (factory_) {
57 return factory_->ShouldFallbackToNetwork();
58 } else {
59 return url_request_job_->ShouldFallbackToNetwork();
60 }
61 }
62
63 ui::PageTransition GetPageTransition() {
64 if (factory_) {
65 return factory_->GetPageTransition();
66 } else {
67 const ResourceRequestInfo* info =
68 ResourceRequestInfo::ForRequest(url_request_job_->request());
69 // ResourceRequestInfo may not be set in some tests.
70 if (!info)
71 return ui::PAGE_TRANSITION_LINK;
72 return info->GetPageTransition();
73 }
74 }
75
76 size_t GetURLChainSize() const {
77 if (factory_) {
78 return factory_->GetURLChainSize();
79 } else {
80 return url_request_job_->request()->url_chain().size();
81 }
82 }
83
84 void ForwardToServiceWorker() {
85 LOG(ERROR) << "Wrapper::ForwardToServiceWorker";
86 if (factory_) {
87 factory_->ForwardToServiceWorker();
88 } else {
89 url_request_job_->ForwardToServiceWorker();
90 }
91 }
92
93 void FallbackToNetworkOrRenderer() {
94 if (factory_) {
95 factory_->FallbackToNetworkOrRenderer();
96 } else {
97 url_request_job_->FallbackToNetworkOrRenderer();
98 }
99 }
100
101 void FailDueToLostController() {
102 if (factory_) {
103 factory_->FailDueToLostController();
104 } else {
105 url_request_job_->FailDueToLostController();
106 }
107 }
108
109 bool WasCanceled() const {
110 if (factory_) {
111 return factory_->WasCanceled();
112 } else {
113 return !url_request_job_;
114 }
115 }
116
117 private:
118 base::WeakPtr<ServiceWorkerURLRequestJob> url_request_job_;
119 ServiceWorkerControlleeURLLoaderFactory* factory_;
120
121 DISALLOW_COPY_AND_ASSIGN(JobWrapper);
122 };
123
35 namespace { 124 namespace {
36 125
37 bool MaybeForwardToServiceWorker(ServiceWorkerURLRequestJob* job, 126 bool MaybeForwardToServiceWorker(
38 const ServiceWorkerVersion* version) { 127 ServiceWorkerControlleeRequestHandler::JobWrapper* job,
128 const ServiceWorkerVersion* version) {
39 DCHECK(job); 129 DCHECK(job);
40 DCHECK(version); 130 DCHECK(version);
41 DCHECK_NE(version->fetch_handler_existence(), 131 DCHECK_NE(version->fetch_handler_existence(),
42 ServiceWorkerVersion::FetchHandlerExistence::UNKNOWN); 132 ServiceWorkerVersion::FetchHandlerExistence::UNKNOWN);
43 if (version->fetch_handler_existence() == 133 if (version->fetch_handler_existence() ==
44 ServiceWorkerVersion::FetchHandlerExistence::EXISTS) { 134 ServiceWorkerVersion::FetchHandlerExistence::EXISTS) {
45 job->ForwardToServiceWorker(); 135 job->ForwardToServiceWorker();
46 return true; 136 return true;
47 } 137 }
48 138
49 job->FallbackToNetworkOrRenderer(); 139 job->FallbackToNetworkOrRenderer();
50 return false; 140 return false;
51 } 141 }
52 142
53 ui::PageTransition GetPageTransition(net::URLRequest* request) {
54 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request);
55 // ResourceRequestInfo may not be set in some tests.
56 if (!info)
57 return ui::PAGE_TRANSITION_LINK;
58 return info->GetPageTransition();
59 }
60
61 } // namespace 143 } // namespace
62 144
63 ServiceWorkerControlleeRequestHandler::ServiceWorkerControlleeRequestHandler( 145 ServiceWorkerControlleeRequestHandler::ServiceWorkerControlleeRequestHandler(
64 base::WeakPtr<ServiceWorkerContextCore> context, 146 base::WeakPtr<ServiceWorkerContextCore> context,
65 base::WeakPtr<ServiceWorkerProviderHost> provider_host, 147 base::WeakPtr<ServiceWorkerProviderHost> provider_host,
66 base::WeakPtr<storage::BlobStorageContext> blob_storage_context, 148 base::WeakPtr<storage::BlobStorageContext> blob_storage_context,
67 FetchRequestMode request_mode, 149 FetchRequestMode request_mode,
68 FetchCredentialsMode credentials_mode, 150 FetchCredentialsMode credentials_mode,
69 FetchRedirectMode redirect_mode, 151 FetchRedirectMode redirect_mode,
70 ResourceType resource_type, 152 ResourceType resource_type,
71 RequestContextType request_context_type, 153 RequestContextType request_context_type,
72 RequestContextFrameType frame_type, 154 RequestContextFrameType frame_type,
73 scoped_refptr<ResourceRequestBodyImpl> body) 155 scoped_refptr<ResourceRequestBodyImpl> body)
156 #if 0
157 NetworkFallbackCallback network_fallback_callback)
158 #endif
74 : ServiceWorkerRequestHandler(context, 159 : ServiceWorkerRequestHandler(context,
75 provider_host, 160 provider_host,
76 blob_storage_context, 161 blob_storage_context,
77 resource_type), 162 resource_type),
78 is_main_resource_load_( 163 is_main_resource_load_(
79 ServiceWorkerUtils::IsMainResourceType(resource_type)), 164 ServiceWorkerUtils::IsMainResourceType(resource_type)),
80 is_main_frame_load_(resource_type == RESOURCE_TYPE_MAIN_FRAME), 165 is_main_frame_load_(resource_type == RESOURCE_TYPE_MAIN_FRAME),
81 request_mode_(request_mode), 166 request_mode_(request_mode),
82 credentials_mode_(credentials_mode), 167 credentials_mode_(credentials_mode),
83 redirect_mode_(redirect_mode), 168 redirect_mode_(redirect_mode),
84 request_context_type_(request_context_type), 169 request_context_type_(request_context_type),
85 frame_type_(frame_type), 170 frame_type_(frame_type),
86 body_(body), 171 body_(body),
87 force_update_started_(false), 172 force_update_started_(false),
88 use_network_(false), 173 use_network_(false),
89 weak_factory_(this) {} 174 #if 0
175 network_fallback_callback_(network_fallback_callback),
176 #endif
177 weak_factory_(this) {
178 }
90 179
91 ServiceWorkerControlleeRequestHandler:: 180 ServiceWorkerControlleeRequestHandler::
92 ~ServiceWorkerControlleeRequestHandler() { 181 ~ServiceWorkerControlleeRequestHandler() {
182 LOG(ERROR) << "dead: " << stripped_url_;
183 base::debug::StackTrace st;
184 st.Print();
185
93 // Navigation triggers an update to occur shortly after the page and 186 // Navigation triggers an update to occur shortly after the page and
94 // its initial subresources load. 187 // its initial subresources load.
95 if (provider_host_ && provider_host_->active_version()) { 188 if (provider_host_ && provider_host_->active_version()) {
96 if (is_main_resource_load_ && !force_update_started_) 189 if (is_main_resource_load_ && !force_update_started_)
97 provider_host_->active_version()->ScheduleUpdate(); 190 provider_host_->active_version()->ScheduleUpdate();
98 else 191 else
99 provider_host_->active_version()->DeferScheduledUpdate(); 192 provider_host_->active_version()->DeferScheduledUpdate();
100 } 193 }
101 194
102 if (is_main_resource_load_ && provider_host_) 195 if (is_main_resource_load_ && provider_host_)
(...skipping 30 matching lines...) Expand all
133 } 226 }
134 227
135 // It's for original request (A) or redirect case (B-a or B-b). 228 // It's for original request (A) or redirect case (B-a or B-b).
136 std::unique_ptr<ServiceWorkerURLRequestJob> job( 229 std::unique_ptr<ServiceWorkerURLRequestJob> job(
137 new ServiceWorkerURLRequestJob( 230 new ServiceWorkerURLRequestJob(
138 request, network_delegate, provider_host_->client_uuid(), 231 request, network_delegate, provider_host_->client_uuid(),
139 blob_storage_context_, resource_context, request_mode_, 232 blob_storage_context_, resource_context, request_mode_,
140 credentials_mode_, redirect_mode_, resource_type_, 233 credentials_mode_, redirect_mode_, resource_type_,
141 request_context_type_, frame_type_, body_, 234 request_context_type_, frame_type_, body_,
142 ServiceWorkerFetchType::FETCH, base::nullopt, this)); 235 ServiceWorkerFetchType::FETCH, base::nullopt, this));
143 job_ = job->GetWeakPtr(); 236 job_ = base::MakeUnique<JobWrapper>(job->GetWeakPtr());
144 237
145 resource_context_ = resource_context; 238 resource_context_ = resource_context;
146 239
147 if (is_main_resource_load_) 240 if (is_main_resource_load_)
148 PrepareForMainResource(request); 241 PrepareForMainResource(request->url(), request->first_party_for_cookies());
149 else 242 else
150 PrepareForSubResource(); 243 PrepareForSubResource();
151 244
152 if (job_->ShouldFallbackToNetwork()) { 245 if (job_->ShouldFallbackToNetwork()) {
153 // If we know we can fallback to network at this point (in case 246 // If we know we can fallback to network at this point (in case
154 // the storage lookup returned immediately), just destroy the job and return 247 // the storage lookup returned immediately), just destroy the job and return
155 // NULL here to fallback to network. 248 // NULL here to fallback to network.
156 249
157 // If this is a subresource request, all subsequent requests should also use 250 // If this is a subresource request, all subsequent requests should also use
158 // the network. 251 // the network.
159 if (!is_main_resource_load_) 252 if (!is_main_resource_load_)
160 use_network_ = true; 253 use_network_ = true;
161 254
162 job.reset(); 255 job.reset();
163 ClearJob(); 256 ClearJob();
164 } 257 }
165 258
166 return job.release(); 259 return job.release();
167 } 260 }
168 261
262 mojom::URLLoaderFactoryPtr
263 ServiceWorkerControlleeRequestHandler::MaybeGetURLLoaderFactory(
264 const ResourceRequest& request,
265 ResourceContext* resource_context,
266 std::unique_ptr<ServiceWorkerRequestHandler> request_handler) {
267 LOG(ERROR)
268 << "ServiceWorkerControlleeRequestHandler::MaybeGetURLLoaderFactory: "
269 << request.url.spec();
270 ClearJob();
271 // TODO(scottmg):
272 // ServiceWorkerResponseInfo::ResetDataForRequest(request);
273
274 if (!context_ || !provider_host_) {
275 // We can't do anything other than to fall back to network.
276 return mojom::URLLoaderFactoryPtr();
277 }
278
279 DCHECK(is_main_resource_load_);
280
281 // This may get called multiple times for original and redirect requests:
282 // A. original request case: use_network_ is false, no previous location info.
283 // B. redirect or restarted request case:
284 // a) use_network_ is false if the previous location was forwarded to SW.
285 // b) use_network_ is false if the previous location was fallback.
286 // c) use_network_ is true if additional restart was required to fall back.
287
288 // Fall back to network. (Case B-c)
289 if (use_network_) {
290 // Once a subresource request has fallen back to the network once, it will
291 // never be handled by a service worker. This is not true of main frame
292 // requests.
293 if (is_main_resource_load_)
294 use_network_ = false;
295 return mojom::URLLoaderFactoryPtr();
296 }
297
298 mojom::URLLoaderFactoryPtr url_loader_factory;
299 auto factory_impl = base::MakeUnique<ServiceWorkerControlleeURLLoaderFactory>(
300 std::move(request_handler), provider_host_->client_uuid(),
301 blob_storage_context_, resource_context, request_mode_, credentials_mode_,
302 redirect_mode_, resource_type_, request_context_type_, frame_type_, body_,
303 ServiceWorkerFetchType::FETCH, base::nullopt, this);
304 auto* factory = factory_impl.get();
305 mojo::MakeStrongBinding(std::move(factory_impl),
306 mojo::MakeRequest(&url_loader_factory));
307
308 // It's for original request (A) or redirect case (B-a or B-b).
309 job_ = base::MakeUnique<JobWrapper>(factory);
310
311 resource_context_ = resource_context;
312
313 if (is_main_resource_load_)
314 PrepareForMainResource(request.url, request.first_party_for_cookies);
315
316 if (job_->ShouldFallbackToNetwork()) {
317 // If we know we can fallback to network at this point (in case
318 // the storage lookup returned immediately), just destroy the job and return
319 // NULL here to fallback to network.
320
321 // If this is a subresource request, all subsequent requests should also use
322 // the network.
323 if (!is_main_resource_load_)
324 use_network_ = true;
325
326 ClearJob();
327 return mojom::URLLoaderFactoryPtr();
328 }
329
330 LOG(ERROR) << " returning a Real Factory";
331 return url_loader_factory;
332 }
333
169 void ServiceWorkerControlleeRequestHandler::PrepareForMainResource( 334 void ServiceWorkerControlleeRequestHandler::PrepareForMainResource(
170 const net::URLRequest* request) { 335 const GURL& url,
336 const GURL& first_party_for_cookies) {
171 DCHECK(job_.get()); 337 DCHECK(job_.get());
172 DCHECK(context_); 338 DCHECK(context_);
173 DCHECK(provider_host_); 339 DCHECK(provider_host_);
174 TRACE_EVENT_ASYNC_BEGIN1( 340 TRACE_EVENT_ASYNC_BEGIN1(
175 "ServiceWorker", 341 "ServiceWorker",
176 "ServiceWorkerControlleeRequestHandler::PrepareForMainResource", 342 "ServiceWorkerControlleeRequestHandler::PrepareForMainResource",
177 job_.get(), 343 job_.get(), "URL", url.spec());
178 "URL", request->url().spec()); 344 LOG(ERROR) << "PrepareForMainResource: " << url.spec();
179 // The corresponding provider_host may already have associated a registration 345 // The corresponding provider_host may already have associated a registration
180 // in redirect case, unassociate it now. 346 // in redirect case, unassociate it now.
181 provider_host_->DisassociateRegistration(); 347 provider_host_->DisassociateRegistration();
182 348
183 // Also prevent a registrater job for establishing an association to a new 349 // Also prevent a registrater job for establishing an association to a new
184 // registration while we're finding an existing registration. 350 // registration while we're finding an existing registration.
185 provider_host_->SetAllowAssociation(false); 351 provider_host_->SetAllowAssociation(false);
186 352
187 stripped_url_ = net::SimplifyUrlForRequest(request->url()); 353 stripped_url_ = net::SimplifyUrlForRequest(url);
188 provider_host_->SetDocumentUrl(stripped_url_); 354 provider_host_->SetDocumentUrl(stripped_url_);
189 provider_host_->SetTopmostFrameUrl(request->first_party_for_cookies()); 355 provider_host_->SetTopmostFrameUrl(first_party_for_cookies);
190 context_->storage()->FindRegistrationForDocument( 356 context_->storage()->FindRegistrationForDocument(
191 stripped_url_, base::Bind(&self::DidLookupRegistrationForMainResource, 357 stripped_url_, base::Bind(&self::DidLookupRegistrationForMainResource,
192 weak_factory_.GetWeakPtr())); 358 weak_factory_.GetWeakPtr()));
193 } 359 }
194 360
195 void ServiceWorkerControlleeRequestHandler:: 361 void ServiceWorkerControlleeRequestHandler::
196 DidLookupRegistrationForMainResource( 362 DidLookupRegistrationForMainResource(
197 ServiceWorkerStatusCode status, 363 ServiceWorkerStatusCode status,
198 scoped_refptr<ServiceWorkerRegistration> registration) { 364 scoped_refptr<ServiceWorkerRegistration> registration) {
199 // The job may have been canceled and then destroyed before this was invoked. 365 // The job may have been canceled and then destroyed before this was invoked.
200 if (!job_) 366 LOG(ERROR) << "DidLookupRegistrationForMainResource: " << stripped_url_
367 << ": " << ServiceWorkerStatusToString(status);
368 if (job_->WasCanceled())
201 return; 369 return;
202 370
203 const bool need_to_update = !force_update_started_ && registration && 371 const bool need_to_update = !force_update_started_ && registration &&
204 context_->force_update_on_page_load(); 372 context_->force_update_on_page_load();
205 373
206 if (provider_host_ && !need_to_update) 374 if (provider_host_ && !need_to_update)
207 provider_host_->SetAllowAssociation(true); 375 provider_host_->SetAllowAssociation(true);
208 if (status != SERVICE_WORKER_OK || !provider_host_ || !context_) { 376 if (status != SERVICE_WORKER_OK || !provider_host_ || !context_) {
209 job_->FallbackToNetwork(); 377 job_->FallbackToNetwork();
210 TRACE_EVENT_ASYNC_END1( 378 TRACE_EVENT_ASYNC_END1(
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 "Status", status, 473 "Status", status,
306 "Info", 474 "Info",
307 "ServiceWorkerVersion is not available, so falling back to network"); 475 "ServiceWorkerVersion is not available, so falling back to network");
308 return; 476 return;
309 } 477 }
310 478
311 DCHECK_NE(active_version->fetch_handler_existence(), 479 DCHECK_NE(active_version->fetch_handler_existence(),
312 ServiceWorkerVersion::FetchHandlerExistence::UNKNOWN); 480 ServiceWorkerVersion::FetchHandlerExistence::UNKNOWN);
313 ServiceWorkerMetrics::CountControlledPageLoad( 481 ServiceWorkerMetrics::CountControlledPageLoad(
314 active_version->site_for_uma(), stripped_url_, is_main_frame_load_, 482 active_version->site_for_uma(), stripped_url_, is_main_frame_load_,
315 GetPageTransition(job_->request()), job_->request()->url_chain().size()); 483 job_->GetPageTransition(), job_->GetURLChainSize());
316 484
317 bool is_forwarded = 485 bool is_forwarded =
318 MaybeForwardToServiceWorker(job_.get(), active_version.get()); 486 MaybeForwardToServiceWorker(job_.get(), active_version.get());
319 487
320 TRACE_EVENT_ASYNC_END2( 488 TRACE_EVENT_ASYNC_END2(
321 "ServiceWorker", 489 "ServiceWorker",
322 "ServiceWorkerControlleeRequestHandler::PrepareForMainResource", 490 "ServiceWorkerControlleeRequestHandler::PrepareForMainResource",
323 job_.get(), "Status", status, "Info", 491 job_.get(), "Status", status, "Info",
324 (is_forwarded) ? "Forwarded to the ServiceWorker" 492 (is_forwarded) ? "Forwarded to the ServiceWorker"
325 : "Skipped the ServiceWorker which has no fetch handler"); 493 : "Skipped the ServiceWorker which has no fetch handler");
326 } 494 }
327 495
328 void ServiceWorkerControlleeRequestHandler::OnVersionStatusChanged( 496 void ServiceWorkerControlleeRequestHandler::OnVersionStatusChanged(
329 ServiceWorkerRegistration* registration, 497 ServiceWorkerRegistration* registration,
330 ServiceWorkerVersion* version) { 498 ServiceWorkerVersion* version) {
331 // The job may have been canceled and then destroyed before this was invoked. 499 // The job may have been canceled and then destroyed before this was invoked.
332 if (!job_) 500 if (job_->WasCanceled())
333 return; 501 return;
334 502
335 if (provider_host_) 503 if (provider_host_)
336 provider_host_->SetAllowAssociation(true); 504 provider_host_->SetAllowAssociation(true);
337 if (version != registration->active_version() || 505 if (version != registration->active_version() ||
338 version->status() != ServiceWorkerVersion::ACTIVATED || 506 version->status() != ServiceWorkerVersion::ACTIVATED ||
339 !provider_host_) { 507 !provider_host_) {
340 job_->FallbackToNetwork(); 508 job_->FallbackToNetwork();
341 return; 509 return;
342 } 510 }
343 511
344 DCHECK_NE(version->fetch_handler_existence(), 512 DCHECK_NE(version->fetch_handler_existence(),
345 ServiceWorkerVersion::FetchHandlerExistence::UNKNOWN); 513 ServiceWorkerVersion::FetchHandlerExistence::UNKNOWN);
346 ServiceWorkerMetrics::CountControlledPageLoad( 514 ServiceWorkerMetrics::CountControlledPageLoad(
347 version->site_for_uma(), stripped_url_, is_main_frame_load_, 515 version->site_for_uma(), stripped_url_, is_main_frame_load_,
348 GetPageTransition(job_->request()), job_->request()->url_chain().size()); 516 job_->GetPageTransition(), job_->GetURLChainSize());
349 517
350 provider_host_->AssociateRegistration(registration, 518 provider_host_->AssociateRegistration(registration,
351 false /* notify_controllerchange */); 519 false /* notify_controllerchange */);
352 520
353 MaybeForwardToServiceWorker(job_.get(), version); 521 MaybeForwardToServiceWorker(job_.get(), version);
354 } 522 }
355 523
356 void ServiceWorkerControlleeRequestHandler::DidUpdateRegistration( 524 void ServiceWorkerControlleeRequestHandler::DidUpdateRegistration(
357 const scoped_refptr<ServiceWorkerRegistration>& original_registration, 525 const scoped_refptr<ServiceWorkerRegistration>& original_registration,
358 ServiceWorkerStatusCode status, 526 ServiceWorkerStatusCode status,
359 const std::string& status_message, 527 const std::string& status_message,
360 int64_t registration_id) { 528 int64_t registration_id) {
361 DCHECK(force_update_started_); 529 DCHECK(force_update_started_);
362 530
363 // The job may have been canceled and then destroyed before this was invoked. 531 // The job may have been canceled and then destroyed before this was invoked.
364 if (!job_) 532 if (job_->WasCanceled())
365 return; 533 return;
366 534
367 if (!context_) { 535 if (!context_) {
368 job_->FallbackToNetwork(); 536 job_->FallbackToNetwork();
369 return; 537 return;
370 } 538 }
371 if (status != SERVICE_WORKER_OK || 539 if (status != SERVICE_WORKER_OK ||
372 !original_registration->installing_version()) { 540 !original_registration->installing_version()) {
373 // Update failed. Look up the registration again since the original 541 // Update failed. Look up the registration again since the original
374 // registration was possibly unregistered in the meantime. 542 // registration was possibly unregistered in the meantime.
375 context_->storage()->FindRegistrationForDocument( 543 context_->storage()->FindRegistrationForDocument(
376 stripped_url_, base::Bind(&self::DidLookupRegistrationForMainResource, 544 stripped_url_, base::Bind(&self::DidLookupRegistrationForMainResource,
377 weak_factory_.GetWeakPtr())); 545 weak_factory_.GetWeakPtr()));
378 return; 546 return;
379 } 547 }
380 DCHECK_EQ(original_registration->id(), registration_id); 548 DCHECK_EQ(original_registration->id(), registration_id);
381 scoped_refptr<ServiceWorkerVersion> new_version = 549 scoped_refptr<ServiceWorkerVersion> new_version =
382 original_registration->installing_version(); 550 original_registration->installing_version();
383 new_version->ReportForceUpdateToDevTools(); 551 new_version->ReportForceUpdateToDevTools();
384 new_version->set_skip_waiting(true); 552 new_version->set_skip_waiting(true);
385 new_version->RegisterStatusChangeCallback(base::Bind( 553 new_version->RegisterStatusChangeCallback(base::Bind(
386 &self::OnUpdatedVersionStatusChanged, weak_factory_.GetWeakPtr(), 554 &self::OnUpdatedVersionStatusChanged, weak_factory_.GetWeakPtr(),
387 original_registration, new_version)); 555 original_registration, new_version));
388 } 556 }
389 557
390 void ServiceWorkerControlleeRequestHandler::OnUpdatedVersionStatusChanged( 558 void ServiceWorkerControlleeRequestHandler::OnUpdatedVersionStatusChanged(
391 const scoped_refptr<ServiceWorkerRegistration>& registration, 559 const scoped_refptr<ServiceWorkerRegistration>& registration,
392 const scoped_refptr<ServiceWorkerVersion>& version) { 560 const scoped_refptr<ServiceWorkerVersion>& version) {
393 // The job may have been canceled and then destroyed before this was invoked. 561 // The job may have been canceled and then destroyed before this was invoked.
394 if (!job_) 562 if (job_->WasCanceled())
395 return; 563 return;
396 564
397 if (!context_) { 565 if (!context_) {
398 job_->FallbackToNetwork(); 566 job_->FallbackToNetwork();
399 return; 567 return;
400 } 568 }
401 if (version->status() == ServiceWorkerVersion::ACTIVATED || 569 if (version->status() == ServiceWorkerVersion::ACTIVATED ||
402 version->status() == ServiceWorkerVersion::REDUNDANT) { 570 version->status() == ServiceWorkerVersion::REDUNDANT) {
403 // When the status is REDUNDANT, the update failed (eg: script error), we 571 // When the status is REDUNDANT, the update failed (eg: script error), we
404 // continue with the incumbent version. 572 // continue with the incumbent version.
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 DCHECK(provider_host_); 636 DCHECK(provider_host_);
469 // Detach the controller so subresource requests also skip the worker. 637 // Detach the controller so subresource requests also skip the worker.
470 provider_host_->NotifyControllerLost(); 638 provider_host_->NotifyControllerLost();
471 } 639 }
472 640
473 void ServiceWorkerControlleeRequestHandler::ClearJob() { 641 void ServiceWorkerControlleeRequestHandler::ClearJob() {
474 job_.reset(); 642 job_.reset();
475 } 643 }
476 644
477 } // namespace content 645 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698