Index: third_party/WebKit/Source/core/loader/NetworkQuietDetector.h |
diff --git a/third_party/WebKit/Source/core/loader/NetworkQuietDetector.h b/third_party/WebKit/Source/core/loader/NetworkQuietDetector.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..403cd2bb5d47c56cbc85faef897d9d6eee2e8bab |
--- /dev/null |
+++ b/third_party/WebKit/Source/core/loader/NetworkQuietDetector.h |
@@ -0,0 +1,52 @@ |
+// 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 NetworkQuietDetector_h |
+#define NetworkQuietDetector_h |
+ |
+#include "core/CoreExport.h" |
+#include "platform/Timer.h" |
+#include "platform/heap/Handle.h" |
+#include "platform/wtf/HashSet.h" |
+#include "platform/wtf/Noncopyable.h" |
+ |
+namespace blink { |
+ |
+class Document; |
+ |
+// NetworkQuietDetector observes network request count everytime a load is |
+// finshed after DOMLoadedEventEnd is fired, and signals a network idleness |
+// signal to GRC when there are no more than 2 network connection active during |
+// 1 second. |
+class CORE_EXPORT NetworkQuietDetector |
+ : public GarbageCollectedFinalized<NetworkQuietDetector> { |
+ WTF_MAKE_NONCOPYABLE(NetworkQuietDetector); |
+ |
+ public: |
+ NetworkQuietDetector(Document*); |
+ virtual ~NetworkQuietDetector() {} |
+ |
+ void CheckNetworkStable(); |
+ |
+ DECLARE_TRACE(); |
+ |
+ private: |
+ friend class NetworkQuietDetectorTest; |
+ |
+ // The page is n-quiet if there are no more than n active network requests for |
+ // this duration of time. |
+ static constexpr double kNetwork2QuietWindowSeconds = 1.0; |
+ |
+ int ActiveConnections(); |
+ void SetNetworkQuietTimers(int active_connections); |
+ void Network2QuietTimerFired(TimerBase*); |
+ |
+ bool network2_quiet_reached_ = false; |
+ Member<Document> document_; |
+ TaskRunnerTimer<NetworkQuietDetector> network2_quiet_timer_; |
+}; |
+ |
+} // namespace blink |
+ |
+#endif |