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

Unified Diff: content/public/test/cancelling_navigation_throttle.h

Issue 2834543003: [subresource_filter] SB throttle can send multiple speculative requests. (Closed)
Patch Set: engedy review Created 3 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: content/public/test/cancelling_navigation_throttle.h
diff --git a/content/public/test/cancelling_navigation_throttle.h b/content/public/test/cancelling_navigation_throttle.h
new file mode 100644
index 0000000000000000000000000000000000000000..af9a80b33cbebe1be0dc5e2cfdd2963778ccd3da
--- /dev/null
+++ b/content/public/test/cancelling_navigation_throttle.h
@@ -0,0 +1,58 @@
+// 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.
+
+#ifndef CONTENT_PUBLIC_TEST_CANCELLING_NAVIGATION_THROTTLE_H_
+#define CONTENT_PUBLIC_TEST_CANCELLING_NAVIGATION_THROTTLE_H_
+
+#include "base/macros.h"
+#include "base/memory/weak_ptr.h"
+#include "content/public/browser/navigation_throttle.h"
+
+namespace content {
+
+class NavigationHandle;
+
+// This class can be used to cancel navigations synchronously or asynchronously
+// at a specific time in the NavigationThrottle lifecycle.
+//
+// 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.
+class CancellingNavigationThrottle : public NavigationThrottle {
+ public:
+ 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
+ WILL_START_REQUEST,
+ WILL_REDIRECT_REQUEST,
+ WILL_PROCESS_RESPONSE,
+ NEVER,
+ };
+
+ enum ResultSynchrony {
+ SYNCHRONOUS,
+ ASYNCHRONOUS,
+ };
+
+ CancellingNavigationThrottle(NavigationHandle* handle,
+ CancelTime cancel_time,
+ ResultSynchrony sync);
+ ~CancellingNavigationThrottle() override;
+
+ NavigationThrottle::ThrottleCheckResult WillStartRequest() override;
+ NavigationThrottle::ThrottleCheckResult WillRedirectRequest() override;
+ NavigationThrottle::ThrottleCheckResult WillProcessResponse() override;
+
+ private:
+ NavigationThrottle::ThrottleCheckResult ProcessState(bool should_cancel);
+ void MaybeCancel(bool cancel);
+
+ private:
+ const CancelTime cancel_time_;
+ const ResultSynchrony sync_;
+
+ base::WeakPtrFactory<CancellingNavigationThrottle> weak_ptr_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(CancellingNavigationThrottle);
+};
+
+} // namespace content
+
+#endif // CONTENT_PUBLIC_TEST_CANCELLING_NAVIGATION_THROTTLE_H_

Powered by Google App Engine
This is Rietveld 408576698