Commit 4b628d14 authored by Kenichi Ishibashi's avatar Kenichi Ishibashi Committed by Commit Bot

Remove ServiceWorkerUtils::ResourceResponseHeadAndMetadata

It was used only from DidReadInfo() in service_worker_disk_cache.cc
to convert an HttpResponseInfo to URLResponseHead. Since
service_worker_disk_cache.cc will be moved to the storage service
it wouldn't be able to depend on content/. Move conversion logic
to DidReadInfo() and remove ResourceResponseHeadAndMetadata.

Bug: 1055677
Change-Id: I379fc52fcb41fb97f67045492cc8b4d743813398
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2309609Reviewed-by: default avatarMakoto Shimazu <shimazu@chromium.org>
Commit-Queue: Kenichi Ishibashi <bashi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#790304}
parent 6b1a0c46
......@@ -6,7 +6,6 @@
#include <utility>
#include "content/common/service_worker/service_worker_utils.h"
#include "net/base/io_buffer.h"
#include "services/network/public/mojom/url_loader_factory.mojom.h"
......@@ -25,16 +24,29 @@ void DidReadInfo(base::WeakPtr<AppCacheResponseIO> reader,
return;
}
DCHECK(io_buffer->http_info);
auto response_and_metadata =
ServiceWorkerUtils::CreateResourceResponseHeadAndMetadata(
io_buffer->http_info.get(),
/*options=*/network::mojom::kURLLoadOptionSendSSLInfoWithResponse,
/*request_start_time=*/base::TimeTicks(),
/*response_start_time=*/base::TimeTicks::Now(),
io_buffer->response_data_size);
std::move(callback).Run(result, std::move(response_and_metadata.head),
std::move(response_and_metadata.metadata));
const net::HttpResponseInfo* http_info = io_buffer->http_info.get();
DCHECK(http_info);
DCHECK(http_info->headers);
auto head = network::mojom::URLResponseHead::New();
head->request_start = base::TimeTicks();
head->response_start = base::TimeTicks::Now();
head->request_time = http_info->request_time;
head->response_time = http_info->response_time;
head->headers = http_info->headers;
head->headers->GetMimeType(&head->mime_type);
head->headers->GetCharset(&head->charset);
head->content_length = io_buffer->response_data_size;
head->was_fetched_via_spdy = http_info->was_fetched_via_spdy;
head->was_alpn_negotiated = http_info->was_alpn_negotiated;
head->connection_info = http_info->connection_info;
head->alpn_negotiated_protocol = http_info->alpn_negotiated_protocol;
head->remote_endpoint = http_info->remote_endpoint;
head->cert_status = http_info->ssl_info.cert_status;
head->ssl_info = http_info->ssl_info;
std::move(callback).Run(result, std::move(head),
std::move(http_info->metadata));
}
} // namespace
......@@ -63,11 +75,6 @@ void ServiceWorkerResponseWriter::WriteResponseHead(
const network::mojom::URLResponseHead& response_head,
int response_data_size,
net::CompletionOnceCallback callback) {
// This is copied from CreateHttpResponseInfoAndCheckHeaders().
// TODO(bashi): Use CreateHttpResponseInfoAndCheckHeaders()
// once we remove URLResponseHead -> HttpResponseInfo -> URLResponseHead
// conversion, which drops some information needed for validation
// (e.g. mime type).
auto response_info = std::make_unique<net::HttpResponseInfo>();
response_info->headers = response_head.headers;
if (response_head.ssl_info.has_value())
......
......@@ -13,11 +13,8 @@
#include "content/public/common/content_features.h"
#include "content/public/common/content_switches.h"
#include "content/public/common/origin_util.h"
#include "net/base/io_buffer.h"
#include "net/base/load_flags.h"
#include "net/http/http_byte_range.h"
#include "net/http/http_util.h"
#include "net/url_request/url_request.h"
#include "services/network/public/cpp/features.h"
#include "services/network/public/mojom/url_loader_factory.mojom.h"
#include "third_party/blink/public/common/features.h"
......@@ -248,51 +245,6 @@ const char* ServiceWorkerUtils::FetchResponseSourceToSuffix(
return ".Unknown";
}
ServiceWorkerUtils::ResourceResponseHeadAndMetadata::
ResourceResponseHeadAndMetadata(
network::mojom::URLResponseHeadPtr head,
scoped_refptr<net::IOBufferWithSize> metadata)
: head(std::move(head)), metadata(std::move(metadata)) {}
ServiceWorkerUtils::ResourceResponseHeadAndMetadata::
ResourceResponseHeadAndMetadata(ResourceResponseHeadAndMetadata&& other) =
default;
ServiceWorkerUtils::ResourceResponseHeadAndMetadata::
~ResourceResponseHeadAndMetadata() = default;
ServiceWorkerUtils::ResourceResponseHeadAndMetadata
ServiceWorkerUtils::CreateResourceResponseHeadAndMetadata(
const net::HttpResponseInfo* http_info,
uint32_t options,
base::TimeTicks request_start_time,
base::TimeTicks response_start_time,
int response_data_size) {
DCHECK(http_info);
DCHECK(http_info->headers);
auto head = network::mojom::URLResponseHead::New();
head->request_start = request_start_time;
head->response_start = response_start_time;
head->request_time = http_info->request_time;
head->response_time = http_info->response_time;
head->headers = http_info->headers;
head->headers->GetMimeType(&head->mime_type);
head->headers->GetCharset(&head->charset);
head->content_length = response_data_size;
head->was_fetched_via_spdy = http_info->was_fetched_via_spdy;
head->was_alpn_negotiated = http_info->was_alpn_negotiated;
head->connection_info = http_info->connection_info;
head->alpn_negotiated_protocol = http_info->alpn_negotiated_protocol;
head->remote_endpoint = http_info->remote_endpoint;
head->cert_status = http_info->ssl_info.cert_status;
if (options & network::mojom::kURLLoadOptionSendSSLInfoWithResponse)
head->ssl_info = http_info->ssl_info;
return {std::move(head), std::move(http_info->metadata)};
}
bool LongestScopeMatcher::MatchLongest(const GURL& scope) {
if (!ServiceWorkerUtils::ScopeMatches(scope, url_))
return false;
......
......@@ -14,8 +14,6 @@
#include "base/macros.h"
#include "content/common/content_export.h"
#include "content/public/common/content_switches.h"
#include "net/http/http_request_headers.h"
#include "services/network/public/mojom/url_response_head.mojom.h"
#include "third_party/blink/public/common/fetch/fetch_api_request_headers_map.h"
#include "third_party/blink/public/common/service_worker/service_worker_status_code.h"
#include "third_party/blink/public/mojom/fetch/fetch_api_request.mojom.h"
......@@ -77,26 +75,6 @@ class ServiceWorkerUtils {
CONTENT_EXPORT static const char* FetchResponseSourceToSuffix(
network::mojom::FetchResponseSource source);
struct CONTENT_EXPORT ResourceResponseHeadAndMetadata {
ResourceResponseHeadAndMetadata(
network::mojom::URLResponseHeadPtr head,
scoped_refptr<net::IOBufferWithSize> metadata);
ResourceResponseHeadAndMetadata(ResourceResponseHeadAndMetadata&& other);
ResourceResponseHeadAndMetadata(
const ResourceResponseHeadAndMetadata& other) = delete;
~ResourceResponseHeadAndMetadata();
network::mojom::URLResponseHeadPtr head;
scoped_refptr<net::IOBufferWithSize> metadata;
};
CONTENT_EXPORT static ResourceResponseHeadAndMetadata
CreateResourceResponseHeadAndMetadata(const net::HttpResponseInfo* http_info,
uint32_t options,
base::TimeTicks request_start_time,
base::TimeTicks response_start_time,
int response_data_size);
private:
static bool IsPathRestrictionSatisfiedInternal(
const GURL& scope,
......
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