summaryrefslogtreecommitdiffstats
path: root/net
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
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')
-rw-r--r--net/base/host_resolver_impl.cc3
-rw-r--r--net/base/request_priority.h2
-rw-r--r--net/http/http_network_transaction.cc16
-rw-r--r--net/http/http_network_transaction.h2
-rw-r--r--net/socket/client_socket_pool_base_unittest.cc16
-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
-rw-r--r--net/url_request/url_request.h2
10 files changed, 111 insertions, 25 deletions
diff --git a/net/base/host_resolver_impl.cc b/net/base/host_resolver_impl.cc
index 8d5fe26..43889ac 100644
--- a/net/base/host_resolver_impl.cc
+++ b/net/base/host_resolver_impl.cc
@@ -560,7 +560,8 @@ class HostResolverImpl::IPv6ProbeJob
// and increasing for lower priorities.
COMPILE_ASSERT(HIGHEST == 0u &&
LOWEST > HIGHEST &&
- NUM_PRIORITIES > LOWEST,
+ IDLE > LOWEST &&
+ NUM_PRIORITIES > IDLE,
priority_indexes_incompatible);
// JobPool contains all the information relating to queued requests, including
diff --git a/net/base/request_priority.h b/net/base/request_priority.h
index 6d9b2a5..ca7a1ec 100644
--- a/net/base/request_priority.h
+++ b/net/base/request_priority.h
@@ -15,10 +15,10 @@ enum RequestPriority {
MEDIUM,
LOW,
LOWEST,
+ IDLE,
NUM_PRIORITIES,
};
} // namespace net
#endif // NET_BASE_REQUEST_PRIORITY_H__
-
diff --git a/net/http/http_network_transaction.cc b/net/http/http_network_transaction.cc
index e553ec4..ee98cca 100644
--- a/net/http/http_network_transaction.cc
+++ b/net/http/http_network_transaction.cc
@@ -1882,6 +1882,22 @@ std::string HttpNetworkTransaction::DescribeState(State state) {
return description;
}
+// TODO(gavinp): re-adjust this once SPDY v3 has three priority bits,
+// eliminating the need for this folding.
+int ConvertRequestPriorityToSpdyPriority(const RequestPriority priority) {
+ DCHECK(HIGHEST <= priority && priority < NUM_PRIORITIES);
+ switch (priority) {
+ case LOWEST:
+ return SPDY_PRIORITY_LOWEST-1;
+ case IDLE:
+ return SPDY_PRIORITY_LOWEST;
+ default:
+ return priority;
+ }
+}
+
+
+
#undef STATE_CASE
} // namespace net
diff --git a/net/http/http_network_transaction.h b/net/http/http_network_transaction.h
index 695d7b9..b3a083c 100644
--- a/net/http/http_network_transaction.h
+++ b/net/http/http_network_transaction.h
@@ -340,6 +340,8 @@ class HttpNetworkTransaction : public HttpTransaction {
DISALLOW_COPY_AND_ASSIGN(HttpNetworkTransaction);
};
+int ConvertRequestPriorityToSpdyPriority(RequestPriority priority);
+
} // namespace net
#endif // NET_HTTP_HTTP_NETWORK_TRANSACTION_H_
diff --git a/net/socket/client_socket_pool_base_unittest.cc b/net/socket/client_socket_pool_base_unittest.cc
index 55f1949..bc3669d 100644
--- a/net/socket/client_socket_pool_base_unittest.cc
+++ b/net/socket/client_socket_pool_base_unittest.cc
@@ -749,7 +749,7 @@ TEST_F(ClientSocketPoolBaseTest, TotalLimitRespectsPriority) {
EXPECT_EQ(5, GetOrderOfRequest(7));
// Make sure we test order of all requests made.
- EXPECT_EQ(kIndexOutOfBounds, GetOrderOfRequest(8));
+ EXPECT_EQ(kIndexOutOfBounds, GetOrderOfRequest(9));
}
TEST_F(ClientSocketPoolBaseTest, TotalLimitRespectsGroupLimit) {
@@ -1026,6 +1026,7 @@ TEST_F(ClientSocketPoolBaseTest, PendingRequests) {
EXPECT_EQ(OK, StartRequest("a", kDefaultPriority));
EXPECT_EQ(OK, StartRequest("a", kDefaultPriority));
+ EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", IDLE));
EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", LOWEST));
EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", MEDIUM));
EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", HIGHEST));
@@ -1040,14 +1041,15 @@ TEST_F(ClientSocketPoolBaseTest, PendingRequests) {
EXPECT_EQ(1, GetOrderOfRequest(1));
EXPECT_EQ(2, GetOrderOfRequest(2));
- EXPECT_EQ(6, GetOrderOfRequest(3));
- EXPECT_EQ(4, GetOrderOfRequest(4));
- EXPECT_EQ(3, GetOrderOfRequest(5));
- EXPECT_EQ(5, GetOrderOfRequest(6));
- EXPECT_EQ(7, GetOrderOfRequest(7));
+ EXPECT_EQ(8, GetOrderOfRequest(3));
+ EXPECT_EQ(6, GetOrderOfRequest(4));
+ EXPECT_EQ(4, GetOrderOfRequest(5));
+ EXPECT_EQ(3, GetOrderOfRequest(6));
+ EXPECT_EQ(5, GetOrderOfRequest(7));
+ EXPECT_EQ(7, GetOrderOfRequest(8));
// Make sure we test order of all requests made.
- EXPECT_EQ(kIndexOutOfBounds, GetOrderOfRequest(8));
+ EXPECT_EQ(kIndexOutOfBounds, GetOrderOfRequest(9));
}
TEST_F(ClientSocketPoolBaseTest, PendingRequests_NoKeepAlive) {
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
diff --git a/net/url_request/url_request.h b/net/url_request/url_request.h
index a6ef386..06b1048 100644
--- a/net/url_request/url_request.h
+++ b/net/url_request/url_request.h
@@ -545,7 +545,7 @@ class URLRequest : public NonThreadSafe {
net::RequestPriority priority() const { return priority_; }
void set_priority(net::RequestPriority priority) {
DCHECK_GE(priority, net::HIGHEST);
- DCHECK_LE(priority, net::LOWEST);
+ DCHECK_LT(priority, net::NUM_PRIORITIES);
priority_ = priority;
}