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 #ifndef CONTENT_PUBLIC_TEST_CANCELLING_NAVIGATION_THROTTLE_H_ | |
6 #define CONTENT_PUBLIC_TEST_CANCELLING_NAVIGATION_THROTTLE_H_ | |
7 | |
8 #include "base/macros.h" | |
9 #include "base/memory/weak_ptr.h" | |
10 #include "content/public/browser/navigation_throttle.h" | |
11 | |
12 namespace content { | |
13 | |
14 class NavigationHandle; | |
15 | |
16 // This class can be used to cancel navigations synchronously or asynchronously | |
17 // at a specific time in the NavigationThrottle lifecycle. | |
18 // | |
19 // Consider using it in conjunction with NavigationSimulator. | |
clamy
2017/04/24 12:07:12
nit: Could you add a
TODO(clamy): Check if this co
Charlie Harrison
2017/04/24 18:25:10
Done.
| |
20 class CancellingNavigationThrottle : public NavigationThrottle { | |
21 public: | |
22 enum CancelTime { | |
clamy
2017/04/24 12:07:12
nit: could this be made an enum class?
Charlie Harrison
2017/04/24 18:25:10
It could, but tests using these enums are already
| |
23 WILL_START_REQUEST, | |
24 WILL_REDIRECT_REQUEST, | |
25 WILL_PROCESS_RESPONSE, | |
26 NEVER, | |
27 }; | |
28 | |
29 enum ResultSynchrony { | |
30 SYNCHRONOUS, | |
31 ASYNCHRONOUS, | |
32 }; | |
33 | |
34 CancellingNavigationThrottle(NavigationHandle* handle, | |
35 CancelTime cancel_time, | |
36 ResultSynchrony sync); | |
37 ~CancellingNavigationThrottle() override; | |
38 | |
39 NavigationThrottle::ThrottleCheckResult WillStartRequest() override; | |
40 NavigationThrottle::ThrottleCheckResult WillRedirectRequest() override; | |
41 NavigationThrottle::ThrottleCheckResult WillProcessResponse() override; | |
42 | |
43 private: | |
44 NavigationThrottle::ThrottleCheckResult ProcessState(bool should_cancel); | |
45 void MaybeCancel(bool cancel); | |
46 | |
47 private: | |
48 const CancelTime cancel_time_; | |
49 const ResultSynchrony sync_; | |
50 | |
51 base::WeakPtrFactory<CancellingNavigationThrottle> weak_ptr_factory_; | |
52 | |
53 DISALLOW_COPY_AND_ASSIGN(CancellingNavigationThrottle); | |
54 }; | |
55 | |
56 } // namespace content | |
57 | |
58 #endif // CONTENT_PUBLIC_TEST_CANCELLING_NAVIGATION_THROTTLE_H_ | |
OLD | NEW |