OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "content/public/test/cancelling_navigation_throttle.h" |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "content/public/browser/browser_thread.h" |
| 9 #include "content/public/browser/navigation_handle.h" |
| 10 |
| 11 namespace content { |
| 12 |
| 13 CancellingNavigationThrottle::CancellingNavigationThrottle( |
| 14 NavigationHandle* handle, |
| 15 CancelTime cancel_time, |
| 16 ResultSynchrony sync) |
| 17 : NavigationThrottle(handle), |
| 18 cancel_time_(cancel_time), |
| 19 sync_(sync), |
| 20 weak_ptr_factory_(this) {} |
| 21 |
| 22 CancellingNavigationThrottle::~CancellingNavigationThrottle() {} |
| 23 |
| 24 NavigationThrottle::ThrottleCheckResult |
| 25 CancellingNavigationThrottle::WillStartRequest() { |
| 26 return ProcessState(cancel_time_ == WILL_START_REQUEST); |
| 27 } |
| 28 |
| 29 NavigationThrottle::ThrottleCheckResult |
| 30 CancellingNavigationThrottle::WillRedirectRequest() { |
| 31 return ProcessState(cancel_time_ == WILL_REDIRECT_REQUEST); |
| 32 } |
| 33 |
| 34 NavigationThrottle::ThrottleCheckResult |
| 35 CancellingNavigationThrottle::WillProcessResponse() { |
| 36 return ProcessState(cancel_time_ == WILL_PROCESS_RESPONSE); |
| 37 } |
| 38 |
| 39 NavigationThrottle::ThrottleCheckResult |
| 40 CancellingNavigationThrottle::ProcessState(bool should_cancel) { |
| 41 if (sync_ == ASYNCHRONOUS) { |
| 42 BrowserThread::PostTask( |
| 43 BrowserThread::UI, FROM_HERE, |
| 44 base::Bind(&CancellingNavigationThrottle::MaybeCancel, |
| 45 weak_ptr_factory_.GetWeakPtr(), should_cancel)); |
| 46 return NavigationThrottle::DEFER; |
| 47 } |
| 48 return should_cancel ? NavigationThrottle::CANCEL |
| 49 : NavigationThrottle::PROCEED; |
| 50 } |
| 51 |
| 52 const char* CancellingNavigationThrottle::GetNameForLogging() { |
| 53 return "CancellingNavigationThrottle"; |
| 54 } |
| 55 |
| 56 void CancellingNavigationThrottle::MaybeCancel(bool cancel) { |
| 57 if (cancel) |
| 58 navigation_handle()->CancelDeferredNavigation(NavigationThrottle::CANCEL); |
| 59 else |
| 60 navigation_handle()->Resume(); |
| 61 } |
| 62 |
| 63 } // namespace content |
OLD | NEW |