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

Unified 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: Created 4 years, 8 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
« no previous file with comments | « no previous file | net/base/network_stream_throttler.cc » ('j') | net/http/http_network_transaction.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/base/network_stream_throttler.h
diff --git a/net/base/network_stream_throttler.h b/net/base/network_stream_throttler.h
new file mode 100644
index 0000000000000000000000000000000000000000..75ee556088cfd76668d7fa8f0863ec48f76cd565
--- /dev/null
+++ b/net/base/network_stream_throttler.h
@@ -0,0 +1,87 @@
+// Copyright 2016 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 NET_BASE_NETWORK_STREAM_THROTTLER_H_
+#define NET_BASE_NETWORK_STREAM_THROTTLER_H_
+
+#include "base/memory/weak_ptr.h"
+#include "net/base/priority_queue.h"
+#include "net/base/request_priority.h"
+
+namespace net {
+
+class NetworkStreamThrottler {
+ public:
+ // Abstract base class other classes can inherit from to get
+ // notifications from throttle state changes.
+ class Delegate {
+ public:
+ virtual ~Delegate() {}
+
+ // Called whenever the throttle state of this stream has changed.
+ // The new state can be determined through Throttle::throttled().
+ virtual void OnThrottleStateChanged() = 0;
+ };
+
+ // Concrete class owned by external stream representations that
+ // routes notifications.
+ class Throttle {
+ public:
+ ~Throttle();
+
+ bool throttled() { return throttled_; }
+
+ // The caller must make sure that |*delegate| outlives this
+ // object.
+ void set_delegate(Delegate* delegate) { delegate_ = delegate; }
+
+ // Note that this may result in a possibly reentrant call to
+ // |Delegate::OnThrottleStateChanged|.
+ void SetPriority(RequestPriority priority);
+
+ private:
+ friend NetworkStreamThrottler;
+
+ using QueuePointer = PriorityQueue<Throttle*>::Pointer;
+
+ Throttle(bool throttled,
+ RequestPriority priority,
+ base::WeakPtr<NetworkStreamThrottler> throttler);
+
+ void NotifyThrottleStateChanged(bool new_throttle_state);
+ QueuePointer queue_pointer() { return queue_pointer_; }
+ void set_queue_pointer(const QueuePointer& pointer) {
+ queue_pointer_ = pointer;
+ }
+
+ bool throttled_;
+ RequestPriority priority_;
+ Delegate* delegate_;
+ PriorityQueue<Throttle*>::Pointer queue_pointer_;
+
+ base::WeakPtr<NetworkStreamThrottler> throttler_;
+
+ DISALLOW_COPY_AND_ASSIGN(Throttle);
+ };
+
+ NetworkStreamThrottler();
+ ~NetworkStreamThrottler();
+
+ scoped_ptr<Throttle> CreateThrottle(RequestPriority priority);
+
+ private:
+ void OnStreamPriorityChanged(Throttle* throttle,
+ RequestPriority old_priority,
+ RequestPriority new_priority);
+ void OnStreamDestroyed(Throttle* throttle);
+
+ PriorityQueue<Throttle*> priority_queue_;
+ base::WeakPtrFactory<NetworkStreamThrottler> factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(NetworkStreamThrottler);
+};
+
+} // namespace net
+
+#endif // NET_BASE_NETWORK_STREAM_THROTTLER_H_
« no previous file with comments | « no previous file | net/base/network_stream_throttler.cc » ('j') | net/http/http_network_transaction.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698