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

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

Issue 18546008: [SPDY] Use WeakPtr<SpdySession> everywhere but SpdySessionPool (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix test, other minor formatting/comment changes Created 7 years, 5 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_test_util_common.h ('k') | net/spdy/spdy_websocket_stream.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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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_test_util_common.h" 5 #include "net/spdy/spdy_test_util_common.h"
6 6
7 #include <cstddef> 7 #include <cstddef>
8 8
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 size_t frame_size = frame.size(); 262 size_t frame_size = frame.size();
263 if (framer.ProcessInput(frame.data(), frame_size) != frame_size) { 263 if (framer.ProcessInput(frame.data(), frame_size) != frame_size) {
264 return false; 264 return false;
265 } 265 }
266 *priority = priority_getter.priority(); 266 *priority = priority_getter.priority();
267 return true; 267 return true;
268 } 268 }
269 269
270 base::WeakPtr<SpdyStream> CreateStreamSynchronously( 270 base::WeakPtr<SpdyStream> CreateStreamSynchronously(
271 SpdyStreamType type, 271 SpdyStreamType type,
272 const scoped_refptr<SpdySession>& session, 272 const base::WeakPtr<SpdySession>& session,
273 const GURL& url, 273 const GURL& url,
274 RequestPriority priority, 274 RequestPriority priority,
275 const BoundNetLog& net_log) { 275 const BoundNetLog& net_log) {
276 SpdyStreamRequest stream_request; 276 SpdyStreamRequest stream_request;
277 int rv = stream_request.StartRequest(type, session, url, priority, net_log, 277 int rv = stream_request.StartRequest(type, session, url, priority, net_log,
278 CompletionCallback()); 278 CompletionCallback());
279 return 279 return
280 (rv == OK) ? stream_request.ReleaseStream() : base::WeakPtr<SpdyStream>(); 280 (rv == OK) ? stream_request.ReleaseStream() : base::WeakPtr<SpdyStream>();
281 } 281 }
282 282
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 482
483 SpdyURLRequestContext::~SpdyURLRequestContext() { 483 SpdyURLRequestContext::~SpdyURLRequestContext() {
484 } 484 }
485 485
486 bool HasSpdySession(SpdySessionPool* pool, const SpdySessionKey& key) { 486 bool HasSpdySession(SpdySessionPool* pool, const SpdySessionKey& key) {
487 return pool->FindAvailableSession(key, BoundNetLog()) != NULL; 487 return pool->FindAvailableSession(key, BoundNetLog()) != NULL;
488 } 488 }
489 489
490 namespace { 490 namespace {
491 491
492 scoped_refptr<SpdySession> CreateSpdySessionHelper( 492 base::WeakPtr<SpdySession> CreateSpdySessionHelper(
493 const scoped_refptr<HttpNetworkSession>& http_session, 493 const scoped_refptr<HttpNetworkSession>& http_session,
494 const SpdySessionKey& key, 494 const SpdySessionKey& key,
495 const BoundNetLog& net_log, 495 const BoundNetLog& net_log,
496 Error expected_status, 496 Error expected_status,
497 bool is_secure) { 497 bool is_secure) {
498 EXPECT_FALSE(HasSpdySession(http_session->spdy_session_pool(), key)); 498 EXPECT_FALSE(HasSpdySession(http_session->spdy_session_pool(), key));
499 499
500 scoped_refptr<TransportSocketParams> transport_params( 500 scoped_refptr<TransportSocketParams> transport_params(
501 new TransportSocketParams( 501 new TransportSocketParams(
502 key.host_port_pair(), MEDIUM, false, false, 502 key.host_port_pair(), MEDIUM, false, false,
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 http_session->GetTransportSocketPool( 536 http_session->GetTransportSocketPool(
537 HttpNetworkSession::NORMAL_SOCKET_POOL), 537 HttpNetworkSession::NORMAL_SOCKET_POOL),
538 net_log); 538 net_log);
539 } 539 }
540 540
541 if (rv == ERR_IO_PENDING) 541 if (rv == ERR_IO_PENDING)
542 rv = callback.WaitForResult(); 542 rv = callback.WaitForResult();
543 543
544 EXPECT_EQ(OK, rv); 544 EXPECT_EQ(OK, rv);
545 545
546 scoped_refptr<SpdySession> spdy_session; 546 base::WeakPtr<SpdySession> spdy_session;
547 EXPECT_EQ( 547 EXPECT_EQ(
548 expected_status, 548 expected_status,
549 http_session->spdy_session_pool()->CreateAvailableSessionFromSocket( 549 http_session->spdy_session_pool()->CreateAvailableSessionFromSocket(
550 key, connection.Pass(), net_log, OK, &spdy_session, 550 key, connection.Pass(), net_log, OK, &spdy_session,
551 is_secure)); 551 is_secure));
552 EXPECT_EQ(expected_status == OK, spdy_session != NULL); 552 EXPECT_EQ(expected_status == OK, spdy_session != NULL);
553 EXPECT_EQ(expected_status == OK, 553 EXPECT_EQ(expected_status == OK,
554 HasSpdySession(http_session->spdy_session_pool(), key)); 554 HasSpdySession(http_session->spdy_session_pool(), key));
555 return spdy_session; 555 return spdy_session;
556 } 556 }
557 557
558 } // namespace 558 } // namespace
559 559
560 scoped_refptr<SpdySession> CreateInsecureSpdySession( 560 base::WeakPtr<SpdySession> CreateInsecureSpdySession(
561 const scoped_refptr<HttpNetworkSession>& http_session, 561 const scoped_refptr<HttpNetworkSession>& http_session,
562 const SpdySessionKey& key, 562 const SpdySessionKey& key,
563 const BoundNetLog& net_log) { 563 const BoundNetLog& net_log) {
564 return CreateSpdySessionHelper(http_session, key, net_log, 564 return CreateSpdySessionHelper(http_session, key, net_log,
565 OK, false /* is_secure */); 565 OK, false /* is_secure */);
566 } 566 }
567 567
568 void TryCreateInsecureSpdySessionExpectingFailure( 568 void TryCreateInsecureSpdySessionExpectingFailure(
569 const scoped_refptr<HttpNetworkSession>& http_session, 569 const scoped_refptr<HttpNetworkSession>& http_session,
570 const SpdySessionKey& key, 570 const SpdySessionKey& key,
571 Error expected_error, 571 Error expected_error,
572 const BoundNetLog& net_log) { 572 const BoundNetLog& net_log) {
573 DCHECK_LT(expected_error, ERR_IO_PENDING); 573 DCHECK_LT(expected_error, ERR_IO_PENDING);
574 CreateSpdySessionHelper(http_session, key, net_log, 574 CreateSpdySessionHelper(http_session, key, net_log,
575 expected_error, false /* is_secure */); 575 expected_error, false /* is_secure */);
576 } 576 }
577 577
578 scoped_refptr<SpdySession> CreateSecureSpdySession( 578 base::WeakPtr<SpdySession> CreateSecureSpdySession(
579 const scoped_refptr<HttpNetworkSession>& http_session, 579 const scoped_refptr<HttpNetworkSession>& http_session,
580 const SpdySessionKey& key, 580 const SpdySessionKey& key,
581 const BoundNetLog& net_log) { 581 const BoundNetLog& net_log) {
582 return CreateSpdySessionHelper(http_session, key, net_log, 582 return CreateSpdySessionHelper(http_session, key, net_log,
583 OK, true /* is_secure */); 583 OK, true /* is_secure */);
584 } 584 }
585 585
586 namespace { 586 namespace {
587 587
588 // A ClientSocket used for CreateFakeSpdySession() below. 588 // A ClientSocket used for CreateFakeSpdySession() below.
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
633 633
634 virtual bool GetSSLInfo(SSLInfo* ssl_info) OVERRIDE { 634 virtual bool GetSSLInfo(SSLInfo* ssl_info) OVERRIDE {
635 ADD_FAILURE(); 635 ADD_FAILURE();
636 return false; 636 return false;
637 } 637 }
638 638
639 private: 639 private:
640 int read_result_; 640 int read_result_;
641 }; 641 };
642 642
643 scoped_refptr<SpdySession> CreateFakeSpdySessionHelper( 643 base::WeakPtr<SpdySession> CreateFakeSpdySessionHelper(
644 SpdySessionPool* pool, 644 SpdySessionPool* pool,
645 const SpdySessionKey& key, 645 const SpdySessionKey& key,
646 Error expected_status) { 646 Error expected_status) {
647 EXPECT_NE(expected_status, ERR_IO_PENDING); 647 EXPECT_NE(expected_status, ERR_IO_PENDING);
648 EXPECT_FALSE(HasSpdySession(pool, key)); 648 EXPECT_FALSE(HasSpdySession(pool, key));
649 scoped_refptr<SpdySession> spdy_session; 649 base::WeakPtr<SpdySession> spdy_session;
650 scoped_ptr<ClientSocketHandle> handle(new ClientSocketHandle()); 650 scoped_ptr<ClientSocketHandle> handle(new ClientSocketHandle());
651 handle->set_socket(new FakeSpdySessionClientSocket( 651 handle->set_socket(new FakeSpdySessionClientSocket(
652 expected_status == OK ? ERR_IO_PENDING : expected_status)); 652 expected_status == OK ? ERR_IO_PENDING : expected_status));
653 EXPECT_EQ( 653 EXPECT_EQ(
654 expected_status, 654 expected_status,
655 pool->CreateAvailableSessionFromSocket( 655 pool->CreateAvailableSessionFromSocket(
656 key, handle.Pass(), BoundNetLog(), OK, &spdy_session, 656 key, handle.Pass(), BoundNetLog(), OK, &spdy_session,
657 true /* is_secure */)); 657 true /* is_secure */));
658 EXPECT_EQ(expected_status == OK, spdy_session != NULL); 658 EXPECT_EQ(expected_status == OK, spdy_session != NULL);
659 EXPECT_EQ(expected_status == OK, HasSpdySession(pool, key)); 659 EXPECT_EQ(expected_status == OK, HasSpdySession(pool, key));
660 return spdy_session; 660 return spdy_session;
661 } 661 }
662 662
663 } // namespace 663 } // namespace
664 664
665 scoped_refptr<SpdySession> CreateFakeSpdySession(SpdySessionPool* pool, 665 base::WeakPtr<SpdySession> CreateFakeSpdySession(SpdySessionPool* pool,
666 const SpdySessionKey& key) { 666 const SpdySessionKey& key) {
667 return CreateFakeSpdySessionHelper(pool, key, OK); 667 return CreateFakeSpdySessionHelper(pool, key, OK);
668 } 668 }
669 669
670 void TryCreateFakeSpdySessionExpectingFailure(SpdySessionPool* pool, 670 void TryCreateFakeSpdySessionExpectingFailure(SpdySessionPool* pool,
671 const SpdySessionKey& key, 671 const SpdySessionKey& key,
672 Error expected_error) { 672 Error expected_error) {
673 DCHECK_LT(expected_error, ERR_IO_PENDING); 673 DCHECK_LT(expected_error, ERR_IO_PENDING);
674 CreateFakeSpdySessionHelper(pool, key, expected_error); 674 CreateFakeSpdySessionHelper(pool, key, expected_error);
675 } 675 }
(...skipping 603 matching lines...) Expand 10 before | Expand all | Expand 10 after
1279 (*headers)[GetSchemeKey()] = scheme.c_str(); 1279 (*headers)[GetSchemeKey()] = scheme.c_str();
1280 (*headers)[GetVersionKey()] = "HTTP/1.1"; 1280 (*headers)[GetVersionKey()] = "HTTP/1.1";
1281 if (content_length) { 1281 if (content_length) {
1282 std::string length_str = base::Int64ToString(*content_length); 1282 std::string length_str = base::Int64ToString(*content_length);
1283 (*headers)["content-length"] = length_str; 1283 (*headers)["content-length"] = length_str;
1284 } 1284 }
1285 return headers.Pass(); 1285 return headers.Pass();
1286 } 1286 }
1287 1287
1288 } // namespace net 1288 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/spdy_test_util_common.h ('k') | net/spdy/spdy_websocket_stream.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698