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

Side by Side Diff: content/browser/renderer_host/socket_stream_dispatcher_host.cc

Issue 18932005: Reduce the complexity of WebSocketThrottle's wakeup code (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: android_dbg build fix Created 7 years, 5 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | net/base/net_error_list.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #include "content/browser/renderer_host/socket_stream_dispatcher_host.h" 5 #include "content/browser/renderer_host/socket_stream_dispatcher_host.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "content/browser/renderer_host/socket_stream_host.h" 10 #include "content/browser/renderer_host/socket_stream_host.h"
11 #include "content/browser/ssl/ssl_manager.h" 11 #include "content/browser/ssl/ssl_manager.h"
12 #include "content/common/resource_messages.h" 12 #include "content/common/resource_messages.h"
13 #include "content/common/socket_stream.h" 13 #include "content/common/socket_stream.h"
14 #include "content/common/socket_stream_messages.h" 14 #include "content/common/socket_stream_messages.h"
15 #include "content/public/browser/content_browser_client.h" 15 #include "content/public/browser/content_browser_client.h"
16 #include "content/public/browser/global_request_id.h" 16 #include "content/public/browser/global_request_id.h"
17 #include "net/base/net_errors.h"
17 #include "net/cookies/canonical_cookie.h" 18 #include "net/cookies/canonical_cookie.h"
18 #include "net/url_request/url_request_context_getter.h" 19 #include "net/url_request/url_request_context_getter.h"
19 #include "net/websockets/websocket_job.h" 20 #include "net/websockets/websocket_job.h"
20 #include "net/websockets/websocket_throttle.h" 21 #include "net/websockets/websocket_throttle.h"
21 22
22 namespace content { 23 namespace content {
23 24
25 namespace {
26
27 const size_t kMaxSocketStreamHosts = 16 * 1024;
28
29 } // namespace
30
24 SocketStreamDispatcherHost::SocketStreamDispatcherHost( 31 SocketStreamDispatcherHost::SocketStreamDispatcherHost(
25 int render_process_id, 32 int render_process_id,
26 ResourceMessageFilter::URLRequestContextSelector* selector, 33 ResourceMessageFilter::URLRequestContextSelector* selector,
27 ResourceContext* resource_context) 34 ResourceContext* resource_context)
28 : render_process_id_(render_process_id), 35 : render_process_id_(render_process_id),
29 url_request_context_selector_(selector), 36 url_request_context_selector_(selector),
30 resource_context_(resource_context), 37 resource_context_(resource_context),
31 weak_ptr_factory_(this), 38 weak_ptr_factory_(this),
32 on_shutdown_(false) { 39 on_shutdown_(false) {
33 DCHECK(selector); 40 DCHECK(selector);
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 197
191 // Message handlers called by OnMessageReceived. 198 // Message handlers called by OnMessageReceived.
192 void SocketStreamDispatcherHost::OnConnect(int render_view_id, 199 void SocketStreamDispatcherHost::OnConnect(int render_view_id,
193 const GURL& url, 200 const GURL& url,
194 int socket_id) { 201 int socket_id) {
195 DVLOG(2) << "SocketStreamDispatcherHost::OnConnect" 202 DVLOG(2) << "SocketStreamDispatcherHost::OnConnect"
196 << " render_view_id=" << render_view_id 203 << " render_view_id=" << render_view_id
197 << " url=" << url 204 << " url=" << url
198 << " socket_id=" << socket_id; 205 << " socket_id=" << socket_id;
199 DCHECK_NE(kNoSocketId, socket_id); 206 DCHECK_NE(kNoSocketId, socket_id);
207
208 if (hosts_.size() >= kMaxSocketStreamHosts) {
209 if (!Send(new SocketStreamMsg_Failed(socket_id,
210 net::ERR_TOO_MANY_SOCKET_STREAMS))) {
211 DVLOG(1) << "SocketStreamMsg_Failed failed.";
212 }
213 if (!Send(new SocketStreamMsg_Closed(socket_id))) {
214 DVLOG(1) << "SocketStreamMsg_Closed failed.";
215 }
216 return;
217 }
218
200 if (hosts_.Lookup(socket_id)) { 219 if (hosts_.Lookup(socket_id)) {
201 DVLOG(1) << "socket_id=" << socket_id << " already registered."; 220 DVLOG(1) << "socket_id=" << socket_id << " already registered.";
202 return; 221 return;
203 } 222 }
204 223
205 // Note that the SocketStreamHost is responsible for checking that |url| 224 // Note that the SocketStreamHost is responsible for checking that |url|
206 // is valid. 225 // is valid.
207 SocketStreamHost* socket_stream_host = 226 SocketStreamHost* socket_stream_host =
208 new SocketStreamHost(this, render_view_id, socket_id); 227 new SocketStreamHost(this, render_view_id, socket_id);
209 hosts_.AddWithID(socket_stream_host, socket_id); 228 hosts_.AddWithID(socket_stream_host, socket_id);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 iter.Advance()) { 275 iter.Advance()) {
257 int socket_id = iter.GetCurrentKey(); 276 int socket_id = iter.GetCurrentKey();
258 const SocketStreamHost* socket_stream_host = iter.GetCurrentValue(); 277 const SocketStreamHost* socket_stream_host = iter.GetCurrentValue();
259 delete socket_stream_host; 278 delete socket_stream_host;
260 hosts_.Remove(socket_id); 279 hosts_.Remove(socket_id);
261 } 280 }
262 on_shutdown_ = true; 281 on_shutdown_ = true;
263 } 282 }
264 283
265 } // namespace content 284 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | net/base/net_error_list.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698