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 #include "content/browser/renderer_host/websocket_host.h" | 5 #include "content/browser/renderer_host/websocket_host.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/location.h" |
8 #include "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
| 10 #include "base/single_thread_task_runner.h" |
9 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
| 12 #include "base/thread_task_runner_handle.h" |
10 #include "content/browser/renderer_host/websocket_dispatcher_host.h" | 13 #include "content/browser/renderer_host/websocket_dispatcher_host.h" |
11 #include "content/browser/ssl/ssl_error_handler.h" | 14 #include "content/browser/ssl/ssl_error_handler.h" |
12 #include "content/browser/ssl/ssl_manager.h" | 15 #include "content/browser/ssl/ssl_manager.h" |
13 #include "content/common/websocket_messages.h" | 16 #include "content/common/websocket_messages.h" |
14 #include "ipc/ipc_message_macros.h" | 17 #include "ipc/ipc_message_macros.h" |
15 #include "net/http/http_request_headers.h" | 18 #include "net/http/http_request_headers.h" |
16 #include "net/http/http_response_headers.h" | 19 #include "net/http/http_response_headers.h" |
17 #include "net/http/http_util.h" | 20 #include "net/http/http_util.h" |
18 #include "net/ssl/ssl_info.h" | 21 #include "net/ssl/ssl_info.h" |
19 #include "net/websockets/websocket_channel.h" | 22 #include "net/websockets/websocket_channel.h" |
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
348 const url::Origin& origin, | 351 const url::Origin& origin, |
349 int render_frame_id) { | 352 int render_frame_id) { |
350 DVLOG(3) << "WebSocketHost::OnAddChannelRequest" | 353 DVLOG(3) << "WebSocketHost::OnAddChannelRequest" |
351 << " routing_id=" << routing_id_ << " socket_url=\"" << socket_url | 354 << " routing_id=" << routing_id_ << " socket_url=\"" << socket_url |
352 << "\" requested_protocols=\"" | 355 << "\" requested_protocols=\"" |
353 << JoinString(requested_protocols, ", ") << "\" origin=\"" | 356 << JoinString(requested_protocols, ", ") << "\" origin=\"" |
354 << origin.string() << "\""; | 357 << origin.string() << "\""; |
355 | 358 |
356 DCHECK(!channel_); | 359 DCHECK(!channel_); |
357 if (delay_ > base::TimeDelta()) { | 360 if (delay_ > base::TimeDelta()) { |
358 base::MessageLoop::current()->PostDelayedTask( | 361 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
359 FROM_HERE, | 362 FROM_HERE, |
360 base::Bind(&WebSocketHost::AddChannel, | 363 base::Bind(&WebSocketHost::AddChannel, weak_ptr_factory_.GetWeakPtr(), |
361 weak_ptr_factory_.GetWeakPtr(), | 364 socket_url, requested_protocols, origin, render_frame_id), |
362 socket_url, | |
363 requested_protocols, | |
364 origin, | |
365 render_frame_id), | |
366 delay_); | 365 delay_); |
367 } else { | 366 } else { |
368 AddChannel(socket_url, requested_protocols, origin, render_frame_id); | 367 AddChannel(socket_url, requested_protocols, origin, render_frame_id); |
369 } | 368 } |
370 // |this| may have been deleted here. | 369 // |this| may have been deleted here. |
371 } | 370 } |
372 | 371 |
373 void WebSocketHost::AddChannel( | 372 void WebSocketHost::AddChannel( |
374 const GURL& socket_url, | 373 const GURL& socket_url, |
375 const std::vector<std::string>& requested_protocols, | 374 const std::vector<std::string>& requested_protocols, |
(...skipping 11 matching lines...) Expand all Loading... |
387 new WebSocketEventHandler(dispatcher_, routing_id_, render_frame_id)); | 386 new WebSocketEventHandler(dispatcher_, routing_id_, render_frame_id)); |
388 channel_.reset( | 387 channel_.reset( |
389 new net::WebSocketChannel(event_interface.Pass(), url_request_context_)); | 388 new net::WebSocketChannel(event_interface.Pass(), url_request_context_)); |
390 | 389 |
391 if (pending_flow_control_quota_ > 0) { | 390 if (pending_flow_control_quota_ > 0) { |
392 // channel_->SendFlowControl(pending_flow_control_quota_) must be called | 391 // channel_->SendFlowControl(pending_flow_control_quota_) must be called |
393 // after channel_->SendAddChannelRequest() below. | 392 // after channel_->SendAddChannelRequest() below. |
394 // We post OnFlowControl() here using |weak_ptr_factory_| instead of | 393 // We post OnFlowControl() here using |weak_ptr_factory_| instead of |
395 // calling SendFlowControl directly, because |this| may have been deleted | 394 // calling SendFlowControl directly, because |this| may have been deleted |
396 // after channel_->SendAddChannelRequest(). | 395 // after channel_->SendAddChannelRequest(). |
397 base::MessageLoop::current()->PostTask( | 396 base::ThreadTaskRunnerHandle::Get()->PostTask( |
398 FROM_HERE, | 397 FROM_HERE, base::Bind(&WebSocketHost::OnFlowControl, |
399 base::Bind(&WebSocketHost::OnFlowControl, | 398 weak_ptr_factory_.GetWeakPtr(), |
400 weak_ptr_factory_.GetWeakPtr(), | 399 pending_flow_control_quota_)); |
401 pending_flow_control_quota_)); | |
402 pending_flow_control_quota_ = 0; | 400 pending_flow_control_quota_ = 0; |
403 } | 401 } |
404 | 402 |
405 channel_->SendAddChannelRequest(socket_url, requested_protocols, origin); | 403 channel_->SendAddChannelRequest(socket_url, requested_protocols, origin); |
406 // |this| may have been deleted here. | 404 // |this| may have been deleted here. |
407 } | 405 } |
408 | 406 |
409 void WebSocketHost::OnSendFrame(bool fin, | 407 void WebSocketHost::OnSendFrame(bool fin, |
410 WebSocketMessageType type, | 408 WebSocketMessageType type, |
411 const std::vector<char>& data) { | 409 const std::vector<char>& data) { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
449 ""); | 447 ""); |
450 DCHECK_EQ(WebSocketDispatcherHost::WEBSOCKET_HOST_DELETED, result); | 448 DCHECK_EQ(WebSocketDispatcherHost::WEBSOCKET_HOST_DELETED, result); |
451 return; | 449 return; |
452 } | 450 } |
453 | 451 |
454 // TODO(yhirano): Handle |was_clean| appropriately. | 452 // TODO(yhirano): Handle |was_clean| appropriately. |
455 channel_->StartClosingHandshake(code, reason); | 453 channel_->StartClosingHandshake(code, reason); |
456 } | 454 } |
457 | 455 |
458 } // namespace content | 456 } // namespace content |
OLD | NEW |