| Index: content/public/test/cancelling_navigation_throttle.cc
|
| diff --git a/content/public/test/cancelling_navigation_throttle.cc b/content/public/test/cancelling_navigation_throttle.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..4a3b7713d5cc041dff9ee13a8c3fe1cbd347d48e
|
| --- /dev/null
|
| +++ b/content/public/test/cancelling_navigation_throttle.cc
|
| @@ -0,0 +1,59 @@
|
| +// Copyright 2017 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "content/public/test/cancelling_navigation_throttle.h"
|
| +
|
| +#include "base/bind.h"
|
| +#include "content/public/browser/browser_thread.h"
|
| +#include "content/public/browser/navigation_handle.h"
|
| +
|
| +namespace content {
|
| +
|
| +CancellingNavigationThrottle::CancellingNavigationThrottle(
|
| + NavigationHandle* handle,
|
| + CancelTime cancel_time,
|
| + ResultSynchrony sync)
|
| + : NavigationThrottle(handle),
|
| + cancel_time_(cancel_time),
|
| + sync_(sync),
|
| + weak_ptr_factory_(this) {}
|
| +
|
| +CancellingNavigationThrottle::~CancellingNavigationThrottle() {}
|
| +
|
| +NavigationThrottle::ThrottleCheckResult
|
| +CancellingNavigationThrottle::WillStartRequest() {
|
| + return ProcessState(cancel_time_ == WILL_START_REQUEST);
|
| +}
|
| +
|
| +NavigationThrottle::ThrottleCheckResult
|
| +CancellingNavigationThrottle::WillRedirectRequest() {
|
| + return ProcessState(cancel_time_ == WILL_REDIRECT_REQUEST);
|
| +}
|
| +
|
| +NavigationThrottle::ThrottleCheckResult
|
| +CancellingNavigationThrottle::WillProcessResponse() {
|
| + return ProcessState(cancel_time_ == WILL_PROCESS_RESPONSE);
|
| +}
|
| +
|
| +NavigationThrottle::ThrottleCheckResult
|
| +CancellingNavigationThrottle::ProcessState(bool should_cancel) {
|
| + if (sync_ == ASYNCHRONOUS) {
|
| + BrowserThread::PostTask(
|
| + BrowserThread::UI, FROM_HERE,
|
| + base::Bind(&CancellingNavigationThrottle::MaybeCancel,
|
| + weak_ptr_factory_.GetWeakPtr(), should_cancel));
|
| + return NavigationThrottle::DEFER;
|
| + }
|
| + return should_cancel ? NavigationThrottle::CANCEL
|
| + : NavigationThrottle::PROCEED;
|
| +}
|
| +
|
| +void CancellingNavigationThrottle::MaybeCancel(bool cancel) {
|
| + if (cancel)
|
| + navigation_handle()->CancelDeferredNavigation(NavigationThrottle::CANCEL);
|
| + else
|
| + navigation_handle()->Resume();
|
| +}
|
| +
|
| +} // namespace content
|
|
|