Commit d9255995 authored by Takashi Toyoshima's avatar Takashi Toyoshima Committed by Commit Bot

OOR-CORS: call Resource::SetSourceOrigin on each Resource creation

This is a preparation to merge the source origin and the fetcher origin
in Resource. Now the source origin is set when the Resource is cacheable,
or for preloads.

With this logic, in most cases, SetSourceOrigin is called twice, or
isn't called for some cases that do not need the origin for managing
the memory cache.

This patch makes the origin available on each Resource creation
so that all Resource instances can have it to be used for another
purpose, e.g. caching meta information for SW, and so on.

Bug: 803766
Change-Id: Ib03fbe52f473d6cf70a5920c94f4bf421d851334
Reviewed-on: https://chromium-review.googlesource.com/940364Reviewed-by: default avatarYutaka Hirano <yhirano@chromium.org>
Commit-Queue: Takashi Toyoshima <toyoshim@chromium.org>
Cr-Commit-Position: refs/heads/master@{#541392}
parent 63237231
...@@ -466,6 +466,7 @@ Resource* ResourceFetcher::ResourceForStaticData( ...@@ -466,6 +466,7 @@ Resource* ResourceFetcher::ResourceForStaticData(
resource->SetResourceBuffer(data); resource->SetResourceBuffer(data);
resource->SetIdentifier(CreateUniqueIdentifier()); resource->SetIdentifier(CreateUniqueIdentifier());
resource->SetCacheIdentifier(cache_identifier); resource->SetCacheIdentifier(cache_identifier);
resource->SetSourceOrigin(GetSourceOrigin(params.Options()));
resource->Finish(0.0, Context().GetLoadingTaskRunner().get()); resource->Finish(0.0, Context().GetLoadingTaskRunner().get());
if (!substitute_data.IsValid()) if (!substitute_data.IsValid())
...@@ -482,6 +483,7 @@ Resource* ResourceFetcher::ResourceForBlockedRequest( ...@@ -482,6 +483,7 @@ Resource* ResourceFetcher::ResourceForBlockedRequest(
params.GetResourceRequest(), params.Options(), params.DecoderOptions()); params.GetResourceRequest(), params.Options(), params.DecoderOptions());
resource->SetStatus(ResourceStatus::kPending); resource->SetStatus(ResourceStatus::kPending);
resource->NotifyStartLoad(); resource->NotifyStartLoad();
resource->SetSourceOrigin(GetSourceOrigin(params.Options()));
resource->FinishAsError(ResourceError::CancelledDueToAccessCheckError( resource->FinishAsError(ResourceError::CancelledDueToAccessCheckError(
params.Url(), blocked_reason), params.Url(), blocked_reason),
Context().GetLoadingTaskRunner().get()); Context().GetLoadingTaskRunner().get());
...@@ -875,8 +877,6 @@ void ResourceFetcher::AddToMemoryCacheIfNeeded(const FetchParameters& params, ...@@ -875,8 +877,6 @@ void ResourceFetcher::AddToMemoryCacheIfNeeded(const FetchParameters& params,
if (!ShouldResourceBeAddedToMemoryCache(params, resource)) if (!ShouldResourceBeAddedToMemoryCache(params, resource))
return; return;
resource->SetSourceOrigin(GetSourceOrigin(params.Options()));
GetMemoryCache()->Add(resource); GetMemoryCache()->Add(resource);
} }
...@@ -898,6 +898,7 @@ Resource* ResourceFetcher::CreateResourceForLoading( ...@@ -898,6 +898,7 @@ Resource* ResourceFetcher::CreateResourceForLoading(
resource->SetPreloadDiscoveryTime(params.PreloadDiscoveryTime()); resource->SetPreloadDiscoveryTime(params.PreloadDiscoveryTime());
} }
resource->SetCacheIdentifier(cache_identifier); resource->SetCacheIdentifier(cache_identifier);
resource->SetSourceOrigin(GetSourceOrigin(params.Options()));
AddToMemoryCacheIfNeeded(params, resource); AddToMemoryCacheIfNeeded(params, resource);
return resource; return resource;
...@@ -1011,8 +1012,6 @@ void ResourceFetcher::InsertAsPreloadIfNecessary(Resource* resource, ...@@ -1011,8 +1012,6 @@ void ResourceFetcher::InsertAsPreloadIfNecessary(Resource* resource,
if (preloads_.find(key) != preloads_.end()) if (preloads_.find(key) != preloads_.end())
return; return;
resource->SetSourceOrigin(GetSourceOrigin(params.Options()));
preloads_.insert(key, resource); preloads_.insert(key, resource);
resource->MarkAsPreload(); resource->MarkAsPreload();
if (preloaded_urls_for_test_) if (preloaded_urls_for_test_)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment