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

Unified Diff: content/browser/renderer_host/websocket_dispatcher_host.h

Issue 972963002: Per-renderer WebSocket throttling (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix content_unittests Created 5 years, 10 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
Index: content/browser/renderer_host/websocket_dispatcher_host.h
diff --git a/content/browser/renderer_host/websocket_dispatcher_host.h b/content/browser/renderer_host/websocket_dispatcher_host.h
index b9cdd343837ea2e57429adf1933455d5e2f84151..95ef4c38919cdbcd2afc3157f1a62809a05e0649 100644
--- a/content/browser/renderer_host/websocket_dispatcher_host.h
+++ b/content/browser/renderer_host/websocket_dispatcher_host.h
@@ -12,6 +12,8 @@
#include "base/callback.h"
#include "base/compiler_specific.h"
#include "base/containers/hash_tables.h"
+#include "base/time/time.h"
+#include "base/timer/timer.h"
#include "content/common/content_export.h"
#include "content/common/websocket.h"
#include "content/public/browser/browser_message_filter.h"
@@ -32,9 +34,10 @@ class CONTENT_EXPORT WebSocketDispatcherHost : public BrowserMessageFilter {
public:
typedef base::Callback<net::URLRequestContext*()> GetRequestContextCallback;
- // Given a routing_id, WebSocketHostFactory returns a new instance of
- // WebSocketHost or its subclass.
- typedef base::Callback<WebSocketHost*(int)> WebSocketHostFactory; // NOLINT
+ // Given a routing_id and delay, WebSocketHostFactory returns a new
+ // instance of WebSocketHost or its subclass.
+ typedef base::Callback<WebSocketHost*(int, base::TimeDelta)>
+ WebSocketHostFactory;
// Return value for methods that may delete the WebSocketHost. This enum is
// binary-compatible with net::WebSocketEventInterface::ChannelState, to make
@@ -118,7 +121,7 @@ class CONTENT_EXPORT WebSocketDispatcherHost : public BrowserMessageFilter {
~WebSocketDispatcherHost() override;
- WebSocketHost* CreateWebSocketHost(int routing_id);
+ WebSocketHost* CreateWebSocketHost(int routing_id, base::TimeDelta delay);
// Looks up a WebSocketHost object by |routing_id|. Returns the object if one
// is found, or NULL otherwise.
@@ -134,6 +137,11 @@ class CONTENT_EXPORT WebSocketDispatcherHost : public BrowserMessageFilter {
// removes it from the |hosts_| table.
void DeleteWebSocketHost(int routing_id);
+ // Calculate delay for per-renderer WebSocket throttling.
+ base::TimeDelta CalculateDelay() const;
+
+ void FinishThrottlingPeriod();
+
// Table of WebSocketHost objects, owned by this object, indexed by
// routing_id.
WebSocketHostTable hosts_;
@@ -147,6 +155,19 @@ class CONTENT_EXPORT WebSocketDispatcherHost : public BrowserMessageFilter {
WebSocketHostFactory websocket_host_factory_;
+ // Timer and counters for per-renderer WebSocket throttling.
+ base::RepeatingTimer<WebSocketDispatcherHost> timer_;
+ // The current number of pending connections.
+ int num_pending_connections_;
+ // The number of handshakes that failed in the current and previous time
+ // period.
+ int64 num_current_succeeded_connections_;
Adam Rice 2015/03/04 08:20:50 It seems this type should be written int64_t (this
hiroshige 2015/03/04 11:13:15 Done.
+ int64 num_previous_succeeded_connections_;
+ // The number of handshakes that succeeded in the current and previous time
+ // period.
+ int64 num_current_failed_connections_;
+ int64 num_previous_failed_connections_;
+
DISALLOW_COPY_AND_ASSIGN(WebSocketDispatcherHost);
};

Powered by Google App Engine
This is Rietveld 408576698