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

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

Issue 2834543003: [subresource_filter] SB throttle can send multiple speculative requests. (Closed)
Patch Set: rebase on #468982 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..dede865d1452a0dd450580d075785b6cb2534554
--- /dev/null
+++ b/content/public/test/cancelling_navigation_throttle.h
@@ -0,0 +1,62 @@
+// 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.
+// TODO(clamy): Check if this could be used in unit tests exercising
+// NavigationThrottle code.
+class CancellingNavigationThrottle : public NavigationThrottle {
+ public:
+ enum CancelTime {
+ 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:
+ NavigationThrottle::ThrottleCheckResult WillStartRequest() override;
+ NavigationThrottle::ThrottleCheckResult WillRedirectRequest() override;
+ NavigationThrottle::ThrottleCheckResult WillProcessResponse() override;
+ const char* GetNameForLogging() 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