Chromium Code Reviews| OLD | NEW |
|---|---|
| 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" |
| 11 #include "base/string_tokenizer.h" | 11 #include "base/string_tokenizer.h" |
| 12 #include "base/values.h" | |
| 12 #include "googleurl/src/gurl.h" | 13 #include "googleurl/src/gurl.h" |
| 13 #include "net/base/net_errors.h" | 14 #include "net/base/net_errors.h" |
| 14 #include "net/base/net_log.h" | 15 #include "net/base/net_log.h" |
| 15 #include "net/cookies/cookie_store.h" | 16 #include "net/cookies/cookie_store.h" |
| 16 #include "net/base/io_buffer.h" | 17 #include "net/base/io_buffer.h" |
| 17 #include "net/http/http_network_session.h" | 18 #include "net/http/http_network_session.h" |
| 18 #include "net/http/http_transaction_factory.h" | 19 #include "net/http/http_transaction_factory.h" |
| 19 #include "net/http/http_util.h" | 20 #include "net/http/http_util.h" |
| 20 #include "net/spdy/spdy_session.h" | 21 #include "net/spdy/spdy_session.h" |
| 21 #include "net/spdy/spdy_session_pool.h" | 22 #include "net/spdy/spdy_session_pool.h" |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 48 friend struct base::DefaultLazyInstanceTraits<WebSocketJobInitSingleton>; | 49 friend struct base::DefaultLazyInstanceTraits<WebSocketJobInitSingleton>; |
| 49 WebSocketJobInitSingleton() { | 50 WebSocketJobInitSingleton() { |
| 50 net::SocketStreamJob::RegisterProtocolFactory("ws", WebSocketJobFactory); | 51 net::SocketStreamJob::RegisterProtocolFactory("ws", WebSocketJobFactory); |
| 51 net::SocketStreamJob::RegisterProtocolFactory("wss", WebSocketJobFactory); | 52 net::SocketStreamJob::RegisterProtocolFactory("wss", WebSocketJobFactory); |
| 52 } | 53 } |
| 53 }; | 54 }; |
| 54 | 55 |
| 55 static base::LazyInstance<WebSocketJobInitSingleton> g_websocket_job_init = | 56 static base::LazyInstance<WebSocketJobInitSingleton> g_websocket_job_init = |
| 56 LAZY_INSTANCE_INITIALIZER; | 57 LAZY_INSTANCE_INITIALIZER; |
| 57 | 58 |
| 59 Value* NetLogWebSocketHandshakeResponseHandlerCallback( | |
| 60 const net::WebSocketHandshakeResponseHandler* handler, | |
| 61 net::NetLog::LogLevel log_level) { | |
| 62 std::string headers = handler->GetRawResponse(); | |
| 63 return net::NetLogWebSocketHandshakeCallback(&headers, log_level); | |
| 64 } | |
| 65 | |
| 58 } // anonymous namespace | 66 } // anonymous namespace |
| 59 | 67 |
| 60 namespace net { | 68 namespace net { |
| 61 | 69 |
| 62 bool WebSocketJob::websocket_over_spdy_enabled_ = false; | 70 bool WebSocketJob::websocket_over_spdy_enabled_ = false; |
| 63 | 71 |
| 64 // static | 72 // static |
| 65 void WebSocketJob::EnsureInit() { | 73 void WebSocketJob::EnsureInit() { |
| 66 g_websocket_job_init.Get(); | 74 g_websocket_job_init.Get(); |
| 67 } | 75 } |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 386 } | 394 } |
| 387 | 395 |
| 388 void WebSocketJob::DoSendData() { | 396 void WebSocketJob::DoSendData() { |
| 389 if (spdy_websocket_stream_.get()) { | 397 if (spdy_websocket_stream_.get()) { |
| 390 linked_ptr<SpdyHeaderBlock> headers(new SpdyHeaderBlock); | 398 linked_ptr<SpdyHeaderBlock> headers(new SpdyHeaderBlock); |
| 391 handshake_request_->GetRequestHeaderBlock( | 399 handshake_request_->GetRequestHeaderBlock( |
| 392 socket_->url(), headers.get(), &challenge_); | 400 socket_->url(), headers.get(), &challenge_); |
| 393 spdy_websocket_stream_->SendRequest(headers); | 401 spdy_websocket_stream_->SendRequest(headers); |
| 394 } else { | 402 } else { |
| 395 const std::string& handshake_request = | 403 const std::string& handshake_request = |
| 396 handshake_request_->GetRawRequest(); | 404 handshake_request_->GetRawRequest(); |
|
mmenke
2012/06/14 14:18:02
This mutates the handshake_request and thus is non
| |
| 397 handshake_request_sent_ = 0; | 405 handshake_request_sent_ = 0; |
| 398 socket_->net_log()->AddEvent( | 406 socket_->net_log()->AddEvent( |
| 399 NetLog::TYPE_WEB_SOCKET_SEND_REQUEST_HEADERS, | 407 NetLog::TYPE_WEB_SOCKET_SEND_REQUEST_HEADERS, |
| 400 make_scoped_refptr( | 408 base::Bind(&NetLogWebSocketHandshakeCallback, &handshake_request)); |
|
eroman
2012/06/14 17:19:40
This is confusing. There are two identically named
mmenke
2012/06/14 17:30:06
They actually have different, but confusingly simi
| |
| 401 new NetLogWebSocketHandshakeParameter(handshake_request))); | |
| 402 socket_->SendData(handshake_request.data(), | 409 socket_->SendData(handshake_request.data(), |
| 403 handshake_request.size()); | 410 handshake_request.size()); |
| 404 } | 411 } |
| 405 // Just buffered in |handshake_request_|. | 412 // Just buffered in |handshake_request_|. |
| 406 started_to_send_handshake_request_ = true; | 413 started_to_send_handshake_request_ = true; |
| 407 } | 414 } |
| 408 | 415 |
| 409 void WebSocketJob::OnSentHandshakeRequest( | 416 void WebSocketJob::OnSentHandshakeRequest( |
| 410 SocketStream* socket, int amount_sent) { | 417 SocketStream* socket, int amount_sent) { |
| 411 DCHECK_EQ(state_, CONNECTING); | 418 DCHECK_EQ(state_, CONNECTING); |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 432 received_data_after_handshake_.end(), data, data + len); | 439 received_data_after_handshake_.end(), data, data + len); |
| 433 return; | 440 return; |
| 434 } | 441 } |
| 435 | 442 |
| 436 size_t response_length = handshake_response_->ParseRawResponse(data, len); | 443 size_t response_length = handshake_response_->ParseRawResponse(data, len); |
| 437 if (!handshake_response_->HasResponse()) { | 444 if (!handshake_response_->HasResponse()) { |
| 438 // not yet. we need more data. | 445 // not yet. we need more data. |
| 439 return; | 446 return; |
| 440 } | 447 } |
| 441 // handshake message is completed. | 448 // handshake message is completed. |
| 449 std::string raw_response = handshake_response_->GetRawResponse(); | |
|
eroman
2012/06/14 17:19:40
This is unused. See comment above, perhaps you mea
mmenke
2012/06/14 17:30:06
Done. That's what I did initially, actually but t
eroman
2012/06/14 18:12:21
I generally like deferring construction of the str
| |
| 442 socket_->net_log()->AddEvent( | 450 socket_->net_log()->AddEvent( |
| 443 NetLog::TYPE_WEB_SOCKET_READ_RESPONSE_HEADERS, | 451 NetLog::TYPE_WEB_SOCKET_READ_RESPONSE_HEADERS, |
| 444 make_scoped_refptr(new NetLogWebSocketHandshakeParameter( | 452 base::Bind(&NetLogWebSocketHandshakeResponseHandlerCallback, |
| 445 handshake_response_->GetRawResponse()))); | 453 handshake_response_.get())); |
| 446 if (len - response_length > 0) { | 454 if (len - response_length > 0) { |
| 447 // If we received extra data, it should be frame data. | 455 // If we received extra data, it should be frame data. |
| 448 DCHECK(received_data_after_handshake_.empty()); | 456 DCHECK(received_data_after_handshake_.empty()); |
| 449 received_data_after_handshake_.assign(data + response_length, data + len); | 457 received_data_after_handshake_.assign(data + response_length, data + len); |
| 450 } | 458 } |
| 451 SaveCookiesAndNotifyHeaderComplete(); | 459 SaveCookiesAndNotifyHeaderComplete(); |
| 452 } | 460 } |
| 453 | 461 |
| 454 void WebSocketJob::SaveCookiesAndNotifyHeaderComplete() { | 462 void WebSocketJob::SaveCookiesAndNotifyHeaderComplete() { |
| 455 // handshake message is completed. | 463 // handshake message is completed. |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 651 | 659 |
| 652 scoped_refptr<IOBufferWithSize> next_buffer = send_buffer_queue_.front(); | 660 scoped_refptr<IOBufferWithSize> next_buffer = send_buffer_queue_.front(); |
| 653 send_buffer_queue_.pop_front(); | 661 send_buffer_queue_.pop_front(); |
| 654 current_send_buffer_ = new DrainableIOBuffer(next_buffer, | 662 current_send_buffer_ = new DrainableIOBuffer(next_buffer, |
| 655 next_buffer->size()); | 663 next_buffer->size()); |
| 656 SendDataInternal(current_send_buffer_->data(), | 664 SendDataInternal(current_send_buffer_->data(), |
| 657 current_send_buffer_->BytesRemaining()); | 665 current_send_buffer_->BytesRemaining()); |
| 658 } | 666 } |
| 659 | 667 |
| 660 } // namespace net | 668 } // namespace net |
| OLD | NEW |