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

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

Issue 5216002: Merge 66630 - Fix SPDY crash on race when canceling a stream that just got cr... (Closed) Base URL: svn://svn.chromium.org/chrome/branches/552/src/
Patch Set: Created 10 years, 1 month 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_unittest.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) 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 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 268
269 if (connection_->is_initialized()) { 269 if (connection_->is_initialized()) {
270 // With Spdy we can't recycle sockets. 270 // With Spdy we can't recycle sockets.
271 connection_->socket()->Disconnect(); 271 connection_->socket()->Disconnect();
272 } 272 }
273 273
274 // Streams should all be gone now. 274 // Streams should all be gone now.
275 DCHECK_EQ(0u, num_active_streams()); 275 DCHECK_EQ(0u, num_active_streams());
276 DCHECK_EQ(0u, num_unclaimed_pushed_streams()); 276 DCHECK_EQ(0u, num_unclaimed_pushed_streams());
277 277
278 DCHECK(pending_callback_map_.empty());
279
278 RecordHistograms(); 280 RecordHistograms();
279 281
280 net_log_.EndEvent(NetLog::TYPE_SPDY_SESSION, NULL); 282 net_log_.EndEvent(NetLog::TYPE_SPDY_SESSION, NULL);
281 } 283 }
282 284
283 net::Error SpdySession::InitializeWithSocket( 285 net::Error SpdySession::InitializeWithSocket(
284 ClientSocketHandle* connection, 286 ClientSocketHandle* connection,
285 bool is_secure, 287 bool is_secure,
286 int certificate_error_code) { 288 int certificate_error_code) {
287 static StatsCounter spdy_sessions("spdy.sessions"); 289 static StatsCounter spdy_sessions("spdy.sessions");
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 bool no_pending_create_streams = true; 357 bool no_pending_create_streams = true;
356 for (int i = 0;i < NUM_PRIORITIES;++i) { 358 for (int i = 0;i < NUM_PRIORITIES;++i) {
357 if (!create_stream_queues_[i].empty()) { 359 if (!create_stream_queues_[i].empty()) {
358 PendingCreateStream pending_create = create_stream_queues_[i].front(); 360 PendingCreateStream pending_create = create_stream_queues_[i].front();
359 create_stream_queues_[i].pop(); 361 create_stream_queues_[i].pop();
360 no_pending_create_streams = false; 362 no_pending_create_streams = false;
361 int error = CreateStreamImpl(*pending_create.url, 363 int error = CreateStreamImpl(*pending_create.url,
362 pending_create.priority, 364 pending_create.priority,
363 pending_create.spdy_stream, 365 pending_create.spdy_stream,
364 *pending_create.stream_net_log); 366 *pending_create.stream_net_log);
367 scoped_refptr<SpdyStream>* stream = pending_create.spdy_stream;
368 DCHECK(!ContainsKey(pending_callback_map_, stream));
369 pending_callback_map_[stream] =
370 CallbackResultPair(pending_create.callback, error);
365 MessageLoop::current()->PostTask( 371 MessageLoop::current()->PostTask(
366 FROM_HERE, 372 FROM_HERE,
367 method_factory_.NewRunnableMethod( 373 method_factory_.NewRunnableMethod(
368 &SpdySession::InvokeUserStreamCreationCallback, 374 &SpdySession::InvokeUserStreamCreationCallback, stream));
369 pending_create.callback, error));
370 break; 375 break;
371 } 376 }
372 } 377 }
373 if (no_pending_create_streams) 378 if (no_pending_create_streams)
374 return; // there were no streams in any queue 379 return; // there were no streams in any queue
375 } 380 }
376 } 381 }
377 382
378 void SpdySession::CancelPendingCreateStreams( 383 void SpdySession::CancelPendingCreateStreams(
379 const scoped_refptr<SpdyStream>* spdy_stream) { 384 const scoped_refptr<SpdyStream>* spdy_stream) {
385 PendingCallbackMap::iterator it = pending_callback_map_.find(spdy_stream);
386 if (it != pending_callback_map_.end()) {
387 pending_callback_map_.erase(it);
388 return;
389 }
390
380 for (int i = 0;i < NUM_PRIORITIES;++i) { 391 for (int i = 0;i < NUM_PRIORITIES;++i) {
381 PendingCreateStreamQueue tmp; 392 PendingCreateStreamQueue tmp;
382 // Make a copy removing this trans 393 // Make a copy removing this trans
383 while (!create_stream_queues_[i].empty()) { 394 while (!create_stream_queues_[i].empty()) {
384 PendingCreateStream pending_create = create_stream_queues_[i].front(); 395 PendingCreateStream pending_create = create_stream_queues_[i].front();
385 create_stream_queues_[i].pop(); 396 create_stream_queues_[i].pop();
386 if (pending_create.spdy_stream != spdy_stream) 397 if (pending_create.spdy_stream != spdy_stream)
387 tmp.push(pending_create); 398 tmp.push(pending_create);
388 } 399 }
389 // Now copy it back 400 // Now copy it back
(...skipping 906 matching lines...) Expand 10 before | Expand all | Expand 10 after
1296 UMA_HISTOGRAM_CUSTOM_COUNTS("Net.SpdySettingsRetransRate", 1307 UMA_HISTOGRAM_CUSTOM_COUNTS("Net.SpdySettingsRetransRate",
1297 setting.second, 1308 setting.second,
1298 1, 100, 50); 1309 1, 100, 50);
1299 break; 1310 break;
1300 } 1311 }
1301 } 1312 }
1302 } 1313 }
1303 } 1314 }
1304 1315
1305 void SpdySession::InvokeUserStreamCreationCallback( 1316 void SpdySession::InvokeUserStreamCreationCallback(
1306 CompletionCallback* callback, int rv) { 1317 scoped_refptr<SpdyStream>* stream) {
1307 callback->Run(rv); 1318 PendingCallbackMap::iterator it = pending_callback_map_.find(stream);
1319
1320 // Exit if the request has already been cancelled.
1321 if (it == pending_callback_map_.end())
1322 return;
1323
1324 CompletionCallback* callback = it->second.callback;
1325 int result = it->second.result;
1326 pending_callback_map_.erase(it);
1327 callback->Run(result);
1308 } 1328 }
1309 1329
1310 } // namespace net 1330 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/spdy_session.h ('k') | net/spdy/spdy_session_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698