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