diff options
-rw-r--r-- | chrome/browser/renderer_host/resource_dispatcher_host.cc | 17 | ||||
-rw-r--r-- | net/base/request_priority.h | 22 | ||||
-rw-r--r-- | net/flip/flip_session.cc | 26 | ||||
-rw-r--r-- | net/flip/flip_session.h | 4 | ||||
-rw-r--r-- | net/http/http_network_transaction_unittest.cc | 3 | ||||
-rw-r--r-- | net/http/http_request_info.h | 5 | ||||
-rw-r--r-- | net/socket/client_socket_handle.h | 5 | ||||
-rw-r--r-- | net/socket/client_socket_pool.h | 3 | ||||
-rw-r--r-- | net/socket/client_socket_pool_base.cc | 4 | ||||
-rw-r--r-- | net/socket/client_socket_pool_base.h | 13 | ||||
-rw-r--r-- | net/socket/client_socket_pool_base_unittest.cc | 130 | ||||
-rw-r--r-- | net/socket/socket_test_util.h | 2 | ||||
-rw-r--r-- | net/socket/tcp_client_socket_pool.cc | 2 | ||||
-rw-r--r-- | net/socket/tcp_client_socket_pool.h | 2 | ||||
-rw-r--r-- | net/socket/tcp_client_socket_pool_unittest.cc | 82 | ||||
-rw-r--r-- | net/url_request/url_request.cc | 2 | ||||
-rw-r--r-- | net/url_request/url_request.h | 13 | ||||
-rw-r--r-- | webkit/glue/resource_type.h | 14 |
18 files changed, 195 insertions, 154 deletions
diff --git a/chrome/browser/renderer_host/resource_dispatcher_host.cc b/chrome/browser/renderer_host/resource_dispatcher_host.cc index 036d907..89d13bb 100644 --- a/chrome/browser/renderer_host/resource_dispatcher_host.cc +++ b/chrome/browser/renderer_host/resource_dispatcher_host.cc @@ -533,11 +533,20 @@ void ResourceDispatcherHost::BeginRequest( // If the request is for the top level page or a frame/iframe, then we // should prioritize it higher than other resource types. Currently, we // just use priorities 1 and 0. - if (request_data.resource_type == ResourceType::MAIN_FRAME || - request_data.resource_type == ResourceType::SUB_FRAME) { - request->set_priority(1); + if (ResourceType::IsFrame(request_data.resource_type)) { + request->set_priority(net::HIGHEST); } else { - request->set_priority(0); + switch (request_data.resource_type) { + case ResourceType::STYLESHEET: + case ResourceType::SCRIPT: + request->set_priority(net::MEDIUM); + break; + case ResourceType::IMAGE: + request->set_priority(net::LOWEST); + break; + default: + request->set_priority(net::LOW); + } } } diff --git a/net/base/request_priority.h b/net/base/request_priority.h new file mode 100644 index 0000000..b618ef2 --- /dev/null +++ b/net/base/request_priority.h @@ -0,0 +1,22 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef NET_BASE_REQUEST_PRIORITY_H__ +#define NET_BASE_REQUEST_PRIORITY_H__ + +namespace net { + +// Prioritization used in various parts of the networking code such +// as connection prioritization and resource loading prioritization. +enum RequestPriority { + HIGHEST = 0, // 0 must be the highest priority. + MEDIUM, + LOW, + LOWEST +}; + +} // namespace net + +#endif // NET_BASE_REQUEST_PRIORITY_H__ + diff --git a/net/flip/flip_session.cc b/net/flip/flip_session.cc index fc446f4..f501b58 100644 --- a/net/flip/flip_session.cc +++ b/net/flip/flip_session.cc @@ -210,8 +210,8 @@ FlipSession::~FlipSession() { net::Error FlipSession::Connect(const std::string& group_name, const HostResolver::RequestInfo& host, - int priority) { - DCHECK(priority >= FLIP_PRIORITY_HIGHEST && priority < FLIP_PRIORITY_LOWEST); + RequestPriority priority) { + DCHECK(priority >= FLIP_PRIORITY_HIGHEST && priority <= FLIP_PRIORITY_LOWEST); // If the connect process is started, let the caller continue. if (state_ > IDLE) @@ -271,22 +271,8 @@ scoped_refptr<FlipStream> FlipSession::GetOrCreateStream( LOG(INFO) << "FlipStream: Creating stream " << stream_id << " for " << url; // TODO(mbelshe): Optimize memory allocations - int priority = request.priority; - - // Hack for the priorities - // TODO(mbelshe): These need to be plumbed through the Http Network Stack. - if (path.find(".css") != path.npos) { - priority = 1; - } else if (path.find(".html") != path.npos) { - priority = 0; - } else if (path.find(".js") != path.npos) { - priority = 1; - } else { - priority = 3; - } - - DCHECK(priority >= FLIP_PRIORITY_HIGHEST && - priority <= FLIP_PRIORITY_LOWEST); + DCHECK(request.priority >= FLIP_PRIORITY_HIGHEST && + request.priority <= FLIP_PRIORITY_LOWEST); // Convert from HttpRequestHeaders to Flip Headers. flip::FlipHeaderBlock headers; @@ -298,12 +284,12 @@ scoped_refptr<FlipStream> FlipSession::GetOrCreateStream( // Create a SYN_STREAM packet and add to the output queue. scoped_ptr<flip::FlipSynStreamControlFrame> syn_frame( - flip_framer_.CreateSynStream(stream_id, priority, flags, false, + flip_framer_.CreateSynStream(stream_id, request.priority, flags, false, &headers)); int length = flip::FlipFrame::size() + syn_frame->length(); IOBuffer* buffer = new IOBuffer(length); memcpy(buffer->data(), syn_frame->data(), length); - queue_.push(FlipIOBuffer(buffer, length, priority, stream)); + queue_.push(FlipIOBuffer(buffer, length, request.priority, stream)); static StatsCounter flip_requests("flip.requests"); flip_requests.Increment(); diff --git a/net/flip/flip_session.h b/net/flip/flip_session.h index 545b902..a0be118 100644 --- a/net/flip/flip_session.h +++ b/net/flip/flip_session.h @@ -15,6 +15,7 @@ #include "net/base/io_buffer.h" #include "net/base/load_states.h" #include "net/base/net_errors.h" +#include "net/base/request_priority.h" #include "net/base/ssl_config_service.h" #include "net/base/upload_data_stream.h" #include "net/flip/flip_framer.h" @@ -43,7 +44,8 @@ class FlipSession : public base::RefCounted<FlipSession>, // Note that this call does not wait for the connect to complete. Callers can // immediately start using the FlipSession while it connects. net::Error Connect(const std::string& group_name, - const HostResolver::RequestInfo& host, int priority); + const HostResolver::RequestInfo& host, + RequestPriority priority); // Get a stream for a given |request|. In the typical case, this will involve // the creation of a new stream (and will send the SYN frame). If the server diff --git a/net/http/http_network_transaction_unittest.cc b/net/http/http_network_transaction_unittest.cc index a17e6e9..7d64bb1 100644 --- a/net/http/http_network_transaction_unittest.cc +++ b/net/http/http_network_transaction_unittest.cc @@ -7,6 +7,7 @@ #include "base/compiler_specific.h" #include "net/base/completion_callback.h" #include "net/base/mock_host_resolver.h" +#include "net/base/request_priority.h" #include "net/base/ssl_config_service_defaults.h" #include "net/base/ssl_info.h" #include "net/base/test_completion_callback.h" @@ -186,7 +187,7 @@ class CaptureGroupNameSocketPool : public TCPClientSocketPool { virtual int RequestSocket(const std::string& group_name, const void* socket_params, - int priority, + RequestPriority priority, ClientSocketHandle* handle, CompletionCallback* callback, LoadLog* load_log) { diff --git a/net/http/http_request_info.h b/net/http/http_request_info.h index 1382171..7ada539 100644 --- a/net/http/http_request_info.h +++ b/net/http/http_request_info.h @@ -8,13 +8,14 @@ #include <string> #include "base/ref_counted.h" #include "googleurl/src/gurl.h" +#include "net/base/request_priority.h" #include "net/base/upload_data.h" namespace net { class HttpRequestInfo { public: - HttpRequestInfo() : load_flags(0), priority(0) { + HttpRequestInfo() : load_flags(0), priority(LOWEST) { } // The requested URL. @@ -40,7 +41,7 @@ class HttpRequestInfo { int load_flags; // The priority level for this request. - int priority; + RequestPriority priority; }; } // namespace net diff --git a/net/socket/client_socket_handle.h b/net/socket/client_socket_handle.h index 25a2f35..bf7bf8a 100644 --- a/net/socket/client_socket_handle.h +++ b/net/socket/client_socket_handle.h @@ -14,6 +14,7 @@ #include "net/base/completion_callback.h" #include "net/base/load_states.h" #include "net/base/net_errors.h" +#include "net/base/request_priority.h" #include "net/socket/client_socket.h" #include "net/socket/client_socket_pool.h" @@ -59,7 +60,7 @@ class ClientSocketHandle { template <typename SocketParams, typename PoolType> int Init(const std::string& group_name, const SocketParams& socket_params, - int priority, + RequestPriority priority, CompletionCallback* callback, PoolType* pool, LoadLog* load_log); @@ -146,7 +147,7 @@ class ClientSocketHandle { template <typename SocketParams, typename PoolType> int ClientSocketHandle::Init(const std::string& group_name, const SocketParams& socket_params, - int priority, + RequestPriority priority, CompletionCallback* callback, PoolType* pool, LoadLog* load_log) { diff --git a/net/socket/client_socket_pool.h b/net/socket/client_socket_pool.h index 2c55e91..4bd1a58 100644 --- a/net/socket/client_socket_pool.h +++ b/net/socket/client_socket_pool.h @@ -13,6 +13,7 @@ #include "net/base/completion_callback.h" #include "net/base/host_resolver.h" #include "net/base/load_states.h" +#include "net/base/request_priority.h" namespace net { @@ -49,7 +50,7 @@ class ClientSocketPool : public base::RefCounted<ClientSocketPool> { // Profiling information for the request is saved to |load_log| if non-NULL. virtual int RequestSocket(const std::string& group_name, const void* params, - int priority, + RequestPriority priority, ClientSocketHandle* handle, CompletionCallback* callback, LoadLog* load_log) = 0; diff --git a/net/socket/client_socket_pool_base.cc b/net/socket/client_socket_pool_base.cc index 9413005..9701937 100644 --- a/net/socket/client_socket_pool_base.cc +++ b/net/socket/client_socket_pool_base.cc @@ -136,7 +136,7 @@ void ClientSocketPoolBaseHelper::InsertRequestIntoQueue( LoadLog::TYPE_SOCKET_POOL_WAITING_IN_QUEUE); RequestQueue::iterator it = pending_requests->begin(); - while (it != pending_requests->end() && r->priority() <= (*it)->priority()) + while (it != pending_requests->end() && r->priority() >= (*it)->priority()) ++it; pending_requests->insert(it, r); } @@ -437,7 +437,7 @@ int ClientSocketPoolBaseHelper::FindTopStalledGroup(Group** group, if (has_slot) stalled_group_count++; bool has_higher_priority = !top_group || - group.TopPendingPriority() > top_group->TopPendingPriority(); + group.TopPendingPriority() < top_group->TopPendingPriority(); if (has_slot && has_higher_priority) { top_group = &group; top_group_name = &i->first; diff --git a/net/socket/client_socket_pool_base.h b/net/socket/client_socket_pool_base.h index b9c28e9..cfad0a0 100644 --- a/net/socket/client_socket_pool_base.h +++ b/net/socket/client_socket_pool_base.h @@ -36,6 +36,7 @@ #include "net/base/load_log.h" #include "net/base/load_states.h" #include "net/base/net_errors.h" +#include "net/base/request_priority.h" #include "net/socket/client_socket.h" #include "net/socket/client_socket_pool.h" @@ -126,7 +127,7 @@ class ClientSocketPoolBaseHelper public: Request(ClientSocketHandle* handle, CompletionCallback* callback, - int priority, + RequestPriority priority, LoadLog* load_log) : handle_(handle), callback_(callback), priority_(priority), load_log_(load_log) {} @@ -135,13 +136,13 @@ class ClientSocketPoolBaseHelper ClientSocketHandle* handle() const { return handle_; } CompletionCallback* callback() const { return callback_; } - int priority() const { return priority_; } + RequestPriority priority() const { return priority_; } LoadLog* load_log() const { return load_log_.get(); } private: ClientSocketHandle* const handle_; CompletionCallback* const callback_; - const int priority_; + const RequestPriority priority_; const scoped_refptr<LoadLog> load_log_; DISALLOW_COPY_AND_ASSIGN(Request); @@ -260,7 +261,7 @@ class ClientSocketPoolBaseHelper max_sockets_per_group; } - int TopPendingPriority() const { + RequestPriority TopPendingPriority() const { return pending_requests.front()->priority(); } @@ -406,7 +407,7 @@ class ClientSocketPoolBase { public: Request(ClientSocketHandle* handle, CompletionCallback* callback, - int priority, + RequestPriority priority, const SocketParams& params, LoadLog* load_log) : internal::ClientSocketPoolBaseHelper::Request( @@ -459,7 +460,7 @@ class ClientSocketPoolBase { // ownership is transferred in the asynchronous (ERR_IO_PENDING) case. int RequestSocket(const std::string& group_name, const SocketParams& params, - int priority, + RequestPriority priority, ClientSocketHandle* handle, CompletionCallback* callback, LoadLog* load_log) { diff --git a/net/socket/client_socket_pool_base_unittest.cc b/net/socket/client_socket_pool_base_unittest.cc index 1aa25c2..1799e09 100644 --- a/net/socket/client_socket_pool_base_unittest.cc +++ b/net/socket/client_socket_pool_base_unittest.cc @@ -11,6 +11,7 @@ #include "net/base/load_log.h" #include "net/base/load_log_unittest.h" #include "net/base/net_errors.h" +#include "net/base/request_priority.h" #include "net/base/test_completion_callback.h" #include "net/socket/client_socket.h" #include "net/socket/client_socket_factory.h" @@ -24,7 +25,7 @@ namespace { const int kDefaultMaxSockets = 4; const int kDefaultMaxSocketsPerGroup = 2; -const int kDefaultPriority = 5; +const net::RequestPriority kDefaultPriority = MEDIUM; typedef ClientSocketPoolBase<const void*> TestClientSocketPoolBase; @@ -283,7 +284,7 @@ class TestClientSocketPool : public ClientSocketPool { virtual int RequestSocket( const std::string& group_name, const void* params, - int priority, + net::RequestPriority priority, ClientSocketHandle* handle, CompletionCallback* callback, LoadLog* load_log) { @@ -407,7 +408,8 @@ class ClientSocketPoolBaseTest : public ClientSocketPoolTest { connect_job_factory_); } - int StartRequest(const std::string& group_name, int priority) { + int StartRequest(const std::string& group_name, + net::RequestPriority priority) { return StartRequestUsingPool<TestClientSocketPool, const void*>( pool_.get(), group_name, priority, NULL); } @@ -441,7 +443,7 @@ class ClientSocketPoolBaseTest : public ClientSocketPoolTest { // the compiler will infer (in this case, incorrectly) that NULL is of type int. int InitHandle(ClientSocketHandle* handle, const std::string& group_name, - int priority, + net::RequestPriority priority, CompletionCallback* callback, TestClientSocketPool* pool, LoadLog* load_log) { @@ -522,7 +524,7 @@ TEST_F(ClientSocketPoolBaseTest, BasicAsynchronous) { connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); scoped_refptr<LoadLog> log(new LoadLog(LoadLog::kUnbounded)); TestSocketRequest req(&request_order_, &completion_count_); - int rv = InitHandle(req.handle(), "a", 0, &req, pool_.get(), log); + int rv = InitHandle(req.handle(), "a", LOW, &req, pool_.get(), log); EXPECT_EQ(ERR_IO_PENDING, rv); EXPECT_EQ(LOAD_STATE_CONNECTING, pool_->GetLoadState("a", req.handle())); EXPECT_EQ(OK, req.WaitForResult()); @@ -652,17 +654,17 @@ TEST_F(ClientSocketPoolBaseTest, TotalLimitReachedNewGroup) { TEST_F(ClientSocketPoolBaseTest, TotalLimitRespectsPriority) { CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); - EXPECT_EQ(OK, StartRequest("b", 3)); - EXPECT_EQ(OK, StartRequest("a", 3)); - EXPECT_EQ(OK, StartRequest("b", 6)); - EXPECT_EQ(OK, StartRequest("a", 6)); + EXPECT_EQ(OK, StartRequest("b", LOWEST)); + EXPECT_EQ(OK, StartRequest("a", MEDIUM)); + EXPECT_EQ(OK, StartRequest("b", HIGHEST)); + EXPECT_EQ(OK, StartRequest("a", LOWEST)); EXPECT_EQ(static_cast<int>(requests_.size()), client_socket_factory_.allocation_count()); - EXPECT_EQ(ERR_IO_PENDING, StartRequest("c", 4)); - EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", 5)); - EXPECT_EQ(ERR_IO_PENDING, StartRequest("b", 7)); + EXPECT_EQ(ERR_IO_PENDING, StartRequest("c", LOWEST)); + EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", MEDIUM)); + EXPECT_EQ(ERR_IO_PENDING, StartRequest("b", HIGHEST)); ReleaseAllConnections(KEEP_ALIVE); @@ -677,8 +679,8 @@ TEST_F(ClientSocketPoolBaseTest, TotalLimitRespectsPriority) { EXPECT_EQ(3, GetOrderOfRequest(3)); EXPECT_EQ(4, GetOrderOfRequest(4)); - // Request ("b", 7) has the highest priority, then ("a", 5), - // and then ("c", 4). + // Request ("b", HIGHEST) has the highest priority, then ("a", MEDIUM), + // and then ("c", LOWEST). EXPECT_EQ(7, GetOrderOfRequest(5)); EXPECT_EQ(6, GetOrderOfRequest(6)); EXPECT_EQ(5, GetOrderOfRequest(7)); @@ -690,17 +692,17 @@ TEST_F(ClientSocketPoolBaseTest, TotalLimitRespectsPriority) { TEST_F(ClientSocketPoolBaseTest, TotalLimitRespectsGroupLimit) { CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); - EXPECT_EQ(OK, StartRequest("a", 3)); - EXPECT_EQ(OK, StartRequest("a", 6)); - EXPECT_EQ(OK, StartRequest("b", 3)); - EXPECT_EQ(OK, StartRequest("b", 6)); + EXPECT_EQ(OK, StartRequest("a", LOWEST)); + EXPECT_EQ(OK, StartRequest("a", LOW)); + EXPECT_EQ(OK, StartRequest("b", HIGHEST)); + EXPECT_EQ(OK, StartRequest("b", MEDIUM)); EXPECT_EQ(static_cast<int>(requests_.size()), client_socket_factory_.allocation_count()); - EXPECT_EQ(ERR_IO_PENDING, StartRequest("c", 6)); - EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", 4)); - EXPECT_EQ(ERR_IO_PENDING, StartRequest("b", 7)); + EXPECT_EQ(ERR_IO_PENDING, StartRequest("c", MEDIUM)); + EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", LOW)); + EXPECT_EQ(ERR_IO_PENDING, StartRequest("b", HIGHEST)); ReleaseAllConnections(KEEP_ALIVE); @@ -822,11 +824,11 @@ TEST_F(ClientSocketPoolBaseTest, PendingRequests) { EXPECT_EQ(OK, StartRequest("a", kDefaultPriority)); EXPECT_EQ(OK, StartRequest("a", kDefaultPriority)); - EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", 1)); - EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", 3)); - EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", 4)); - EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", 2)); - EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", 1)); + EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", LOWEST)); + EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", MEDIUM)); + EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", HIGHEST)); + EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", LOW)); + EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", LOWEST)); ReleaseAllConnections(KEEP_ALIVE); @@ -851,11 +853,11 @@ TEST_F(ClientSocketPoolBaseTest, PendingRequests_NoKeepAlive) { EXPECT_EQ(OK, StartRequest("a", kDefaultPriority)); EXPECT_EQ(OK, StartRequest("a", kDefaultPriority)); - EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", 1)); - EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", 3)); - EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", 4)); - EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", 2)); - EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", 1)); + EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", LOWEST)); + EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", MEDIUM)); + EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", HIGHEST)); + EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", LOW)); + EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", LOWEST)); ReleaseAllConnections(NO_KEEP_ALIVE); @@ -931,11 +933,11 @@ TEST_F(ClientSocketPoolBaseTest, CancelRequest) { EXPECT_EQ(OK, StartRequest("a", kDefaultPriority)); EXPECT_EQ(OK, StartRequest("a", kDefaultPriority)); - EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", 1)); - EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", 3)); - EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", 4)); - EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", 2)); - EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", 1)); + EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", LOWEST)); + EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", MEDIUM)); + EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", HIGHEST)); + EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", LOW)); + EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", LOWEST)); // Cancel a request. size_t index_to_cancel = kDefaultMaxSocketsPerGroup + 2; @@ -1218,7 +1220,7 @@ TEST_F(ClientSocketPoolBaseTest, GroupWithPendingRequestsIsNotEmpty) { const int kMaxSocketsPerGroup = 2; CreatePool(kMaxSockets, kMaxSocketsPerGroup); - const int kHighPriority = kDefaultPriority + 100; + const RequestPriority kHighPriority = HIGHEST; EXPECT_EQ(OK, StartRequest("a", kDefaultPriority)); EXPECT_EQ(OK, StartRequest("a", kDefaultPriority)); @@ -1261,7 +1263,8 @@ TEST_F(ClientSocketPoolBaseTest_LateBinding, ConnectJob_NoTimeoutOnSynchronousCompletion) { TestConnectJobDelegate delegate; ClientSocketHandle ignored; - TestClientSocketPoolBase::Request request(&ignored, NULL, 0, NULL, NULL); + TestClientSocketPoolBase::Request request(&ignored, NULL, LOWEST, NULL, + NULL); scoped_ptr<TestConnectJob> job( new TestConnectJob(TestConnectJob::kMockJob, "a", @@ -1276,7 +1279,8 @@ TEST_F(ClientSocketPoolBaseTest_LateBinding, TEST_F(ClientSocketPoolBaseTest_LateBinding, ConnectJob_TimedOut) { TestConnectJobDelegate delegate; ClientSocketHandle ignored; - TestClientSocketPoolBase::Request request(&ignored, NULL, 0, NULL, NULL); + TestClientSocketPoolBase::Request request(&ignored, NULL, LOWEST, NULL, + NULL); // Deleted by TestConnectJobDelegate. TestConnectJob* job = new TestConnectJob(TestConnectJob::kMockPendingJob, @@ -1318,7 +1322,7 @@ TEST_F(ClientSocketPoolBaseTest_LateBinding, BasicAsynchronous) { connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); TestSocketRequest req(&request_order_, &completion_count_); scoped_refptr<LoadLog> log(new LoadLog(LoadLog::kUnbounded)); - int rv = InitHandle(req.handle(), "a", 0, &req, pool_.get(), log); + int rv = InitHandle(req.handle(), "a", LOWEST, &req, pool_.get(), log); EXPECT_EQ(ERR_IO_PENDING, rv); EXPECT_EQ(LOAD_STATE_CONNECTING, pool_->GetLoadState("a", req.handle())); EXPECT_EQ(OK, req.WaitForResult()); @@ -1389,11 +1393,11 @@ TEST_F(ClientSocketPoolBaseTest_LateBinding, PendingRequests) { EXPECT_EQ(OK, StartRequest("a", kDefaultPriority)); EXPECT_EQ(OK, StartRequest("a", kDefaultPriority)); - EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", 1)); - EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", 3)); - EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", 4)); - EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", 2)); - EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", 1)); + EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", LOWEST)); + EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", MEDIUM)); + EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", HIGHEST)); + EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", LOW)); + EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", LOWEST)); ReleaseAllConnections(KEEP_ALIVE); @@ -1418,11 +1422,11 @@ TEST_F(ClientSocketPoolBaseTest_LateBinding, PendingRequests_NoKeepAlive) { EXPECT_EQ(OK, StartRequest("a", kDefaultPriority)); EXPECT_EQ(OK, StartRequest("a", kDefaultPriority)); - EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", 1)); - EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", 3)); - EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", 4)); - EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", 2)); - EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", 1)); + EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", LOWEST)); + EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", MEDIUM)); + EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", HIGHEST)); + EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", LOW)); + EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", LOWEST)); ReleaseAllConnections(NO_KEEP_ALIVE); @@ -1529,11 +1533,11 @@ TEST_F(ClientSocketPoolBaseTest_LateBinding, CancelRequest) { EXPECT_EQ(OK, StartRequest("a", kDefaultPriority)); EXPECT_EQ(OK, StartRequest("a", kDefaultPriority)); - EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", 1)); - EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", 3)); - EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", 4)); - EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", 2)); - EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", 1)); + EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", LOWEST)); + EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", MEDIUM)); + EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", HIGHEST)); + EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", LOW)); + EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", LOWEST)); // Cancel a request. size_t index_to_cancel = kDefaultMaxSocketsPerGroup + 2; @@ -1564,10 +1568,10 @@ TEST_F(ClientSocketPoolBaseTest_LateBinding, CancelRequestLimitsJobs) { connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); - EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", 1)); - EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", 2)); - EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", 3)); - EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", 4)); + EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", LOWEST)); + EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", LOW)); + EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", MEDIUM)); + EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", HIGHEST)); EXPECT_EQ(kDefaultMaxSocketsPerGroup, pool_->NumConnectJobsInGroup("a")); requests_[2]->handle()->Reset(); @@ -1798,7 +1802,7 @@ TEST_F(ClientSocketPoolBaseTest_LateBinding, const int kMaxSocketsPerGroup = 2; CreatePool(kMaxSockets, kMaxSocketsPerGroup); - const int kHighPriority = kDefaultPriority + 100; + const RequestPriority kHighPriority = HIGHEST; EXPECT_EQ(OK, StartRequest("a", kDefaultPriority)); EXPECT_EQ(OK, StartRequest("a", kDefaultPriority)); @@ -1838,12 +1842,12 @@ TEST_F(ClientSocketPoolBaseTest_LateBinding, CleanupTimedOutIdleSockets) { // Startup two mock pending connect jobs, which will sit in the MessageLoop. TestSocketRequest req(&request_order_, &completion_count_); - int rv = InitHandle(req.handle(), "a", 0, &req, pool_.get(), NULL); + int rv = InitHandle(req.handle(), "a", LOWEST, &req, pool_.get(), NULL); EXPECT_EQ(ERR_IO_PENDING, rv); EXPECT_EQ(LOAD_STATE_CONNECTING, pool_->GetLoadState("a", req.handle())); TestSocketRequest req2(&request_order_, &completion_count_); - rv = InitHandle(req2.handle(), "a", 0, &req2, pool_.get(), NULL); + rv = InitHandle(req2.handle(), "a", LOWEST, &req2, pool_.get(), NULL); EXPECT_EQ(ERR_IO_PENDING, rv); EXPECT_EQ(LOAD_STATE_CONNECTING, pool_->GetLoadState("a", req2.handle())); @@ -1869,7 +1873,7 @@ TEST_F(ClientSocketPoolBaseTest_LateBinding, CleanupTimedOutIdleSockets) { // used socket. Request it to make sure that it's used. pool_->CleanupTimedOutIdleSockets(); - rv = InitHandle(req.handle(), "a", 0, &req, pool_.get(), NULL); + rv = InitHandle(req.handle(), "a", LOWEST, &req, pool_.get(), NULL); EXPECT_EQ(OK, rv); EXPECT_TRUE(req.handle()->is_reused()); } diff --git a/net/socket/socket_test_util.h b/net/socket/socket_test_util.h index 2813fe4..5f17f71 100644 --- a/net/socket/socket_test_util.h +++ b/net/socket/socket_test_util.h @@ -414,7 +414,7 @@ class ClientSocketPoolTest : public testing::Test { template <typename PoolType, typename SocketParams> int StartRequestUsingPool(PoolType* socket_pool, const std::string& group_name, - int priority, + RequestPriority priority, const SocketParams& socket_params) { DCHECK(socket_pool); TestSocketRequest* request = new TestSocketRequest(&request_order_, diff --git a/net/socket/tcp_client_socket_pool.cc b/net/socket/tcp_client_socket_pool.cc index 37d2d8c..84899da 100644 --- a/net/socket/tcp_client_socket_pool.cc +++ b/net/socket/tcp_client_socket_pool.cc @@ -172,7 +172,7 @@ TCPClientSocketPool::~TCPClientSocketPool() {} int TCPClientSocketPool::RequestSocket( const std::string& group_name, const void* resolve_info, - int priority, + RequestPriority priority, ClientSocketHandle* handle, CompletionCallback* callback, LoadLog* load_log) { diff --git a/net/socket/tcp_client_socket_pool.h b/net/socket/tcp_client_socket_pool.h index 8a3d1f7..49c0aa7 100644 --- a/net/socket/tcp_client_socket_pool.h +++ b/net/socket/tcp_client_socket_pool.h @@ -85,7 +85,7 @@ class TCPClientSocketPool : public ClientSocketPool { virtual int RequestSocket(const std::string& group_name, const void* resolve_info, - int priority, + RequestPriority priority, ClientSocketHandle* handle, CompletionCallback* callback, LoadLog* load_log); diff --git a/net/socket/tcp_client_socket_pool_unittest.cc b/net/socket/tcp_client_socket_pool_unittest.cc index e73b7d3..b3560be 100644 --- a/net/socket/tcp_client_socket_pool_unittest.cc +++ b/net/socket/tcp_client_socket_pool_unittest.cc @@ -21,7 +21,7 @@ namespace { const int kMaxSockets = 32; const int kMaxSocketsPerGroup = 6; -const int kDefaultPriority = 5; +const net::RequestPriority kDefaultPriority = LOW; class MockClientSocket : public ClientSocket { public: @@ -203,7 +203,7 @@ class TCPClientSocketPoolTest : public ClientSocketPoolTest { &client_socket_factory_)) { } - int StartRequest(const std::string& group_name, int priority) { + int StartRequest(const std::string& group_name, RequestPriority priority) { return StartRequestUsingPool( pool_.get(), group_name, priority, ignored_request_info_); } @@ -218,7 +218,7 @@ TEST_F(TCPClientSocketPoolTest, Basic) { TestCompletionCallback callback; ClientSocketHandle handle; HostResolver::RequestInfo info("www.google.com", 80); - int rv = handle.Init("a", info, 0, &callback, pool_.get(), NULL); + int rv = handle.Init("a", info, LOW, &callback, pool_.get(), NULL); EXPECT_EQ(ERR_IO_PENDING, rv); EXPECT_FALSE(handle.is_initialized()); EXPECT_FALSE(handle.socket()); @@ -273,16 +273,16 @@ TEST_F(TCPClientSocketPoolTest, PendingRequests) { EXPECT_EQ(OK, StartRequest("a", kDefaultPriority)); // The rest are pending since we've used all active sockets. - EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", 1)); - EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", 7)); - EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", 9)); - EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", 5)); - EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", 6)); - EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", 2)); - EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", 8)); - EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", 3)); - EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", 4)); - EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", 1)); + EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", HIGHEST)); + EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", LOWEST)); + EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", LOWEST)); + EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", MEDIUM)); + EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", LOW)); + EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", HIGHEST)); + EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", LOWEST)); + EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", MEDIUM)); + EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", MEDIUM)); + EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", HIGHEST)); ReleaseAllConnections(KEEP_ALIVE); @@ -299,17 +299,17 @@ TEST_F(TCPClientSocketPoolTest, PendingRequests) { EXPECT_EQ(5, GetOrderOfRequest(5)); EXPECT_EQ(6, GetOrderOfRequest(6)); - // Make sure that rest o the requests complete in the order of priority. - EXPECT_EQ(15, GetOrderOfRequest(7)); - EXPECT_EQ(9, GetOrderOfRequest(8)); - EXPECT_EQ(7, GetOrderOfRequest(9)); - EXPECT_EQ(11, GetOrderOfRequest(10)); - EXPECT_EQ(10, GetOrderOfRequest(11)); - EXPECT_EQ(14, GetOrderOfRequest(12)); - EXPECT_EQ(8, GetOrderOfRequest(13)); - EXPECT_EQ(13, GetOrderOfRequest(14)); + // Make sure that rest of the requests complete in the order of priority. + EXPECT_EQ(7, GetOrderOfRequest(7)); + EXPECT_EQ(14, GetOrderOfRequest(8)); + EXPECT_EQ(15, GetOrderOfRequest(9)); + EXPECT_EQ(10, GetOrderOfRequest(10)); + EXPECT_EQ(13, GetOrderOfRequest(11)); + EXPECT_EQ(8, GetOrderOfRequest(12)); + EXPECT_EQ(16, GetOrderOfRequest(13)); + EXPECT_EQ(11, GetOrderOfRequest(14)); EXPECT_EQ(12, GetOrderOfRequest(15)); - EXPECT_EQ(16, GetOrderOfRequest(16)); + EXPECT_EQ(9, GetOrderOfRequest(16)); // Make sure we test order of all requests made. EXPECT_EQ(kIndexOutOfBounds, GetOrderOfRequest(17)); @@ -441,16 +441,16 @@ TEST_F(TCPClientSocketPoolTest, CancelRequest) { EXPECT_EQ(OK, StartRequest("a", kDefaultPriority)); // Reached per-group limit, queue up requests. - EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", 1)); - EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", 7)); - EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", 9)); - EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", 5)); - EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", 6)); - EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", 2)); - EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", 8)); - EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", 3)); - EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", 4)); - EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", 1)); + EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", LOWEST)); + EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", HIGHEST)); + EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", HIGHEST)); + EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", MEDIUM)); + EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", MEDIUM)); + EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", LOW)); + EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", HIGHEST)); + EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", LOW)); + EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", LOW)); + EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", LOWEST)); // Cancel a request. size_t index_to_cancel = kMaxSocketsPerGroup + 2; @@ -470,14 +470,14 @@ TEST_F(TCPClientSocketPoolTest, CancelRequest) { EXPECT_EQ(5, GetOrderOfRequest(5)); EXPECT_EQ(6, GetOrderOfRequest(6)); EXPECT_EQ(14, GetOrderOfRequest(7)); - EXPECT_EQ(8, GetOrderOfRequest(8)); + EXPECT_EQ(7, GetOrderOfRequest(8)); EXPECT_EQ(kRequestNotFound, GetOrderOfRequest(9)); // Canceled request. - EXPECT_EQ(10, GetOrderOfRequest(10)); - EXPECT_EQ(9, GetOrderOfRequest(11)); - EXPECT_EQ(13, GetOrderOfRequest(12)); - EXPECT_EQ(7, GetOrderOfRequest(13)); + EXPECT_EQ(9, GetOrderOfRequest(10)); + EXPECT_EQ(10, GetOrderOfRequest(11)); + EXPECT_EQ(11, GetOrderOfRequest(12)); + EXPECT_EQ(8, GetOrderOfRequest(13)); EXPECT_EQ(12, GetOrderOfRequest(14)); - EXPECT_EQ(11, GetOrderOfRequest(15)); + EXPECT_EQ(13, GetOrderOfRequest(15)); EXPECT_EQ(15, GetOrderOfRequest(16)); // Make sure we test order of all requests made. @@ -499,7 +499,7 @@ class RequestSocketCallback : public CallbackRunner< Tuple1<int> > { handle_->Reset(); within_callback_ = true; int rv = handle_->Init( - "a", HostResolver::RequestInfo("www.google.com", 80), 0, + "a", HostResolver::RequestInfo("www.google.com", 80), LOWEST, this, pool_.get(), NULL); EXPECT_EQ(OK, rv); } @@ -520,7 +520,7 @@ TEST_F(TCPClientSocketPoolTest, RequestTwice) { ClientSocketHandle handle; RequestSocketCallback callback(&handle, pool_.get()); int rv = handle.Init( - "a", HostResolver::RequestInfo("www.google.com", 80), 0, + "a", HostResolver::RequestInfo("www.google.com", 80), LOWEST, &callback, pool_.get(), NULL); ASSERT_EQ(ERR_IO_PENDING, rv); diff --git a/net/url_request/url_request.cc b/net/url_request/url_request.cc index 6aa2574..b4ea82f 100644 --- a/net/url_request/url_request.cc +++ b/net/url_request/url_request.cc @@ -48,7 +48,7 @@ URLRequest::URLRequest(const GURL& url, Delegate* delegate) enable_profiling_(false), redirect_limit_(kMaxRedirects), final_upload_progress_(0), - priority_(0), + priority_(net::LOWEST), ALLOW_THIS_IN_INITIALIZER_LIST(request_tracker_node_(this)) { SIMPLE_STATS_COUNTER("URLRequestCount"); diff --git a/net/url_request/url_request.h b/net/url_request/url_request.h index d342b7d..1b73b95 100644 --- a/net/url_request/url_request.h +++ b/net/url_request/url_request.h @@ -18,6 +18,7 @@ #include "googleurl/src/gurl.h" #include "net/base/load_log.h" #include "net/base/load_states.h" +#include "net/base/request_priority.h" #include "net/http/http_response_info.h" #include "net/url_request/request_tracker.h" #include "net/url_request/url_request_status.h" @@ -494,11 +495,11 @@ class URLRequest { // Returns the expected content size if available int64 GetExpectedContentSize() const; - // Returns the priority level for this request. A larger value indicates - // higher priority. Negative values are not used. - int priority() const { return priority_; } - void set_priority(int priority) { - DCHECK_GE(priority, 0); + // Returns the priority level for this request. + net::RequestPriority priority() const { return priority_; } + void set_priority(net::RequestPriority priority) { + DCHECK_GE(priority, net::HIGHEST); + DCHECK_LE(priority, net::LOWEST); priority_ = priority; } @@ -608,7 +609,7 @@ class URLRequest { // The priority level for this request. Objects like ClientSocketPool use // this to determine which URLRequest to allocate sockets to first. - int priority_; + net::RequestPriority priority_; RequestTracker<URLRequest>::Node request_tracker_node_; base::LeakTracker<URLRequest> leak_tracker_; diff --git a/webkit/glue/resource_type.h b/webkit/glue/resource_type.h index 1edae95..14f228b 100644 --- a/webkit/glue/resource_type.h +++ b/webkit/glue/resource_type.h @@ -12,7 +12,11 @@ class ResourceType { enum Type { MAIN_FRAME = 0, // top level page SUB_FRAME, // frame or iframe - SUB_RESOURCE, // a resource like images, js, css + STYLESHEET, // a CSS stylesheet + SCRIPT, // an external script + IMAGE, // an image (jpg/gif/png/etc) + FONT_RESOURCE, // a font + SUB_RESOURCE, // an "other" subresource. OBJECT, // an object (or embed) tag for a plugin, // or a resource that a plugin requested. MEDIA, // a media resource. @@ -32,6 +36,14 @@ class ResourceType { return type == MAIN_FRAME || type == SUB_FRAME; } + static bool IsSubresource(ResourceType::Type type) { + return type == STYLESHEET || + type == SCRIPT || + type == IMAGE || + type == FONT_RESOURCE || + type == SUB_RESOURCE; + } + private: // Don't instantiate this class. ResourceType(); |