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/memory/weak_ptr.h" | 8 #include "base/memory/weak_ptr.h" |
9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "content/browser/renderer_host/websocket_dispatcher_host.h" | 10 #include "content/browser/renderer_host/websocket_dispatcher_host.h" |
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
360 base::Bind(&WebSocketHost::AddChannel, | 360 base::Bind(&WebSocketHost::AddChannel, |
361 weak_ptr_factory_.GetWeakPtr(), | 361 weak_ptr_factory_.GetWeakPtr(), |
362 socket_url, | 362 socket_url, |
363 requested_protocols, | 363 requested_protocols, |
364 origin, | 364 origin, |
365 render_frame_id), | 365 render_frame_id), |
366 delay_); | 366 delay_); |
367 } else { | 367 } else { |
368 AddChannel(socket_url, requested_protocols, origin, render_frame_id); | 368 AddChannel(socket_url, requested_protocols, origin, render_frame_id); |
369 } | 369 } |
370 // |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, |
376 const url::Origin& origin, | 375 const url::Origin& origin, |
377 int render_frame_id) { | 376 int render_frame_id) { |
378 DVLOG(3) << "WebSocketHost::AddChannel" | 377 DVLOG(3) << "WebSocketHost::AddChannel" |
379 << " routing_id=" << routing_id_ << " socket_url=\"" << socket_url | 378 << " routing_id=" << routing_id_ << " socket_url=\"" << socket_url |
380 << "\" requested_protocols=\"" | 379 << "\" requested_protocols=\"" |
381 << JoinString(requested_protocols, ", ") << "\" origin=\"" | 380 << JoinString(requested_protocols, ", ") << "\" origin=\"" |
382 << origin.string() << "\""; | 381 << origin.string() << "\""; |
383 | 382 |
384 DCHECK(!channel_); | 383 DCHECK(!channel_); |
385 | 384 |
386 scoped_ptr<net::WebSocketEventInterface> event_interface( | 385 scoped_ptr<net::WebSocketEventInterface> event_interface( |
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_)); |
| 389 channel_->SendAddChannelRequest(socket_url, requested_protocols, origin); |
390 | 390 |
391 if (pending_flow_control_quota_ > 0) { | 391 if (pending_flow_control_quota_ > 0) { |
392 // channel_->SendFlowControl(pending_flow_control_quota_) must be called | 392 channel_->SendFlowControl(pending_flow_control_quota_); |
393 // after channel_->SendAddChannelRequest() below. | |
394 // We post OnFlowControl() here using |weak_ptr_factory_| instead of | |
395 // calling SendFlowControl directly, because |this| may have been deleted | |
396 // after channel_->SendAddChannelRequest(). | |
397 base::MessageLoop::current()->PostTask( | |
398 FROM_HERE, | |
399 base::Bind(&WebSocketHost::OnFlowControl, | |
400 weak_ptr_factory_.GetWeakPtr(), | |
401 pending_flow_control_quota_)); | |
402 pending_flow_control_quota_ = 0; | 393 pending_flow_control_quota_ = 0; |
403 } | 394 } |
404 | |
405 channel_->SendAddChannelRequest(socket_url, requested_protocols, origin); | |
406 // |this| may have been deleted here. | |
407 } | 395 } |
408 | 396 |
409 void WebSocketHost::OnSendFrame(bool fin, | 397 void WebSocketHost::OnSendFrame(bool fin, |
410 WebSocketMessageType type, | 398 WebSocketMessageType type, |
411 const std::vector<char>& data) { | 399 const std::vector<char>& data) { |
412 DVLOG(3) << "WebSocketHost::OnSendFrame" | 400 DVLOG(3) << "WebSocketHost::OnSendFrame" |
413 << " routing_id=" << routing_id_ << " fin=" << fin | 401 << " routing_id=" << routing_id_ << " fin=" << fin |
414 << " type=" << type << " data is " << data.size() << " bytes"; | 402 << " type=" << type << " data is " << data.size() << " bytes"; |
415 | 403 |
416 DCHECK(channel_); | 404 DCHECK(channel_); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
449 ""); | 437 ""); |
450 DCHECK_EQ(WebSocketDispatcherHost::WEBSOCKET_HOST_DELETED, result); | 438 DCHECK_EQ(WebSocketDispatcherHost::WEBSOCKET_HOST_DELETED, result); |
451 return; | 439 return; |
452 } | 440 } |
453 | 441 |
454 // TODO(yhirano): Handle |was_clean| appropriately. | 442 // TODO(yhirano): Handle |was_clean| appropriately. |
455 channel_->StartClosingHandshake(code, reason); | 443 channel_->StartClosingHandshake(code, reason); |
456 } | 444 } |
457 | 445 |
458 } // namespace content | 446 } // namespace content |
OLD | NEW |