Commit 7e9e9c1c authored by Mohamed Abdelhalim's avatar Mohamed Abdelhalim Committed by Commit Bot

Navigation: Remove NavigationRequest::RunCompleteCallback.

Make the callback function boolean, that return true to skip the
On*ChecksComplete functions.

And use |state| instead of |complete_callback| to determine the right
function to call.

Bug: 916537
Change-Id: I4ae0af25e687868d121a238c31632b89b0c0df2e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1919210Reviewed-by: default avatarCamille Lamy <clamy@chromium.org>
Reviewed-by: default avatarArthur Sonzogni <arthursonzogni@chromium.org>
Commit-Queue: Mohamed Abdelhalim <zetamoo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#719119}
parent 83fadb5f
......@@ -394,7 +394,7 @@ class CONTENT_EXPORT NavigationRequest
// Simulates renderer aborting navigation.
void RendererAbortedNavigationForTesting();
typedef base::OnceCallback<void(NavigationThrottle::ThrottleCheckResult)>
typedef base::OnceCallback<bool(NavigationThrottle::ThrottleCheckResult)>
ThrottleChecksFinishedCallback;
NavigationThrottle* GetDeferringThrottleForTesting() const {
......@@ -697,14 +697,10 @@ class CONTENT_EXPORT NavigationRequest
// TODO(zetamoo): Remove the Will* methods and fold them into their callers.
// Called when the URLRequest will start in the network stack. |callback| will
// be called when all throttle checks have completed. This will allow the
// caller to cancel the navigation or let it proceed.
void WillStartRequest(ThrottleChecksFinishedCallback callback);
// Called when the URLRequest will start in the network stack.
void WillStartRequest();
// Called when the URLRequest will be redirected in the network stack.
// |callback| will be called when all throttles check have completed. This
// will allow the caller to cancel the navigation or let it proceed.
// This will also inform the delegate that the request was redirected.
//
// |post_redirect_process| is the renderer process we expect to use to commit
......@@ -712,14 +708,10 @@ class CONTENT_EXPORT NavigationRequest
// no live process that can be used. In that case, a suitable renderer process
// will be created at commit time.
void WillRedirectRequest(const GURL& new_referrer_url,
RenderProcessHost* post_redirect_process,
ThrottleChecksFinishedCallback callback);
RenderProcessHost* post_redirect_process);
// Called when the URLRequest will fail. |callback| will be called when all
// throttles check have completed. This will allow the caller to explicitly
// cancel the navigation (with a custom error code and/or custom error page
// HTML) or let the failure proceed as normal.
void WillFailRequest(ThrottleChecksFinishedCallback callback);
// Called when the URLRequest will fail.
void WillFailRequest();
// Called when the URLRequest has delivered response headers and metadata.
// |callback| will be called when all throttle checks have completed,
......@@ -727,7 +719,7 @@ class CONTENT_EXPORT NavigationRequest
// NavigationHandle will not call |callback| with a result of DEFER.
// If the result is PROCEED, then 'ReadyToCommitNavigation' will be called
// just before calling |callback|.
void WillProcessResponse(ThrottleChecksFinishedCallback callback);
void WillProcessResponse();
// Checks for attempts to navigate to a page that is already referenced more
// than once in the frame's ancestors. This is a helper function used by
......@@ -748,8 +740,7 @@ class CONTENT_EXPORT NavigationRequest
// Updates the state of the navigation handle after encountering a server
// redirect.
void UpdateStateFollowingRedirect(const GURL& new_referrer_url,
ThrottleChecksFinishedCallback callback);
void UpdateStateFollowingRedirect(const GURL& new_referrer_url);
// NeedsUrlLoader() returns true if the navigation needs to use the
// NavigationURLLoader for loading the document.
......@@ -787,11 +778,6 @@ class CONTENT_EXPORT NavigationRequest
// navigation or an error page.
bool IsWaitingToCommit();
// Helper function to run and reset the |complete_callback_|. This marks the
// end of a round of NavigationThrottleChecks.
// TODO(zetamoo): This can be removed once the navigation states are merged.
void RunCompleteCallback(NavigationThrottle::ThrottleCheckResult result);
// Called if READY_TO_COMMIT -> COMMIT state transition takes an unusually
// long time.
void OnCommitTimeout();
......@@ -1026,12 +1012,9 @@ class CONTENT_EXPORT NavigationRequest
// with this html as content and |net_error| as the network error.
std::string post_commit_error_page_html_;
// This callback will be run when all throttle checks have been performed.
// TODO(zetamoo): This can be removed once the navigation states are merged.
ThrottleChecksFinishedCallback complete_callback_;
// This test-only callback will be run when all throttle checks have been
// performed.
// performed. If the callback returns true, On*ChecksComplete functions are
// skipped, and only the test callback is being performed.
// TODO(clamy): Revisit the unit test architecture.
ThrottleChecksFinishedCallback complete_callback_for_testing_;
......
......@@ -90,11 +90,13 @@ class NavigationRequestTest : public RenderViewHostImplTestHarness {
was_callback_called_ = false;
callback_result_ = NavigationThrottle::DEFER;
// It's safe to use base::Unretained since the NavigationHandle is owned by
// It's safe to use base::Unretained since the NavigationRequest is owned by
// the NavigationRequestTest.
request_->WillStartRequest(
request_->set_complete_callback_for_testing(
base::BindOnce(&NavigationRequestTest::UpdateThrottleCheckResult,
base::Unretained(this)));
request_->WillStartRequest();
}
// Helper function to call WillRedirectRequest on |handle|. If this function
......@@ -106,12 +108,13 @@ class NavigationRequestTest : public RenderViewHostImplTestHarness {
was_callback_called_ = false;
callback_result_ = NavigationThrottle::DEFER;
// It's safe to use base::Unretained since the NavigationHandle is owned by
// It's safe to use base::Unretained since the NavigationRequest is owned by
// the NavigationRequestTest.
request_->WillRedirectRequest(
GURL(), nullptr,
request_->set_complete_callback_for_testing(
base::BindOnce(&NavigationRequestTest::UpdateThrottleCheckResult,
base::Unretained(this)));
request_->WillRedirectRequest(GURL(), nullptr);
}
// Helper function to call WillFailRequest on |handle|. If this function
......@@ -124,11 +127,13 @@ class NavigationRequestTest : public RenderViewHostImplTestHarness {
callback_result_ = NavigationThrottle::DEFER;
request_->set_net_error(net_error_code);
// It's safe to use base::Unretained since the NavigationHandle is owned by
// It's safe to use base::Unretained since the NavigationRequest is owned by
// the NavigationRequestTest.
request_->WillFailRequest(
request_->set_complete_callback_for_testing(
base::BindOnce(&NavigationRequestTest::UpdateThrottleCheckResult,
base::Unretained(this)));
request_->WillFailRequest();
}
// Whether the callback was called.
......@@ -199,10 +204,11 @@ class NavigationRequestTest : public RenderViewHostImplTestHarness {
// The callback provided to NavigationRequest::WillStartRequest,
// NavigationRequest::WillRedirectRequest, and
// NavigationRequest::WillFailRequest during the tests.
void UpdateThrottleCheckResult(
bool UpdateThrottleCheckResult(
NavigationThrottle::ThrottleCheckResult result) {
callback_result_ = result;
was_callback_called_ = true;
return true;
}
std::unique_ptr<NavigationRequest> request_;
......
......@@ -1209,12 +1209,12 @@ class NavigationHandleGrabber : public WebContentsObserver {
base::Unretained(this), navigation_handle));
}
void SendingNavigationCommitted(
bool SendingNavigationCommitted(
NavigationHandle* navigation_handle,
NavigationThrottle::ThrottleCheckResult result) {
if (navigation_handle->GetURL().path() != "/title2.html")
return;
ExecuteScriptAsync(web_contents(), "document.open();");
if (navigation_handle->GetURL().path() == "/title2.html")
ExecuteScriptAsync(web_contents(), "document.open();");
return false;
}
void DidFinishNavigation(NavigationHandle* navigation_handle) override {
......
......@@ -1173,7 +1173,7 @@ void NavigationSimulatorImpl::Wait() {
run_loop.Run();
}
void NavigationSimulatorImpl::OnThrottleChecksComplete(
bool NavigationSimulatorImpl::OnThrottleChecksComplete(
NavigationThrottle::ThrottleCheckResult result) {
CHECK(!last_throttle_check_result_);
last_throttle_check_result_ = result;
......@@ -1181,13 +1181,14 @@ void NavigationSimulatorImpl::OnThrottleChecksComplete(
std::move(wait_closure_).Run();
if (throttle_checks_complete_closure_)
std::move(throttle_checks_complete_closure_).Run();
return false;
}
void NavigationSimulatorImpl::PrepareCompleteCallbackOnRequest() {
last_throttle_check_result_.reset();
request_->set_complete_callback_for_testing(
base::BindOnce(&NavigationSimulatorImpl::OnThrottleChecksComplete,
weak_factory_.GetWeakPtr()));
base::Unretained(this)));
}
RenderFrameHost* NavigationSimulatorImpl::GetFinalRenderFrameHost() {
......
......@@ -214,7 +214,7 @@ class NavigationSimulatorImpl : public NavigationSimulator,
// Sets |last_throttle_check_result_| and calls both the
// |wait_closure_| and the |throttle_checks_complete_closure_|, if they are
// set.
void OnThrottleChecksComplete(NavigationThrottle::ThrottleCheckResult result);
bool OnThrottleChecksComplete(NavigationThrottle::ThrottleCheckResult result);
// Helper method to set the OnThrottleChecksComplete callback on the
// NavigationRequest.
......
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