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 NetworkQuietDetector_h |
| 6 #define NetworkQuietDetector_h |
| 7 |
| 8 #include "core/CoreExport.h" |
| 9 #include "platform/Supplementable.h" |
| 10 #include "platform/Timer.h" |
| 11 #include "platform/heap/Handle.h" |
| 12 #include "platform/wtf/Noncopyable.h" |
| 13 |
| 14 namespace blink { |
| 15 |
| 16 class Document; |
| 17 |
| 18 // NetworkQuietDetector observes network request count everytime a load is |
| 19 // finshed after DOMContentLoadedEventEnd is fired, and signals a network |
| 20 // idleness signal to GRC when there are no more than 2 network connection |
| 21 // active in 1 second. |
| 22 class CORE_EXPORT NetworkQuietDetector |
| 23 : public GarbageCollectedFinalized<NetworkQuietDetector>, |
| 24 public Supplement<Document> { |
| 25 WTF_MAKE_NONCOPYABLE(NetworkQuietDetector); |
| 26 USING_GARBAGE_COLLECTED_MIXIN(NetworkQuietDetector); |
| 27 |
| 28 public: |
| 29 static NetworkQuietDetector& From(Document&); |
| 30 virtual ~NetworkQuietDetector() {} |
| 31 |
| 32 void CheckNetworkStable(); |
| 33 |
| 34 DECLARE_VIRTUAL_TRACE(); |
| 35 |
| 36 private: |
| 37 friend class NetworkQuietDetectorTest; |
| 38 |
| 39 // The page is n-quiet if there are no more than n active network requests for |
| 40 // this duration of time. |
| 41 static constexpr double kNetwork2QuietWindowSeconds = 1.0; |
| 42 |
| 43 explicit NetworkQuietDetector(Document&); |
| 44 Document* GetDocument(); |
| 45 int ActiveConnections(); |
| 46 void SetNetworkQuietTimers(int active_connections); |
| 47 void Network2QuietTimerFired(TimerBase*); |
| 48 |
| 49 bool network2_quiet_reached_ = false; |
| 50 TaskRunnerTimer<NetworkQuietDetector> network2_quiet_timer_; |
| 51 }; |
| 52 |
| 53 } // namespace blink |
| 54 |
| 55 #endif |
OLD | NEW |