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

Side by Side Diff: third_party/WebKit/Source/core/loader/NetworkQuietDetector.h

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

Powered by Google App Engine
This is Rietveld 408576698