Commit 33aff669 authored by Ryan Hamilton's avatar Ryan Hamilton Committed by Commit Bot

Change Http2PriorityDependencies::DependencyUpdate to include weight

so that callers do not have to compute it.

Change-Id: I6b9270073337c9a5827fadc6eefe169e057e43d1
Reviewed-on: https://chromium-review.googlesource.com/917330
Commit-Queue: Ryan Hamilton <rch@chromium.org>
Reviewed-by: default avatarRandy Smith <rdsmith@chromium.org>
Cr-Commit-Position: refs/heads/master@{#537549}
parent 778f6c1e
...@@ -910,11 +910,7 @@ void QuicChromiumClientSession::UpdateStreamPriority( ...@@ -910,11 +910,7 @@ void QuicChromiumClientSession::UpdateStreamPriority(
if (headers_include_h2_stream_dependency_) { if (headers_include_h2_stream_dependency_) {
auto updates = priority_dependency_state_.OnStreamUpdate(id, new_priority); auto updates = priority_dependency_state_.OnStreamUpdate(id, new_priority);
for (auto update : updates) { for (auto update : updates) {
QuicSpdyStream* stream = GetSpdyDataStream(update.id); WritePriority(update.id, update.parent_stream_id, update.weight,
DCHECK(stream);
int weight =
Spdy3PriorityToHttp2Weight(stream->QuicSpdyStream::priority());
WritePriority(update.id, update.parent_stream_id, weight,
update.exclusive); update.exclusive);
} }
} }
......
...@@ -135,18 +135,20 @@ Http2PriorityDependencies::OnStreamUpdate(SpdyStreamId id, ...@@ -135,18 +135,20 @@ Http2PriorityDependencies::OnStreamUpdate(SpdyStreamId id,
// |old_parent|. // |old_parent|.
IdList::iterator old_child; IdList::iterator old_child;
if (ChildOfStream(id, &old_child)) { if (ChildOfStream(id, &old_child)) {
int weight = Spdy3PriorityToHttp2Weight(old_child->second);
if (old_has_parent) { if (old_has_parent) {
result.push_back({old_child->first, old_parent->first, true}); result.push_back({old_child->first, old_parent->first, weight, true});
} else { } else {
result.push_back({old_child->first, 0, true}); result.push_back({old_child->first, 0, weight, true});
} }
} }
int weight = Spdy3PriorityToHttp2Weight(new_priority);
// |id| moves to be dependent on |new_parent|. // |id| moves to be dependent on |new_parent|.
if (new_has_parent) { if (new_has_parent) {
result.push_back({id, new_parent->first, true}); result.push_back({id, new_parent->first, weight, true});
} else { } else {
result.push_back({id, 0, true}); result.push_back({id, 0, weight, true});
} }
} }
......
...@@ -45,6 +45,7 @@ class NET_EXPORT_PRIVATE Http2PriorityDependencies { ...@@ -45,6 +45,7 @@ class NET_EXPORT_PRIVATE Http2PriorityDependencies {
struct DependencyUpdate { struct DependencyUpdate {
SpdyStreamId id; SpdyStreamId id;
SpdyStreamId parent_stream_id; SpdyStreamId parent_stream_id;
int weight;
bool exclusive; bool exclusive;
}; };
......
...@@ -16,14 +16,14 @@ namespace net { ...@@ -16,14 +16,14 @@ namespace net {
bool operator==(const Http2PriorityDependencies::DependencyUpdate& a, bool operator==(const Http2PriorityDependencies::DependencyUpdate& a,
const Http2PriorityDependencies::DependencyUpdate& b) { const Http2PriorityDependencies::DependencyUpdate& b) {
return a.id == b.id && a.parent_stream_id == b.parent_stream_id && return a.id == b.id && a.parent_stream_id == b.parent_stream_id &&
a.exclusive == b.exclusive; a.weight == b.weight && a.exclusive == b.exclusive;
} }
std::ostream& operator<<( std::ostream& operator<<(
std::ostream& os, std::ostream& os,
const std::vector<Http2PriorityDependencies::DependencyUpdate>& v) { const std::vector<Http2PriorityDependencies::DependencyUpdate>& v) {
for (auto e : v) { for (auto e : v) {
os << "{" << e.id << "," << e.parent_stream_id << "," os << "{" << e.id << "," << e.parent_stream_id << "," << e.weight << ","
<< (e.exclusive ? "true" : "false") << "}"; << (e.exclusive ? "true" : "false") << "}";
} }
return os; return os;
...@@ -67,6 +67,7 @@ class HttpPriorityDependencyTest : public PlatformTest { ...@@ -67,6 +67,7 @@ class HttpPriorityDependencyTest : public PlatformTest {
struct ExpectedDependencyUpdate { struct ExpectedDependencyUpdate {
SpdyStreamId id; SpdyStreamId id;
SpdyStreamId parent_id; SpdyStreamId parent_id;
int weight;
}; };
void TestStreamUpdate(SpdyStreamId id, void TestStreamUpdate(SpdyStreamId id,
...@@ -75,7 +76,8 @@ class HttpPriorityDependencyTest : public PlatformTest { ...@@ -75,7 +76,8 @@ class HttpPriorityDependencyTest : public PlatformTest {
auto value = dependency_state_.OnStreamUpdate(id, new_priority); auto value = dependency_state_.OnStreamUpdate(id, new_priority);
std::vector<Http2PriorityDependencies::DependencyUpdate> expected_value; std::vector<Http2PriorityDependencies::DependencyUpdate> expected_value;
for (auto e : expected) { for (auto e : expected) {
expected_value.push_back({e.id, e.parent_id, true /* exclusive */}); expected_value.push_back(
{e.id, e.parent_id, e.weight, true /* exclusive */});
} }
if (value != expected_value) { if (value != expected_value) {
ADD_FAILURE() << "OnStreamUpdate(" << id << ", " << int(new_priority) ADD_FAILURE() << "OnStreamUpdate(" << id << ", " << int(new_priority)
...@@ -210,6 +212,10 @@ TEST_F(HttpPriorityDependencyTest, UpdateThreeStreams) { ...@@ -210,6 +212,10 @@ TEST_F(HttpPriorityDependencyTest, UpdateThreeStreams) {
TestStreamCreation(second_id, MEDIUM, first_id); TestStreamCreation(second_id, MEDIUM, first_id);
TestStreamCreation(third_id, LOWEST, second_id); TestStreamCreation(third_id, LOWEST, second_id);
const int highest_weight = Spdy3PriorityToHttp2Weight(HIGHEST);
const int medium_weight = Spdy3PriorityToHttp2Weight(MEDIUM);
const int lowest_weight = Spdy3PriorityToHttp2Weight(LOWEST);
std::vector<ExpectedDependencyUpdate> empty; std::vector<ExpectedDependencyUpdate> empty;
// no-op: still at top. // no-op: still at top.
...@@ -222,16 +228,22 @@ TEST_F(HttpPriorityDependencyTest, UpdateThreeStreams) { ...@@ -222,16 +228,22 @@ TEST_F(HttpPriorityDependencyTest, UpdateThreeStreams) {
TestStreamUpdate(third_id, LOWEST, empty); TestStreamUpdate(third_id, LOWEST, empty);
// second moves to top, first moves below second. // second moves to top, first moves below second.
TestStreamUpdate(first_id, MEDIUM, {{second_id, 0}, {first_id, second_id}}); TestStreamUpdate(
first_id, MEDIUM,
{{second_id, 0, medium_weight}, {first_id, second_id, medium_weight}});
// third moves to top. // third moves to top.
TestStreamUpdate(third_id, HIGHEST, {{third_id, 0}}); TestStreamUpdate(third_id, HIGHEST, {{third_id, 0, highest_weight}});
// third moves to bottom. // third moves to bottom.
TestStreamUpdate(third_id, LOWEST, {{second_id, 0}, {third_id, first_id}}); TestStreamUpdate(
third_id, LOWEST,
{{second_id, 0, medium_weight}, {third_id, first_id, lowest_weight}});
// first moves to top. // first moves to top.
TestStreamUpdate(first_id, HIGHEST, {{third_id, second_id}, {first_id, 0}}); TestStreamUpdate(
first_id, HIGHEST,
{{third_id, second_id, lowest_weight}, {first_id, 0, highest_weight}});
} }
// A more complex example parallel to a simple web page with pushed responses. // A more complex example parallel to a simple web page with pushed responses.
...@@ -252,15 +264,20 @@ TEST_F(HttpPriorityDependencyTest, UpdateComplex) { ...@@ -252,15 +264,20 @@ TEST_F(HttpPriorityDependencyTest, UpdateComplex) {
TestStreamCreation(sixth_id, MEDIUM, fifth_id); TestStreamCreation(sixth_id, MEDIUM, fifth_id);
TestStreamCreation(seventh_id, LOW, sixth_id); TestStreamCreation(seventh_id, LOW, sixth_id);
const int highest_weight = Spdy3PriorityToHttp2Weight(HIGHEST);
const int medium_weight = Spdy3PriorityToHttp2Weight(MEDIUM);
const int lowest_weight = Spdy3PriorityToHttp2Weight(LOWEST);
// second matches a HIGHEST priority response. // second matches a HIGHEST priority response.
// 3 moves under 7 // 3 moves under 7
// 2 moves under 4 // 2 moves under 4
TestStreamUpdate(second_id, HIGHEST, TestStreamUpdate(second_id, HIGHEST,
{{third_id, seventh_id}, {second_id, fourth_id}}); {{third_id, seventh_id, lowest_weight},
{second_id, fourth_id, highest_weight}});
// third matches a MEDIUM priority response. // third matches a MEDIUM priority response.
// 3 moves under 6 // 3 moves under 6
TestStreamUpdate(third_id, MEDIUM, {{third_id, sixth_id}}); TestStreamUpdate(third_id, MEDIUM, {{third_id, sixth_id, medium_weight}});
} }
} // namespace net } // namespace net
...@@ -866,9 +866,7 @@ int SpdySession::GetPushedStream(const GURL& url, ...@@ -866,9 +866,7 @@ int SpdySession::GetPushedStream(const GURL& url,
for (auto u : updates) { for (auto u : updates) {
ActiveStreamMap::iterator it = active_streams_.find(u.id); ActiveStreamMap::iterator it = active_streams_.find(u.id);
DCHECK(it != active_streams_.end()); DCHECK(it != active_streams_.end());
int weight = Spdy3PriorityToHttp2Weight( EnqueuePriorityFrame(u.id, u.parent_stream_id, u.weight, u.exclusive);
ConvertRequestPriorityToSpdyPriority(it->second->priority()));
EnqueuePriorityFrame(u.id, u.parent_stream_id, weight, u.exclusive);
} }
return OK; return OK;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment