Commit 26e2a366 authored by Matt Menke's avatar Matt Menke Committed by Commit Bot

Remove the ability for URLRequests to be restarted.

This is not longer being used.  It had been used by AppCache and the
Data Reduction Proxy, neither of which hook directly into net anymore.

Bug: 934009
Change-Id: I9351b2bc889fa4474f3ac91bf7f7041b4ae6d092
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1790489
Commit-Queue: Matt Menke <mmenke@chromium.org>
Reviewed-by: default avatarEric Roman <eroman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#695431}
parent 1ba39268
...@@ -705,13 +705,6 @@ void URLRequest::StartJob(URLRequestJob* job) { ...@@ -705,13 +705,6 @@ void URLRequest::StartJob(URLRequestJob* job) {
job_->Start(); job_->Start();
} }
void URLRequest::Restart() {
// Should only be called if the original job didn't make any progress.
DCHECK(job_.get() && !job_->has_response_started());
RestartWithJob(
URLRequestJobManager::GetInstance()->CreateJob(this, network_delegate_));
}
void URLRequest::RestartWithJob(URLRequestJob* job) { void URLRequest::RestartWithJob(URLRequestJob* job) {
DCHECK(job->request() == this); DCHECK(job->request() == this);
PrepareToRestart(); PrepareToRestart();
......
...@@ -789,10 +789,6 @@ class NET_EXPORT URLRequest : public base::SupportsUserData { ...@@ -789,10 +789,6 @@ class NET_EXPORT URLRequest : public base::SupportsUserData {
void NotifyReceivedRedirect(const RedirectInfo& redirect_info, void NotifyReceivedRedirect(const RedirectInfo& redirect_info,
bool* defer_redirect); bool* defer_redirect);
// Allow an interceptor's URLRequestJob to restart this request.
// Should only be called if the original job has not started a response.
void Restart();
private: private:
friend class URLRequestJob; friend class URLRequestJob;
friend class URLRequestContext; friend class URLRequestContext;
......
...@@ -571,12 +571,6 @@ void URLRequestJob::NotifyCanceled() { ...@@ -571,12 +571,6 @@ void URLRequestJob::NotifyCanceled() {
} }
} }
void URLRequestJob::NotifyRestartRequired() {
DCHECK(!has_handled_response_);
if (GetStatus().status() != URLRequestStatus::CANCELED)
request_->Restart();
}
void URLRequestJob::OnCallToDelegate(NetLogEventType type) { void URLRequestJob::OnCallToDelegate(NetLogEventType type) {
request_->OnCallToDelegate(type); request_->OnCallToDelegate(type);
} }
......
...@@ -285,10 +285,6 @@ class NET_EXPORT URLRequestJob { ...@@ -285,10 +285,6 @@ class NET_EXPORT URLRequestJob {
// that we were canceled. // that we were canceled.
void NotifyCanceled(); void NotifyCanceled();
// Notifies the job the request should be restarted.
// Should only be called if the job has not started a response.
void NotifyRestartRequired();
// See corresponding functions in url_request.h. // See corresponding functions in url_request.h.
void OnCallToDelegate(NetLogEventType type); void OnCallToDelegate(NetLogEventType type);
void OnCallToDelegateComplete(); void OnCallToDelegateComplete();
......
...@@ -927,17 +927,6 @@ TEST_F(URLRequestTest, InvalidReferrerTest) { ...@@ -927,17 +927,6 @@ TEST_F(URLRequestTest, InvalidReferrerTest) {
EXPECT_TRUE(d.request_failed()); EXPECT_TRUE(d.request_failed());
} }
// Custom URLRequestJobs for use with interceptor tests
class RestartTestJob : public URLRequestTestJob {
public:
RestartTestJob(URLRequest* request, NetworkDelegate* network_delegate)
: URLRequestTestJob(request, network_delegate, true) {}
protected:
void StartAsync() override { this->NotifyRestartRequired(); }
private:
~RestartTestJob() override = default;
};
class CancelTestJob : public URLRequestTestJob { class CancelTestJob : public URLRequestTestJob {
public: public:
explicit CancelTestJob(URLRequest* request, NetworkDelegate* network_delegate) explicit CancelTestJob(URLRequest* request, NetworkDelegate* network_delegate)
...@@ -948,21 +937,6 @@ class CancelTestJob : public URLRequestTestJob { ...@@ -948,21 +937,6 @@ class CancelTestJob : public URLRequestTestJob {
~CancelTestJob() override = default; ~CancelTestJob() override = default;
}; };
class CancelThenRestartTestJob : public URLRequestTestJob {
public:
explicit CancelThenRestartTestJob(URLRequest* request,
NetworkDelegate* network_delegate)
: URLRequestTestJob(request, network_delegate, true) {
}
protected:
void StartAsync() override {
request_->Cancel();
this->NotifyRestartRequired();
}
private:
~CancelThenRestartTestJob() override = default;
};
// An Interceptor for use with interceptor tests. // An Interceptor for use with interceptor tests.
class MockURLRequestInterceptor : public URLRequestInterceptor { class MockURLRequestInterceptor : public URLRequestInterceptor {
public: public:
...@@ -992,18 +966,21 @@ class MockURLRequestInterceptor : public URLRequestInterceptor { ...@@ -992,18 +966,21 @@ class MockURLRequestInterceptor : public URLRequestInterceptor {
} }
MockURLRequestInterceptor() MockURLRequestInterceptor()
: intercept_main_request_(false), restart_main_request_(false), : intercept_main_request_(false),
cancel_main_request_(false), cancel_then_restart_main_request_(false), cancel_main_request_(false),
simulate_main_network_error_(false), simulate_main_network_error_(false),
intercept_redirect_(false), cancel_redirect_request_(false), intercept_redirect_(false),
intercept_final_response_(false), cancel_final_request_(false), cancel_redirect_request_(false),
intercept_final_response_(false),
cancel_final_request_(false),
use_url_request_http_job_(false), use_url_request_http_job_(false),
did_intercept_main_(false), did_restart_main_(false), did_intercept_main_(false),
did_cancel_main_(false), did_cancel_then_restart_main_(false), did_cancel_main_(false),
did_simulate_error_main_(false), did_simulate_error_main_(false),
did_intercept_redirect_(false), did_cancel_redirect_(false), did_intercept_redirect_(false),
did_intercept_final_(false), did_cancel_final_(false) { did_cancel_redirect_(false),
} did_intercept_final_(false),
did_cancel_final_(false) {}
~MockURLRequestInterceptor() override = default; ~MockURLRequestInterceptor() override = default;
...@@ -1011,21 +988,11 @@ class MockURLRequestInterceptor : public URLRequestInterceptor { ...@@ -1011,21 +988,11 @@ class MockURLRequestInterceptor : public URLRequestInterceptor {
URLRequestJob* MaybeInterceptRequest( URLRequestJob* MaybeInterceptRequest(
URLRequest* request, URLRequest* request,
NetworkDelegate* network_delegate) const override { NetworkDelegate* network_delegate) const override {
if (restart_main_request_) {
restart_main_request_ = false;
did_restart_main_ = true;
return new RestartTestJob(request, network_delegate);
}
if (cancel_main_request_) { if (cancel_main_request_) {
cancel_main_request_ = false; cancel_main_request_ = false;
did_cancel_main_ = true; did_cancel_main_ = true;
return new CancelTestJob(request, network_delegate); return new CancelTestJob(request, network_delegate);
} }
if (cancel_then_restart_main_request_) {
cancel_then_restart_main_request_ = false;
did_cancel_then_restart_main_ = true;
return new CancelThenRestartTestJob(request, network_delegate);
}
if (simulate_main_network_error_) { if (simulate_main_network_error_) {
simulate_main_network_error_ = false; simulate_main_network_error_ = false;
did_simulate_error_main_ = true; did_simulate_error_main_ = true;
...@@ -1110,19 +1077,10 @@ class MockURLRequestInterceptor : public URLRequestInterceptor { ...@@ -1110,19 +1077,10 @@ class MockURLRequestInterceptor : public URLRequestInterceptor {
main_request_load_timing_info_ = main_request_load_timing_info; main_request_load_timing_info_ = main_request_load_timing_info;
} }
void set_restart_main_request(bool restart_main_request) {
restart_main_request_ = restart_main_request;
}
void set_cancel_main_request(bool cancel_main_request) { void set_cancel_main_request(bool cancel_main_request) {
cancel_main_request_ = cancel_main_request; cancel_main_request_ = cancel_main_request;
} }
void set_cancel_then_restart_main_request(
bool cancel_then_restart_main_request) {
cancel_then_restart_main_request_ = cancel_then_restart_main_request;
}
void set_simulate_main_network_error(bool simulate_main_network_error) { void set_simulate_main_network_error(bool simulate_main_network_error) {
simulate_main_network_error_ = simulate_main_network_error; simulate_main_network_error_ = simulate_main_network_error;
} }
...@@ -1167,18 +1125,10 @@ class MockURLRequestInterceptor : public URLRequestInterceptor { ...@@ -1167,18 +1125,10 @@ class MockURLRequestInterceptor : public URLRequestInterceptor {
return did_intercept_main_; return did_intercept_main_;
} }
bool did_restart_main() const {
return did_restart_main_;
}
bool did_cancel_main() const { bool did_cancel_main() const {
return did_cancel_main_; return did_cancel_main_;
} }
bool did_cancel_then_restart_main() const {
return did_cancel_then_restart_main_;
}
bool did_simulate_error_main() const { bool did_simulate_error_main() const {
return did_simulate_error_main_; return did_simulate_error_main_;
} }
...@@ -1208,9 +1158,7 @@ class MockURLRequestInterceptor : public URLRequestInterceptor { ...@@ -1208,9 +1158,7 @@ class MockURLRequestInterceptor : public URLRequestInterceptor {
mutable LoadTimingInfo main_request_load_timing_info_; mutable LoadTimingInfo main_request_load_timing_info_;
// These indicate actions that can be taken within MaybeInterceptRequest. // These indicate actions that can be taken within MaybeInterceptRequest.
mutable bool restart_main_request_;
mutable bool cancel_main_request_; mutable bool cancel_main_request_;
mutable bool cancel_then_restart_main_request_;
mutable bool simulate_main_network_error_; mutable bool simulate_main_network_error_;
// Indicate whether to intercept redirects, and if so specify the response to // Indicate whether to intercept redirects, and if so specify the response to
...@@ -1236,9 +1184,7 @@ class MockURLRequestInterceptor : public URLRequestInterceptor { ...@@ -1236,9 +1184,7 @@ class MockURLRequestInterceptor : public URLRequestInterceptor {
// These indicate if the interceptor did something or not. // These indicate if the interceptor did something or not.
mutable bool did_intercept_main_; mutable bool did_intercept_main_;
mutable bool did_restart_main_;
mutable bool did_cancel_main_; mutable bool did_cancel_main_;
mutable bool did_cancel_then_restart_main_;
mutable bool did_simulate_error_main_; mutable bool did_simulate_error_main_;
mutable bool did_intercept_redirect_; mutable bool did_intercept_redirect_;
mutable bool did_cancel_redirect_; mutable bool did_cancel_redirect_;
...@@ -1397,38 +1343,6 @@ TEST_F(URLRequestInterceptorTest, InterceptNetworkError) { ...@@ -1397,38 +1343,6 @@ TEST_F(URLRequestInterceptorTest, InterceptNetworkError) {
EXPECT_EQ(0, d.received_redirect_count()); EXPECT_EQ(0, d.received_redirect_count());
} }
TEST_F(URLRequestInterceptorTest, InterceptRestartRequired) {
// Restart the main request.
interceptor()->set_restart_main_request(true);
// then intercept the new main request and respond with an OK response
interceptor()->set_intercept_main_request(true);
interceptor()->set_main_headers(MockURLRequestInterceptor::ok_headers());
interceptor()->set_main_data(MockURLRequestInterceptor::ok_data());
TestDelegate d;
std::unique_ptr<URLRequest> req(default_context().CreateRequest(
GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d,
TRAFFIC_ANNOTATION_FOR_TESTS));
req->set_method("GET");
req->Start();
d.RunUntilComplete();
// Check that the interceptor got called as expected.
EXPECT_TRUE(interceptor()->did_restart_main());
EXPECT_TRUE(interceptor()->did_intercept_main());
// Check that we received one good response.
int status = d.request_status();
EXPECT_EQ(OK, status);
if (status == OK)
EXPECT_EQ(200, req->response_headers()->response_code());
EXPECT_EQ(MockURLRequestInterceptor::ok_data(), d.data_received());
EXPECT_EQ(1, d.response_started_count());
EXPECT_EQ(0, d.received_redirect_count());
}
TEST_F(URLRequestInterceptorTest, InterceptRespectsCancelMain) { TEST_F(URLRequestInterceptorTest, InterceptRespectsCancelMain) {
// Intercept the main request and cancel from within the restarted job. // Intercept the main request and cancel from within the restarted job.
interceptor()->set_cancel_main_request(true); interceptor()->set_cancel_main_request(true);
...@@ -1509,31 +1423,6 @@ TEST_F(URLRequestInterceptorTest, InterceptRespectsCancelFinal) { ...@@ -1509,31 +1423,6 @@ TEST_F(URLRequestInterceptorTest, InterceptRespectsCancelFinal) {
EXPECT_EQ(ERR_ABORTED, d.request_status()); EXPECT_EQ(ERR_ABORTED, d.request_status());
} }
TEST_F(URLRequestInterceptorTest, InterceptRespectsCancelInRestart) {
// Intercept the main request and cancel then restart from within that job.
interceptor()->set_cancel_then_restart_main_request(true);
// Set up to intercept the final response and override it with an OK response.
interceptor()->set_intercept_final_response(true);
interceptor()->set_final_headers(MockURLRequestInterceptor::ok_headers());
interceptor()->set_final_data(MockURLRequestInterceptor::ok_data());
TestDelegate d;
std::unique_ptr<URLRequest> req(default_context().CreateRequest(
GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d,
TRAFFIC_ANNOTATION_FOR_TESTS));
req->set_method("GET");
req->Start();
d.RunUntilComplete();
// Check that the interceptor got called as expected.
EXPECT_TRUE(interceptor()->did_cancel_then_restart_main());
EXPECT_FALSE(interceptor()->did_intercept_final());
// Check that we see a canceled request.
EXPECT_EQ(ERR_ABORTED, d.request_status());
}
// "Normal" LoadTimingInfo as returned by a job. Everything is in order, not // "Normal" LoadTimingInfo as returned by a job. Everything is in order, not
// reused. |connect_time_flags| is used to indicate if there should be dns // reused. |connect_time_flags| is used to indicate if there should be dns
// or SSL times, and |used_proxy| is used for proxy times. // or SSL times, and |used_proxy| is used for proxy times.
......
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