Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Side by Side Diff: net/spdy/http2_priority_dependencies.cc

Issue 1779733003: Fix bug in net::RequestPriority -> HTTP/2 dependency conversion. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "net/spdy/http2_priority_dependencies.h"
6
7 #include "base/metrics/field_trial.h"
8
9 namespace net {
10
11 // Field trial constants
12 const char kSpdyDependenciesFieldTrial[] = "SpdyEnableDependencies";
13 const char kSpdyDepencenciesFieldTrialDisable[] = "Disable";
14
15 // Whether the creation of SPDY dependencies based on priority is
16 // enabled by default.
17 static bool priority_dependency_enabled_default = true;
18
19 Http2PriorityDependencies::Http2PriorityDependencies()
20 : enabled_(priority_dependency_enabled_default) {
21 if (base::FieldTrialList::FindFullName(kSpdyDependenciesFieldTrial) ==
22 kSpdyDepencenciesFieldTrialDisable) {
23 enabled_ = false;
24 }
25 }
26
27 Http2PriorityDependencies::~Http2PriorityDependencies() {}
28
29 bool Http2PriorityDependencies::SetEnabledDefaultForTesting(bool enabled) {
30 bool result = priority_dependency_enabled_default;
31 priority_dependency_enabled_default = enabled;
32 return result;
33 }
34
35 void Http2PriorityDependencies::OnStreamSynSent(
36 SpdyStreamId id,
37 RequestPriority priority,
38 SpdyStreamId* dependent_stream_id,
39 bool* exclusive) {
40 if (!enabled_) {
41 *dependent_stream_id = 0;
42 *exclusive = false;
43 return;
44 }
45
46 DCHECK(entry_by_stream_id_.end() == entry_by_stream_id_.find(id));
Bence 2016/03/10 20:21:13 I'm not sure it is customary to use Yoda condition
Randy Smith (Not in Mondays) 2016/03/16 19:38:10 I've seen at least one tear on chromium-dev suppor
47
48 *dependent_stream_id = 0ul;
49 *exclusive = true;
50
51 // Find the next highest entry in total order.
52 for (int i = priority; i <= HIGHEST; ++i) {
53 if (!id_priority_lists_[i].empty()) {
54 *dependent_stream_id = id_priority_lists_[i].back().first;
55 break;
56 }
57 }
58
59 id_priority_lists_[priority].push_back(std::make_pair(id, priority));
60 IdList::iterator it = id_priority_lists_[priority].end();
61 entry_by_stream_id_[id] = --it;
Bence 2016/03/10 20:21:13 Nit: use back instead of end-1.
Randy Smith (Not in Mondays) 2016/03/16 19:38:10 The problem with back() is that it returns the ent
Bence 2016/03/17 01:48:59 Sorry, I missed that. Okay.
62 }
63
64 void Http2PriorityDependencies::OnStreamDestruction(SpdyStreamId id) {
65 if (!enabled_)
66 return;
67
68 EntryMap::iterator emit = entry_by_stream_id_.find(id);
69
70 // This routine may be called without a matching call to
71 // OnStreamSynSent above, in the case of server push. In that case,
72 // it's a no-op.
73 if (emit == entry_by_stream_id_.end())
74 return;
Bence 2016/03/10 20:21:13 Nit: add empty line after return.
Randy Smith (Not in Mondays) 2016/03/16 19:38:10 Done.
75 id_priority_lists_[emit->second->second].erase(emit->second);
Bence 2016/03/10 20:21:14 Optional: |IdList::iterator it = emit->second| for
Randy Smith (Not in Mondays) 2016/03/16 19:38:10 Done.
76 entry_by_stream_id_.erase(emit);
77 }
78
79 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698