Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(238)

Side by Side Diff: net/websockets/websocket_job.cc

Issue 10843050: WebSocket over SPDY: handshake support for both of SPDY/2 and SPDY/3 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: reflects yutak's review Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "net/websockets/websocket_job.h" 5 #include "net/websockets/websocket_job.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 73
74 WebSocketJob::WebSocketJob(SocketStream::Delegate* delegate) 74 WebSocketJob::WebSocketJob(SocketStream::Delegate* delegate)
75 : delegate_(delegate), 75 : delegate_(delegate),
76 state_(INITIALIZED), 76 state_(INITIALIZED),
77 waiting_(false), 77 waiting_(false),
78 handshake_request_(new WebSocketHandshakeRequestHandler), 78 handshake_request_(new WebSocketHandshakeRequestHandler),
79 handshake_response_(new WebSocketHandshakeResponseHandler), 79 handshake_response_(new WebSocketHandshakeResponseHandler),
80 started_to_send_handshake_request_(false), 80 started_to_send_handshake_request_(false),
81 handshake_request_sent_(0), 81 handshake_request_sent_(0),
82 response_cookies_save_index_(0), 82 response_cookies_save_index_(0),
83 protocol_version_(0),
83 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)), 84 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)),
84 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_for_send_pending_(this)) { 85 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_for_send_pending_(this)) {
85 } 86 }
86 87
87 WebSocketJob::~WebSocketJob() { 88 WebSocketJob::~WebSocketJob() {
88 DCHECK_EQ(CLOSED, state_); 89 DCHECK_EQ(CLOSED, state_);
89 DCHECK(!delegate_); 90 DCHECK(!delegate_);
90 DCHECK(!socket_.get()); 91 DCHECK(!socket_.get());
91 } 92 }
92 93
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 } 306 }
306 307
307 int WebSocketJob::OnReceivedSpdyResponseHeader( 308 int WebSocketJob::OnReceivedSpdyResponseHeader(
308 const SpdyHeaderBlock& headers, int status) { 309 const SpdyHeaderBlock& headers, int status) {
309 DCHECK_NE(INITIALIZED, state_); 310 DCHECK_NE(INITIALIZED, state_);
310 if (state_ != CONNECTING) 311 if (state_ != CONNECTING)
311 return status; 312 return status;
312 if (status != OK) 313 if (status != OK)
313 return status; 314 return status;
314 // TODO(toyoshim): Fallback to non-spdy connection? 315 // TODO(toyoshim): Fallback to non-spdy connection?
315 handshake_response_->ParseResponseHeaderBlock(headers, challenge_); 316 handshake_response_->ParseResponseHeaderBlock(headers,
317 challenge_,
318 protocol_version_);
316 319
317 SaveCookiesAndNotifyHeaderComplete(); 320 SaveCookiesAndNotifyHeaderComplete();
318 return OK; 321 return OK;
319 } 322 }
320 323
321 void WebSocketJob::OnSentSpdyData(int amount_sent) { 324 void WebSocketJob::OnSentSpdyData(int amount_sent) {
322 DCHECK_NE(INITIALIZED, state_); 325 DCHECK_NE(INITIALIZED, state_);
323 DCHECK_NE(CONNECTING, state_); 326 DCHECK_NE(CONNECTING, state_);
324 if (state_ == CLOSED) 327 if (state_ == CLOSED)
325 return; 328 return;
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 void WebSocketJob::LoadCookieCallback(const std::string& cookie) { 385 void WebSocketJob::LoadCookieCallback(const std::string& cookie) {
383 if (!cookie.empty()) 386 if (!cookie.empty())
384 handshake_request_->AppendHeaderIfMissing("Cookie", cookie); 387 handshake_request_->AppendHeaderIfMissing("Cookie", cookie);
385 DoSendData(); 388 DoSendData();
386 } 389 }
387 390
388 void WebSocketJob::DoSendData() { 391 void WebSocketJob::DoSendData() {
389 if (spdy_websocket_stream_.get()) { 392 if (spdy_websocket_stream_.get()) {
390 scoped_ptr<SpdyHeaderBlock> headers(new SpdyHeaderBlock); 393 scoped_ptr<SpdyHeaderBlock> headers(new SpdyHeaderBlock);
391 handshake_request_->GetRequestHeaderBlock( 394 handshake_request_->GetRequestHeaderBlock(
392 socket_->url(), headers.get(), &challenge_); 395 socket_->url(), headers.get(), &challenge_, protocol_version_);
393 spdy_websocket_stream_->SendRequest(headers.Pass()); 396 spdy_websocket_stream_->SendRequest(headers.Pass());
394 } else { 397 } else {
395 const std::string& handshake_request = 398 const std::string& handshake_request =
396 handshake_request_->GetRawRequest(); 399 handshake_request_->GetRawRequest();
397 handshake_request_sent_ = 0; 400 handshake_request_sent_ = 0;
398 socket_->net_log()->AddEvent( 401 socket_->net_log()->AddEvent(
399 NetLog::TYPE_WEB_SOCKET_SEND_REQUEST_HEADERS, 402 NetLog::TYPE_WEB_SOCKET_SEND_REQUEST_HEADERS,
400 base::Bind(&NetLogWebSocketHandshakeCallback, &handshake_request)); 403 base::Bind(&NetLogWebSocketHandshakeCallback, &handshake_request));
401 socket_->SendData(handshake_request.data(), 404 socket_->SendData(handshake_request.data(),
402 handshake_request.size()); 405 handshake_request.size());
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
560 spdy_pool->Get(pair, *socket_->net_log()); 563 spdy_pool->Get(pair, *socket_->net_log());
561 SSLInfo ssl_info; 564 SSLInfo ssl_info;
562 bool was_npn_negotiated; 565 bool was_npn_negotiated;
563 NextProto protocol_negotiated = kProtoUnknown; 566 NextProto protocol_negotiated = kProtoUnknown;
564 bool use_ssl = spdy_session->GetSSLInfo( 567 bool use_ssl = spdy_session->GetSSLInfo(
565 &ssl_info, &was_npn_negotiated, &protocol_negotiated); 568 &ssl_info, &was_npn_negotiated, &protocol_negotiated);
566 if (socket_->is_secure() && !use_ssl) 569 if (socket_->is_secure() && !use_ssl)
567 return OK; 570 return OK;
568 571
569 // Create SpdyWebSocketStream. 572 // Create SpdyWebSocketStream.
573 protocol_version_ = spdy_session->GetProtocolVersion();
570 spdy_websocket_stream_.reset(new SpdyWebSocketStream(spdy_session, this)); 574 spdy_websocket_stream_.reset(new SpdyWebSocketStream(spdy_session, this));
571 575
572 int result = spdy_websocket_stream_->InitializeStream( 576 int result = spdy_websocket_stream_->InitializeStream(
573 socket_->url(), MEDIUM, *socket_->net_log()); 577 socket_->url(), MEDIUM, *socket_->net_log());
574 if (result == OK) { 578 if (result == OK) {
575 OnConnected(socket_, kMaxPendingSendAllowed); 579 OnConnected(socket_, kMaxPendingSendAllowed);
576 return ERR_PROTOCOL_SWITCHED; 580 return ERR_PROTOCOL_SWITCHED;
577 } 581 }
578 if (result != ERR_IO_PENDING) { 582 if (result != ERR_IO_PENDING) {
579 spdy_websocket_stream_.reset(); 583 spdy_websocket_stream_.reset();
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
650 654
651 scoped_refptr<IOBufferWithSize> next_buffer = send_buffer_queue_.front(); 655 scoped_refptr<IOBufferWithSize> next_buffer = send_buffer_queue_.front();
652 send_buffer_queue_.pop_front(); 656 send_buffer_queue_.pop_front();
653 current_send_buffer_ = new DrainableIOBuffer(next_buffer, 657 current_send_buffer_ = new DrainableIOBuffer(next_buffer,
654 next_buffer->size()); 658 next_buffer->size());
655 SendDataInternal(current_send_buffer_->data(), 659 SendDataInternal(current_send_buffer_->data(),
656 current_send_buffer_->BytesRemaining()); 660 current_send_buffer_->BytesRemaining());
657 } 661 }
658 662
659 } // namespace net 663 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698