summaryrefslogtreecommitdiffstats
path: root/net/spdy
diff options
context:
space:
mode:
authorgavinp@google.com <gavinp@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-31 01:30:03 +0000
committergavinp@google.com <gavinp@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-31 01:30:03 +0000
commitc9c6f5cbd15124457b0fe77f03fda9e4c4855f48 (patch)
treec23bd4ba9fbe29cfd872bc38f4f3b808c39fd949 /net/spdy
parent8dd21c4de17c8011703f3ac5a6e155b6325f65a2 (diff)
downloadchromium_src-c9c6f5cbd15124457b0fe77f03fda9e4c4855f48.zip
chromium_src-c9c6f5cbd15124457b0fe77f03fda9e4c4855f48.tar.gz
chromium_src-c9c6f5cbd15124457b0fe77f03fda9e4c4855f48.tar.bz2
Implement prefetching in chrome
With this CL (see also issue 2910009), chrome will support basic prefetching. You can optionally deactivate prefetching with the command line argument --disable-prefetch. A new RequestPriority was created as well, IDLE, which is lower than LOWEST. Unfortunately, SPDY has only two bits for priority, so as a temporary measure (pending SPDY v3 which will have three), we have a mapping in SPDY that folds net::LOWEST and net::IDLE together. BUG=13505 TEST=http://gemal.dk/browserspy/prefetch.php Review URL: http://codereview.chromium.org/3050016 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@54421 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/spdy')
-rw-r--r--net/spdy/spdy_network_transaction_unittest.cc65
-rw-r--r--net/spdy/spdy_session.cc11
-rw-r--r--net/spdy/spdy_stream_unittest.cc2
-rw-r--r--net/spdy/spdy_test_util.cc17
4 files changed, 80 insertions, 15 deletions
diff --git a/net/spdy/spdy_network_transaction_unittest.cc b/net/spdy/spdy_network_transaction_unittest.cc
index 66feee0..f29d69f 100644
--- a/net/spdy/spdy_network_transaction_unittest.cc
+++ b/net/spdy/spdy_network_transaction_unittest.cc
@@ -289,6 +289,59 @@ TEST_P(SpdyNetworkTransactionTest, Get) {
EXPECT_EQ("hello!", out.response_data);
}
+TEST_P(SpdyNetworkTransactionTest, GetAtEachPriority) {
+ for (RequestPriority p = HIGHEST; p < NUM_PRIORITIES;
+ p = RequestPriority(p+1)) {
+ // Construct the request.
+ scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyGet(NULL, 0, false, 1, p));
+ MockWrite writes[] = { CreateMockWrite(*req) };
+
+ const int spdy_prio = reinterpret_cast<spdy::SpdySynStreamControlFrame*>(
+ req.get())->priority();
+ // this repeats the RequestPriority-->SpdyPriority mapping from
+ // SpdyFramer::ConvertRequestPriorityToSpdyPriority to make
+ // sure it's being done right.
+ switch(p) {
+ case HIGHEST:
+ EXPECT_EQ(0, spdy_prio);
+ break;
+ case MEDIUM:
+ EXPECT_EQ(1, spdy_prio);
+ break;
+ case LOW:
+ case LOWEST:
+ EXPECT_EQ(2, spdy_prio);
+ break;
+ case IDLE:
+ EXPECT_EQ(3, spdy_prio);
+ break;
+ default:
+ FAIL();
+ }
+
+ scoped_ptr<spdy::SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0, 1));
+ scoped_ptr<spdy::SpdyFrame> body(ConstructSpdyBodyFrame(1, true));
+ MockRead reads[] = {
+ CreateMockRead(*resp),
+ CreateMockRead(*body),
+ MockRead(true, 0, 0) // EOF
+ };
+
+ scoped_refptr<DelayedSocketData> data(
+ new DelayedSocketData(1, reads, arraysize(reads),
+ writes, arraysize(writes)));
+ HttpRequestInfo http_req = CreateGetRequest();
+ http_req.priority = p;
+
+ NormalSpdyTransactionHelper helper(http_req, BoundNetLog(), GetParam());
+ helper.RunToCompletion(data.get());
+ TransactionHelperResult out = helper.output();
+ EXPECT_EQ(OK, out.rv);
+ EXPECT_EQ("HTTP/1.1 200 OK", out.status_line);
+ EXPECT_EQ("hello!", out.response_data);
+ }
+}
+
// Start three gets simultaniously; making sure that multiplexed
// streams work properly.
@@ -1482,7 +1535,8 @@ TEST_P(SpdyNetworkTransactionTest, SynReplyHeadersVary) {
spdy::SYN_REPLY, // Syn Reply
1, // Stream ID
0, // Associated Stream ID
- SPDY_PRIORITY_LOWEST, // Priority
+ net::ConvertRequestPriorityToSpdyPriority(LOWEST),
+ // Priority
spdy::CONTROL_FLAG_NONE, // Control Flags
false, // Compressed
spdy::INVALID, // Status
@@ -1650,7 +1704,8 @@ TEST_P(SpdyNetworkTransactionTest, InvalidSynReply) {
spdy::SYN_REPLY, // Kind = SynReply
1, // Stream ID
0, // Associated stream ID
- SPDY_PRIORITY_LOWEST, // Priority
+ net::ConvertRequestPriorityToSpdyPriority(LOWEST),
+ // Priority
spdy::CONTROL_FLAG_NONE, // Control Flags
false, // Compressed
spdy::INVALID, // Status
@@ -2411,7 +2466,8 @@ TEST_P(SpdyNetworkTransactionTest, SettingsSaved) {
spdy::SYN_REPLY, // Syn Reply
1, // Stream ID
0, // Associated Stream ID
- SPDY_PRIORITY_LOWEST, // Priority
+ net::ConvertRequestPriorityToSpdyPriority(LOWEST),
+ // Priority
spdy::CONTROL_FLAG_NONE, // Control Flags
false, // Compressed
spdy::INVALID, // Status
@@ -2515,7 +2571,8 @@ TEST_P(SpdyNetworkTransactionTest, SettingsPlayback) {
spdy::SYN_REPLY, // Syn Reply
1, // Stream ID
0, // Associated Stream ID
- SPDY_PRIORITY_LOWEST, // Priority
+ net::ConvertRequestPriorityToSpdyPriority(LOWEST),
+ // Priority
spdy::CONTROL_FLAG_NONE, // Control Flags
false, // Compressed
spdy::INVALID, // Status
diff --git a/net/spdy/spdy_session.cc b/net/spdy/spdy_session.cc
index 9f2b82f..7ff500a 100644
--- a/net/spdy/spdy_session.cc
+++ b/net/spdy/spdy_session.cc
@@ -226,7 +226,7 @@ net::Error SpdySession::Connect(
const std::string& group_name,
const scoped_refptr<TCPSocketParams>& destination,
RequestPriority priority) {
- DCHECK(priority >= SPDY_PRIORITY_HIGHEST && priority <= SPDY_PRIORITY_LOWEST);
+ DCHECK(priority >= net::HIGHEST && priority < net::NUM_PRIORITIES);
// If the connect process is started, let the caller continue.
if (state_ > IDLE)
@@ -385,8 +385,7 @@ int SpdySession::CreateStreamImpl(
LOG(INFO) << "SpdyStream: Creating stream " << stream_id << " for " << url;
// TODO(mbelshe): Optimize memory allocations
- DCHECK(priority >= SPDY_PRIORITY_HIGHEST &&
- priority <= SPDY_PRIORITY_LOWEST);
+ DCHECK(priority >= net::HIGHEST && priority < net::NUM_PRIORITIES);
DCHECK_EQ(active_streams_[stream_id].get(), stream.get());
return OK;
@@ -404,8 +403,10 @@ int SpdySession::WriteSynStream(
CHECK_EQ(stream->stream_id(), stream_id);
scoped_ptr<spdy::SpdySynStreamControlFrame> syn_frame(
- spdy_framer_.CreateSynStream(stream_id, 0, priority, flags, false,
- headers.get()));
+ spdy_framer_.CreateSynStream(
+ stream_id, 0,
+ ConvertRequestPriorityToSpdyPriority(priority),
+ flags, false, headers.get()));
QueueFrame(syn_frame.get(), priority, stream);
static StatsCounter spdy_requests("spdy.requests");
diff --git a/net/spdy/spdy_stream_unittest.cc b/net/spdy/spdy_stream_unittest.cc
index 4daad96..471a1786 100644
--- a/net/spdy/spdy_stream_unittest.cc
+++ b/net/spdy/spdy_stream_unittest.cc
@@ -141,7 +141,7 @@ TEST_F(SpdyStreamTest, SendDataAfterOpen) {
spdy::SYN_STREAM,
1,
0,
- SPDY_PRIORITY_LOWEST,
+ net::ConvertRequestPriorityToSpdyPriority(LOWEST),
spdy::CONTROL_FLAG_NONE,
false,
spdy::INVALID,
diff --git a/net/spdy/spdy_test_util.cc b/net/spdy/spdy_test_util.cc
index 5d65b4a..2b75b0c 100644
--- a/net/spdy/spdy_test_util.cc
+++ b/net/spdy/spdy_test_util.cc
@@ -8,6 +8,8 @@
#include "base/basictypes.h"
#include "base/string_util.h"
+#include "net/http/http_network_transaction.h"
+#include "net/spdy/spdy_framer.h"
namespace net {
@@ -261,7 +263,8 @@ spdy::SpdyFrame* ConstructSpdyGet(const char* const url,
spdy::SYN_STREAM, // Kind = Syn
stream_id, // Stream ID
0, // Associated stream ID
- request_priority, // Priority
+ net::ConvertRequestPriorityToSpdyPriority(request_priority),
+ // Priority
spdy::CONTROL_FLAG_FIN, // Control Flags
compressed, // Compressed
spdy::INVALID, // Status
@@ -319,7 +322,8 @@ spdy::SpdyFrame* ConstructSpdyGet(const char* const extra_headers[],
spdy::SYN_STREAM, // Kind = Syn
stream_id, // Stream ID
0, // Associated stream ID
- request_priority, // Priority
+ net::ConvertRequestPriorityToSpdyPriority(request_priority),
+ // Priority
spdy::CONTROL_FLAG_FIN, // Control Flags
compressed, // Compressed
spdy::INVALID, // Status
@@ -358,7 +362,8 @@ spdy::SpdyFrame* ConstructSpdyGetSynReply(const char* const extra_headers[],
spdy::SYN_REPLY, // Kind = SynReply
stream_id, // Stream ID
0, // Associated stream ID
- SPDY_PRIORITY_LOWEST, // Priority
+ net::ConvertRequestPriorityToSpdyPriority(LOWEST),
+ // Priority
spdy::CONTROL_FLAG_NONE, // Control Flags
false, // Compressed
spdy::INVALID, // Status
@@ -396,7 +401,8 @@ spdy::SpdyFrame* ConstructSpdyPost(int64 content_length,
spdy::SYN_STREAM, // Kind = Syn
1, // Stream ID
0, // Associated stream ID
- SPDY_PRIORITY_LOWEST, // Priority
+ net::ConvertRequestPriorityToSpdyPriority(LOWEST),
+ // Priority
spdy::CONTROL_FLAG_NONE, // Control Flags
false, // Compressed
spdy::INVALID, // Status
@@ -437,7 +443,8 @@ spdy::SpdyFrame* ConstructSpdyPostSynReply(const char* const extra_headers[],
spdy::SYN_REPLY, // Kind = SynReply
1, // Stream ID
0, // Associated stream ID
- SPDY_PRIORITY_LOWEST, // Priority
+ net::ConvertRequestPriorityToSpdyPriority(LOWEST),
+ // Priority
spdy::CONTROL_FLAG_NONE, // Control Flags
false, // Compressed
spdy::INVALID, // Status