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

Side by Side Diff: net/base/network_stream_throttler.h

Issue 1901533002: Implementation of network level throttler. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Incorporated latest round of comments." . Created 4 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 2016 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 NET_BASE_NETWORK_STREAM_THROTTLER_H_
6 #define NET_BASE_NETWORK_STREAM_THROTTLER_H_
7
8 #include <memory>
9
10 #include "base/memory/weak_ptr.h"
11 #include "net/base/net_export.h"
12 #include "net/base/priority_queue.h"
13 #include "net/base/request_priority.h"
14
15 namespace net {
16
17 // This class controls throttling based on priority level and number of
18 // outstanding requests. It vends Throttle objects, and tracks
19 // outstanding requests by the lifetime of those objects. Consumers
20 // determine whether or not they are throttled by consulting those
21 // Throttle objects.
22 //
23 // This class must outlive all Throttles created from it via CreateThrottle().
24 //
25 // Methods are virtual to allow for test mocks.
26 class NET_EXPORT_PRIVATE NetworkStreamThrottler {
27 public:
28 // Abstract base class other classes can inherit from to get
29 // notifications from throttle state changes.
30 class NET_EXPORT_PRIVATE Delegate {
31 public:
32 // Called whenever the throttle state of this stream has changed.
33 // The new state can be determined through Throttle::IsThrottled().
34 //
35 // Note that this call may occur as the result of either a call to
36 // Throttle::SetPriority (on the throttle related to this delegate
37 // or another throttle) or the destruciton of a Throttle, and if
38 // so will occur synchronously during those events. It will not
39 // be called from the destructor of the Throttle associated with
40 // the Delegate.
41 virtual void OnThrottleStateChanged() = 0;
42
43 protected:
44 virtual ~Delegate() {}
45 };
46
47 // Class owned by external stream representations that
48 // routes notifications. It may be constructed in either the
49 // throttled or unthrottled state according to the state of the
50 // NetworkStreamThrottler; if it's constructed in the throttled
51 // state, it will only make a single transition to unthrottled,
52 // which will be signaled by delegate->OnThrottleStateChanged().
53 // If it's constructed in the unthrottled state, it will remain
54 // there.
55 class NET_EXPORT_PRIVATE Throttle {
56 public:
57 virtual ~Throttle() {}
58
59 virtual bool IsThrottled() const = 0;
60
61 // Note that this may result in a possibly reentrant call to
62 // |Delegate::OnThrottleStateChanged|, as well as the resumption
63 // of this or other requests, which may result in request completion
64 // and destruction before return. Any caller of this function
65 // should not rely on this object or containing objects surviving
66 // this call.
67 virtual void SetPriority(RequestPriority priority) = 0;
68
69 protected:
70 Throttle() {}
71
72 private:
73 DISALLOW_COPY_AND_ASSIGN(Throttle);
74 };
75
76 virtual ~NetworkStreamThrottler() {}
77
78 // Caller must ensure that |*delegate| outlives the returned
79 // Throttle.
80 virtual std::unique_ptr<Throttle> CreateThrottle(Delegate* delegate,
81 RequestPriority priority,
82 bool ignore_limits) = 0;
83
84 static std::unique_ptr<NetworkStreamThrottler> CreateThrottler();
85
86 protected:
87 NetworkStreamThrottler() {}
88
89 private:
90 DISALLOW_COPY_AND_ASSIGN(NetworkStreamThrottler);
91 };
92
93 } // namespace net
94
95 #endif // NET_BASE_NETWORK_STREAM_THROTTLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698