Chromium Code Reviews| 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 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 307 | 307 |
| 308 void WebSocketEventHandler::SSLErrorHandlerDelegate::ContinueSSLRequest() { | 308 void WebSocketEventHandler::SSLErrorHandlerDelegate::ContinueSSLRequest() { |
| 309 DVLOG(3) << "SSLErrorHandlerDelegate::ContinueSSLRequest"; | 309 DVLOG(3) << "SSLErrorHandlerDelegate::ContinueSSLRequest"; |
| 310 callbacks_->ContinueSSLRequest(); | 310 callbacks_->ContinueSSLRequest(); |
| 311 } | 311 } |
| 312 | 312 |
| 313 } // namespace | 313 } // namespace |
| 314 | 314 |
| 315 WebSocketHost::WebSocketHost(int routing_id, | 315 WebSocketHost::WebSocketHost(int routing_id, |
| 316 WebSocketDispatcherHost* dispatcher, | 316 WebSocketDispatcherHost* dispatcher, |
| 317 net::URLRequestContext* url_request_context) | 317 net::URLRequestContext* url_request_context, |
| 318 int delay_in_ms) | |
| 318 : dispatcher_(dispatcher), | 319 : dispatcher_(dispatcher), |
| 319 url_request_context_(url_request_context), | 320 url_request_context_(url_request_context), |
| 320 routing_id_(routing_id) { | 321 routing_id_(routing_id), |
| 322 delay_in_ms_(delay_in_ms), | |
| 323 pending_flow_control_quota_(-1), | |
| 324 handshake_succeeded_(false), | |
| 325 weak_ptr_factory_(this) { | |
| 321 DVLOG(1) << "WebSocketHost: created routing_id=" << routing_id; | 326 DVLOG(1) << "WebSocketHost: created routing_id=" << routing_id; |
| 322 } | 327 } |
| 323 | 328 |
| 324 WebSocketHost::~WebSocketHost() {} | 329 WebSocketHost::~WebSocketHost() {} |
| 325 | 330 |
| 326 void WebSocketHost::GoAway() { | 331 void WebSocketHost::GoAway() { |
| 327 OnDropChannel(false, static_cast<uint16>(net::kWebSocketErrorGoingAway), ""); | 332 OnDropChannel(false, static_cast<uint16>(net::kWebSocketErrorGoingAway), ""); |
| 328 } | 333 } |
| 329 | 334 |
| 330 bool WebSocketHost::OnMessageReceived(const IPC::Message& message) { | 335 bool WebSocketHost::OnMessageReceived(const IPC::Message& message) { |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 344 const std::vector<std::string>& requested_protocols, | 349 const std::vector<std::string>& requested_protocols, |
| 345 const url::Origin& origin, | 350 const url::Origin& origin, |
| 346 int render_frame_id) { | 351 int render_frame_id) { |
| 347 DVLOG(3) << "WebSocketHost::OnAddChannelRequest" | 352 DVLOG(3) << "WebSocketHost::OnAddChannelRequest" |
| 348 << " routing_id=" << routing_id_ << " socket_url=\"" << socket_url | 353 << " routing_id=" << routing_id_ << " socket_url=\"" << socket_url |
| 349 << "\" requested_protocols=\"" | 354 << "\" requested_protocols=\"" |
| 350 << JoinString(requested_protocols, ", ") << "\" origin=\"" | 355 << JoinString(requested_protocols, ", ") << "\" origin=\"" |
| 351 << origin.string() << "\""; | 356 << origin.string() << "\""; |
| 352 | 357 |
| 353 DCHECK(!channel_); | 358 DCHECK(!channel_); |
| 359 if (delay_in_ms_ > 0) { | |
| 360 base::MessageLoop::current()->PostDelayedTask( | |
| 361 FROM_HERE, | |
| 362 base::Bind(&WebSocketHost::AddChannel, | |
| 363 weak_ptr_factory_.GetWeakPtr(), | |
| 364 socket_url, | |
| 365 requested_protocols, | |
| 366 origin, | |
| 367 render_frame_id), | |
| 368 base::TimeDelta::FromMilliseconds(delay_in_ms_)); | |
| 369 } else { | |
| 370 AddChannel(socket_url, requested_protocols, origin, render_frame_id); | |
| 371 } | |
| 372 } | |
| 373 | |
| 374 void WebSocketHost::AddChannel( | |
| 375 const GURL& socket_url, | |
| 376 const std::vector<std::string>& requested_protocols, | |
| 377 const url::Origin& origin, | |
| 378 int render_frame_id) { | |
| 379 DVLOG(3) << "WebSocketHost::AddChannel" | |
| 380 << " routing_id=" << routing_id_ << " socket_url=\"" << socket_url | |
| 381 << "\" requested_protocols=\"" | |
| 382 << JoinString(requested_protocols, ", ") << "\" origin=\"" | |
| 383 << origin.string() << "\""; | |
| 384 | |
| 385 DCHECK(!channel_); | |
| 386 | |
| 354 scoped_ptr<net::WebSocketEventInterface> event_interface( | 387 scoped_ptr<net::WebSocketEventInterface> event_interface( |
| 355 new WebSocketEventHandler(dispatcher_, routing_id_, render_frame_id)); | 388 new WebSocketEventHandler(dispatcher_, routing_id_, render_frame_id)); |
| 356 channel_.reset( | 389 channel_.reset( |
| 357 new net::WebSocketChannel(event_interface.Pass(), url_request_context_)); | 390 new net::WebSocketChannel(event_interface.Pass(), url_request_context_)); |
| 358 channel_->SendAddChannelRequest(socket_url, requested_protocols, origin); | 391 channel_->SendAddChannelRequest(socket_url, requested_protocols, origin); |
| 392 | |
| 393 if (pending_flow_control_quota_ >= 0) { | |
| 394 channel_->SendFlowControl(pending_flow_control_quota_); | |
|
Adam Rice
2015/03/03 15:10:03
I suggest setting pending_flow_control_quota_ to 0
hiroshige
2015/03/04 06:02:38
Done.
| |
| 395 } | |
| 359 } | 396 } |
| 360 | 397 |
| 361 void WebSocketHost::OnSendFrame(bool fin, | 398 void WebSocketHost::OnSendFrame(bool fin, |
| 362 WebSocketMessageType type, | 399 WebSocketMessageType type, |
| 363 const std::vector<char>& data) { | 400 const std::vector<char>& data) { |
| 364 DVLOG(3) << "WebSocketHost::OnSendFrame" | 401 DVLOG(3) << "WebSocketHost::OnSendFrame" |
| 365 << " routing_id=" << routing_id_ << " fin=" << fin | 402 << " routing_id=" << routing_id_ << " fin=" << fin |
| 366 << " type=" << type << " data is " << data.size() << " bytes"; | 403 << " type=" << type << " data is " << data.size() << " bytes"; |
| 367 | 404 |
| 368 DCHECK(channel_); | 405 DCHECK(channel_); |
| 369 channel_->SendFrame(fin, MessageTypeToOpCode(type), data); | 406 channel_->SendFrame(fin, MessageTypeToOpCode(type), data); |
| 370 } | 407 } |
| 371 | 408 |
| 372 void WebSocketHost::OnFlowControl(int64 quota) { | 409 void WebSocketHost::OnFlowControl(int64 quota) { |
| 373 DVLOG(3) << "WebSocketHost::OnFlowControl" | 410 DVLOG(3) << "WebSocketHost::OnFlowControl" |
| 374 << " routing_id=" << routing_id_ << " quota=" << quota; | 411 << " routing_id=" << routing_id_ << " quota=" << quota; |
| 375 | 412 |
| 376 DCHECK(channel_); | 413 if (!channel_) { |
| 414 // WebSocketChannel is not yet created due to the delay introduced by | |
| 415 // Per-renderer WebSocket throttling. | |
| 416 // SendFlowControl() is called after WebSocketChannel is created. | |
| 417 pending_flow_control_quota_ = quota; | |
|
Adam Rice
2015/03/03 15:10:02
This should be += because flow control quota is al
hiroshige
2015/03/04 06:02:38
Done.
| |
| 418 return; | |
| 419 } | |
| 420 | |
| 377 channel_->SendFlowControl(quota); | 421 channel_->SendFlowControl(quota); |
| 378 } | 422 } |
| 379 | 423 |
| 380 void WebSocketHost::OnDropChannel(bool was_clean, | 424 void WebSocketHost::OnDropChannel(bool was_clean, |
| 381 uint16 code, | 425 uint16 code, |
| 382 const std::string& reason) { | 426 const std::string& reason) { |
| 383 DVLOG(3) << "WebSocketHost::OnDropChannel" | 427 DVLOG(3) << "WebSocketHost::OnDropChannel" |
| 384 << " routing_id=" << routing_id_ << " was_clean=" << was_clean | 428 << " routing_id=" << routing_id_ << " was_clean=" << was_clean |
| 385 << " code=" << code << " reason=\"" << reason << "\""; | 429 << " code=" << code << " reason=\"" << reason << "\""; |
| 386 | 430 |
| 387 DCHECK(channel_); | 431 if (!channel_) { |
| 432 // WebSocketChannel is not yet created due to the delay introduced by | |
| 433 // Per-renderer WebSocket throttling. | |
| 434 WebSocketDispatcherHost::WebSocketHostState result = | |
| 435 dispatcher_->DoDropChannel(routing_id_, was_clean, code, reason); | |
|
Adam Rice
2015/03/03 15:10:03
We should not use the values from the renderer in
hiroshige
2015/03/04 06:02:38
Done.
| |
| 436 DCHECK_EQ(WebSocketDispatcherHost::WEBSOCKET_HOST_DELETED, result); | |
| 437 return; | |
| 438 } | |
| 439 | |
| 388 // TODO(yhirano): Handle |was_clean| appropriately. | 440 // TODO(yhirano): Handle |was_clean| appropriately. |
| 389 channel_->StartClosingHandshake(code, reason); | 441 channel_->StartClosingHandshake(code, reason); |
| 390 } | 442 } |
| 391 | 443 |
| 392 } // namespace content | 444 } // namespace content |
| OLD | NEW |