0

Reland "Convert SimpleURLLoader to use mojom types."

This is a reland of cd4d366ba3

Original change's description:
> Convert SimpleURLLoader to use mojom types.
>
> This CL Converts the SimpleURLLoader to use the mojom URLResponseHead
> struct instead of the native ResourceResponseHead struct.
>
> Change-Id: I016b0731930b4589ba6169aa2e24ad45dc6675cf
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1790273
> Reviewed-by: Kinuko Yasuda <kinuko@chromium.org>
> Reviewed-by: Avi Drissman <avi@chromium.org>
> Reviewed-by: Kyle Horimoto <khorimoto@chromium.org>
> Reviewed-by: Sorin Jianu <sorin@chromium.org>
> Reviewed-by: Charles . <charleszhao@chromium.org>
> Reviewed-by: Boris Sazonov <bsazonov@chromium.org>
> Reviewed-by: Ryo Hashimoto <hashimoto@chromium.org>
> Reviewed-by: Robert Kaplow <rkaplow@chromium.org>
> Reviewed-by: Tarun Bansal <tbansal@chromium.org>
> Reviewed-by: Hajime Hoshi <hajimehoshi@chromium.org>
> Reviewed-by: Matt Menke <mmenke@chromium.org>
> Reviewed-by: Danyao Wang <danyao@chromium.org>
> Reviewed-by: David Trainor <dtrainor@chromium.org>
> Reviewed-by: Owen Min <zmin@chromium.org>
> Commit-Queue: Lucas Gadani <lfg@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#697317}

Change-Id: I51e7519f8ec48ee625ab9eed03b4829d7993e511
Tbr: kinuko@chromium.org, avi@chromium.org, khorimoto@chromium.org, sorin@chromium.org, charleszhao@chromium.org, bsazonov@chromium.org, hashimoto@chromium.org, rkaplow@chromium.org, tbansal@chromium.org, hajimehoshi@chromium.org, mmenke@chromium.org, danyao@chromium.org, dtrainor@chromium.org, zmin@chromium.org
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1811199
Reviewed-by: Lucas Gadani <lfg@chromium.org>
Reviewed-by: Tao Wu <wutao@chromium.org>
Reviewed-by: Boris Sazonov <bsazonov@chromium.org>
Reviewed-by: Owen Min <zmin@chromium.org>
Reviewed-by: Kyle Horimoto <khorimoto@chromium.org>
Commit-Queue: Lucas Gadani <lfg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#697743}
This commit is contained in:
Lucas Furukawa Gadani
2019-09-18 19:55:08 +00:00
committed by Commit Bot
parent 936f6b2c30
commit 962a30cce1
77 changed files with 232 additions and 189 deletions
chrome
chromeos/services
components
content
google_apis
services

@ -20,6 +20,7 @@
#include "net/url_request/url_request_job.h"
#include "services/network/public/cpp/resource_request.h"
#include "services/network/public/cpp/simple_url_loader.h"
#include "services/network/public/mojom/url_response_head.mojom.h"
#include "url/gurl.h"
#include "url/origin.h"
@ -125,7 +126,7 @@ void DetachedResourceRequest::Start(
void DetachedResourceRequest::OnRedirectCallback(
const net::RedirectInfo& redirect_info,
const network::ResourceResponseHead& response_head,
const network::mojom::URLResponseHead& response_head,
std::vector<std::string>* to_be_removed_headers) {
redirects_++;
}

@ -13,6 +13,7 @@
#include "base/callback.h"
#include "base/time/time.h"
#include "net/url_request/url_request.h"
#include "services/network/public/mojom/url_response_head.mojom-forward.h"
#include "url/gurl.h"
namespace content {
@ -25,7 +26,6 @@ struct RedirectInfo;
namespace network {
class SimpleURLLoader;
struct ResourceResponseHead;
} // namespace network
namespace customtabs {
@ -70,7 +70,7 @@ class DetachedResourceRequest {
static void Start(std::unique_ptr<DetachedResourceRequest> request,
content::BrowserContext* browser_context);
void OnRedirectCallback(const net::RedirectInfo& redirect_info,
const network::ResourceResponseHead& response_head,
const network::mojom::URLResponseHead& response_head,
std::vector<std::string>* to_be_removed_headers);
void OnResponseCallback(std::unique_ptr<std::string> response_body);

@ -26,7 +26,7 @@
#include "net/http/http_request_headers.h"
#include "net/traffic_annotation/network_traffic_annotation.h"
#include "services/network/public/cpp/network_connection_tracker.h"
#include "services/network/public/cpp/resource_response.h"
#include "services/network/public/mojom/url_response_head.mojom-forward.h"
#include "url/gurl.h"
#if defined(OS_ANDROID)
@ -65,7 +65,7 @@ class AvailabilityProber
// delegate returns true, no more probes would be attempted until there is a
// change in the network or |SendNowIfInactive| is called.
virtual bool IsResponseSuccess(net::Error net_error,
const network::ResourceResponseHead* head,
const network::mojom::URLResponseHead* head,
std::unique_ptr<std::string> body) = 0;
};

@ -44,7 +44,7 @@ class TestDelegate : public AvailabilityProber::Delegate {
bool ShouldSendNextProbe() override { return should_send_next_probe_; }
bool IsResponseSuccess(net::Error net_error,
const network::ResourceResponseHead* head,
const network::mojom::URLResponseHead* head,
std::unique_ptr<std::string> body) override {
got_head_ = head;
return net_error == net::OK && head &&

@ -18,8 +18,8 @@
#include "net/http/http_status_code.h"
#include "net/traffic_annotation/network_traffic_annotation_test_helper.h"
#include "services/network/public/cpp/resource_request.h"
#include "services/network/public/cpp/resource_response.h"
#include "services/network/public/cpp/weak_wrapper_shared_url_loader_factory.h"
#include "services/network/public/mojom/url_response_head.mojom.h"
#include "services/network/test/test_network_connection_tracker.h"
#include "services/network/test/test_url_loader_factory.h"
#include "services/network/test/test_utils.h"
@ -38,7 +38,7 @@ class TestDelegate : public AvailabilityProber::Delegate {
bool ShouldSendNextProbe() override { return should_send_next_probe_; }
bool IsResponseSuccess(net::Error net_error,
const network::ResourceResponseHead* head,
const network::mojom::URLResponseHead* head,
std::unique_ptr<std::string> body) override {
return net_error == net::OK && head &&
head->headers->response_code() == net::HTTP_OK;

@ -966,11 +966,11 @@ bool CaptivePortalBrowserTest::OnIntercept(
net::HttpResponseInfo info;
info.headers = base::MakeRefCounted<net::HttpResponseHeaders>(
net::HttpUtil::AssembleRawHeaders(headers));
network::ResourceResponseHead response;
response.headers = info.headers;
response.headers->GetMimeType(&response.mime_type);
response.encoded_data_length = 0;
params->client->OnReceiveRedirect(redirect_info, response);
auto response = network::mojom::URLResponseHead::New();
response->headers = info.headers;
response->headers->GetMimeType(&response->mime_type);
response->encoded_data_length = 0;
params->client->OnReceiveRedirect(redirect_info, std::move(response));
}
if (behind_captive_portal_) {

@ -99,6 +99,7 @@
#include "net/url_request/url_request_context.h"
#include "net/url_request/url_request_context_getter.h"
#include "services/network/public/cpp/features.h"
#include "services/network/public/cpp/resource_response.h"
#include "third_party/blink/public/platform/web_input_event.h"
#include "ui/compositor/compositor_switches.h"
#include "ui/gl/gl_switches.h"

@ -77,6 +77,7 @@
#include "net/traffic_annotation/network_traffic_annotation.h"
#include "services/network/public/cpp/simple_url_loader.h"
#include "services/network/public/cpp/simple_url_loader_stream_consumer.h"
#include "services/network/public/mojom/url_response_head.mojom.h"
#include "third_party/blink/public/mojom/renderer_preferences.mojom.h"
#include "third_party/blink/public/public_buildflags.h"
#include "ui/base/page_transition_types.h"
@ -393,7 +394,7 @@ class DevToolsUIBindings::NetworkResourceLoader
private:
void OnResponseStarted(const GURL& final_url,
const network::ResourceResponseHead& response_head) {
const network::mojom::URLResponseHead& response_head) {
response_headers_ = response_head.headers;
}

@ -10,8 +10,8 @@
#include "content/public/browser/browser_thread.h"
#include "net/traffic_annotation/network_traffic_annotation.h"
#include "net/url_request/url_fetcher.h"
#include "services/network/public/cpp/resource_response.h"
#include "services/network/public/cpp/simple_url_loader.h"
#include "services/network/public/mojom/url_response_head.mojom.h"
namespace extensions {
namespace image_writer {
@ -136,7 +136,7 @@ void WriteFromUrlOperation::DestroySimpleURLLoader() {
void WriteFromUrlOperation::OnResponseStarted(
const GURL& final_url,
const network::ResourceResponseHead& response_head) {
const network::mojom::URLResponseHead& response_head) {
total_response_bytes_ = response_head.content_length;
}

@ -9,10 +9,10 @@
#include "chrome/browser/extensions/api/image_writer_private/operation.h"
#include "services/network/public/mojom/url_loader_factory.mojom.h"
#include "services/network/public/mojom/url_response_head.mojom-forward.h"
#include "url/gurl.h"
namespace network {
struct ResourceResponseHead;
class SimpleURLLoader;
} // namespace network
@ -53,7 +53,7 @@ class WriteFromUrlOperation : public Operation {
private:
void DestroySimpleURLLoader();
void OnResponseStarted(const GURL& final_url,
const network::ResourceResponseHead& response_head);
const network::mojom::URLResponseHead& response_head);
void OnDataDownloaded(uint64_t current);
void OnSimpleLoaderComplete(base::FilePath file_path);
void VerifyDownloadCompare(base::OnceClosure continuation,

@ -48,7 +48,7 @@ void DeviceDescriptionFetcher::ProcessResponse(const std::string& response) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(fetcher_);
const network::ResourceResponseHead* response_info =
const network::mojom::URLResponseHead* response_info =
fetcher_->GetResponseHead();
DCHECK(response_info);

@ -19,6 +19,7 @@
#include "net/url_request/redirect_info.h"
#include "services/network/public/cpp/resource_request.h"
#include "services/network/public/cpp/simple_url_loader.h"
#include "services/network/public/mojom/url_response_head.mojom.h"
// The maximum number of retries allowed for GET requests.
constexpr int kMaxRetries = 2;
@ -79,7 +80,7 @@ DialURLFetcher::~DialURLFetcher() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
}
const network::ResourceResponseHead* DialURLFetcher::GetResponseHead() const {
const network::mojom::URLResponseHead* DialURLFetcher::GetResponseHead() const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return loader_ ? loader_->ResponseInfo() : nullptr;
}
@ -148,7 +149,7 @@ void DialURLFetcher::ReportError(int response_code,
void DialURLFetcher::ReportRedirectError(
const net::RedirectInfo& redirect_info,
const network::ResourceResponseHead& response_head,
const network::mojom::URLResponseHead& response_head,
std::vector<std::string>* to_be_removed_headers) {
// Cancel the request.
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);

@ -11,8 +11,9 @@
#include "base/callback.h"
#include "base/optional.h"
#include "services/network/public/mojom/url_response_head.mojom.h"
#include "services/network/public/mojom/url_loader_factory.mojom.h"
#include "services/network/public/mojom/url_response_head.mojom-forward.h"
#include "services/network/public/mojom/url_response_head.mojom.h"
#include "url/gurl.h"
namespace net {
@ -21,7 +22,6 @@ struct RedirectInfo;
namespace network {
class SimpleURLLoader;
struct ResourceResponseHead;
} // namespace network
namespace media_router {
@ -57,7 +57,7 @@ class DialURLFetcher {
// owned by underlying |loader_| object and is reset per HTTP request. Returns
// nullptr if this function is called before |loader_| has informed the caller
// of completion.
const network::ResourceResponseHead* GetResponseHead() const;
const network::mojom::URLResponseHead* GetResponseHead() const;
private:
friend class TestDialURLFetcher;
@ -81,7 +81,7 @@ class DialURLFetcher {
// Invokes the error callback due to redirect, and aborts the request.
void ReportRedirectError(const net::RedirectInfo& redirect_info,
const network::ResourceResponseHead& response_head,
const network::mojom::URLResponseHead& response_head,
std::vector<std::string>* to_be_removed_headers);
// Runs |error_cb_| with |message| and clears it.

@ -25,7 +25,7 @@ GURL GetAppURL(const MediaSinkInternal& sink, const std::string& app_name) {
// Returns the Application Instance URL from the POST response headers given by
// |response_info|.
GURL GetApplicationInstanceURL(
const network::ResourceResponseHead& response_info) {
const network::mojom::URLResponseHead& response_info) {
if (!response_info.headers)
return GURL();
@ -264,7 +264,7 @@ void DialActivityManager::OnLaunchSuccess(const MediaRoute::Id& route_id,
return;
auto& record = record_it->second;
const network::ResourceResponseHead* response_info =
const network::mojom::URLResponseHead* response_info =
record->pending_launch_request->fetcher->GetResponseHead();
DCHECK(response_info);

@ -8,6 +8,7 @@
#include "net/url_request/report_sender.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#include "services/network/public/cpp/simple_url_loader.h"
#include "services/network/public/mojom/url_response_head.mojom.h"
namespace {
@ -46,7 +47,7 @@ class SimpleURLLoaderOwner {
~SimpleURLLoaderOwner() = default;
void OnResponseStarted(const GURL& final_url,
const network::ResourceResponseHead& response_head) {
const network::mojom::URLResponseHead& response_head) {
OnDone(&response_head, net::OK);
}
@ -54,7 +55,7 @@ class SimpleURLLoaderOwner {
OnDone(loader_->ResponseInfo(), loader_->NetError());
}
void OnDone(const network::ResourceResponseHead* response_head,
void OnDone(const network::mojom::URLResponseHead* response_head,
int net_error) {
if (net_error == net::OK) {
if (success_callback_)

@ -452,7 +452,7 @@ bool PreviewsLitePageDecider::ShouldSendNextProbe() {
bool PreviewsLitePageDecider::IsResponseSuccess(
net::Error net_error,
const network::ResourceResponseHead* head,
const network::mojom::URLResponseHead* head,
std::unique_ptr<std::string> body) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
// Any HTTP response is fine, so long as we got it.

@ -104,7 +104,7 @@ class PreviewsLitePageDecider
// AvailabilityProber::Delegate:
bool ShouldSendNextProbe() override;
bool IsResponseSuccess(net::Error net_error,
const network::ResourceResponseHead* head,
const network::mojom::URLResponseHead* head,
std::unique_ptr<std::string> body) override;
// The time after which it is ok to send the server more preview requests.

@ -117,7 +117,7 @@ bool PreviewsLitePageRedirectURLLoader::ShouldSendNextProbe() {
bool PreviewsLitePageRedirectURLLoader::IsResponseSuccess(
net::Error net_error,
const network::ResourceResponseHead* head,
const network::mojom::URLResponseHead* head,
std::unique_ptr<std::string> body) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
// Any HTTP response is fine, so long as we got it.

@ -58,7 +58,7 @@ class PreviewsLitePageRedirectURLLoader : public network::mojom::URLLoader,
// AvailabilityProber::Delegate:
bool ShouldSendNextProbe() override;
bool IsResponseSuccess(net::Error net_error,
const network::ResourceResponseHead* head,
const network::mojom::URLResponseHead* head,
std::unique_ptr<std::string> body) override;
private:

@ -28,6 +28,7 @@
#include "services/network/public/cpp/resource_request.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#include "services/network/public/cpp/simple_url_loader.h"
#include "services/network/public/mojom/url_response_head.mojom.h"
using net::DefineNetworkTrafficAnnotation;
@ -146,7 +147,7 @@ void GCDApiFlowImpl::OnAccessTokenFetchComplete(
void GCDApiFlowImpl::OnDownloadedToString(
std::unique_ptr<std::string> response_body) {
const network::ResourceResponseHead* response_info =
const network::mojom::URLResponseHead* response_info =
url_loader_->ResponseInfo();
if (url_loader_->NetError() != net::OK || !response_info) {

@ -27,6 +27,7 @@
#include "net/base/load_flags.h"
#include "net/http/http_status_code.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#include "services/network/public/mojom/url_response_head.mojom.h"
namespace cloud_print {
@ -220,7 +221,7 @@ void PrivetURLLoader::SetUploadData(const std::string& upload_content_type,
void PrivetURLLoader::OnResponseStarted(
const GURL& final_url,
const network::ResourceResponseHead& response_head) {
const network::mojom::URLResponseHead& response_head) {
if (!response_head.headers ||
response_head.headers->response_code() == net::HTTP_SERVICE_UNAVAILABLE) {
url_loader_.reset();

@ -17,6 +17,7 @@
#include "base/values.h"
#include "net/traffic_annotation/network_traffic_annotation.h"
#include "services/network/public/cpp/simple_url_loader.h"
#include "services/network/public/mojom/url_response_head.mojom-forward.h"
#include "url/gurl.h"
namespace network {
@ -115,7 +116,7 @@ class PrivetURLLoader {
void RequestTokenRefresh();
void RefreshToken(const std::string& token);
void OnResponseStarted(const GURL& final_url,
const network::ResourceResponseHead& response_head);
const network::mojom::URLResponseHead& response_head);
void OnDownloadedToString(std::unique_ptr<std::string> response_body);
void OnDownloadedToFile(base::FilePath path);
bool CheckURLLoaderForError();

@ -272,7 +272,8 @@ TEST_F(ChromeSigninProxyingURLLoaderFactoryTest, ModifyHeaders) {
// Wait for the request to complete and check the response.
base::RunLoop().RunUntilIdle();
EXPECT_EQ(net::OK, loader()->NetError());
const network::ResourceResponseHead* response_head = loader()->ResponseInfo();
const network::mojom::URLResponseHead* response_head =
loader()->ResponseInfo();
ASSERT_TRUE(response_head && response_head->headers);
EXPECT_FALSE(response_head->headers->HasHeader("X-Response-3"));
EXPECT_TRUE(response_head->headers->HasHeader("X-Response-4"));

@ -19,6 +19,7 @@
#include "services/network/public/cpp/resource_response.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#include "services/network/public/cpp/simple_url_loader.h"
#include "services/network/public/mojom/url_response_head.mojom.h"
CommonNameMismatchHandler::CommonNameMismatchHandler(
const GURL& request_url,
@ -125,7 +126,7 @@ void CommonNameMismatchHandler::Cancel() {
void CommonNameMismatchHandler::OnSimpleLoaderHandler(
const GURL& final_url,
const network::ResourceResponseHead* head) {
const network::mojom::URLResponseHead* head) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(IsCheckingSuggestedUrl());
DCHECK(!check_url_callback_.is_null());
@ -149,14 +150,14 @@ void CommonNameMismatchHandler::OnSimpleLoaderHandler(
void CommonNameMismatchHandler::OnSimpleLoaderRedirect(
const net::RedirectInfo& redirect_info,
const network::ResourceResponseHead& response_head,
const network::mojom::URLResponseHead& response_head,
std::vector<std::string>* to_be_removed_headers) {
OnSimpleLoaderHandler(redirect_info.new_url, &response_head);
}
void CommonNameMismatchHandler::OnSimpleLoaderResponseStarted(
const GURL& final_url,
const network::ResourceResponseHead& response_head) {
const network::mojom::URLResponseHead& response_head) {
OnSimpleLoaderHandler(final_url, &response_head);
}

@ -15,6 +15,7 @@
#include "base/memory/scoped_refptr.h"
#include "base/sequence_checker.h"
#include "base/time/time.h"
#include "services/network/public/mojom/url_response_head.mojom-forward.h"
#include "url/gurl.h"
namespace net {
@ -22,7 +23,6 @@ struct RedirectInfo;
} // namespace net
namespace network {
struct ResourceResponseHead;
class SharedURLLoaderFactory;
class SimpleURLLoader;
} // namespace network
@ -80,14 +80,14 @@ class CommonNameMismatchHandler {
private:
void OnSimpleLoaderHandler(const GURL& final_url,
const network::ResourceResponseHead* head);
const network::mojom::URLResponseHead* head);
void OnSimpleLoaderRedirect(
const net::RedirectInfo& redirect_info,
const network::ResourceResponseHead& response_head,
const network::mojom::URLResponseHead& response_head,
std::vector<std::string>* to_be_removed_headers);
void OnSimpleLoaderResponseStarted(
const GURL& final_url,
const network::ResourceResponseHead& response_head);
const network::mojom::URLResponseHead& response_head);
void OnSimpleLoaderComplete(std::unique_ptr<std::string> response_body);
// Returns true if the check is currently running.

@ -29,6 +29,7 @@
#include "services/network/public/cpp/resource_request.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#include "services/network/public/cpp/simple_url_loader.h"
#include "services/network/public/mojom/url_response_head.mojom.h"
#include "url/gurl.h"
#include "url/url_constants.h"
@ -221,7 +222,7 @@ void ChromeOmniboxNavigationObserver::WebContentsDestroyed() {
void ChromeOmniboxNavigationObserver::OnURLRedirect(
const net::RedirectInfo& redirect_info,
const network::ResourceResponseHead& response_head,
const network::mojom::URLResponseHead& response_head,
std::vector<std::string>* to_be_removed_headers) {
bool valid_redirect = IsValidNavigation(alternate_nav_match_.destination_url,
redirect_info.new_url);

@ -18,13 +18,13 @@
#include "content/public/browser/reload_type.h"
#include "content/public/browser/web_contents_observer.h"
#include "net/url_request/url_fetcher_delegate.h"
#include "services/network/public/mojom/url_response_head.mojom-forward.h"
class Profile;
class ShortcutsBackend;
class TemplateURLService;
namespace network {
struct ResourceResponseHead;
class SharedURLLoaderFactory;
class SimpleURLLoader;
}
@ -115,7 +115,7 @@ class ChromeOmniboxNavigationObserver : public OmniboxNavigationObserver,
// See SimpleURLLoader::OnRedirectCallback for info on the signature.
void OnURLRedirect(const net::RedirectInfo& redirect_info,
const network::ResourceResponseHead& response_head,
const network::mojom::URLResponseHead& response_head,
std::vector<std::string>* to_be_removed_headers);
// Called from either OnURLLoadComplete or OnURLRedirect.

@ -58,6 +58,7 @@ include_rules = [
"+rlz/buildflags/buildflags.h",
"+sandbox/linux/services/credentials.h",
"+services/network/public/cpp",
"+services/network/public/mojom",
"+third_party/blink/public/mojom",
"+third_party/boringssl/src/include",
"+third_party/metrics_proto", # For heap profiler test.

@ -7,6 +7,7 @@
#include "chrome/common/net/safe_search_util.h"
#include "components/variations/net/variations_http_headers.h"
#include "services/network/public/cpp/resource_response.h"
#include "services/network/public/mojom/url_response_head.mojom.h"
#if BUILDFLAG(ENABLE_EXTENSIONS)
#include "extensions/common/extension_urls.h"
@ -63,7 +64,8 @@ void GoogleURLLoaderThrottle::WillRedirectRequest(
bool* /* defer */,
std::vector<std::string>* to_be_removed_headers,
net::HttpRequestHeaders* modified_headers) {
variations::RemoveVariationsHeaderIfNeeded(*redirect_info, response_head,
network::mojom::URLResponseHeadPtr response_head_ptr = response_head;
variations::RemoveVariationsHeaderIfNeeded(*redirect_info, *response_head_ptr,
to_be_removed_headers);
// URLLoaderThrottles can only change the redirect URL when the network

@ -17,6 +17,7 @@
#include "services/network/public/cpp/header_util.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#include "services/network/public/cpp/simple_url_loader.h"
#include "services/network/public/mojom/url_response_head.mojom.h"
using assistant_client::HttpConnection;
using network::SharedURLLoaderFactory;
@ -395,7 +396,7 @@ void ChromiumHttpConnection::OnURLLoadComplete(
void ChromiumHttpConnection::OnResponseStarted(
const GURL& final_url,
const network::ResourceResponseHead& response_header) {
const network::mojom::URLResponseHead& response_header) {
if (enable_header_response_ && response_header.headers) {
// Only propagate |OnHeaderResponse()| once before any |OnPartialResponse()|
// invoked to honor the API contract.

@ -17,9 +17,9 @@
#include "libassistant/shared/internal_api/http_connection.h"
#include "mojo/public/cpp/bindings/receiver_set.h"
#include "net/http/http_request_headers.h"
#include "services/network/public/cpp/resource_response.h"
#include "services/network/public/cpp/simple_url_loader_stream_consumer.h"
#include "services/network/public/mojom/chunked_data_pipe_getter.mojom.h"
#include "services/network/public/mojom/url_response_head.mojom-forward.h"
#include "url/gurl.h"
namespace network {
@ -89,8 +89,9 @@ class ChromiumHttpConnection
void OnURLLoadComplete(std::unique_ptr<std::string> response_body);
// Callback invoked when the response of the http connection has started.
void OnResponseStarted(const GURL& final_url,
const network::ResourceResponseHead& response_header);
void OnResponseStarted(
const GURL& final_url,
const network::mojom::URLResponseHead& response_header);
Delegate* const delegate_;
scoped_refptr<base::SequencedTaskRunner> task_runner_;

@ -9,6 +9,7 @@
#include "net/base/url_util.h"
#include "net/traffic_annotation/network_traffic_annotation.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#include "services/network/public/mojom/url_response_head.mojom.h"
namespace chromeos {
@ -115,7 +116,7 @@ std::string CryptAuthApiCallFlow::GetRequestTypeForBody(
}
void CryptAuthApiCallFlow::ProcessApiCallSuccess(
const network::ResourceResponseHead* head,
const network::mojom::URLResponseHead* head,
std::unique_ptr<std::string> body) {
if (!body) {
error_callback_.Run(NetworkRequestError::kResponseMalformed);
@ -126,7 +127,7 @@ void CryptAuthApiCallFlow::ProcessApiCallSuccess(
void CryptAuthApiCallFlow::ProcessApiCallFailure(
int net_error,
const network::ResourceResponseHead* head,
const network::mojom::URLResponseHead* head,
std::unique_ptr<std::string> body) {
base::Optional<NetworkRequestError> error;
std::string error_message;

@ -88,10 +88,10 @@ class CryptAuthApiCallFlow : public OAuth2ApiCallFlow {
std::string CreateApiCallBody() override;
std::string CreateApiCallBodyContentType() override;
std::string GetRequestTypeForBody(const std::string& body) override;
void ProcessApiCallSuccess(const network::ResourceResponseHead* head,
void ProcessApiCallSuccess(const network::mojom::URLResponseHead* head,
std::unique_ptr<std::string> body) override;
void ProcessApiCallFailure(int net_error,
const network::ResourceResponseHead* head,
const network::mojom::URLResponseHead* head,
std::unique_ptr<std::string> body) override;
net::PartialNetworkTrafficAnnotationTag GetNetworkTrafficAnnotationTag()
override;

@ -543,7 +543,7 @@ void DataReductionProxyConfigServiceClient::HandleResponse(
config_storer_.Run(encoded_config);
// Record timing metrics on successful requests only.
const network::ResourceResponseHead* info = url_loader_->ResponseInfo();
const network::mojom::URLResponseHead* info = url_loader_->ResponseInfo();
base::TimeDelta http_request_rtt =
info->response_start - info->request_start;
UMA_HISTOGRAM_TIMES("DataReductionProxy.ConfigService.HttpRequestRTT",

@ -11,6 +11,7 @@
#include "net/traffic_annotation/network_traffic_annotation.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#include "services/network/public/cpp/simple_url_loader.h"
#include "services/network/public/mojom/url_response_head.mojom.h"
namespace {
@ -59,7 +60,7 @@ void SecureProxyChecker::OnURLLoadCompleteOrRedirect(
void SecureProxyChecker::OnURLLoaderRedirect(
const net::RedirectInfo& redirect_info,
const network::ResourceResponseHead& response_head,
const network::mojom::URLResponseHead& response_head,
std::vector<std::string>* to_be_removed_headers) {
OnURLLoadCompleteOrRedirect(std::string(), net::ERR_ABORTED,
redirect_info.status_code);

@ -11,6 +11,7 @@
#include "base/callback.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "services/network/public/mojom/url_response_head.mojom-forward.h"
namespace net {
struct RedirectInfo;
@ -19,7 +20,6 @@ struct RedirectInfo;
namespace network {
class SharedURLLoaderFactory;
class SimpleURLLoader;
struct ResourceResponseHead;
} // namespace network
namespace data_reduction_proxy {
@ -44,7 +44,7 @@ class SecureProxyChecker {
int response_code);
void OnURLLoaderRedirect(const net::RedirectInfo& redirect_info,
const network::ResourceResponseHead& response_head,
const network::mojom::URLResponseHead& response_head,
std::vector<std::string>* to_be_removed_headers);
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory_;

@ -24,6 +24,7 @@
#include "services/network/public/cpp/shared_url_loader_factory.h"
#include "services/network/public/cpp/simple_url_loader.h"
#include "services/network/public/mojom/network_service.mojom.h"
#include "services/network/public/mojom/url_response_head.mojom.h"
namespace data_reduction_proxy {
@ -200,14 +201,14 @@ void WarmupURLFetcher::GetWarmupURLWithQueryParam(
void WarmupURLFetcher::OnURLLoadResponseStarted(
const GURL& final_url,
const network::ResourceResponseHead& response_head) {
const network::mojom::URLResponseHead& response_head) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
proxy_server_ = response_head.proxy_server;
}
void WarmupURLFetcher::OnURLLoaderRedirect(
const net::RedirectInfo& redirect_info,
const network::ResourceResponseHead& response_head,
const network::mojom::URLResponseHead& response_head,
std::vector<std::string>* to_be_removed_headers) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
proxy_server_ = response_head.proxy_server;

@ -16,6 +16,7 @@
#include "mojo/public/cpp/bindings/remote.h"
#include "net/base/proxy_server.h"
#include "services/network/public/mojom/network_context.mojom.h"
#include "services/network/public/mojom/url_response_head.mojom-forward.h"
class GURL;
@ -24,7 +25,6 @@ struct RedirectInfo;
} // namespace net
namespace network {
struct ResourceResponseHead;
class SimpleURLLoader;
} // namespace network
@ -86,11 +86,11 @@ class WarmupURLFetcher {
// URL loader callback when response starts.
void OnURLLoadResponseStarted(
const GURL& final_url,
const network::ResourceResponseHead& response_head);
const network::mojom::URLResponseHead& response_head);
// URL loader callback for redirections.
void OnURLLoaderRedirect(const net::RedirectInfo& redirect_info,
const network::ResourceResponseHead& response_head,
const network::mojom::URLResponseHead& response_head,
std::vector<std::string>* to_be_removed_headers);
// URL loader completion callback.

@ -11,6 +11,7 @@
#include "components/download/internal/background_service/blob_task_proxy.h"
#include "net/base/load_flags.h"
#include "net/traffic_annotation/network_traffic_annotation.h"
#include "services/network/public/mojom/url_response_head.mojom.h"
#include "storage/browser/blob/blob_data_handle.h"
#include "storage/browser/blob/blob_storage_context.h"
@ -140,7 +141,7 @@ void InMemoryDownloadImpl::OnComplete(bool success) {
// OnComplete() called without OnResponseStarted(). This will happen when the
// request was aborted.
if (!started_)
OnResponseStarted(GURL(), network::ResourceResponseHead());
OnResponseStarted(GURL(), network::mojom::URLResponseHead());
NotifyDelegateDownloadComplete();
}
@ -223,14 +224,14 @@ void InMemoryDownloadImpl::SendRequest() {
void InMemoryDownloadImpl::OnRedirect(
const net::RedirectInfo& redirect_info,
const network::ResourceResponseHead& response_head,
const network::mojom::URLResponseHead& response_head,
std::vector<std::string>* to_be_removed_headers) {
url_chain_.push_back(redirect_info.new_url);
}
void InMemoryDownloadImpl::OnResponseStarted(
const GURL& final_url,
const network::ResourceResponseHead& response_head) {
const network::mojom::URLResponseHead& response_head) {
started_ = true;
response_headers_ = response_head.headers;

@ -20,6 +20,7 @@
#include "services/network/public/cpp/simple_url_loader.h"
#include "services/network/public/cpp/simple_url_loader_stream_consumer.h"
#include "services/network/public/mojom/url_loader_factory.mojom.h"
#include "services/network/public/mojom/url_response_head.mojom-forward.h"
class GURL;
@ -207,12 +208,12 @@ class InMemoryDownloadImpl : public network::SimpleURLLoaderStreamConsumer,
// Called when the server redirects to another URL.
void OnRedirect(const net::RedirectInfo& redirect_info,
const network::ResourceResponseHead& response_head,
const network::mojom::URLResponseHead& response_head,
std::vector<std::string>* to_be_removed_headers);
// Called when the response of the final URL is received.
void OnResponseStarted(const GURL& final_url,
const network::ResourceResponseHead& response_head);
const network::mojom::URLResponseHead& response_head);
void OnUploadProgress(uint64_t position, uint64_t total);

@ -738,7 +738,7 @@ TEST_F(NetExportFileWriterTest, StartWithNetworkContextActive) {
simple_loader->SetOnRedirectCallback(base::BindRepeating(
[](base::RepeatingClosure notify_log,
const net::RedirectInfo& redirect_info,
const network::ResourceResponseHead& response_head,
const network::mojom::URLResponseHead& response_head,
std::vector<std::string>* to_be_removed_headers) { notify_log.Run(); },
run_loop.QuitClosure()));
simple_loader->DownloadToStringOfUnboundedSizeUntilCrashAndDie(

@ -11,6 +11,7 @@ include_rules = [
"+net",
"+services/metrics/public",
"+services/network/public/cpp",
"+services/network/public/mojom",
"+services/network/test",
"+third_party/libaddressinput",
"+third_party/re2",

@ -27,6 +27,7 @@
#include "net/traffic_annotation/network_traffic_annotation.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#include "services/network/public/cpp/simple_url_loader.h"
#include "services/network/public/mojom/url_response_head.mojom.h"
#include "url/url_constants.h"
namespace payments {
@ -181,7 +182,7 @@ PaymentManifestDownloader::Download::~Download() {}
void PaymentManifestDownloader::OnURLLoaderRedirect(
network::SimpleURLLoader* url_loader,
const net::RedirectInfo& redirect_info,
const network::ResourceResponseHead& response_head,
const network::mojom::URLResponseHead& response_head,
std::vector<std::string>* to_be_removed_headers) {
auto download_it = downloads_.find(url_loader);
DCHECK(download_it != downloads_.end());

@ -14,6 +14,7 @@
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
#include "services/network/public/mojom/url_response_head.mojom-forward.h"
#include "url/gurl.h"
namespace net {
@ -24,7 +25,6 @@ struct RedirectInfo;
namespace network {
class SharedURLLoaderFactory;
class SimpleURLLoader;
struct ResourceResponseHead;
} // namespace network
namespace payments {
@ -128,7 +128,7 @@ class PaymentManifestDownloader {
// Called by SimpleURLLoader on a redirect.
void OnURLLoaderRedirect(network::SimpleURLLoader* url_loader,
const net::RedirectInfo& redirect_info,
const network::ResourceResponseHead& response_head,
const network::mojom::URLResponseHead& response_head,
std::vector<std::string>* to_be_removed_headers);
// Called by SimpleURLLoader on completion.

@ -77,7 +77,7 @@ class PaymentMethodManifestDownloaderTest : public testing::Test {
downloader_.OnURLLoaderRedirect(
downloader_.GetLoaderForTesting(), redirect_info,
network::ResourceResponseHead(), &to_be_removed_headers);
network::mojom::URLResponseHead(), &to_be_removed_headers);
}
GURL GetOriginalURL() { return downloader_.GetLoaderOriginalURLForTesting(); }

@ -46,7 +46,7 @@ class ExternalPolicyDataFetcher::Job
int64_t max_size);
void Cancel();
void OnResponseStarted(const GURL& final_url,
const network::ResourceResponseHead& response_head);
const network::mojom::URLResponseHead& response_head);
// network::SimpleURLLoaderStreamConsumer implementation
void OnDataReceived(base::StringPiece string_piece,
@ -134,7 +134,7 @@ void ExternalPolicyDataFetcher::Job::Cancel() {
void ExternalPolicyDataFetcher::Job::OnResponseStarted(
const GURL& /* final_url */,
const network::ResourceResponseHead& response_head) {
const network::mojom::URLResponseHead& response_head) {
if (response_head.content_length != -1 &&
response_head.content_length > max_size_) {
url_loader_.reset();

@ -13,6 +13,7 @@ include_rules = [
"+google_apis",
"+net",
"+services/network/public/cpp",
"+services/network/public/mojom",
"+ui",
"+third_party/metrics_proto",

@ -24,7 +24,7 @@
#include "net/base/net_errors.h"
#include "net/traffic_annotation/network_traffic_annotation.h"
#include "services/network/public/cpp/resource_request.h"
#include "services/network/public/cpp/resource_response.h"
#include "services/network/public/mojom/url_response_head.mojom.h"
#include "url/gurl.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
@ -258,7 +258,7 @@ void TranslateController::OnRequestFetchComplete(
// |ResponseInfo()| may be a nullptr if response is incomplete.
int response_code = 0;
std::string status_text;
const network::ResourceResponseHead* response_head =
const network::mojom::URLResponseHead* response_head =
url_loader->ResponseInfo();
if (response_head && response_head->headers) {
net::HttpResponseHeaders* headers = response_head->headers.get();

@ -1,5 +1,6 @@
include_rules = [
"+net",
"+services/network/public/cpp",
"+services/network/public/mojom",
"+services/network/test",
]

@ -15,6 +15,7 @@
#include "services/network/public/cpp/resource_response.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#include "services/network/public/cpp/simple_url_loader.h"
#include "services/network/public/mojom/url_response_head.mojom.h"
#include "url/gurl.h"
namespace {
@ -180,7 +181,7 @@ void NetworkFetcherImpl::DownloadToFile(
void NetworkFetcherImpl::OnResponseStartedCallback(
ResponseStartedCallback response_started_callback,
const GURL& final_url,
const network::ResourceResponseHead& response_head) {
const network::mojom::URLResponseHead& response_head) {
std::move(response_started_callback)
.Run(final_url,
response_head.headers ? response_head.headers->response_code() : -1,

@ -13,9 +13,9 @@
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "components/update_client/network.h"
#include "services/network/public/mojom/url_response_head.mojom-forward.h"
namespace network {
struct ResourceResponseHead;
class SharedURLLoaderFactory;
class SimpleURLLoader;
} // namespace network
@ -47,7 +47,7 @@ class NetworkFetcherImpl : public NetworkFetcher {
void OnResponseStartedCallback(
ResponseStartedCallback response_started_callback,
const GURL& final_url,
const network::ResourceResponseHead& response_head);
const network::mojom::URLResponseHead& response_head);
void OnProgressCallback(ProgressCallback response_started_callback,
uint64_t current);

@ -23,6 +23,7 @@
#include "services/network/public/cpp/resource_request.h"
#include "services/network/public/cpp/resource_response.h"
#include "services/network/public/cpp/simple_url_loader.h"
#include "services/network/public/mojom/url_response_head.mojom.h"
#include "url/gurl.h"
namespace variations {
@ -173,7 +174,7 @@ bool AppendVariationsHeaderUnknownSignedIn(const GURL& url,
void RemoveVariationsHeaderIfNeeded(
const net::RedirectInfo& redirect_info,
const network::ResourceResponseHead& response_head,
const network::mojom::URLResponseHead& response_head,
std::vector<std::string>* to_be_removed_headers) {
if (!ShouldAppendVariationsHeader(redirect_info.new_url))
to_be_removed_headers->push_back(kClientDataHeader);

@ -11,6 +11,7 @@
#include <vector>
#include "services/network/public/mojom/network_context.mojom.h"
#include "services/network/public/mojom/url_response_head.mojom-forward.h"
namespace net {
struct NetworkTrafficAnnotationTag;
@ -19,7 +20,6 @@ struct RedirectInfo;
namespace network {
struct ResourceRequest;
struct ResourceResponseHead;
class SimpleURLLoader;
} // namespace network
@ -61,7 +61,7 @@ bool AppendVariationsHeaderUnknownSignedIn(const GURL& url,
// URL occurs.
void RemoveVariationsHeaderIfNeeded(
const net::RedirectInfo& redirect_info,
const network::ResourceResponseHead& response_head,
const network::mojom::URLResponseHead& response_head,
std::vector<std::string>* to_be_removed_headers);
// Creates a SimpleURLLoader that will include the variations header for

@ -57,6 +57,7 @@
#include "services/network/public/cpp/resource_request.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#include "services/network/public/cpp/simple_url_loader.h"
#include "services/network/public/mojom/url_response_head.mojom.h"
#include "ui/base/device_form_factor.h"
#include "url/gurl.h"
@ -685,7 +686,7 @@ void VariationsService::OnSimpleLoaderComplete(
void VariationsService::OnSimpleLoaderRedirect(
const net::RedirectInfo& redirect_info,
const network::ResourceResponseHead& response_head,
const network::mojom::URLResponseHead& response_head,
std::vector<std::string>* to_be_removed_headers) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
OnSimpleLoaderCompleteOrRedirect(nullptr, true);
@ -716,7 +717,7 @@ void VariationsService::OnSimpleLoaderCompleteOrRedirect(
if (!was_redirect) {
final_url_was_https =
pending_seed_request_->GetFinalURL().SchemeIs(url::kHttpsScheme);
const network::ResourceResponseHead* response_info =
const network::mojom::URLResponseHead* response_info =
pending_seed_request_->ResponseInfo();
if (response_info && response_info->headers) {
headers = response_info->headers;

@ -28,7 +28,7 @@
#include "components/version_info/version_info.h"
#include "components/web_resource/resource_request_allowed_notifier.h"
#include "net/url_request/redirect_info.h"
#include "services/network/public/cpp/resource_response.h"
#include "services/network/public/mojom/url_response_head.mojom-forward.h"
#include "url/gurl.h"
class PrefService;
@ -317,7 +317,7 @@ class VariationsService
// Called by SimpleURLLoader when |pending_seed_request_| load is redirected.
void OnSimpleLoaderRedirect(
const net::RedirectInfo& redirect_info,
const network::ResourceResponseHead& response_head,
const network::mojom::URLResponseHead& response_head,
std::vector<std::string>* to_be_removed_headers);
// Handles post-fetch events.

@ -36,6 +36,7 @@
#include "services/network/public/cpp/simple_url_loader.h"
#include "services/network/public/cpp/simple_url_loader_stream_consumer.h"
#include "services/network/public/mojom/url_loader_factory.mojom.h"
#include "services/network/public/mojom/url_response_head.mojom.h"
#include "url/gurl.h"
namespace content {
@ -95,7 +96,7 @@ class SaveFileManager::SimpleURLLoaderHelper
int render_process_id,
int render_frame_routing_id,
const GURL& final_url,
const network::ResourceResponseHead& response_head) {
const network::mojom::URLResponseHead& response_head) {
std::string content_disposition;
if (response_head.headers) {
response_head.headers->GetNormalizedHeader("Content-Disposition",

@ -38,6 +38,7 @@
#include "net/traffic_annotation/network_traffic_annotation.h"
#include "services/network/public/cpp/simple_url_loader.h"
#include "services/network/public/cpp/simple_url_loader_stream_consumer.h"
#include "services/network/public/mojom/url_response_head.mojom.h"
#if !defined(OS_ANDROID)
#include "content/public/browser/devtools_frontend_host.h"
@ -86,7 +87,7 @@ class ShellDevToolsBindings::NetworkResourceLoader
private:
void OnResponseStarted(const GURL& final_url,
const network::ResourceResponseHead& response_head) {
const network::mojom::URLResponseHead& response_head) {
response_headers_ = response_head.headers;
}

@ -30,6 +30,7 @@
#include "net/base/load_flags.h"
#include "net/base/mime_util.h"
#include "net/http/http_util.h"
#include "services/network/public/mojom/url_response_head.mojom.h"
namespace {
@ -83,7 +84,7 @@ void ParseJsonOnBlockingPool(
// Returns response headers as a string. Returns a warning message if
// |response_head| does not contain a valid response. Used only for debugging.
std::string GetResponseHeadersAsString(
const network::ResourceResponseHead& response_head) {
const network::mojom::URLResponseHead& response_head) {
// Check that response code indicates response headers are valid (i.e. not
// malformed) before we retrieve the headers.
if (response_head.headers->response_code() == -1)
@ -394,7 +395,7 @@ void UrlFetchRequestBase::OnUploadProgress(
void UrlFetchRequestBase::OnResponseStarted(
const GURL& final_url,
const network::ResourceResponseHead& response_head) {
const network::mojom::URLResponseHead& response_head) {
DVLOG(1) << "Response headers:\n"
<< GetResponseHeadersAsString(response_head);
response_content_length_ = response_head.content_length;
@ -480,7 +481,7 @@ void UrlFetchRequestBase::OnComplete(bool success) {
void UrlFetchRequestBase::OnOutputFileClosed(bool success) {
DCHECK(download_data_);
const network::ResourceResponseHead* response_info;
const network::mojom::URLResponseHead* response_info;
if (url_loader_) {
response_info = url_loader_->ResponseInfo();
if (response_info) {
@ -600,7 +601,7 @@ EntryActionRequest::EntryActionRequest(RequestSender* sender,
EntryActionRequest::~EntryActionRequest() {}
void EntryActionRequest::ProcessURLFetchResults(
const network::ResourceResponseHead* response_head,
const network::mojom::URLResponseHead* response_head,
base::FilePath response_file,
std::string response_body) {
callback_.Run(GetErrorCode());
@ -630,7 +631,7 @@ InitiateUploadRequestBase::InitiateUploadRequestBase(
InitiateUploadRequestBase::~InitiateUploadRequestBase() {}
void InitiateUploadRequestBase::ProcessURLFetchResults(
const network::ResourceResponseHead* response_head,
const network::mojom::URLResponseHead* response_head,
base::FilePath response_file,
std::string response_body) {
std::string upload_location;
@ -698,7 +699,7 @@ std::string UploadRangeRequestBase::GetRequestType() const {
}
void UploadRangeRequestBase::ProcessURLFetchResults(
const network::ResourceResponseHead* response_head,
const network::mojom::URLResponseHead* response_head,
base::FilePath response_file,
std::string response_body) {
DriveApiErrorCode code = GetErrorCode();
@ -1012,7 +1013,7 @@ void DownloadFileRequestBase::GetOutputFilePath(
}
void DownloadFileRequestBase::ProcessURLFetchResults(
const network::ResourceResponseHead* response_head,
const network::mojom::URLResponseHead* response_head,
base::FilePath response_file,
std::string response_body) {
download_action_callback_.Run(GetErrorCode(), response_file);

@ -22,9 +22,9 @@
#include "base/sequenced_task_runner.h"
#include "base/threading/thread_checker.h"
#include "google_apis/drive/drive_api_error_codes.h"
#include "services/network/public/cpp/resource_response.h"
#include "services/network/public/cpp/simple_url_loader.h"
#include "services/network/public/cpp/simple_url_loader_stream_consumer.h"
#include "services/network/public/mojom/url_response_head.mojom-forward.h"
#include "url/gurl.h"
namespace base {
@ -182,7 +182,7 @@ class UrlFetchRequestBase : public AuthenticatedRequestInterface,
// |response_body| may be truncated and only contain the starting portion
// of the resource.
virtual void ProcessURLFetchResults(
const network::ResourceResponseHead* response_head,
const network::mojom::URLResponseHead* response_head,
base::FilePath response_file,
std::string response_body) = 0;
@ -258,7 +258,7 @@ class UrlFetchRequestBase : public AuthenticatedRequestInterface,
// Called when the SimpleURLLoader first receives a response.
void OnResponseStarted(const GURL& final_url,
const network::ResourceResponseHead& response_head);
const network::mojom::URLResponseHead& response_head);
// Invokes callback with |code| and request to delete the request to
// |sender_|.
@ -338,7 +338,7 @@ class EntryActionRequest : public UrlFetchRequestBase {
protected:
// Overridden from UrlFetchRequestBase.
void ProcessURLFetchResults(
const network::ResourceResponseHead* response_head,
const network::mojom::URLResponseHead* response_head,
base::FilePath response_file,
std::string response_body) override;
void RunCallbackOnPrematureFailure(DriveApiErrorCode code) override;
@ -380,7 +380,7 @@ class InitiateUploadRequestBase : public UrlFetchRequestBase {
// UrlFetchRequestBase overrides.
void ProcessURLFetchResults(
const network::ResourceResponseHead* response_head,
const network::mojom::URLResponseHead* response_head,
base::FilePath response_file,
std::string response_body) override;
void RunCallbackOnPrematureFailure(DriveApiErrorCode code) override;
@ -430,7 +430,7 @@ class UploadRangeRequestBase : public UrlFetchRequestBase {
GURL GetURL() const override;
std::string GetRequestType() const override;
void ProcessURLFetchResults(
const network::ResourceResponseHead* response_head,
const network::mojom::URLResponseHead* response_head,
base::FilePath response_file,
std::string response_body) override;
void RunCallbackOnPrematureFailure(DriveApiErrorCode code) override;
@ -656,7 +656,7 @@ class DownloadFileRequestBase : public UrlFetchRequestBase {
void GetOutputFilePath(base::FilePath* local_file_path,
GetContentCallback* get_content_callback) override;
void ProcessURLFetchResults(
const network::ResourceResponseHead* response_head,
const network::mojom::URLResponseHead* response_head,
base::FilePath response_file,
std::string response_body) override;
void RunCallbackOnPrematureFailure(DriveApiErrorCode code) override;

@ -25,6 +25,7 @@
#include "net/traffic_annotation/network_traffic_annotation_test_helper.h"
#include "services/network/network_service.h"
#include "services/network/public/cpp/weak_wrapper_shared_url_loader_factory.h"
#include "services/network/public/mojom/url_response_head.mojom.h"
#include "services/network/test/test_network_service_client.h"
#include "testing/gtest/include/gtest/gtest.h"
@ -49,7 +50,7 @@ class FakeUrlFetchRequest : public UrlFetchRequestBase {
protected:
GURL GetURL() const override { return url_; }
void ProcessURLFetchResults(
const network::ResourceResponseHead* response_head,
const network::mojom::URLResponseHead* response_head,
base::FilePath response_file,
std::string response_body) override {
callback_.Run(GetErrorCode());

@ -27,6 +27,7 @@
#include "google_apis/drive/time_util.h"
#include "net/base/url_util.h"
#include "net/http/http_response_headers.h"
#include "services/network/public/mojom/url_response_head.mojom.h"
namespace google_apis {
namespace drive {
@ -1138,7 +1139,7 @@ bool SingleBatchableDelegateRequest::GetContentData(
}
void SingleBatchableDelegateRequest::ProcessURLFetchResults(
const network::ResourceResponseHead* response_head,
const network::mojom::URLResponseHead* response_head,
base::FilePath response_file,
std::string response_body) {
delegate_->NotifyResult(
@ -1319,7 +1320,7 @@ std::vector<std::string> BatchUploadRequest::GetExtraRequestHeaders() const {
}
void BatchUploadRequest::ProcessURLFetchResults(
const network::ResourceResponseHead* response_head,
const network::mojom::URLResponseHead* response_head,
base::FilePath response_file,
std::string response_body) {
if (!IsSuccessfulDriveApiErrorCode(GetErrorCode())) {

@ -24,6 +24,7 @@
#include "google_apis/drive/drive_api_parser.h"
#include "google_apis/drive/drive_api_url_generator.h"
#include "google_apis/drive/drive_common_callbacks.h"
#include "services/network/public/mojom/url_response_head.mojom-forward.h"
namespace google_apis {
@ -151,7 +152,7 @@ class DriveApiDataRequest : public DriveApiPartialFieldRequest {
protected:
// UrlFetchRequestBase overrides.
void ProcessURLFetchResults(
const network::ResourceResponseHead* response_head,
const network::mojom::URLResponseHead* response_head,
base::FilePath response_file,
std::string response_body) override {
DriveApiErrorCode error = GetErrorCode();
@ -1159,7 +1160,7 @@ class SingleBatchableDelegateRequest : public UrlFetchRequestBase {
std::string* upload_content) override;
void RunCallbackOnPrematureFailure(DriveApiErrorCode code) override;
void ProcessURLFetchResults(
const network::ResourceResponseHead* response_head,
const network::mojom::URLResponseHead* response_head,
base::FilePath response_file,
std::string response_body) override;
void OnUploadProgress(int64_t current, int64_t total);
@ -1222,7 +1223,7 @@ class BatchUploadRequest : public UrlFetchRequestBase {
bool GetContentData(std::string* upload_content_type,
std::string* upload_content) override;
void ProcessURLFetchResults(
const network::ResourceResponseHead* response_head,
const network::mojom::URLResponseHead* response_head,
base::FilePath response_file,
std::string response_body) override;
void RunCallbackOnPrematureFailure(DriveApiErrorCode code) override;

@ -17,6 +17,7 @@
#include "services/network/public/cpp/resource_request.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#include "services/network/public/cpp/simple_url_loader.h"
#include "services/network/public/mojom/url_response_head.mojom.h"
namespace {
static const char kAuthorizationValueFormat[] = "Bearer %s";

@ -11,10 +11,10 @@
#include "base/macros.h"
#include "base/memory/scoped_refptr.h"
#include "net/traffic_annotation/network_traffic_annotation.h"
#include "services/network/public/mojom/url_response_head.mojom-forward.h"
#include "url/gurl.h"
namespace network {
struct ResourceResponseHead;
class SimpleURLLoader;
class SharedURLLoaderFactory;
}
@ -49,13 +49,15 @@ class OAuth2ApiCallFlow {
// Sub-classes can expose an appropriate observer interface by implementing
// these template methods.
// Called when the API call finished successfully. |body| may be null.
virtual void ProcessApiCallSuccess(const network::ResourceResponseHead* head,
std::unique_ptr<std::string> body) = 0;
virtual void ProcessApiCallSuccess(
const network::mojom::URLResponseHead* head,
std::unique_ptr<std::string> body) = 0;
// Called when the API call failed. |head| or |body| might be null.
virtual void ProcessApiCallFailure(int net_error,
const network::ResourceResponseHead* head,
std::unique_ptr<std::string> body) = 0;
virtual void ProcessApiCallFailure(
int net_error,
const network::mojom::URLResponseHead* head,
std::unique_ptr<std::string> body) = 0;
virtual net::PartialNetworkTrafficAnnotationTag
GetNetworkTrafficAnnotationTag() = 0;

@ -22,6 +22,7 @@
#include "net/http/http_status_code.h"
#include "net/traffic_annotation/network_traffic_annotation_test_helper.h"
#include "services/network/public/cpp/weak_wrapper_shared_url_loader_factory.h"
#include "services/network/public/mojom/url_response_head.mojom.h"
#include "services/network/test/test_url_loader_factory.h"
#include "services/network/test/test_utils.h"
#include "testing/gmock/include/gmock/gmock.h"
@ -54,11 +55,11 @@ class MockApiCallFlow : public OAuth2ApiCallFlow {
MOCK_METHOD0(CreateApiCallUrl, GURL());
MOCK_METHOD0(CreateApiCallBody, std::string());
MOCK_METHOD2(ProcessApiCallSuccess,
void(const network::ResourceResponseHead* head,
void(const network::mojom::URLResponseHead* head,
std::unique_ptr<std::string> body));
MOCK_METHOD3(ProcessApiCallFailure,
void(int net_error,
const network::ResourceResponseHead* head,
const network::mojom::URLResponseHead* head,
std::unique_ptr<std::string> body));
MOCK_METHOD1(ProcessNewAccessToken, void(const std::string& access_token));
MOCK_METHOD1(ProcessMintAccessTokenFailure,

@ -22,7 +22,7 @@
#include "google_apis/gaia/google_service_auth_error.h"
#include "net/base/escape.h"
#include "net/base/net_errors.h"
#include "services/network/public/cpp/resource_response.h"
#include "services/network/public/mojom/url_response_head.mojom.h"
namespace {
@ -56,7 +56,7 @@ const char kMessage[] = "message";
static GoogleServiceAuthError CreateAuthError(
int net_error,
const network::ResourceResponseHead* head,
const network::mojom::URLResponseHead* head,
std::unique_ptr<std::string> body) {
if (net_error == net::ERR_ABORTED) {
return GoogleServiceAuthError(GoogleServiceAuthError::REQUEST_CANCELED);
@ -186,7 +186,7 @@ std::string OAuth2MintTokenFlow::CreateApiCallBody() {
}
void OAuth2MintTokenFlow::ProcessApiCallSuccess(
const network::ResourceResponseHead* head,
const network::mojom::URLResponseHead* head,
std::unique_ptr<std::string> body) {
std::string response_body;
if (body)
@ -230,7 +230,7 @@ void OAuth2MintTokenFlow::ProcessApiCallSuccess(
void OAuth2MintTokenFlow::ProcessApiCallFailure(
int net_error,
const network::ResourceResponseHead* head,
const network::mojom::URLResponseHead* head,
std::unique_ptr<std::string> body) {
ReportFailure(CreateAuthError(net_error, head, std::move(body)));
}

@ -13,6 +13,7 @@
#include "base/memory/weak_ptr.h"
#include "base/strings/string16.h"
#include "google_apis/gaia/oauth2_api_call_flow.h"
#include "services/network/public/mojom/url_response_head.mojom-forward.h"
#include "url/gurl.h"
class GoogleServiceAuthError;
@ -103,10 +104,10 @@ class OAuth2MintTokenFlow : public OAuth2ApiCallFlow {
GURL CreateApiCallUrl() override;
std::string CreateApiCallBody() override;
void ProcessApiCallSuccess(const network::ResourceResponseHead* head,
void ProcessApiCallSuccess(const network::mojom::URLResponseHead* head,
std::unique_ptr<std::string> body) override;
void ProcessApiCallFailure(int net_error,
const network::ResourceResponseHead* head,
const network::mojom::URLResponseHead* head,
std::unique_ptr<std::string> body) override;
net::PartialNetworkTrafficAnnotationTag GetNetworkTrafficAnnotationTag()
override;

@ -17,6 +17,7 @@
#include "google_apis/gaia/oauth2_access_token_fetcher.h"
#include "net/base/net_errors.h"
#include "services/network/public/cpp/resource_response.h"
#include "services/network/public/mojom/url_response_head.mojom.h"
#include "services/network/test/test_utils.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
@ -297,56 +298,59 @@ TEST_F(OAuth2MintTokenFlowTest, ParseIssueAdviceResponse) {
}
TEST_F(OAuth2MintTokenFlowTest, ProcessApiCallSuccess) {
network::ResourceResponseHead head_200 =
network::mojom::URLResponseHeadPtr head_200 =
network::CreateResourceResponseHead(net::HTTP_OK);
{ // No body.
CreateFlow(OAuth2MintTokenFlow::MODE_MINT_TOKEN_NO_FORCE);
EXPECT_CALL(delegate_, OnMintTokenFailure(_));
flow_->ProcessApiCallSuccess(&head_200, nullptr);
flow_->ProcessApiCallSuccess(head_200.get(), nullptr);
}
{ // Bad json.
CreateFlow(OAuth2MintTokenFlow::MODE_MINT_TOKEN_NO_FORCE);
EXPECT_CALL(delegate_, OnMintTokenFailure(_));
flow_->ProcessApiCallSuccess(&head_200,
flow_->ProcessApiCallSuccess(head_200.get(),
std::make_unique<std::string>("foo"));
}
{ // Valid json: no access token.
CreateFlow(OAuth2MintTokenFlow::MODE_MINT_TOKEN_NO_FORCE);
EXPECT_CALL(delegate_, OnMintTokenFailure(_));
flow_->ProcessApiCallSuccess(
&head_200, std::make_unique<std::string>(kTokenResponseNoAccessToken));
head_200.get(),
std::make_unique<std::string>(kTokenResponseNoAccessToken));
}
{ // Valid json: good token response.
CreateFlow(OAuth2MintTokenFlow::MODE_MINT_TOKEN_NO_FORCE);
EXPECT_CALL(delegate_, OnMintTokenSuccess("at1", 3600));
flow_->ProcessApiCallSuccess(
&head_200, std::make_unique<std::string>(kValidTokenResponse));
head_200.get(), std::make_unique<std::string>(kValidTokenResponse));
}
{ // Valid json: no description.
CreateFlow(OAuth2MintTokenFlow::MODE_ISSUE_ADVICE);
EXPECT_CALL(delegate_, OnMintTokenFailure(_));
flow_->ProcessApiCallSuccess(
&head_200,
head_200.get(),
std::make_unique<std::string>(kIssueAdviceResponseNoDescription));
}
{ // Valid json: no detail.
CreateFlow(OAuth2MintTokenFlow::MODE_ISSUE_ADVICE);
EXPECT_CALL(delegate_, OnMintTokenFailure(_));
flow_->ProcessApiCallSuccess(
&head_200, std::make_unique<std::string>(kIssueAdviceResponseNoDetail));
head_200.get(),
std::make_unique<std::string>(kIssueAdviceResponseNoDetail));
}
{ // Valid json: good issue advice response.
CreateFlow(OAuth2MintTokenFlow::MODE_ISSUE_ADVICE);
IssueAdviceInfo ia(CreateIssueAdvice());
EXPECT_CALL(delegate_, OnIssueAdviceSuccess(ia));
flow_->ProcessApiCallSuccess(
&head_200, std::make_unique<std::string>(kValidIssueAdviceResponse));
head_200.get(),
std::make_unique<std::string>(kValidIssueAdviceResponse));
}
}
TEST_F(OAuth2MintTokenFlowTest, ProcessApiCallFailure) {
network::ResourceResponseHead head;
network::mojom::URLResponseHead head;
{ // Null delegate should work fine.
CreateFlow(nullptr, OAuth2MintTokenFlow::MODE_MINT_TOKEN_NO_FORCE, "");
flow_->ProcessApiCallFailure(net::ERR_FAILED, &head, nullptr);

@ -22,6 +22,7 @@
#include "net/traffic_annotation/network_traffic_annotation.h"
#include "services/data_decoder/public/mojom/constants.mojom.h"
#include "services/image_annotation/image_annotation_metrics.h"
#include "services/network/public/mojom/url_response_head.mojom.h"
#include "services/service_manager/public/cpp/connector.h"
#include "url/gurl.h"
@ -624,7 +625,7 @@ void Annotator::OnServerResponseReceived(
const std::unique_ptr<std::string> json_response) {
ReportServerNetError(server_request_it->get()->NetError());
if (const network::ResourceResponseInfo* const response_info =
if (const network::mojom::URLResponseHead* const response_info =
server_request_it->get()->ResponseInfo()) {
ReportServerResponseCode(response_info->headers->response_code());
ReportServerLatency(response_info->response_time -

@ -19,6 +19,7 @@
#include "services/network/public/cpp/resource_request.h"
#include "services/network/public/cpp/simple_url_loader.h"
#include "services/network/public/mojom/url_loader.mojom.h"
#include "services/network/public/mojom/url_response_head.mojom.h"
#include "url/gurl.h"
namespace network {
@ -125,7 +126,7 @@ std::unique_ptr<ResourceRequest> CreatePreflightRequest(
std::unique_ptr<PreflightResult> CreatePreflightResult(
const GURL& final_url,
const ResourceResponseHead& head,
const mojom::URLResponseHead& head,
const ResourceRequest& original_request,
bool tainted,
base::Optional<CorsErrorStatus>* detected_error_status) {
@ -218,7 +219,7 @@ class PreflightController::PreflightLoader final {
private:
void HandleRedirect(const net::RedirectInfo& redirect_info,
const network::ResourceResponseHead& response_head,
const network::mojom::URLResponseHead& response_head,
std::vector<std::string>* to_be_removed_headers) {
// Preflight should not allow any redirect.
FinalizeLoader();
@ -232,7 +233,7 @@ class PreflightController::PreflightLoader final {
}
void HandleResponseHeader(const GURL& final_url,
const ResourceResponseHead& head) {
const mojom::URLResponseHead& head) {
FinalizeLoader();
base::Optional<CorsErrorStatus> detected_error_status;
@ -310,7 +311,7 @@ PreflightController::CreatePreflightRequestForTesting(
std::unique_ptr<PreflightResult>
PreflightController::CreatePreflightResultForTesting(
const GURL& final_url,
const ResourceResponseHead& head,
const mojom::URLResponseHead& head,
const ResourceRequest& original_request,
bool tainted,
base::Optional<CorsErrorStatus>* detected_error_status) {

@ -21,12 +21,11 @@
#include "services/network/public/cpp/resource_request.h"
#include "services/network/public/mojom/fetch_api.mojom.h"
#include "services/network/public/mojom/url_loader_factory.mojom.h"
#include "services/network/public/mojom/url_response_head.mojom-forward.h"
#include "url/gurl.h"
namespace network {
struct ResourceResponseHead;
namespace cors {
// A class to manage CORS-preflight, making a CORS-preflight request, checking
@ -43,7 +42,7 @@ class COMPONENT_EXPORT(NETWORK_SERVICE) PreflightController final {
// Creates a PreflightResult for a specified response parameters for testing.
static std::unique_ptr<PreflightResult> CreatePreflightResultForTesting(
const GURL& final_url,
const ResourceResponseHead& head,
const mojom::URLResponseHead& head,
const ResourceRequest& original_request,
bool tainted,
base::Optional<CorsErrorStatus>* detected_error_status);

@ -390,7 +390,7 @@ TEST_F(PreflightControllerTest, CheckTaintedRequest) {
TEST_F(PreflightControllerTest, CheckResponseWithNullHeaders) {
GURL url = GURL("https://google.com/finullurl");
const ResourceResponseHead response_head;
const mojom::URLResponseHead response_head;
ResourceRequest request;
request.url = url;
request.request_initiator = url::Origin::Create(request.url);

@ -10,8 +10,8 @@
#include "net/http/http_util.h"
#include "services/network/origin_policy/origin_policy_manager.h"
#include "services/network/origin_policy/origin_policy_parser.h"
#include "services/network/public/cpp/resource_response.h"
#include "services/network/public/cpp/simple_url_loader.h"
#include "services/network/public/mojom/url_response_head.mojom.h"
namespace network {
@ -82,7 +82,7 @@ void OriginPolicyFetcher::OnPolicyHasArrived(
void OriginPolicyFetcher::OnPolicyRedirect(
const net::RedirectInfo& redirect_info,
const network::ResourceResponseHead& response_head,
const mojom::URLResponseHead& response_head,
std::vector<std::string>* to_be_removed_headers) {
if (IsValidRedirect(redirect_info)) {
must_redirect_ = false;

@ -14,12 +14,12 @@
#include "services/network/public/cpp/simple_url_loader.h"
#include "services/network/public/mojom/origin_policy_manager.mojom.h"
#include "services/network/public/mojom/url_loader_factory.mojom.h"
#include "services/network/public/mojom/url_response_head.mojom-forward.h"
#include "url/origin.h"
namespace network {
class OriginPolicyManager;
struct ResourceResponseHead;
class COMPONENT_EXPORT(NETWORK_SERVICE) OriginPolicyFetcher {
public:
@ -54,12 +54,12 @@ class COMPONENT_EXPORT(NETWORK_SERVICE) OriginPolicyFetcher {
using FetchCallback = base::OnceCallback<void(std::unique_ptr<std::string>)>;
using RedirectCallback =
base::RepeatingCallback<void(const net::RedirectInfo&,
const ResourceResponseHead&,
const mojom::URLResponseHead&,
std::vector<std::string>*)>;
void OnPolicyHasArrived(std::unique_ptr<std::string> policy_content);
void OnPolicyRedirect(const net::RedirectInfo& redirect_info,
const network::ResourceResponseHead& response_head,
const mojom::URLResponseHead& response_head,
std::vector<std::string>* to_be_removed_headers);
void FetchPolicy(mojom::URLLoaderFactory* factory);

@ -37,11 +37,11 @@
#include "net/traffic_annotation/network_traffic_annotation.h"
#include "services/network/public/cpp/data_element.h"
#include "services/network/public/cpp/resource_request.h"
#include "services/network/public/cpp/resource_response.h"
#include "services/network/public/cpp/simple_url_loader_stream_consumer.h"
#include "services/network/public/mojom/data_pipe_getter.mojom.h"
#include "services/network/public/mojom/url_loader.mojom.h"
#include "services/network/public/mojom/url_loader_factory.mojom.h"
#include "services/network/public/mojom/url_response_head.mojom.h"
namespace network {
@ -230,7 +230,7 @@ class SimpleURLLoaderImpl : public SimpleURLLoader,
void SetTimeoutDuration(base::TimeDelta timeout_duration) override;
int NetError() const override;
const ResourceResponseHead* ResponseInfo() const override;
const mojom::URLResponseHead* ResponseInfo() const override;
const GURL& GetFinalURL() const override;
bool LoadedFromCache() const override;
int64_t GetContentSize() const override;
@ -281,7 +281,7 @@ class SimpleURLLoaderImpl : public SimpleURLLoader,
bool loaded_from_cache = false;
std::unique_ptr<ResourceResponseHead> response_info;
mojom::URLResponseHeadPtr response_info;
};
// Prepares internal state to start a request, and then calls StartRequest().
@ -1389,7 +1389,7 @@ int64_t SimpleURLLoaderImpl::GetContentSize() const {
return request_state_->received_body_size;
}
const ResourceResponseHead* SimpleURLLoaderImpl::ResponseInfo() const {
const mojom::URLResponseHead* SimpleURLLoaderImpl::ResponseInfo() const {
// Should only be called once the request is compelete.
DCHECK(request_state_->finished);
return request_state_->response_info.get();
@ -1576,14 +1576,13 @@ void SimpleURLLoaderImpl::OnReceiveResponse(
// Copy |final_url_| to a stack allocated GURL so it remains valid even if
// the callback deletes |this|.
GURL final_url = final_url_;
std::move(on_response_started_callback_).Run(final_url, response_head);
std::move(on_response_started_callback_).Run(final_url, *response_head);
// If deleted by the callback, bail now.
if (!weak_this)
return;
}
request_state_->response_info =
std::make_unique<ResourceResponseHead>(response_head);
request_state_->response_info = std::move(response_head);
if (!allow_http_error_results_ && response_code / 100 != 2)
FinishWithResult(net::ERR_HTTP_RESPONSE_CODE_FAILURE);
}
@ -1604,7 +1603,7 @@ void SimpleURLLoaderImpl::OnReceiveRedirect(
if (callback) {
base::WeakPtr<SimpleURLLoaderImpl> weak_this =
weak_ptr_factory_.GetWeakPtr();
callback.Run(redirect_info, response_head, &removed_headers);
callback.Run(redirect_info, *response_head, &removed_headers);
// If deleted by the callback, bail now.
if (!weak_this)
return;

@ -15,7 +15,7 @@
#include "base/callback_forward.h"
#include "base/component_export.h"
#include "base/macros.h"
#include "services/network/public/cpp/resource_response.h"
#include "services/network/public/mojom/url_response_head.mojom.h"
class GURL;
@ -115,14 +115,14 @@ class COMPONENT_EXPORT(NETWORK_CPP) SimpleURLLoader {
// removed for requests when a redirect to a non-Google URL occurs.
using OnRedirectCallback =
base::RepeatingCallback<void(const net::RedirectInfo& redirect_info,
const ResourceResponseHead& response_head,
const mojom::URLResponseHead& response_head,
std::vector<std::string>* removed_headers)>;
// Callback used when a response is received. It is safe to delete the
// SimpleURLLoader during the callback.
using OnResponseStartedCallback =
base::OnceCallback<void(const GURL& final_url,
const ResourceResponseHead& response_head)>;
const mojom::URLResponseHead& response_head)>;
// Callback used when an upload progress is reported. It is safe to
// delete the SimpleURLLoader during the callback.
@ -331,10 +331,10 @@ class COMPONENT_EXPORT(NETWORK_CPP) SimpleURLLoader {
// only be called once the loader has informed the caller of completion.
virtual int NetError() const = 0;
// The ResourceResponseHead for the request. Will be nullptr if ResponseInfo
// The URLResponseHead for the request. Will be nullptr if ResponseInfo
// was never received. May only be called once the loader has informed the
// caller of completion.
virtual const ResourceResponseHead* ResponseInfo() const = 0;
virtual const mojom::URLResponseHead* ResponseInfo() const = 0;
// Returns the URL that this loader is processing. May only be called once the
// loader has informed the caller of completion.

@ -47,11 +47,11 @@
#include "net/url_request/redirect_info.h"
#include "services/network/network_service.h"
#include "services/network/public/cpp/resource_request.h"
#include "services/network/public/cpp/resource_response.h"
#include "services/network/public/cpp/simple_url_loader_stream_consumer.h"
#include "services/network/public/cpp/url_loader_completion_status.h"
#include "services/network/public/mojom/network_service.mojom.h"
#include "services/network/public/mojom/url_loader_factory.mojom.h"
#include "services/network/public/mojom/url_response_head.mojom.h"
#include "services/network/test/test_network_context_client.h"
#include "services/network/test/test_network_service_client.h"
#include "testing/gtest/include/gtest/gtest.h"
@ -767,16 +767,16 @@ TEST_P(SimpleURLLoaderTest, OnRedirectCallback) {
int num_redirects = 0;
net::RedirectInfo redirect_info;
network::ResourceResponseHead response_head;
network::mojom::URLResponseHeadPtr response_head;
test_helper->simple_url_loader()->SetOnRedirectCallback(base::BindRepeating(
[](int* num_redirects, net::RedirectInfo* redirect_info_ptr,
network::ResourceResponseHead* response_head_ptr,
network::mojom::URLResponseHeadPtr* response_head_ptr,
const net::RedirectInfo& redirect_info,
const network::ResourceResponseHead& response_head,
const network::mojom::URLResponseHead& response_head,
std::vector<std::string>* to_be_removed_headers) {
++*num_redirects;
*redirect_info_ptr = redirect_info;
*response_head_ptr = response_head;
*response_head_ptr = response_head.Clone();
},
base::Unretained(&num_redirects), base::Unretained(&redirect_info),
base::Unretained(&response_head)));
@ -790,8 +790,8 @@ TEST_P(SimpleURLLoaderTest, OnRedirectCallback) {
EXPECT_EQ(1, num_redirects);
EXPECT_EQ(test_server_.GetURL("/echo"), redirect_info.new_url);
ASSERT_TRUE(response_head.headers);
EXPECT_EQ(301, response_head.headers->response_code());
ASSERT_TRUE(response_head->headers);
EXPECT_EQ(301, response_head->headers->response_code());
}
// Make sure OnRedirectCallback is invoked on each redirect.
@ -805,7 +805,7 @@ TEST_P(SimpleURLLoaderTest, OnRedirectCallbackTwoRedirects) {
int num_redirects = 0;
test_helper->simple_url_loader()->SetOnRedirectCallback(base::BindRepeating(
[](int* num_redirects, const net::RedirectInfo& redirect_info,
const network::ResourceResponseHead& response_head,
const network::mojom::URLResponseHead& response_head,
std::vector<std::string>* to_be_removed_headers) { ++*num_redirects; },
base::Unretained(&num_redirects)));
@ -830,7 +830,7 @@ TEST_P(SimpleURLLoaderTest, DeleteInOnRedirectCallback) {
base::BindRepeating(
[](std::unique_ptr<SimpleLoaderTestHelper> test_helper,
base::RunLoop* run_loop, const net::RedirectInfo& redirect_info,
const network::ResourceResponseHead& response_head,
const network::mojom::URLResponseHead& response_head,
std::vector<std::string>* to_be_removed_headers) {
test_helper.reset();
// Access the parameters to trigger a memory error if they have been
@ -860,7 +860,7 @@ TEST_P(SimpleURLLoaderTest, UploadShortStringWithRedirect) {
int num_redirects = 0;
test_helper->simple_url_loader()->SetOnRedirectCallback(base::BindRepeating(
[](int* num_redirects, const net::RedirectInfo& redirect_info,
const network::ResourceResponseHead& response_head,
const network::mojom::URLResponseHead& response_head,
std::vector<std::string>* to_be_removed_headers) { ++*num_redirects; },
base::Unretained(&num_redirects)));
@ -888,7 +888,7 @@ TEST_P(SimpleURLLoaderTest, UploadLongStringWithRedirect) {
int num_redirects = 0;
test_helper->simple_url_loader()->SetOnRedirectCallback(base::BindRepeating(
[](int* num_redirects, const net::RedirectInfo& redirect_info,
const network::ResourceResponseHead& response_head,
const network::mojom::URLResponseHead& response_head,
std::vector<std::string>* to_be_removed_headers) { ++*num_redirects; },
base::Unretained(&num_redirects)));
@ -920,7 +920,7 @@ TEST_P(SimpleURLLoaderTest,
int num_redirects = 0;
test_helper->simple_url_loader()->SetOnRedirectCallback(base::BindRepeating(
[](int* num_redirects, const net::RedirectInfo& redirect_info,
const network::ResourceResponseHead& response_head,
const network::mojom::URLResponseHead& response_head,
std::vector<std::string>* to_be_removed_headers) {
++*num_redirects;
to_be_removed_headers->push_back("foo");
@ -954,7 +954,7 @@ TEST_P(SimpleURLLoaderTest,
int num_redirects = 0;
test_helper->simple_url_loader()->SetOnRedirectCallback(base::BindRepeating(
[](int* num_redirects, const net::RedirectInfo& redirect_info,
const network::ResourceResponseHead& response_head,
const network::mojom::URLResponseHead& response_head,
std::vector<std::string>* to_be_removed_headers) {
++*num_redirects;
to_be_removed_headers->push_back("bar");
@ -989,7 +989,7 @@ TEST_P(SimpleURLLoaderTest, OnResponseStartedCallback) {
test_helper->simple_url_loader()->SetOnResponseStartedCallback(base::BindOnce(
[](GURL* out_final_url, std::string* foo_header_value,
base::OnceClosure quit_closure, const GURL& final_url,
const ResourceResponseHead& response_head) {
const mojom::URLResponseHead& response_head) {
*out_final_url = final_url;
if (response_head.headers) {
response_head.headers->EnumerateHeader(/*iter=*/nullptr, "foo",
@ -1015,7 +1015,7 @@ TEST_P(SimpleURLLoaderTest, DeleteInOnResponseStartedCallback) {
base::BindOnce(
[](std::unique_ptr<SimpleLoaderTestHelper> test_helper,
base::OnceClosure quit_closure, const GURL& final_url,
const ResourceResponseHead& response_head) {
const mojom::URLResponseHead& response_head) {
// Delete the SimpleURLLoader.
test_helper.reset();
// Access the parameters to trigger a memory error if they have been
@ -1827,41 +1827,41 @@ class MockURLLoader : public network::mojom::URLLoader {
redirect_info.new_url = GURL("bar://foo/");
redirect_info.status_code = 301;
network::ResourceResponseHead response_info;
auto response_info = network::mojom::URLResponseHead::New();
std::string headers(
"HTTP/1.0 301 The Response Has Moved to Another Server\n"
"Location: bar://foo/");
response_info.headers =
response_info->headers =
base::MakeRefCounted<net::HttpResponseHeaders>(
net::HttpUtil::AssembleRawHeaders(headers));
client_->OnReceiveRedirect(redirect_info, response_info);
client_->OnReceiveRedirect(redirect_info, std::move(response_info));
break;
}
case TestLoaderEvent::kReceivedResponse: {
network::ResourceResponseHead response_info;
auto response_info = network::mojom::URLResponseHead::New();
std::string headers("HTTP/1.0 200 OK");
response_info.headers =
response_info->headers =
base::MakeRefCounted<net::HttpResponseHeaders>(
net::HttpUtil::AssembleRawHeaders(headers));
client_->OnReceiveResponse(response_info);
client_->OnReceiveResponse(std::move(response_info));
break;
}
case TestLoaderEvent::kReceived401Response: {
network::ResourceResponseHead response_info;
auto response_info = network::mojom::URLResponseHead::New();
std::string headers("HTTP/1.0 401 Client Borkage");
response_info.headers =
response_info->headers =
base::MakeRefCounted<net::HttpResponseHeaders>(
net::HttpUtil::AssembleRawHeaders(headers));
client_->OnReceiveResponse(response_info);
client_->OnReceiveResponse(std::move(response_info));
break;
}
case TestLoaderEvent::kReceived501Response: {
network::ResourceResponseHead response_info;
auto response_info = network::mojom::URLResponseHead::New();
std::string headers("HTTP/1.0 501 Server Borkage");
response_info.headers =
response_info->headers =
base::MakeRefCounted<net::HttpResponseHeaders>(
net::HttpUtil::AssembleRawHeaders(headers));
client_->OnReceiveResponse(response_info);
client_->OnReceiveResponse(std::move(response_info));
break;
}
case TestLoaderEvent::kBodyBufferReceived: {
@ -2540,7 +2540,7 @@ TEST_P(SimpleURLLoaderTest, RetryAfterRedirect) {
1, SimpleURLLoader::RETRY_ON_5XX);
test_helper->simple_url_loader()->SetOnRedirectCallback(base::BindRepeating(
[](int* num_redirects, const net::RedirectInfo& redirect_info,
const network::ResourceResponseHead& response_head,
const network::mojom::URLResponseHead& response_head,
std::vector<std::string>* to_be_removed_headers) { ++*num_redirects; },
base::Unretained(&num_redirects)));
loader_factory.RunTest(test_helper.get());