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

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: Moved throttle creation and checking to its own state. 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/base/network_stream_throttler.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..841f42ad48de96695725e52d9d784047d456549c
--- /dev/null
+++ b/net/base/network_stream_throttler.h
@@ -0,0 +1,90 @@
+// 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 <memory>
+
+#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() {}
mmenke 2016/04/29 16:57:28 Make the destructor protected? Doesn't matter muc
Randy Smith (Not in Mondays) 2016/05/08 00:46:30 Done.
+
+ // 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_; }
mmenke 2016/04/29 16:57:28 const
Randy Smith (Not in Mondays) 2016/05/08 00:46:30 Done.
+
+ // The caller must make sure that |*delegate| outlives this
+ // object.
+ void set_delegate(Delegate* delegate) { delegate_ = delegate; }
mmenke 2016/04/29 16:57:28 Can we make this a constructor argument instead?
Randy Smith (Not in Mondays) 2016/05/08 00:46:30 Sure. It doesn't look like I ever called this fun
+
+ // 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);
mmenke 2016/04/29 16:57:28 Is there any case where the Throttle can be destro
Randy Smith (Not in Mondays) 2016/05/08 00:46:30 I think you mean the other way around, and no, I d
+
+ void NotifyThrottleStateChanged(bool new_throttle_state);
mmenke 2016/04/29 16:57:28 I don't think we need to take a bool? Seems like
Randy Smith (Not in Mondays) 2016/05/08 00:46:30 Hmmm. This was planning for the long-term; I coul
mmenke 2016/05/09 17:37:48 I missed the constructor parameter when I made tha
+ QueuePointer queue_pointer() { return queue_pointer_; }
mmenke 2016/04/29 16:57:28 const?
Randy Smith (Not in Mondays) 2016/05/08 00:46:30 Done.
+ 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();
+
+ std::unique_ptr<Throttle> CreateThrottle(RequestPriority priority,
+ bool ignore_limits);
+
+ 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/base/network_stream_throttler.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698