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

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

Issue 13009012: [SPDY] Refactor SpdySession's write queue (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix gyp error Created 7 years, 8 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2013 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/spdy_write_queue.h"
6
7 #include <cstddef>
8
9 #include "base/logging.h"
10 #include "net/spdy/spdy_stream.h"
11
12 namespace net {
13
14 SpdyFrameProducer::SpdyFrameProducer() {}
15
16 SpdyFrameProducer::~SpdyFrameProducer() {}
17
18 SimpleFrameProducer::SimpleFrameProducer(scoped_ptr<SpdyFrame> frame)
19 : frame_(frame.Pass()) {}
20
21 SimpleFrameProducer::~SimpleFrameProducer() {}
22
23 scoped_ptr<SpdyFrame> SimpleFrameProducer::ProduceFrame() {
24 DCHECK(frame_);
25 return frame_.Pass();
26 }
27
28 SpdyWriteQueue::PendingWrite::PendingWrite() : frame_producer(NULL) {}
29
30 SpdyWriteQueue::PendingWrite::PendingWrite(
31 SpdyFrameProducer* frame_producer,
32 const scoped_refptr<SpdyStream>& stream)
33 : frame_producer(frame_producer),
34 stream(stream) {}
35
36 SpdyWriteQueue::PendingWrite::~PendingWrite() {}
37
38 SpdyWriteQueue::SpdyWriteQueue() {}
39
40 SpdyWriteQueue::~SpdyWriteQueue() {
41 Clear();
42 }
43
44 void SpdyWriteQueue::Enqueue(RequestPriority priority,
45 scoped_ptr<SpdyFrameProducer> frame_producer,
46 const scoped_refptr<SpdyStream>& stream) {
47 if (stream.get()) {
48 DCHECK_EQ(stream->priority(), priority);
Ryan Hamilton 2013/03/28 15:51:04 alternatively, you could have two Enqueue methods,
akalin 2013/04/06 01:17:48 Eh, I think a single Enqueue is simpler. Added a c
49 }
50 queue_[priority].push_back(PendingWrite(frame_producer.release(), stream));
51 }
52
53 bool SpdyWriteQueue::Dequeue(scoped_ptr<SpdyFrameProducer>* frame_producer,
54 scoped_refptr<SpdyStream>* stream) {
55 for (int i = NUM_PRIORITIES - 1; i >= 0; --i) {
56 if (!queue_[i].empty()) {
Ryan Hamilton 2013/03/28 15:51:04 nit: I think I would write this as: if (queue_[i].
akalin 2013/04/06 01:17:48 The thing is, I think that's more confusing becaus
57 PendingWrite pending_write = queue_[i].front();
58 queue_[i].pop_front();
59 frame_producer->reset(pending_write.frame_producer);
60 *stream = pending_write.stream;
61 return true;
62 }
63 }
64 return false;
65 }
66
67 void SpdyWriteQueue::RemovePendingWritesForStream(
68 const scoped_refptr<SpdyStream>& stream) {
69 DCHECK(stream.get());
70 if (DCHECK_IS_ON()) {
71 // |stream| should not have pending writes in a queue not matching
72 // its priority.
73 for (int i = 0; i < NUM_PRIORITIES; ++i) {
74 if (stream->priority() == i)
75 continue;
76 for (std::deque<PendingWrite>::const_iterator it = queue_[i].begin();
77 it != queue_[i].end(); ++it) {
78 DCHECK_NE(it->stream, stream);
79 }
80 }
81 }
82
83 std::deque<PendingWrite> old_queue;
84 old_queue.swap(queue_[stream->priority()]);
85
86 for (std::deque<PendingWrite>::const_iterator it = old_queue.begin();
87 it != old_queue.end(); ++it) {
88 if (it->stream == stream) {
89 delete it->frame_producer;
90 } else {
91 queue_[stream->priority()].push_back(*it);
Ryan Hamilton 2013/03/28 15:51:04 It looks like deque support an erase() method whic
akalin 2013/04/06 01:17:48 It does have erase(), but it's O(distance from end
Ryan Hamilton 2013/04/08 16:17:14 Good to know! I'm unfamiliar with the internal li
92 }
93 }
94 }
95
96 void SpdyWriteQueue::Clear() {
97 for (int i = 0; i < NUM_PRIORITIES; ++i) {
98 for (std::deque<PendingWrite>::iterator it = queue_[i].begin();
99 it != queue_[i].end(); ++it) {
100 delete it->frame_producer;
101 }
102 queue_[i].clear();
103 }
104 }
105
106 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698