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

Unified Diff: third_party/WebKit/Source/core/loader/NetworkQuietDetector.h

Issue 2925963002: Create NetworkQuietDetector. (Closed)
Patch Set: Updated comments and rebased Created 3 years, 6 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: 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..459e4de96e2865f476b41b50a35c0034b3c3ddbd
--- /dev/null
+++ b/third_party/WebKit/Source/core/loader/NetworkQuietDetector.h
@@ -0,0 +1,55 @@
+// 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/Supplementable.h"
+#include "platform/Timer.h"
+#include "platform/heap/Handle.h"
+#include "platform/wtf/Noncopyable.h"
+
+namespace blink {
+
+class Document;
+
+// NetworkQuietDetector observes network request count everytime a load is
+// finshed after DOMContentLoadedEventEnd is fired, and signals a network
+// idleness signal to GRC when there are no more than 2 network connection
+// active in 1 second.
+class CORE_EXPORT NetworkQuietDetector
+ : public GarbageCollectedFinalized<NetworkQuietDetector>,
+ public Supplement<Document> {
+ WTF_MAKE_NONCOPYABLE(NetworkQuietDetector);
+ USING_GARBAGE_COLLECTED_MIXIN(NetworkQuietDetector);
+
+ public:
+ static NetworkQuietDetector& From(Document&);
+ virtual ~NetworkQuietDetector() {}
+
+ void CheckNetworkStable();
+
+ DECLARE_VIRTUAL_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;
+
+ explicit NetworkQuietDetector(Document&);
+ Document* GetDocument();
+ int ActiveConnections();
+ void SetNetworkQuietTimers(int active_connections);
+ void Network2QuietTimerFired(TimerBase*);
+
+ bool network2_quiet_reached_ = false;
+ TaskRunnerTimer<NetworkQuietDetector> network2_quiet_timer_;
+};
+
+} // namespace blink
+
+#endif

Powered by Google App Engine
This is Rietveld 408576698