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

Side by Side Diff: net/spdy/write_scheduler.h

Issue 2832973003: Split net/spdy into core and chromium subdirectories. (Closed)
Patch Set: Fix some more build rules. Created 3 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
« no previous file with comments | « net/spdy/spdy_write_queue_unittest.cc ('k') | net/spdy/zero_copy_output_buffer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 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 #ifndef NET_SPDY_WRITE_SCHEDULER_H_
6 #define NET_SPDY_WRITE_SCHEDULER_H_
7
8 #include <tuple>
9 #include <vector>
10
11 #include "net/base/net_export.h"
12 #include "net/spdy/spdy_protocol.h"
13
14 namespace net {
15
16 // Abstract superclass for classes that decide which SPDY or HTTP/2 stream to
17 // write next. Concrete subclasses implement various scheduling policies:
18 //
19 // PriorityWriteScheduler: implements SPDY priority-based stream scheduling,
20 // where (writable) higher-priority streams are always given precedence
21 // over lower-priority streams.
22 //
23 // Http2PriorityWriteScheduler: implements SPDY priority-based stream
24 // scheduling coupled with the HTTP/2 stream dependency model. This is only
25 // intended as a transitional step towards Http2WeightedWriteScheduler.
26 //
27 // Http2WeightedWriteScheduler (coming soon): implements the HTTP/2 stream
28 // dependency model with weighted stream scheduling, fully conforming to
29 // RFC 7540.
30 //
31 // The type used to represent stream IDs (StreamIdType) is templated in order
32 // to allow for use by both SPDY and QUIC codebases. It must be a POD that
33 // supports comparison (i.e., a numeric type).
34 //
35 // Each stream can be in one of two states: ready or not ready (for writing).
36 // Ready state is changed by calling the MarkStreamReady() and
37 // MarkStreamNotReady() methods. Only streams in the ready state can be
38 // returned by PopNextReadyStream(); when returned by that method, the stream's
39 // state changes to not ready.
40 template <typename StreamIdType>
41 class NET_EXPORT_PRIVATE WriteScheduler {
42 public:
43 typedef StreamPrecedence<StreamIdType> StreamPrecedenceType;
44
45 virtual ~WriteScheduler() {}
46
47 // Registers new stream |stream_id| with the scheduler, assigning it the
48 // given precedence. If the scheduler supports stream dependencies, the
49 // stream is inserted into the dependency tree under
50 // |precedence.parent_id()|.
51 //
52 // Preconditions: |stream_id| should be unregistered, and
53 // |precedence.parent_id()| should be registered or |kHttp2RootStreamId|.
54 virtual void RegisterStream(StreamIdType stream_id,
55 const StreamPrecedenceType& precedence) = 0;
56
57 // Unregisters the given stream from the scheduler, which will no longer keep
58 // state for it.
59 //
60 // Preconditions: |stream_id| should be registered.
61 virtual void UnregisterStream(StreamIdType stream_id) = 0;
62
63 // Returns true if the given stream is currently registered.
64 virtual bool StreamRegistered(StreamIdType stream_id) const = 0;
65
66 // Returns the precedence of the specified stream. If the scheduler supports
67 // stream dependencies, calling |parent_id()| on the return value returns the
68 // stream's parent, and calling |exclusive()| returns true iff the specified
69 // stream is an only child of the parent stream.
70 //
71 // Preconditions: |stream_id| should be registered.
72 virtual StreamPrecedenceType GetStreamPrecedence(
73 StreamIdType stream_id) const = 0;
74
75 // Updates the precedence of the given stream. If the scheduler supports
76 // stream dependencies, |stream_id|'s parent will be updated to be
77 // |precedence.parent_id()| if it is not already.
78 //
79 // Preconditions: |stream_id| should be unregistered, and
80 // |precedence.parent_id()| should be registered or |kHttp2RootStreamId|.
81 virtual void UpdateStreamPrecedence(
82 StreamIdType stream_id,
83 const StreamPrecedenceType& precedence) = 0;
84
85 // Returns child streams of the given stream, if any. If the scheduler
86 // doesn't support stream dependencies, returns an empty vector.
87 //
88 // Preconditions: |stream_id| should be registered.
89 virtual std::vector<StreamIdType> GetStreamChildren(
90 StreamIdType stream_id) const = 0;
91
92 // Records time (in microseconds) of a read/write event for the given
93 // stream.
94 //
95 // Preconditions: |stream_id| should be registered.
96 virtual void RecordStreamEventTime(StreamIdType stream_id,
97 int64_t now_in_usec) = 0;
98
99 // Returns time (in microseconds) of the last read/write event for a stream
100 // with higher priority than the priority of the given stream, or 0 if there
101 // is no such event.
102 //
103 // Preconditions: |stream_id| should be registered.
104 virtual int64_t GetLatestEventWithPrecedence(
105 StreamIdType stream_id) const = 0;
106
107 // If the scheduler has any ready streams, returns the next scheduled
108 // ready stream, in the process transitioning the stream from ready to not
109 // ready.
110 //
111 // Preconditions: |HasReadyStreams() == true|
112 virtual StreamIdType PopNextReadyStream() = 0;
113
114 // If the scheduler has any ready streams, returns the next scheduled
115 // ready stream and its priority, in the process transitioning the stream from
116 // ready to not ready.
117 //
118 // Preconditions: |HasReadyStreams() == true|
119 virtual std::tuple<StreamIdType, StreamPrecedenceType>
120 PopNextReadyStreamAndPrecedence() = 0;
121
122 // Returns true if there's another stream ahead of the given stream in the
123 // scheduling queue. This function can be called to see if the given stream
124 // should yield work to another stream.
125 //
126 // Preconditions: |stream_id| should be registered.
127 virtual bool ShouldYield(StreamIdType stream_id) const = 0;
128
129 // Marks the stream as ready to write. If the stream was already ready, does
130 // nothing. If add_to_front is true, the stream is scheduled ahead of other
131 // streams of the same priority/weight, otherwise it is scheduled behind them.
132 //
133 // Preconditions: |stream_id| should be registered.
134 virtual void MarkStreamReady(StreamIdType stream_id, bool add_to_front) = 0;
135
136 // Marks the stream as not ready to write. If the stream is not registered or
137 // not ready, does nothing.
138 //
139 // Preconditions: |stream_id| should be registered.
140 virtual void MarkStreamNotReady(StreamIdType stream_id) = 0;
141
142 // Returns true iff the scheduler has any ready streams.
143 virtual bool HasReadyStreams() const = 0;
144
145 // Returns the number of streams currently marked ready.
146 virtual size_t NumReadyStreams() const = 0;
147 };
148
149 } // namespace net
150
151 #endif // NET_SPDY_WRITE_SCHEDULER_H_
OLDNEW
« no previous file with comments | « net/spdy/spdy_write_queue_unittest.cc ('k') | net/spdy/zero_copy_output_buffer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698