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

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

Issue 221833002: Test for WebSocketJob being deleted on the stack (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Make WebSocketJobDeleteTest.OnClose realistic. Created 6 years, 8 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
« no previous file with comments | « no previous file | net/websockets/websocket_job_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 spdy_websocket_stream_.reset(); 297 spdy_websocket_stream_.reset();
298 } 298 }
299 299
300 CompleteIO(result); 300 CompleteIO(result);
301 } 301 }
302 302
303 void WebSocketJob::OnSentSpdyHeaders() { 303 void WebSocketJob::OnSentSpdyHeaders() {
304 DCHECK_NE(INITIALIZED, state_); 304 DCHECK_NE(INITIALIZED, state_);
305 if (state_ != CONNECTING) 305 if (state_ != CONNECTING)
306 return; 306 return;
307 size_t original_length = handshake_request_->original_length();
308 handshake_request_.reset();
307 if (delegate_) 309 if (delegate_)
308 delegate_->OnSentData(socket_.get(), handshake_request_->original_length()); 310 delegate_->OnSentData(socket_.get(), original_length);
309 handshake_request_.reset();
310 } 311 }
311 312
312 void WebSocketJob::OnSpdyResponseHeadersUpdated( 313 void WebSocketJob::OnSpdyResponseHeadersUpdated(
313 const SpdyHeaderBlock& response_headers) { 314 const SpdyHeaderBlock& response_headers) {
314 DCHECK_NE(INITIALIZED, state_); 315 DCHECK_NE(INITIALIZED, state_);
315 if (state_ != CONNECTING) 316 if (state_ != CONNECTING)
316 return; 317 return;
317 // TODO(toyoshim): Fallback to non-spdy connection? 318 // TODO(toyoshim): Fallback to non-spdy connection?
318 handshake_response_->ParseResponseHeaderBlock(response_headers, 319 handshake_response_->ParseResponseHeaderBlock(response_headers,
319 challenge_, 320 challenge_,
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 } 417 }
417 418
418 void WebSocketJob::OnSentHandshakeRequest( 419 void WebSocketJob::OnSentHandshakeRequest(
419 SocketStream* socket, int amount_sent) { 420 SocketStream* socket, int amount_sent) {
420 DCHECK_EQ(state_, CONNECTING); 421 DCHECK_EQ(state_, CONNECTING);
421 handshake_request_sent_ += amount_sent; 422 handshake_request_sent_ += amount_sent;
422 DCHECK_LE(handshake_request_sent_, handshake_request_->raw_length()); 423 DCHECK_LE(handshake_request_sent_, handshake_request_->raw_length());
423 if (handshake_request_sent_ >= handshake_request_->raw_length()) { 424 if (handshake_request_sent_ >= handshake_request_->raw_length()) {
424 // handshake request has been sent. 425 // handshake request has been sent.
425 // notify original size of handshake request to delegate. 426 // notify original size of handshake request to delegate.
427 // Reset the handshake_request_ first in case this object is deleted by the
428 // delegate.
429 size_t original_length = handshake_request_->original_length();
430 handshake_request_.reset();
426 if (delegate_) 431 if (delegate_)
427 delegate_->OnSentData( 432 delegate_->OnSentData(socket, original_length);
428 socket,
429 handshake_request_->original_length());
430 handshake_request_.reset();
431 } 433 }
432 } 434 }
433 435
434 void WebSocketJob::OnReceivedHandshakeResponse( 436 void WebSocketJob::OnReceivedHandshakeResponse(
435 SocketStream* socket, const char* data, int len) { 437 SocketStream* socket, const char* data, int len) {
436 DCHECK_EQ(state_, CONNECTING); 438 DCHECK_EQ(state_, CONNECTING);
437 if (handshake_response_->HasResponse()) { 439 if (handshake_response_->HasResponse()) {
438 // If we already has handshake response, received data should be frame 440 // If we already has handshake response, received data should be frame
439 // data, not handshake message. 441 // data, not handshake message.
440 received_data_after_handshake_.insert( 442 received_data_after_handshake_.insert(
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
693 695
694 scoped_refptr<IOBufferWithSize> next_buffer = send_buffer_queue_.front(); 696 scoped_refptr<IOBufferWithSize> next_buffer = send_buffer_queue_.front();
695 send_buffer_queue_.pop_front(); 697 send_buffer_queue_.pop_front();
696 current_send_buffer_ = 698 current_send_buffer_ =
697 new DrainableIOBuffer(next_buffer.get(), next_buffer->size()); 699 new DrainableIOBuffer(next_buffer.get(), next_buffer->size());
698 SendDataInternal(current_send_buffer_->data(), 700 SendDataInternal(current_send_buffer_->data(),
699 current_send_buffer_->BytesRemaining()); 701 current_send_buffer_->BytesRemaining());
700 } 702 }
701 703
702 } // namespace net 704 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | net/websockets/websocket_job_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698