| 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/spdy/spdy_session.h" | 5 #include "net/spdy/spdy_session.h" |
| 6 | 6 |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
| 9 #include "net/base/io_buffer.h" | 9 #include "net/base/io_buffer.h" |
| 10 #include "net/base/ip_endpoint.h" | 10 #include "net/base/ip_endpoint.h" |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 | 329 |
| 330 // Give the session a SPDY2 framer. | 330 // Give the session a SPDY2 framer. |
| 331 session->buffered_spdy_framer_.reset(new BufferedSpdyFramer(SPDY2, false)); | 331 session->buffered_spdy_framer_.reset(new BufferedSpdyFramer(SPDY2, false)); |
| 332 | 332 |
| 333 // Create the associated stream and add to active streams. | 333 // Create the associated stream and add to active streams. |
| 334 scoped_ptr<SpdyHeaderBlock> request_headers(new SpdyHeaderBlock); | 334 scoped_ptr<SpdyHeaderBlock> request_headers(new SpdyHeaderBlock); |
| 335 (*request_headers)["scheme"] = "http"; | 335 (*request_headers)["scheme"] = "http"; |
| 336 (*request_headers)["host"] = "www.google.com"; | 336 (*request_headers)["host"] = "www.google.com"; |
| 337 (*request_headers)["url"] = "/"; | 337 (*request_headers)["url"] = "/"; |
| 338 | 338 |
| 339 scoped_ptr<SpdyStream> stream( | 339 scoped_ptr<SpdyStream> stream(new SpdyStream(SPDY_REQUEST_RESPONSE_STREAM, |
| 340 new SpdyStream(SPDY_REQUEST_RESPONSE_STREAM, | 340 session.get(), |
| 341 session, std::string(), DEFAULT_PRIORITY, | 341 std::string(), |
| 342 kSpdyStreamInitialWindowSize, | 342 DEFAULT_PRIORITY, |
| 343 kSpdyStreamInitialWindowSize, | 343 kSpdyStreamInitialWindowSize, |
| 344 session->net_log_)); | 344 kSpdyStreamInitialWindowSize, |
| 345 session->net_log_)); |
| 345 stream->SendRequestHeaders(request_headers.Pass(), NO_MORE_DATA_TO_SEND); | 346 stream->SendRequestHeaders(request_headers.Pass(), NO_MORE_DATA_TO_SEND); |
| 346 SpdyStream* stream_ptr = stream.get(); | 347 SpdyStream* stream_ptr = stream.get(); |
| 347 session->InsertCreatedStream(stream.Pass()); | 348 session->InsertCreatedStream(stream.Pass()); |
| 348 stream = session->ActivateCreatedStream(stream_ptr); | 349 stream = session->ActivateCreatedStream(stream_ptr); |
| 349 session->InsertActivatedStream(stream.Pass()); | 350 session->InsertActivatedStream(stream.Pass()); |
| 350 | 351 |
| 351 SpdyHeaderBlock headers; | 352 SpdyHeaderBlock headers; |
| 352 headers["url"] = "http://www.google.com/a.dat"; | 353 headers["url"] = "http://www.google.com/a.dat"; |
| 353 session->OnSynStream(2, 1, 0, 0, true, false, headers); | 354 session->OnSynStream(2, 1, 0, 0, true, false, headers); |
| 354 | 355 |
| (...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 922 HostPortPair test_host_port_pair(test_hosts[0].name, kTestPort); | 923 HostPortPair test_host_port_pair(test_hosts[0].name, kTestPort); |
| 923 | 924 |
| 924 // Initialize session for the first host. | 925 // Initialize session for the first host. |
| 925 scoped_refptr<TransportSocketParams> transport_params( | 926 scoped_refptr<TransportSocketParams> transport_params( |
| 926 new TransportSocketParams(test_host_port_pair, | 927 new TransportSocketParams(test_host_port_pair, |
| 927 MEDIUM, | 928 MEDIUM, |
| 928 false, | 929 false, |
| 929 false, | 930 false, |
| 930 OnHostResolutionCallback())); | 931 OnHostResolutionCallback())); |
| 931 IPPoolingInitializedSession(test_host_port_pair.ToString(), | 932 IPPoolingInitializedSession(test_host_port_pair.ToString(), |
| 932 transport_params, http_session, session); | 933 transport_params, |
| 934 http_session.get(), |
| 935 session.get()); |
| 933 | 936 |
| 934 // TODO(rtenneti): MockClientSocket::GetPeerAddress return's 0 as the port | 937 // TODO(rtenneti): MockClientSocket::GetPeerAddress return's 0 as the port |
| 935 // number. Fix it to return port 80 and then use GetPeerAddress to AddAlias. | 938 // number. Fix it to return port 80 and then use GetPeerAddress to AddAlias. |
| 936 SpdySessionPoolPeer pool_peer(spdy_session_pool); | 939 SpdySessionPoolPeer pool_peer(spdy_session_pool); |
| 937 pool_peer.AddAlias(test_hosts[0].addresses.front(), test_hosts[0].key); | 940 pool_peer.AddAlias(test_hosts[0].addresses.front(), test_hosts[0].key); |
| 938 | 941 |
| 939 // Flush the SpdySession::OnReadComplete() task. | 942 // Flush the SpdySession::OnReadComplete() task. |
| 940 base::MessageLoop::current()->RunUntilIdle(); | 943 base::MessageLoop::current()->RunUntilIdle(); |
| 941 | 944 |
| 942 // The third host has no overlap with the first, so it can't pool IPs. | 945 // The third host has no overlap with the first, so it can't pool IPs. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 959 spdy_session_pool->Get(test_hosts[2].key, BoundNetLog()); | 962 spdy_session_pool->Get(test_hosts[2].key, BoundNetLog()); |
| 960 | 963 |
| 961 // Verify that we have sessions for everything. | 964 // Verify that we have sessions for everything. |
| 962 EXPECT_TRUE(spdy_session_pool->HasSession(test_hosts[0].key)); | 965 EXPECT_TRUE(spdy_session_pool->HasSession(test_hosts[0].key)); |
| 963 EXPECT_TRUE(spdy_session_pool->HasSession(test_hosts[1].key)); | 966 EXPECT_TRUE(spdy_session_pool->HasSession(test_hosts[1].key)); |
| 964 EXPECT_TRUE(spdy_session_pool->HasSession(test_hosts[2].key)); | 967 EXPECT_TRUE(spdy_session_pool->HasSession(test_hosts[2].key)); |
| 965 | 968 |
| 966 // Initialize session for host 2. | 969 // Initialize session for host 2. |
| 967 session_deps.socket_factory->AddSocketDataProvider(&data); | 970 session_deps.socket_factory->AddSocketDataProvider(&data); |
| 968 IPPoolingInitializedSession(test_hosts[2].key.host_port_pair().ToString(), | 971 IPPoolingInitializedSession(test_hosts[2].key.host_port_pair().ToString(), |
| 969 transport_params, http_session, session2); | 972 transport_params, |
| 973 http_session.get(), |
| 974 session2.get()); |
| 970 | 975 |
| 971 // Grab the session to host 1 and verify that it is the same session | 976 // Grab the session to host 1 and verify that it is the same session |
| 972 // we got with host 0, and that is a different than host 2's session. | 977 // we got with host 0, and that is a different than host 2's session. |
| 973 scoped_refptr<SpdySession> session1 = | 978 scoped_refptr<SpdySession> session1 = |
| 974 spdy_session_pool->Get(test_hosts[1].key, BoundNetLog()); | 979 spdy_session_pool->Get(test_hosts[1].key, BoundNetLog()); |
| 975 EXPECT_EQ(session.get(), session1.get()); | 980 EXPECT_EQ(session.get(), session1.get()); |
| 976 EXPECT_NE(session2.get(), session1.get()); | 981 EXPECT_NE(session2.get(), session1.get()); |
| 977 | 982 |
| 978 // Initialize session for host 1. | 983 // Initialize session for host 1. |
| 979 session_deps.socket_factory->AddSocketDataProvider(&data); | 984 session_deps.socket_factory->AddSocketDataProvider(&data); |
| 980 IPPoolingInitializedSession(test_hosts[2].key.host_port_pair().ToString(), | 985 IPPoolingInitializedSession(test_hosts[2].key.host_port_pair().ToString(), |
| 981 transport_params, http_session, session2); | 986 transport_params, |
| 987 http_session.get(), |
| 988 session2.get()); |
| 982 | 989 |
| 983 // Remove the aliases and observe that we still have a session for host1. | 990 // Remove the aliases and observe that we still have a session for host1. |
| 984 pool_peer.RemoveAliases(test_hosts[0].key); | 991 pool_peer.RemoveAliases(test_hosts[0].key); |
| 985 pool_peer.RemoveAliases(test_hosts[1].key); | 992 pool_peer.RemoveAliases(test_hosts[1].key); |
| 986 EXPECT_TRUE(spdy_session_pool->HasSession(test_hosts[1].key)); | 993 EXPECT_TRUE(spdy_session_pool->HasSession(test_hosts[1].key)); |
| 987 | 994 |
| 988 // Expire the host cache | 995 // Expire the host cache |
| 989 session_deps.host_resolver->GetHostCache()->clear(); | 996 session_deps.host_resolver->GetHostCache()->clear(); |
| 990 EXPECT_TRUE(spdy_session_pool->HasSession(test_hosts[1].key)); | 997 EXPECT_TRUE(spdy_session_pool->HasSession(test_hosts[1].key)); |
| 991 | 998 |
| (...skipping 1490 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2482 // Cancelling the request should still not release the session's socket, | 2489 // Cancelling the request should still not release the session's socket, |
| 2483 // since the session is still kept alive by the SpdySessionPool. | 2490 // since the session is still kept alive by the SpdySessionPool. |
| 2484 ASSERT_TRUE(spdy_stream1.get()); | 2491 ASSERT_TRUE(spdy_stream1.get()); |
| 2485 spdy_stream1->Cancel(); | 2492 spdy_stream1->Cancel(); |
| 2486 base::RunLoop().RunUntilIdle(); | 2493 base::RunLoop().RunUntilIdle(); |
| 2487 EXPECT_TRUE(pool->IsStalled()); | 2494 EXPECT_TRUE(pool->IsStalled()); |
| 2488 EXPECT_FALSE(callback2.have_result()); | 2495 EXPECT_FALSE(callback2.have_result()); |
| 2489 } | 2496 } |
| 2490 | 2497 |
| 2491 } // namespace net | 2498 } // namespace net |
| OLD | NEW |