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