summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorszym@chromium.org <szym@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-24 21:09:05 +0000
committerszym@chromium.org <szym@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-24 21:09:05 +0000
commit31ae7abec500e5d497079745490d8ba4986b1ba2 (patch)
treec5b3a979b1b540b8398fb21285a2154957ac7cd7
parent0da2ecf6b25b9b18ab3f009e8ba2181b09735b6f (diff)
downloadchromium_src-31ae7abec500e5d497079745490d8ba4986b1ba2.zip
chromium_src-31ae7abec500e5d497079745490d8ba4986b1ba2.tar.gz
chromium_src-31ae7abec500e5d497079745490d8ba4986b1ba2.tar.bz2
[net] Change order of RequestPriority to natural: higher > lower
BUG=124683 TEST=./net_unittests Review URL: http://codereview.chromium.org/10185007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@133766 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--net/base/host_resolver_impl.cc12
-rw-r--r--net/base/prioritized_dispatcher.cc14
-rw-r--r--net/base/prioritized_dispatcher.h4
-rw-r--r--net/base/prioritized_dispatcher_unittest.cc11
-rw-r--r--net/base/request_priority.h11
-rw-r--r--net/http/http_network_transaction.cc4
-rw-r--r--net/socket/client_socket_pool_base.cc5
-rw-r--r--net/spdy/buffered_spdy_framer.cc2
-rw-r--r--net/spdy/buffered_spdy_framer.h2
-rw-r--r--net/spdy/spdy_http_utils.cc18
-rw-r--r--net/spdy/spdy_io_buffer.cc7
-rw-r--r--net/spdy/spdy_io_buffer.h14
-rw-r--r--net/spdy/spdy_network_transaction_spdy2_unittest.cc4
-rw-r--r--net/spdy/spdy_network_transaction_spdy3_unittest.cc4
-rw-r--r--net/spdy/spdy_session.cc22
-rw-r--r--net/spdy/spdy_session.h2
-rw-r--r--net/spdy/spdy_session_spdy2_unittest.cc40
-rw-r--r--net/spdy/spdy_session_spdy3_unittest.cc40
-rw-r--r--net/spdy/spdy_stream.cc6
-rw-r--r--net/spdy/spdy_stream.h7
-rw-r--r--net/url_request/url_request.h2
21 files changed, 115 insertions, 116 deletions
diff --git a/net/base/host_resolver_impl.cc b/net/base/host_resolver_impl.cc
index 534f3a4..0525459 100644
--- a/net/base/host_resolver_impl.cc
+++ b/net/base/host_resolver_impl.cc
@@ -389,7 +389,7 @@ class PriorityTracker {
void Add(RequestPriority req_priority) {
++total_count_;
++counts_[req_priority];
- if (highest_priority_ > req_priority)
+ if (highest_priority_ < req_priority)
highest_priority_ = req_priority;
}
@@ -399,14 +399,12 @@ class PriorityTracker {
--total_count_;
--counts_[req_priority];
size_t i;
- for (i = highest_priority_; i < NUM_PRIORITIES && !counts_[i]; ++i);
+ for (i = highest_priority_; i > MINIMUM_PRIORITY && !counts_[i]; --i);
highest_priority_ = static_cast<RequestPriority>(i);
- // In absence of requests set default.
- if (highest_priority_ == NUM_PRIORITIES) {
- DCHECK_EQ(0u, total_count_);
- highest_priority_ = IDLE;
- }
+ // In absence of requests, default to MINIMUM_PRIORITY.
+ if (total_count_ == 0)
+ DCHECK_EQ(MINIMUM_PRIORITY, highest_priority_);
}
private:
diff --git a/net/base/prioritized_dispatcher.cc b/net/base/prioritized_dispatcher.cc
index afa12f8..9b96e3f 100644
--- a/net/base/prioritized_dispatcher.cc
+++ b/net/base/prioritized_dispatcher.cc
@@ -19,15 +19,15 @@ PrioritizedDispatcher::PrioritizedDispatcher(const Limits& limits)
max_running_jobs_(limits.reserved_slots.size()),
num_running_jobs_(0) {
size_t total = 0;
- for (size_t i = limits.reserved_slots.size(); i > 0; --i) {
- total += limits.reserved_slots[i - 1];
- max_running_jobs_[i - 1] = total;
+ for (size_t i = 0; i < limits.reserved_slots.size(); ++i) {
+ total += limits.reserved_slots[i];
+ max_running_jobs_[i] = total;
}
// Unreserved slots are available for all priorities.
DCHECK_LE(total, limits.total_jobs) << "sum(reserved_slots) <= total_jobs";
size_t spare = limits.total_jobs - total;
- for (size_t i = 0; i < max_running_jobs_.size(); ++i) {
- max_running_jobs_[i] += spare;
+ for (size_t i = limits.reserved_slots.size(); i > 0; --i) {
+ max_running_jobs_[i - 1] += spare;
}
}
@@ -50,7 +50,7 @@ void PrioritizedDispatcher::Cancel(const Handle& handle) {
}
PrioritizedDispatcher::Job* PrioritizedDispatcher::EvictOldestLowest() {
- Handle handle = queue_.FirstMax();
+ Handle handle = queue_.FirstMin();
if (handle.is_null())
return NULL;
Job* job = handle.value();
@@ -78,7 +78,7 @@ PrioritizedDispatcher::Handle PrioritizedDispatcher::ChangePriority(
void PrioritizedDispatcher::OnJobFinished() {
DCHECK_GT(num_running_jobs_, 0u);
--num_running_jobs_;
- Handle handle = queue_.FirstMin();
+ Handle handle = queue_.FirstMax();
if (handle.is_null()) {
DCHECK_EQ(0u, queue_.size());
return;
diff --git a/net/base/prioritized_dispatcher.h b/net/base/prioritized_dispatcher.h
index c10061b..7e59d4e6 100644
--- a/net/base/prioritized_dispatcher.h
+++ b/net/base/prioritized_dispatcher.h
@@ -13,7 +13,7 @@
namespace net {
-// A priority-based dispatcher of jobs. Dispatch order is by priority (lowest
+// A priority-based dispatcher of jobs. Dispatch order is by priority (highest
// first) and then FIFO. The dispatcher enforces limits on the number of running
// jobs. It never revokes a job once started. The job must call OnJobFinished
// once it finishes in order to dispatch further jobs.
@@ -32,7 +32,7 @@ class NET_EXPORT_PRIVATE PrioritizedDispatcher {
// For example, |total_jobs| = 30 and |reserved_slots| = { 5, 10, 5 }
// allow for at most 30 running jobs in total. If there are already 24 jobs
// running, then there can be 6 more jobs started of which at most 1 can be
- // at priority 1 or 0, but the rest has to be at 0.
+ // at priority 1 or 2, but the rest have to be at 2.
struct NET_EXPORT_PRIVATE Limits {
Limits(Priority num_priorities, size_t total_jobs);
~Limits();
diff --git a/net/base/prioritized_dispatcher_unittest.cc b/net/base/prioritized_dispatcher_unittest.cc
index ff32003..6c19b92 100644
--- a/net/base/prioritized_dispatcher_unittest.cc
+++ b/net/base/prioritized_dispatcher_unittest.cc
@@ -17,11 +17,12 @@ namespace net {
namespace {
// We rely on the priority enum values being sequential having starting at 0,
-// and increasing for lower priorities.
-COMPILE_ASSERT(HIGHEST == 0u &&
- LOWEST > HIGHEST &&
- IDLE > LOWEST &&
- NUM_PRIORITIES > IDLE,
+// and increasing for higher priorities.
+COMPILE_ASSERT(MINIMUM_PRIORITY == 0u &&
+ MINIMUM_PRIORITY == IDLE &&
+ IDLE < LOWEST &&
+ LOWEST < HIGHEST &&
+ HIGHEST < NUM_PRIORITIES,
priority_indexes_incompatible);
class PrioritizedDispatcherTest : public testing::Test {
diff --git a/net/base/request_priority.h b/net/base/request_priority.h
index ca7a1ec..6cf1eef 100644
--- a/net/base/request_priority.h
+++ b/net/base/request_priority.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 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.
@@ -11,11 +11,12 @@ 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,
+ MINIMUM_PRIORITY = 0,
+ IDLE = 0,
LOWEST,
- IDLE,
+ LOW,
+ MEDIUM,
+ HIGHEST,
NUM_PRIORITIES,
};
diff --git a/net/http/http_network_transaction.cc b/net/http/http_network_transaction.cc
index 0a88bb8..43df7ce 100644
--- a/net/http/http_network_transaction.cc
+++ b/net/http/http_network_transaction.cc
@@ -1020,10 +1020,10 @@ void HttpNetworkTransaction::LogTransactionConnectedMetrics() {
}
}
- // Currently, non-zero priority requests are frame or sub-frame resource
+ // Currently, non-HIGHEST priority requests are frame or sub-frame resource
// types. This will change when we also prioritize certain subresources like
// css, js, etc.
- if (request_->priority) {
+ if (request_->priority != HIGHEST) {
UMA_HISTOGRAM_CUSTOM_TIMES(
"Net.Priority_High_Latency_b",
total_duration,
diff --git a/net/socket/client_socket_pool_base.cc b/net/socket/client_socket_pool_base.cc
index ab959cf..521436f 100644
--- a/net/socket/client_socket_pool_base.cc
+++ b/net/socket/client_socket_pool_base.cc
@@ -222,7 +222,7 @@ ClientSocketPoolBaseHelper::CallbackResultPair::~CallbackResultPair() {}
void ClientSocketPoolBaseHelper::InsertRequestIntoQueue(
const Request* r, RequestQueue* pending_requests) {
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);
}
@@ -332,7 +332,6 @@ void ClientSocketPoolBaseHelper::RequestSockets(
int ClientSocketPoolBaseHelper::RequestSocketInternal(
const std::string& group_name,
const Request* request) {
- DCHECK_GE(request->priority(), 0);
ClientSocketHandle* const handle = request->handle();
const bool preconnecting = !handle;
Group* group = GetOrCreateGroup(group_name);
@@ -834,7 +833,7 @@ bool ClientSocketPoolBaseHelper::FindTopStalledGroup(
return true;
has_stalled_group = true;
bool has_higher_priority = !top_group ||
- curr_group->TopPendingPriority() < top_group->TopPendingPriority();
+ curr_group->TopPendingPriority() > top_group->TopPendingPriority();
if (has_higher_priority) {
top_group = curr_group;
top_group_name = &i->first;
diff --git a/net/spdy/buffered_spdy_framer.cc b/net/spdy/buffered_spdy_framer.cc
index 1839b52..bc8af33 100644
--- a/net/spdy/buffered_spdy_framer.cc
+++ b/net/spdy/buffered_spdy_framer.cc
@@ -171,7 +171,7 @@ bool BufferedSpdyFramer::HasError() {
SpdySynStreamControlFrame* BufferedSpdyFramer::CreateSynStream(
SpdyStreamId stream_id,
SpdyStreamId associated_stream_id,
- int priority,
+ SpdyPriority priority,
uint8 credential_slot,
SpdyControlFlags flags,
bool compressed,
diff --git a/net/spdy/buffered_spdy_framer.h b/net/spdy/buffered_spdy_framer.h
index 880f972..b10f46f 100644
--- a/net/spdy/buffered_spdy_framer.h
+++ b/net/spdy/buffered_spdy_framer.h
@@ -110,7 +110,7 @@ class NET_EXPORT_PRIVATE BufferedSpdyFramer
bool HasError();
SpdySynStreamControlFrame* CreateSynStream(SpdyStreamId stream_id,
SpdyStreamId associated_stream_id,
- int priority,
+ SpdyPriority priority,
uint8 credential_slot,
SpdyControlFlags flags,
bool compressed,
diff --git a/net/spdy/spdy_http_utils.cc b/net/spdy/spdy_http_utils.cc
index f029a99..8a51685 100644
--- a/net/spdy/spdy_http_utils.cc
+++ b/net/spdy/spdy_http_utils.cc
@@ -125,21 +125,25 @@ void CreateSpdyHeadersFromHttpRequest(const HttpRequestInfo& info,
}
+COMPILE_ASSERT(HIGHEST - LOWEST < 4 &&
+ HIGHEST - MINIMUM_PRIORITY < 5,
+ request_priority_incompatible_with_spdy);
+
SpdyPriority ConvertRequestPriorityToSpdyPriority(
const RequestPriority priority,
int protocol_version) {
- DCHECK(HIGHEST <= priority && priority < NUM_PRIORITIES);
+ DCHECK_GE(priority, MINIMUM_PRIORITY);
+ DCHECK_LT(priority, NUM_PRIORITIES);
if (protocol_version == 2) {
// SPDY 2 only has 2 bits of priority, but we have 5 RequestPriorities.
- if (priority < LOWEST) {
- return priority;
+ // Map IDLE => 3, LOWEST => 2, LOW => 2, MEDIUM => 1, HIGHEST => 0.
+ if (priority > LOWEST) {
+ return static_cast<SpdyPriority>(HIGHEST - priority);
} else {
- DCHECK_GE(4, priority);
- return priority - 1;
+ return static_cast<SpdyPriority>(HIGHEST - priority - 1);
}
} else {
- DCHECK_GE(7, priority);
- return priority;
+ return static_cast<SpdyPriority>(HIGHEST - priority);
}
}
diff --git a/net/spdy/spdy_io_buffer.cc b/net/spdy/spdy_io_buffer.cc
index f7120c8..5720f7d 100644
--- a/net/spdy/spdy_io_buffer.cc
+++ b/net/spdy/spdy_io_buffer.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 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.
@@ -11,13 +11,14 @@ namespace net {
uint64 SpdyIOBuffer::order_ = 0;
SpdyIOBuffer::SpdyIOBuffer(
- IOBuffer* buffer, int size, int priority, SpdyStream* stream)
+ IOBuffer* buffer, int size, RequestPriority priority, SpdyStream* stream)
: buffer_(new DrainableIOBuffer(buffer, size)),
priority_(priority),
position_(++order_),
stream_(stream) {}
-SpdyIOBuffer::SpdyIOBuffer() : priority_(0), position_(0), stream_(NULL) {}
+SpdyIOBuffer::SpdyIOBuffer() : priority_(HIGHEST), position_(0), stream_(NULL) {
+}
SpdyIOBuffer::~SpdyIOBuffer() {}
diff --git a/net/spdy/spdy_io_buffer.h b/net/spdy/spdy_io_buffer.h
index e96c946..0aaced3 100644
--- a/net/spdy/spdy_io_buffer.h
+++ b/net/spdy/spdy_io_buffer.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 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.
@@ -22,10 +22,10 @@ class NET_EXPORT_PRIVATE SpdyIOBuffer {
// Constructor
// |buffer| is the actual data buffer.
// |size| is the size of the data buffer.
- // |priority| is the priority of this buffer. Lower numbers are higher
- // priority.
+ // |priority| is the priority of this buffer.
// |stream| is a pointer to the stream which is managing this buffer.
- SpdyIOBuffer(IOBuffer* buffer, int size, int priority, SpdyStream* stream);
+ SpdyIOBuffer(IOBuffer* buffer, int size, RequestPriority priority,
+ SpdyStream* stream);
SpdyIOBuffer();
~SpdyIOBuffer();
@@ -33,19 +33,19 @@ class NET_EXPORT_PRIVATE SpdyIOBuffer {
DrainableIOBuffer* buffer() const { return buffer_; }
size_t size() const { return buffer_->size(); }
void release();
- int priority() const { return priority_; }
+ RequestPriority priority() const { return priority_; }
const scoped_refptr<SpdyStream>& stream() const { return stream_; }
// Comparison operator to support sorting.
bool operator<(const SpdyIOBuffer& other) const {
if (priority_ != other.priority_)
- return priority_ > other.priority_;
+ return priority_ < other.priority_;
return position_ > other.position_;
}
private:
scoped_refptr<DrainableIOBuffer> buffer_;
- int priority_;
+ RequestPriority priority_;
uint64 position_;
scoped_refptr<SpdyStream> stream_;
static uint64 order_; // Maintains a FIFO order for equal priorities.
diff --git a/net/spdy/spdy_network_transaction_spdy2_unittest.cc b/net/spdy/spdy_network_transaction_spdy2_unittest.cc
index 6b402b6..978e35e 100644
--- a/net/spdy/spdy_network_transaction_spdy2_unittest.cc
+++ b/net/spdy/spdy_network_transaction_spdy2_unittest.cc
@@ -567,8 +567,8 @@ TEST_P(SpdyNetworkTransactionSpdy2Test, Get) {
}
TEST_P(SpdyNetworkTransactionSpdy2Test, GetAtEachPriority) {
- for (RequestPriority p = HIGHEST; p < NUM_PRIORITIES;
- p = RequestPriority(p+1)) {
+ for (RequestPriority p = MINIMUM_PRIORITY; p < NUM_PRIORITIES;
+ p = RequestPriority(p + 1)) {
// Construct the request.
scoped_ptr<SpdyFrame> req(ConstructSpdyGet(NULL, 0, false, 1, p));
MockWrite writes[] = { CreateMockWrite(*req) };
diff --git a/net/spdy/spdy_network_transaction_spdy3_unittest.cc b/net/spdy/spdy_network_transaction_spdy3_unittest.cc
index dcc48e5..6cfe4a6 100644
--- a/net/spdy/spdy_network_transaction_spdy3_unittest.cc
+++ b/net/spdy/spdy_network_transaction_spdy3_unittest.cc
@@ -569,8 +569,8 @@ TEST_P(SpdyNetworkTransactionSpdy3Test, Get) {
}
TEST_P(SpdyNetworkTransactionSpdy3Test, GetAtEachPriority) {
- for (RequestPriority p = HIGHEST; p < NUM_PRIORITIES;
- p = RequestPriority(p+1)) {
+ for (RequestPriority p = MINIMUM_PRIORITY; p < NUM_PRIORITIES;
+ p = RequestPriority(p + 1)) {
// Construct the request.
scoped_ptr<SpdyFrame> req(ConstructSpdyGet(NULL, 0, false, 1, p));
MockWrite writes[] = { CreateMockWrite(*req) };
diff --git a/net/spdy/spdy_session.cc b/net/spdy/spdy_session.cc
index 278fa25..4f2ac3a 100644
--- a/net/spdy/spdy_session.cc
+++ b/net/spdy/spdy_session.cc
@@ -535,7 +535,7 @@ void SpdySession::ProcessPendingCreateStreams() {
while (!max_concurrent_streams_ ||
active_streams_.size() < max_concurrent_streams_) {
bool no_pending_create_streams = true;
- for (int i = 0;i < NUM_PRIORITIES;++i) {
+ for (int i = NUM_PRIORITIES - 1; i >= MINIMUM_PRIORITY; --i) {
if (!create_stream_queues_[i].empty()) {
PendingCreateStream pending_create = create_stream_queues_[i].front();
create_stream_queues_[i].pop();
@@ -568,7 +568,7 @@ void SpdySession::CancelPendingCreateStreams(
return;
}
- for (int i = 0;i < NUM_PRIORITIES;++i) {
+ for (int i = 0; i < NUM_PRIORITIES; ++i) {
PendingCreateStreamQueue tmp;
// Make a copy removing this trans
while (!create_stream_queues_[i].empty()) {
@@ -590,6 +590,9 @@ int SpdySession::CreateStreamImpl(
RequestPriority priority,
scoped_refptr<SpdyStream>* spdy_stream,
const BoundNetLog& stream_net_log) {
+ DCHECK_GE(priority, MINIMUM_PRIORITY);
+ DCHECK_LT(priority, NUM_PRIORITIES);
+
// Make sure that we don't try to send https/wss over an unauthenticated, but
// encrypted SSL socket.
if (is_secure_ && certificate_error_code_ != OK &&
@@ -622,7 +625,6 @@ int SpdySession::CreateStreamImpl(
static_cast<int>(priority), 0, 10, 11);
// TODO(mbelshe): Optimize memory allocations
- DCHECK(priority >= net::HIGHEST && priority < net::NUM_PRIORITIES);
DCHECK_EQ(active_streams_[stream_id].get(), stream.get());
return OK;
@@ -834,7 +836,7 @@ void SpdySession::ResetStream(SpdyStreamId stream_id,
buffered_spdy_framer_->CreateRstStream(stream_id, status));
// Default to lowest priority unless we know otherwise.
- int priority = 3;
+ RequestPriority priority = net::IDLE;
if(IsStreamActive(stream_id)) {
scoped_refptr<SpdyStream> stream = active_streams_[stream_id];
priority = stream->priority();
@@ -1054,7 +1056,8 @@ void SpdySession::WriteSocket() {
memcpy(buffer->data(), compressed_frame->data(), size);
// Attempt to send the frame.
- in_flight_write_ = SpdyIOBuffer(buffer, size, 0, next_buffer.stream());
+ in_flight_write_ = SpdyIOBuffer(buffer, size, HIGHEST,
+ next_buffer.stream());
} else {
size = uncompressed_frame.length() + SpdyFrame::kHeaderSize;
in_flight_write_ = next_buffer;
@@ -1094,7 +1097,7 @@ void SpdySession::CloseAllStreams(net::Error status) {
unclaimed_pushed_streams_.clear();
}
- for (int i = 0;i < NUM_PRIORITIES;++i) {
+ for (int i = 0; i < NUM_PRIORITIES; ++i) {
while (!create_stream_queues_[i].empty()) {
PendingCreateStream pending_create = create_stream_queues_[i].front();
create_stream_queues_[i].pop();
@@ -1126,7 +1129,7 @@ int SpdySession::GetNewStreamId() {
}
void SpdySession::QueueFrame(SpdyFrame* frame,
- SpdyPriority priority,
+ RequestPriority priority,
SpdyStream* stream) {
int length = SpdyFrame::kHeaderSize + frame->length();
IOBuffer* buffer = new IOBuffer(length);
@@ -1741,7 +1744,7 @@ void SpdySession::SendSettings() {
scoped_ptr<SpdySettingsControlFrame> settings_frame(
buffered_spdy_framer_->CreateSettings(settings_map_new));
sent_settings_ = true;
- QueueFrame(settings_frame.get(), 0, NULL);
+ QueueFrame(settings_frame.get(), HIGHEST, NULL);
}
void SpdySession::HandleSetting(uint32 id, uint32 value) {
@@ -1818,8 +1821,7 @@ void SpdySession::WritePingFrame(uint32 unique_id) {
DCHECK(buffered_spdy_framer_.get());
scoped_ptr<SpdyPingControlFrame> ping_frame(
buffered_spdy_framer_->CreatePingFrame(next_ping_id_));
- QueueFrame(
- ping_frame.get(), buffered_spdy_framer_->GetHighestPriority(), NULL);
+ QueueFrame(ping_frame.get(), HIGHEST, NULL);
if (net_log().IsLoggingAllEvents()) {
net_log().AddEvent(
diff --git a/net/spdy/spdy_session.h b/net/spdy/spdy_session.h
index 68a1a42..7b93171 100644
--- a/net/spdy/spdy_session.h
+++ b/net/spdy/spdy_session.h
@@ -397,7 +397,7 @@ class NET_EXPORT SpdySession : public base::RefCounted<SpdySession>,
// |frame| is the frame to send.
// |priority| is the priority for insertion into the queue.
// |stream| is the stream which this IO is associated with (or NULL).
- void QueueFrame(SpdyFrame* frame, SpdyPriority priority,
+ void QueueFrame(SpdyFrame* frame, RequestPriority priority,
SpdyStream* stream);
// Track active streams in the active stream list.
diff --git a/net/spdy/spdy_session_spdy2_unittest.cc b/net/spdy/spdy_session_spdy2_unittest.cc
index 8afbed2..a4afe3a 100644
--- a/net/spdy/spdy_session_spdy2_unittest.cc
+++ b/net/spdy/spdy_session_spdy2_unittest.cc
@@ -74,36 +74,32 @@ TEST_F(SpdySessionSpdy2Test, SpdyIOBuffer) {
std::priority_queue<SpdyIOBuffer> queue_;
const size_t kQueueSize = 100;
- // Insert 100 items; pri 100 to 1.
+ // Insert items with random priority and increasing buffer size.
for (size_t index = 0; index < kQueueSize; ++index) {
- SpdyIOBuffer buffer(new IOBuffer(), 0, kQueueSize - index, NULL);
- queue_.push(buffer);
+ queue_.push(SpdyIOBuffer(
+ new IOBufferWithSize(index + 1),
+ index + 1,
+ static_cast<RequestPriority>(rand() % NUM_PRIORITIES),
+ NULL));
}
- // Insert several priority 0 items last.
- const size_t kNumDuplicates = 12;
- IOBufferWithSize* buffers[kNumDuplicates];
- for (size_t index = 0; index < kNumDuplicates; ++index) {
- buffers[index] = new IOBufferWithSize(index+1);
- queue_.push(SpdyIOBuffer(buffers[index], buffers[index]->size(), 0, NULL));
- }
-
- EXPECT_EQ(kQueueSize + kNumDuplicates, queue_.size());
+ EXPECT_EQ(kQueueSize, queue_.size());
- // Verify the P0 items come out in FIFO order.
- for (size_t index = 0; index < kNumDuplicates; ++index) {
+ // Verify items come out with decreasing priority or FIFO order.
+ RequestPriority last_priority = NUM_PRIORITIES;
+ size_t last_size = 0;
+ for (size_t index = 0; index < kQueueSize; ++index) {
SpdyIOBuffer buffer = queue_.top();
- EXPECT_EQ(0, buffer.priority());
- EXPECT_EQ(index + 1, buffer.size());
+ EXPECT_LE(buffer.priority(), last_priority);
+ if (buffer.priority() < last_priority)
+ last_size = 0;
+ EXPECT_LT(last_size, buffer.size());
+ last_priority = buffer.priority();
+ last_size = buffer.size();
queue_.pop();
}
- int priority = 1;
- while (queue_.size()) {
- SpdyIOBuffer buffer = queue_.top();
- EXPECT_EQ(priority++, buffer.priority());
- queue_.pop();
- }
+ EXPECT_EQ(0u, queue_.size());
}
TEST_F(SpdySessionSpdy2Test, GoAway) {
diff --git a/net/spdy/spdy_session_spdy3_unittest.cc b/net/spdy/spdy_session_spdy3_unittest.cc
index 3e53ab2..7ac41c3 100644
--- a/net/spdy/spdy_session_spdy3_unittest.cc
+++ b/net/spdy/spdy_session_spdy3_unittest.cc
@@ -74,36 +74,32 @@ TEST_F(SpdySessionSpdy3Test, SpdyIOBuffer) {
std::priority_queue<SpdyIOBuffer> queue_;
const size_t kQueueSize = 100;
- // Insert 100 items; pri 100 to 1.
+ // Insert items with random priority and increasing buffer size
for (size_t index = 0; index < kQueueSize; ++index) {
- SpdyIOBuffer buffer(new IOBuffer(), 0, kQueueSize - index, NULL);
- queue_.push(buffer);
+ queue_.push(SpdyIOBuffer(
+ new IOBufferWithSize(index + 1),
+ index + 1,
+ static_cast<RequestPriority>(rand() % NUM_PRIORITIES),
+ NULL));
}
- // Insert several priority 0 items last.
- const size_t kNumDuplicates = 12;
- IOBufferWithSize* buffers[kNumDuplicates];
- for (size_t index = 0; index < kNumDuplicates; ++index) {
- buffers[index] = new IOBufferWithSize(index+1);
- queue_.push(SpdyIOBuffer(buffers[index], buffers[index]->size(), 0, NULL));
- }
-
- EXPECT_EQ(kQueueSize + kNumDuplicates, queue_.size());
+ EXPECT_EQ(kQueueSize, queue_.size());
- // Verify the P0 items come out in FIFO order.
- for (size_t index = 0; index < kNumDuplicates; ++index) {
+ // Verify items come out with decreasing priority or FIFO order.
+ RequestPriority last_priority = NUM_PRIORITIES;
+ size_t last_size = 0;
+ for (size_t index = 0; index < kQueueSize; ++index) {
SpdyIOBuffer buffer = queue_.top();
- EXPECT_EQ(0, buffer.priority());
- EXPECT_EQ(index + 1, buffer.size());
+ EXPECT_LE(buffer.priority(), last_priority);
+ if (buffer.priority() < last_priority)
+ last_size = 0;
+ EXPECT_LT(last_size, buffer.size());
+ last_priority = buffer.priority();
+ last_size = buffer.size();
queue_.pop();
}
- int priority = 1;
- while (queue_.size()) {
- SpdyIOBuffer buffer = queue_.top();
- EXPECT_EQ(priority++, buffer.priority());
- queue_.pop();
- }
+ EXPECT_EQ(0u, queue_.size());
}
TEST_F(SpdySessionSpdy3Test, GoAway) {
diff --git a/net/spdy/spdy_stream.cc b/net/spdy/spdy_stream.cc
index c8238fc..154cb27 100644
--- a/net/spdy/spdy_stream.cc
+++ b/net/spdy/spdy_stream.cc
@@ -73,7 +73,7 @@ SpdyStream::SpdyStream(SpdySession* session,
const BoundNetLog& net_log)
: continue_buffering_data_(true),
stream_id_(stream_id),
- priority_(0),
+ priority_(HIGHEST),
slot_(0),
stalled_by_flow_control_(false),
send_window_size_(kSpdyStreamInitialWindowSize),
@@ -663,7 +663,7 @@ int SpdyStream::DoSendDomainBoundCert() {
origin.erase(origin.length() - 1); // trim trailing slash
int rv = session_->WriteCredentialFrame(
origin, domain_bound_cert_type_, domain_bound_private_key_,
- domain_bound_cert_, static_cast<RequestPriority>(priority_));
+ domain_bound_cert_, priority_);
if (rv != ERR_IO_PENDING)
return rv;
return OK;
@@ -686,7 +686,7 @@ int SpdyStream::DoSendHeaders() {
CHECK(request_.get());
int result = session_->WriteSynStream(
- stream_id_, static_cast<RequestPriority>(priority_), slot_, flags,
+ stream_id_, priority_, slot_, flags,
request_);
if (result != ERR_IO_PENDING)
return result;
diff --git a/net/spdy/spdy_stream.h b/net/spdy/spdy_stream.h
index 55e8777..5f5ceda 100644
--- a/net/spdy/spdy_stream.h
+++ b/net/spdy/spdy_stream.h
@@ -18,6 +18,7 @@
#include "net/base/io_buffer.h"
#include "net/base/net_export.h"
#include "net/base/net_log.h"
+#include "net/base/request_priority.h"
#include "net/base/server_bound_cert_service.h"
#include "net/base/ssl_client_cert_type.h"
#include "net/base/upload_data.h"
@@ -122,8 +123,8 @@ class NET_EXPORT_PRIVATE SpdyStream
const std::string& path() const { return path_; }
void set_path(const std::string& path) { path_ = path; }
- int priority() const { return priority_; }
- void set_priority(int priority) { priority_ = priority; }
+ RequestPriority priority() const { return priority_; }
+ void set_priority(RequestPriority priority) { priority_ = priority; }
int32 send_window_size() const { return send_window_size_; }
void set_send_window_size(int32 window_size) {
@@ -315,7 +316,7 @@ class NET_EXPORT_PRIVATE SpdyStream
SpdyStreamId stream_id_;
std::string path_;
- int priority_;
+ RequestPriority priority_;
size_t slot_;
// Flow control variables.
diff --git a/net/url_request/url_request.h b/net/url_request/url_request.h
index d73d2fe..ab7e3e1 100644
--- a/net/url_request/url_request.h
+++ b/net/url_request/url_request.h
@@ -572,7 +572,7 @@ class NET_EXPORT URLRequest : NON_EXPORTED_BASE(public base::NonThreadSafe),
// Returns the priority level for this request.
RequestPriority priority() const { return priority_; }
void set_priority(RequestPriority priority) {
- DCHECK_GE(priority, HIGHEST);
+ DCHECK_GE(priority, MINIMUM_PRIORITY);
DCHECK_LT(priority, NUM_PRIORITIES);
priority_ = priority;
}