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

Side by Side Diff: third_party/WebKit/Source/platform/loader/fetch/ResourceFetcher.cpp

Issue 2807533003: [WIP2] off-main-thread loading
Patch Set: call set_is_secure_context in EmbeddedSharedWorkerStub::CreateWorkerFetchContext() 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 /* 1 /*
2 Copyright (C) 1998 Lars Knoll (knoll@mpi-hd.mpg.de) 2 Copyright (C) 1998 Lars Knoll (knoll@mpi-hd.mpg.de)
3 Copyright (C) 2001 Dirk Mueller (mueller@kde.org) 3 Copyright (C) 2001 Dirk Mueller (mueller@kde.org)
4 Copyright (C) 2002 Waldo Bastian (bastian@kde.org) 4 Copyright (C) 2002 Waldo Bastian (bastian@kde.org)
5 Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All 5 Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All
6 rights reserved. 6 rights reserved.
7 Copyright (C) 2009 Torch Mobile Inc. http://www.torchmobile.com/ 7 Copyright (C) 2009 Torch Mobile Inc. http://www.torchmobile.com/
8 8
9 This library is free software; you can redistribute it and/or 9 This library is free software; you can redistribute it and/or
10 modify it under the terms of the GNU Library General Public 10 modify it under the terms of the GNU Library General Public
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 // Fall back to the network if the archive doesn't contain the resource. 416 // Fall back to the network if the archive doesn't contain the resource.
417 if (!archive_resource) 417 if (!archive_resource)
418 return nullptr; 418 return nullptr;
419 data = archive_resource->Data(); 419 data = archive_resource->Data();
420 response.SetURL(url); 420 response.SetURL(url);
421 response.SetMimeType(archive_resource->MimeType()); 421 response.SetMimeType(archive_resource->MimeType());
422 response.SetExpectedContentLength(data->size()); 422 response.SetExpectedContentLength(data->size());
423 response.SetTextEncodingName(archive_resource->TextEncoding()); 423 response.SetTextEncodingName(archive_resource->TextEncoding());
424 } 424 }
425 425
426 Resource* resource = factory.Create(params.GetResourceRequest(), 426 Resource* resource =
427 params.Options(), params.Charset()); 427 factory.Create(params.GetResourceRequest(), params.Options(),
428 params.Charset(), &Context());
428 resource->SetNeedsSynchronousCacheHit(substitute_data.ForceSynchronousLoad()); 429 resource->SetNeedsSynchronousCacheHit(substitute_data.ForceSynchronousLoad());
429 // FIXME: We should provide a body stream here. 430 // FIXME: We should provide a body stream here.
430 resource->ResponseReceived(response, nullptr); 431 resource->ResponseReceived(response, nullptr);
431 resource->SetDataBufferingPolicy(kBufferData); 432 resource->SetDataBufferingPolicy(kBufferData);
432 if (data->size()) 433 if (data->size())
433 resource->SetResourceBuffer(data); 434 resource->SetResourceBuffer(data);
434 resource->SetIdentifier(CreateUniqueIdentifier()); 435 resource->SetIdentifier(CreateUniqueIdentifier());
435 resource->SetCacheIdentifier(cache_identifier); 436 resource->SetCacheIdentifier(cache_identifier);
436 resource->Finish(); 437 resource->Finish();
437 438
438 if (!substitute_data.IsValid()) 439 if (!substitute_data.IsValid())
439 GetMemoryCache()->Add(resource); 440 GetMemoryCache()->Add(resource);
440 441
441 return resource; 442 return resource;
442 } 443 }
443 444
444 Resource* ResourceFetcher::ResourceForBlockedRequest( 445 Resource* ResourceFetcher::ResourceForBlockedRequest(
445 const FetchParameters& params, 446 const FetchParameters& params,
446 const ResourceFactory& factory, 447 const ResourceFactory& factory,
447 ResourceRequestBlockedReason blocked_reason) { 448 ResourceRequestBlockedReason blocked_reason) {
448 Resource* resource = factory.Create(params.GetResourceRequest(), 449 Resource* resource =
449 params.Options(), params.Charset()); 450 factory.Create(params.GetResourceRequest(), params.Options(),
451 params.Charset(), &Context());
450 resource->GetError(ResourceError::CancelledDueToAccessCheckError( 452 resource->GetError(ResourceError::CancelledDueToAccessCheckError(
451 params.Url(), blocked_reason)); 453 params.Url(), blocked_reason));
452 return resource; 454 return resource;
453 } 455 }
454 456
455 void ResourceFetcher::MakePreloadedResourceBlockOnloadIfNeeded( 457 void ResourceFetcher::MakePreloadedResourceBlockOnloadIfNeeded(
456 Resource* resource, 458 Resource* resource,
457 const FetchParameters& params) { 459 const FetchParameters& params) {
458 // TODO(yoav): Test that non-blocking resources (video/audio/track) continue 460 // TODO(yoav): Test that non-blocking resources (video/audio/track) continue
459 // to not-block even after being preloaded and discovered. 461 // to not-block even after being preloaded and discovered.
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
582 bool is_static_data = is_data_url || substitute_data.IsValid() || archive_; 584 bool is_static_data = is_data_url || substitute_data.IsValid() || archive_;
583 if (is_static_data) { 585 if (is_static_data) {
584 resource = ResourceForStaticData(params, factory, substitute_data); 586 resource = ResourceForStaticData(params, factory, substitute_data);
585 // Abort the request if the archive doesn't contain the resource, except in 587 // Abort the request if the archive doesn't contain the resource, except in
586 // the case of data URLs which might have resources such as fonts that need 588 // the case of data URLs which might have resources such as fonts that need
587 // to be decoded only on demand. These data URLs are allowed to be 589 // to be decoded only on demand. These data URLs are allowed to be
588 // processed using the normal ResourceFetcher machinery. 590 // processed using the normal ResourceFetcher machinery.
589 if (!resource && !is_data_url && archive_) 591 if (!resource && !is_data_url && archive_)
590 return nullptr; 592 return nullptr;
591 } 593 }
592 if (!resource) { 594 if (!resource && IsMainThread()) {
593 resource = 595 resource =
594 GetMemoryCache()->ResourceForURL(params.Url(), GetCacheIdentifier()); 596 GetMemoryCache()->ResourceForURL(params.Url(), GetCacheIdentifier());
595 } 597 }
596 598
597 // If we got a preloaded resource from the cache for a non-preload request, 599 // If we got a preloaded resource from the cache for a non-preload request,
598 // we may need to make it block the onload event. 600 // we may need to make it block the onload event.
599 MakePreloadedResourceBlockOnloadIfNeeded(resource, params); 601 MakePreloadedResourceBlockOnloadIfNeeded(resource, params);
600 602
601 const RevalidationPolicy policy = DetermineRevalidationPolicy( 603 const RevalidationPolicy policy = DetermineRevalidationPolicy(
602 factory.GetType(), params, resource, is_static_data); 604 factory.GetType(), params, resource, is_static_data);
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
728 revalidating_request.SetHTTPHeaderField(HTTPNames::If_None_Match, e_tag); 730 revalidating_request.SetHTTPHeaderField(HTTPNames::If_None_Match, e_tag);
729 731
730 resource->SetRevalidatingRequest(revalidating_request); 732 resource->SetRevalidatingRequest(revalidating_request);
731 } 733 }
732 734
733 Resource* ResourceFetcher::CreateResourceForLoading( 735 Resource* ResourceFetcher::CreateResourceForLoading(
734 FetchParameters& params, 736 FetchParameters& params,
735 const String& charset, 737 const String& charset,
736 const ResourceFactory& factory) { 738 const ResourceFactory& factory) {
737 const String cache_identifier = GetCacheIdentifier(); 739 const String cache_identifier = GetCacheIdentifier();
738 DCHECK(!GetMemoryCache()->ResourceForURL(params.GetResourceRequest().Url(), 740 DCHECK(!IsMainThread() ||
741 !GetMemoryCache()->ResourceForURL(params.GetResourceRequest().Url(),
739 cache_identifier)); 742 cache_identifier));
740 743
741 RESOURCE_LOADING_DVLOG(1) << "Loading Resource for " 744 RESOURCE_LOADING_DVLOG(1) << "Loading Resource for "
742 << params.GetResourceRequest().Url().ElidedString(); 745 << params.GetResourceRequest().Url().ElidedString();
743 746
744 Resource* resource = 747 Resource* resource = factory.Create(params.GetResourceRequest(),
745 factory.Create(params.GetResourceRequest(), params.Options(), charset); 748 params.Options(), charset, &Context());
746 resource->SetLinkPreload(params.IsLinkPreload()); 749 resource->SetLinkPreload(params.IsLinkPreload());
747 if (params.IsSpeculativePreload()) { 750 if (params.IsSpeculativePreload()) {
748 resource->SetPreloadDiscoveryTime(params.PreloadDiscoveryTime()); 751 resource->SetPreloadDiscoveryTime(params.PreloadDiscoveryTime());
749 } 752 }
750 resource->SetCacheIdentifier(cache_identifier); 753 resource->SetCacheIdentifier(cache_identifier);
751 754
752 // - Don't add main resource to cache to prevent reuse. 755 // - Don't add main resource to cache to prevent reuse.
753 // - Don't add the resource if its body will not be stored. 756 // - Don't add the resource if its body will not be stored.
754 if (factory.GetType() != Resource::kMainResource && 757 if (IsMainThread() && factory.GetType() != Resource::kMainResource &&
755 params.Options().data_buffering_policy != kDoNotBufferData) { 758 params.Options().data_buffering_policy != kDoNotBufferData) {
756 GetMemoryCache()->Add(resource); 759 GetMemoryCache()->Add(resource);
757 } 760 }
758 return resource; 761 return resource;
759 } 762 }
760 763
761 void ResourceFetcher::StorePerformanceTimingInitiatorInformation( 764 void ResourceFetcher::StorePerformanceTimingInitiatorInformation(
762 Resource* resource) { 765 Resource* resource) {
763 const AtomicString& fetch_initiator = resource->Options().initiator_info.name; 766 const AtomicString& fetch_initiator = resource->Options().initiator_info.name;
764 if (fetch_initiator == FetchInitiatorTypeNames::internal) 767 if (fetch_initiator == FetchInitiatorTypeNames::internal)
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after
1242 DCHECK(loader); 1245 DCHECK(loader);
1243 // TODO(yoav): Convert CHECK to DCHECK if no crash reports come in. 1246 // TODO(yoav): Convert CHECK to DCHECK if no crash reports come in.
1244 CHECK(loaders_.Contains(loader)); 1247 CHECK(loaders_.Contains(loader));
1245 non_blocking_loaders_.insert(loader); 1248 non_blocking_loaders_.insert(loader);
1246 loaders_.erase(loader); 1249 loaders_.erase(loader);
1247 } 1250 }
1248 1251
1249 bool ResourceFetcher::StartLoad(Resource* resource) { 1252 bool ResourceFetcher::StartLoad(Resource* resource) {
1250 DCHECK(resource); 1253 DCHECK(resource);
1251 DCHECK(resource->StillNeedsLoad()); 1254 DCHECK(resource->StillNeedsLoad());
1252 if (!Context().ShouldLoadNewResource(resource->GetType())) { 1255 if (IsMainThread() && !Context().ShouldLoadNewResource(resource->GetType())) {
1253 GetMemoryCache()->Remove(resource); 1256 GetMemoryCache()->Remove(resource);
1254 return false; 1257 return false;
1255 } 1258 }
1256 1259
1257 ResourceRequest request(resource->GetResourceRequest()); 1260 ResourceRequest request(resource->GetResourceRequest());
1258 ResourceResponse response; 1261 ResourceResponse response;
1259 1262
1260 blink::probe::PlatformSendRequest probe(&Context(), resource->Identifier(), 1263 blink::probe::PlatformSendRequest probe(&Context(), resource->Identifier(),
1261 request, response, 1264 request, response,
1262 resource->Options().initiator_info); 1265 resource->Options().initiator_info);
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
1527 visitor->Trace(context_); 1530 visitor->Trace(context_);
1528 visitor->Trace(archive_); 1531 visitor->Trace(archive_);
1529 visitor->Trace(loaders_); 1532 visitor->Trace(loaders_);
1530 visitor->Trace(non_blocking_loaders_); 1533 visitor->Trace(non_blocking_loaders_);
1531 visitor->Trace(document_resources_); 1534 visitor->Trace(document_resources_);
1532 visitor->Trace(preloads_); 1535 visitor->Trace(preloads_);
1533 visitor->Trace(resource_timing_info_map_); 1536 visitor->Trace(resource_timing_info_map_);
1534 } 1537 }
1535 1538
1536 } // namespace blink 1539 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698