Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(174)

Side by Side Diff: content/public/test/cancelling_navigation_throttle.cc

Issue 2834543003: [subresource_filter] SB throttle can send multiple speculative requests. (Closed)
Patch Set: rebase on #468982 Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « content/public/test/cancelling_navigation_throttle.h ('k') | content/test/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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
OLDNEW
« no previous file with comments | « content/public/test/cancelling_navigation_throttle.h ('k') | content/test/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698