Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_WEBSOCKET_DISPATCHER_HOST_H_ | 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_WEBSOCKET_DISPATCHER_HOST_H_ |
| 6 #define CONTENT_BROWSER_RENDERER_HOST_WEBSOCKET_DISPATCHER_HOST_H_ | 6 #define CONTENT_BROWSER_RENDERER_HOST_WEBSOCKET_DISPATCHER_HOST_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
| 14 #include "base/containers/hash_tables.h" | 14 #include "base/containers/hash_tables.h" |
| 15 #include "base/time/time.h" | |
| 16 #include "base/timer/timer.h" | |
| 15 #include "content/common/content_export.h" | 17 #include "content/common/content_export.h" |
| 16 #include "content/common/websocket.h" | 18 #include "content/common/websocket.h" |
| 17 #include "content/public/browser/browser_message_filter.h" | 19 #include "content/public/browser/browser_message_filter.h" |
| 18 | 20 |
| 19 namespace net { | 21 namespace net { |
| 20 class URLRequestContext; | 22 class URLRequestContext; |
| 21 } // namespace net | 23 } // namespace net |
| 22 | 24 |
| 23 namespace content { | 25 namespace content { |
| 24 | 26 |
| 25 struct WebSocketHandshakeRequest; | 27 struct WebSocketHandshakeRequest; |
| 26 struct WebSocketHandshakeResponse; | 28 struct WebSocketHandshakeResponse; |
| 27 class WebSocketHost; | 29 class WebSocketHost; |
| 28 | 30 |
| 29 // Creates a WebSocketHost object for each WebSocket channel, and dispatches | 31 // Creates a WebSocketHost object for each WebSocket channel, and dispatches |
| 30 // WebSocketMsg_* messages sent from renderer to the appropriate WebSocketHost. | 32 // WebSocketMsg_* messages sent from renderer to the appropriate WebSocketHost. |
| 31 class CONTENT_EXPORT WebSocketDispatcherHost : public BrowserMessageFilter { | 33 class CONTENT_EXPORT WebSocketDispatcherHost : public BrowserMessageFilter { |
| 32 public: | 34 public: |
| 33 typedef base::Callback<net::URLRequestContext*()> GetRequestContextCallback; | 35 typedef base::Callback<net::URLRequestContext*()> GetRequestContextCallback; |
| 34 | 36 |
| 35 // Given a routing_id, WebSocketHostFactory returns a new instance of | 37 // Given a routing_id and delay, WebSocketHostFactory returns a new |
| 36 // WebSocketHost or its subclass. | 38 // instance of WebSocketHost or its subclass. |
| 37 typedef base::Callback<WebSocketHost*(int)> WebSocketHostFactory; // NOLINT | 39 typedef base::Callback<WebSocketHost*(int, base::TimeDelta)> |
| 40 WebSocketHostFactory; | |
| 38 | 41 |
| 39 // Return value for methods that may delete the WebSocketHost. This enum is | 42 // Return value for methods that may delete the WebSocketHost. This enum is |
| 40 // binary-compatible with net::WebSocketEventInterface::ChannelState, to make | 43 // binary-compatible with net::WebSocketEventInterface::ChannelState, to make |
| 41 // conversion cheap. By using a separate enum including net/ header files can | 44 // conversion cheap. By using a separate enum including net/ header files can |
| 42 // be avoided. | 45 // be avoided. |
| 43 enum WebSocketHostState { | 46 enum WebSocketHostState { |
| 44 WEBSOCKET_HOST_ALIVE, | 47 WEBSOCKET_HOST_ALIVE, |
| 45 WEBSOCKET_HOST_DELETED | 48 WEBSOCKET_HOST_DELETED |
| 46 }; | 49 }; |
| 47 | 50 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 111 // Returns whether the associated renderer process can read raw cookies. | 114 // Returns whether the associated renderer process can read raw cookies. |
| 112 bool CanReadRawCookies() const; | 115 bool CanReadRawCookies() const; |
| 113 | 116 |
| 114 int render_process_id() const { return process_id_; } | 117 int render_process_id() const { return process_id_; } |
| 115 | 118 |
| 116 private: | 119 private: |
| 117 typedef base::hash_map<int, WebSocketHost*> WebSocketHostTable; | 120 typedef base::hash_map<int, WebSocketHost*> WebSocketHostTable; |
| 118 | 121 |
| 119 ~WebSocketDispatcherHost() override; | 122 ~WebSocketDispatcherHost() override; |
| 120 | 123 |
| 121 WebSocketHost* CreateWebSocketHost(int routing_id); | 124 WebSocketHost* CreateWebSocketHost(int routing_id, base::TimeDelta delay); |
| 122 | 125 |
| 123 // Looks up a WebSocketHost object by |routing_id|. Returns the object if one | 126 // Looks up a WebSocketHost object by |routing_id|. Returns the object if one |
| 124 // is found, or NULL otherwise. | 127 // is found, or NULL otherwise. |
| 125 WebSocketHost* GetHost(int routing_id) const; | 128 WebSocketHost* GetHost(int routing_id) const; |
| 126 | 129 |
| 127 // Sends the passed in IPC::Message via the BrowserMessageFilter::Send() | 130 // Sends the passed in IPC::Message via the BrowserMessageFilter::Send() |
| 128 // method. If sending the IPC fails, assumes that this connection is no | 131 // method. If sending the IPC fails, assumes that this connection is no |
| 129 // longer useable, calls DeleteWebSocketHost(), and returns | 132 // longer useable, calls DeleteWebSocketHost(), and returns |
| 130 // WEBSOCKET_HOST_DELETED. The behaviour is the same for all message types. | 133 // WEBSOCKET_HOST_DELETED. The behaviour is the same for all message types. |
| 131 WebSocketHostState SendOrDrop(IPC::Message* message) WARN_UNUSED_RESULT; | 134 WebSocketHostState SendOrDrop(IPC::Message* message) WARN_UNUSED_RESULT; |
| 132 | 135 |
| 133 // Deletes the WebSocketHost object associated with the given |routing_id| and | 136 // Deletes the WebSocketHost object associated with the given |routing_id| and |
| 134 // removes it from the |hosts_| table. | 137 // removes it from the |hosts_| table. |
| 135 void DeleteWebSocketHost(int routing_id); | 138 void DeleteWebSocketHost(int routing_id); |
| 136 | 139 |
| 140 // Calculate delay for per-renderer WebSocket throttling. | |
| 141 base::TimeDelta CalculateDelay() const; | |
| 142 | |
| 143 void FinishThrottlingPeriod(); | |
| 144 | |
| 137 // Table of WebSocketHost objects, owned by this object, indexed by | 145 // Table of WebSocketHost objects, owned by this object, indexed by |
| 138 // routing_id. | 146 // routing_id. |
| 139 WebSocketHostTable hosts_; | 147 WebSocketHostTable hosts_; |
| 140 | 148 |
| 141 // The the process ID of the associated renderer process. | 149 // The the process ID of the associated renderer process. |
| 142 const int process_id_; | 150 const int process_id_; |
| 143 | 151 |
| 144 // A callback which returns the appropriate net::URLRequestContext for us to | 152 // A callback which returns the appropriate net::URLRequestContext for us to |
| 145 // use. | 153 // use. |
| 146 GetRequestContextCallback get_context_callback_; | 154 GetRequestContextCallback get_context_callback_; |
| 147 | 155 |
| 148 WebSocketHostFactory websocket_host_factory_; | 156 WebSocketHostFactory websocket_host_factory_; |
| 149 | 157 |
| 158 // Timer and counters for per-renderer WebSocket throttling. | |
| 159 base::RepeatingTimer<WebSocketDispatcherHost> timer_; | |
| 160 // The current number of pending connections. | |
| 161 int num_pending_connections_; | |
| 162 // The number of handshakes that failed in the current and previous time | |
| 163 // period. | |
| 164 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.
| |
| 165 int64 num_previous_succeeded_connections_; | |
| 166 // The number of handshakes that succeeded in the current and previous time | |
| 167 // period. | |
| 168 int64 num_current_failed_connections_; | |
| 169 int64 num_previous_failed_connections_; | |
| 170 | |
| 150 DISALLOW_COPY_AND_ASSIGN(WebSocketDispatcherHost); | 171 DISALLOW_COPY_AND_ASSIGN(WebSocketDispatcherHost); |
| 151 }; | 172 }; |
| 152 | 173 |
| 153 } // namespace content | 174 } // namespace content |
| 154 | 175 |
| 155 #endif // CONTENT_BROWSER_RENDERER_HOST_WEBSOCKET_DISPATCHER_HOST_H_ | 176 #endif // CONTENT_BROWSER_RENDERER_HOST_WEBSOCKET_DISPATCHER_HOST_H_ |
| OLD | NEW |