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

Side by Side Diff: net/spdy/spdy_session.cc

Issue 2862027: Fix crash in GetSpdySessionFromSSLSocket in the case where the... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 6 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
« no previous file with comments | « net/spdy/spdy_session.h ('k') | net/spdy/spdy_session_pool.h » ('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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/spdy/spdy_session.h" 5 #include "net/spdy/spdy_session.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/linked_ptr.h" 8 #include "base/linked_ptr.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 if (connection_->is_initialized()) { 293 if (connection_->is_initialized()) {
294 // With Spdy we can't recycle sockets. 294 // With Spdy we can't recycle sockets.
295 connection_->socket()->Disconnect(); 295 connection_->socket()->Disconnect();
296 } 296 }
297 297
298 RecordHistograms(); 298 RecordHistograms();
299 299
300 net_log_.EndEvent(NetLog::TYPE_SPDY_SESSION, NULL); 300 net_log_.EndEvent(NetLog::TYPE_SPDY_SESSION, NULL);
301 } 301 }
302 302
303 void SpdySession::InitializeWithSSLSocket(ClientSocketHandle* connection) { 303 net::Error SpdySession::InitializeWithSSLSocket(
304 ClientSocketHandle* connection) {
304 static StatsCounter spdy_sessions("spdy.sessions"); 305 static StatsCounter spdy_sessions("spdy.sessions");
305 spdy_sessions.Increment(); 306 spdy_sessions.Increment();
306 307
307 AdjustSocketBufferSizes(connection->socket()); 308 AdjustSocketBufferSizes(connection->socket());
308 309
309 state_ = CONNECTED; 310 state_ = CONNECTED;
310 connection_.reset(connection); 311 connection_.reset(connection);
311 is_secure_ = true; // |connection| contains an SSLClientSocket. 312 is_secure_ = true; // |connection| contains an SSLClientSocket.
312 313
313 // This is a newly initialized session that no client should have a handle to 314 // This is a newly initialized session that no client should have a handle to
314 // yet, so there's no need to start writing data as in OnTCPConnect(), but we 315 // yet, so there's no need to start writing data as in OnTCPConnect(), but we
315 // should start reading data. 316 // should start reading data.
316 ReadSocket(); 317 net::Error error = ReadSocket();
318 if (error == ERR_IO_PENDING)
319 return OK;
320 return error;
317 } 321 }
318 322
319 net::Error SpdySession::Connect(const std::string& group_name, 323 net::Error SpdySession::Connect(const std::string& group_name,
320 const TCPSocketParams& destination, 324 const TCPSocketParams& destination,
321 RequestPriority priority) { 325 RequestPriority priority) {
322 DCHECK(priority >= SPDY_PRIORITY_HIGHEST && priority <= SPDY_PRIORITY_LOWEST); 326 DCHECK(priority >= SPDY_PRIORITY_HIGHEST && priority <= SPDY_PRIORITY_LOWEST);
323 327
324 // If the connect process is started, let the caller continue. 328 // If the connect process is started, let the caller continue.
325 if (state_ > IDLE) 329 if (state_ > IDLE)
326 return net::OK; 330 return net::OK;
(...skipping 13 matching lines...) Expand all
340 if (rv == net::ERR_IO_PENDING) 344 if (rv == net::ERR_IO_PENDING)
341 return net::OK; 345 return net::OK;
342 OnTCPConnect(rv); 346 OnTCPConnect(rv);
343 return static_cast<net::Error>(rv); 347 return static_cast<net::Error>(rv);
344 } 348 }
345 349
346 scoped_refptr<SpdyHttpStream> SpdySession::GetOrCreateStream( 350 scoped_refptr<SpdyHttpStream> SpdySession::GetOrCreateStream(
347 const HttpRequestInfo& request, 351 const HttpRequestInfo& request,
348 const UploadDataStream* upload_data, 352 const UploadDataStream* upload_data,
349 const BoundNetLog& stream_net_log) { 353 const BoundNetLog& stream_net_log) {
354 CHECK_NE(state_, CLOSED);
350 const GURL& url = request.url; 355 const GURL& url = request.url;
351 const std::string& path = url.PathForRequest(); 356 const std::string& path = url.PathForRequest();
352 357
353 scoped_refptr<SpdyHttpStream> stream; 358 scoped_refptr<SpdyHttpStream> stream;
354 359
355 // Check if we have a push stream for this path. 360 // Check if we have a push stream for this path.
356 if (request.method == "GET") { 361 if (request.method == "GET") {
357 // Only HTTP will push a stream. 362 // Only HTTP will push a stream.
358 scoped_refptr<SpdyHttpStream> stream = GetPushStream(path); 363 scoped_refptr<SpdyHttpStream> stream = GetPushStream(path);
359 if (stream) { 364 if (stream) {
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
659 // message loop). 664 // message loop).
660 WriteSocketLater(); 665 WriteSocketLater();
661 } else { 666 } else {
662 in_flight_write_.release(); 667 in_flight_write_.release();
663 668
664 // The stream is now errored. Close it down. 669 // The stream is now errored. Close it down.
665 CloseSessionOnError(static_cast<net::Error>(result)); 670 CloseSessionOnError(static_cast<net::Error>(result));
666 } 671 }
667 } 672 }
668 673
669 void SpdySession::ReadSocket() { 674 net::Error SpdySession::ReadSocket() {
670 if (read_pending_) 675 if (read_pending_)
671 return; 676 return OK;
672 677
673 if (state_ == CLOSED) { 678 if (state_ == CLOSED) {
674 NOTREACHED(); 679 NOTREACHED();
675 return; 680 return ERR_UNEXPECTED;
676 } 681 }
677 682
678 CHECK(connection_.get()); 683 CHECK(connection_.get());
679 CHECK(connection_->socket()); 684 CHECK(connection_->socket());
680 int bytes_read = connection_->socket()->Read(read_buffer_.get(), 685 int bytes_read = connection_->socket()->Read(read_buffer_.get(),
681 kReadBufferSize, 686 kReadBufferSize,
682 &read_callback_); 687 &read_callback_);
683 switch (bytes_read) { 688 switch (bytes_read) {
684 case 0: 689 case 0:
685 // Socket is closed! 690 // Socket is closed!
686 CloseSessionOnError(ERR_CONNECTION_CLOSED); 691 CloseSessionOnError(ERR_CONNECTION_CLOSED);
687 return; 692 return ERR_CONNECTION_CLOSED;
688 case net::ERR_IO_PENDING: 693 case net::ERR_IO_PENDING:
689 // Waiting for data. Nothing to do now. 694 // Waiting for data. Nothing to do now.
690 read_pending_ = true; 695 read_pending_ = true;
691 return; 696 return ERR_IO_PENDING;
692 default: 697 default:
693 // Data was read, process it. 698 // Data was read, process it.
694 // Schedule the work through the message loop to avoid recursive 699 // Schedule the work through the message loop to avoid recursive
695 // callbacks. 700 // callbacks.
696 read_pending_ = true; 701 read_pending_ = true;
697 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod( 702 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod(
698 this, &SpdySession::OnReadComplete, bytes_read)); 703 this, &SpdySession::OnReadComplete, bytes_read));
699 break; 704 break;
700 } 705 }
706 return OK;
701 } 707 }
702 708
703 void SpdySession::WriteSocketLater() { 709 void SpdySession::WriteSocketLater() {
704 if (delayed_write_pending_) 710 if (delayed_write_pending_)
705 return; 711 return;
706 712
707 if (state_ < CONNECTED) 713 if (state_ < CONNECTED)
708 return; 714 return;
709 715
710 delayed_write_pending_ = true; 716 delayed_write_pending_ = true;
(...skipping 586 matching lines...) Expand 10 before | Expand all | Expand 10 after
1297 UMA_HISTOGRAM_CUSTOM_COUNTS("Net.SpdySettingsRetransRate", 1303 UMA_HISTOGRAM_CUSTOM_COUNTS("Net.SpdySettingsRetransRate",
1298 setting.second, 1304 setting.second,
1299 1, 100, 50); 1305 1, 100, 50);
1300 break; 1306 break;
1301 } 1307 }
1302 } 1308 }
1303 } 1309 }
1304 } 1310 }
1305 1311
1306 } // namespace net 1312 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/spdy_session.h ('k') | net/spdy/spdy_session_pool.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698