| OLD | NEW |
| 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" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 namespace content { | 23 namespace content { |
| 24 | 24 |
| 25 namespace { | 25 namespace { |
| 26 | 26 |
| 27 const size_t kMaxSocketStreamHosts = 16 * 1024; | 27 const size_t kMaxSocketStreamHosts = 16 * 1024; |
| 28 | 28 |
| 29 } // namespace | 29 } // namespace |
| 30 | 30 |
| 31 SocketStreamDispatcherHost::SocketStreamDispatcherHost( | 31 SocketStreamDispatcherHost::SocketStreamDispatcherHost( |
| 32 int render_process_id, | 32 int render_process_id, |
| 33 ResourceMessageFilter::URLRequestContextSelector* selector, | 33 const GetRequestContextCallback& request_context_callback, |
| 34 ResourceContext* resource_context) | 34 ResourceContext* resource_context) |
| 35 : render_process_id_(render_process_id), | 35 : render_process_id_(render_process_id), |
| 36 url_request_context_selector_(selector), | 36 request_context_callback_(request_context_callback), |
| 37 resource_context_(resource_context), | 37 resource_context_(resource_context), |
| 38 weak_ptr_factory_(this), | 38 weak_ptr_factory_(this), |
| 39 on_shutdown_(false) { | 39 on_shutdown_(false) { |
| 40 DCHECK(selector); | |
| 41 net::WebSocketJob::EnsureInit(); | 40 net::WebSocketJob::EnsureInit(); |
| 42 } | 41 } |
| 43 | 42 |
| 44 bool SocketStreamDispatcherHost::OnMessageReceived(const IPC::Message& message, | 43 bool SocketStreamDispatcherHost::OnMessageReceived(const IPC::Message& message, |
| 45 bool* message_was_ok) { | 44 bool* message_was_ok) { |
| 46 if (on_shutdown_) | 45 if (on_shutdown_) |
| 47 return false; | 46 return false; |
| 48 | 47 |
| 49 bool handled = true; | 48 bool handled = true; |
| 50 IPC_BEGIN_MESSAGE_MAP_EX(SocketStreamDispatcherHost, message, *message_was_ok) | 49 IPC_BEGIN_MESSAGE_MAP_EX(SocketStreamDispatcherHost, message, *message_was_ok) |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 SocketStreamHost* socket_stream_host = hosts_.Lookup(socket_id); | 255 SocketStreamHost* socket_stream_host = hosts_.Lookup(socket_id); |
| 257 DCHECK(socket_stream_host); | 256 DCHECK(socket_stream_host); |
| 258 delete socket_stream_host; | 257 delete socket_stream_host; |
| 259 hosts_.Remove(socket_id); | 258 hosts_.Remove(socket_id); |
| 260 if (!Send(new SocketStreamMsg_Closed(socket_id))) { | 259 if (!Send(new SocketStreamMsg_Closed(socket_id))) { |
| 261 DVLOG(1) << "SocketStreamMsg_Closed failed."; | 260 DVLOG(1) << "SocketStreamMsg_Closed failed."; |
| 262 } | 261 } |
| 263 } | 262 } |
| 264 | 263 |
| 265 net::URLRequestContext* SocketStreamDispatcherHost::GetURLRequestContext() { | 264 net::URLRequestContext* SocketStreamDispatcherHost::GetURLRequestContext() { |
| 266 return url_request_context_selector_->GetRequestContext( | 265 return request_context_callback_.Run(ResourceType::SUB_RESOURCE); |
| 267 ResourceType::SUB_RESOURCE); | |
| 268 } | 266 } |
| 269 | 267 |
| 270 void SocketStreamDispatcherHost::Shutdown() { | 268 void SocketStreamDispatcherHost::Shutdown() { |
| 271 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 269 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 272 // TODO(ukai): Implement IDMap::RemoveAll(). | 270 // TODO(ukai): Implement IDMap::RemoveAll(). |
| 273 for (IDMap<SocketStreamHost>::const_iterator iter(&hosts_); | 271 for (IDMap<SocketStreamHost>::const_iterator iter(&hosts_); |
| 274 !iter.IsAtEnd(); | 272 !iter.IsAtEnd(); |
| 275 iter.Advance()) { | 273 iter.Advance()) { |
| 276 int socket_id = iter.GetCurrentKey(); | 274 int socket_id = iter.GetCurrentKey(); |
| 277 const SocketStreamHost* socket_stream_host = iter.GetCurrentValue(); | 275 const SocketStreamHost* socket_stream_host = iter.GetCurrentValue(); |
| 278 delete socket_stream_host; | 276 delete socket_stream_host; |
| 279 hosts_.Remove(socket_id); | 277 hosts_.Remove(socket_id); |
| 280 } | 278 } |
| 281 on_shutdown_ = true; | 279 on_shutdown_ = true; |
| 282 } | 280 } |
| 283 | 281 |
| 284 } // namespace content | 282 } // namespace content |
| OLD | NEW |