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

Side by Side Diff: third_party/WebKit/Source/modules/fetch/BytesConsumer.h

Issue 2269953004: Implment BytesConsumer::tee (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix Created 4 years, 3 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
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef BytesConsumer_h 5 #ifndef BytesConsumer_h
6 #define BytesConsumer_h 6 #define BytesConsumer_h
7 7
8 #include "modules/ModulesExport.h" 8 #include "modules/ModulesExport.h"
9 #include "platform/blob/BlobData.h" 9 #include "platform/blob/BlobData.h"
10 #include "platform/heap/Handle.h" 10 #include "platform/heap/Handle.h"
11 #include "platform/network/EncodedFormData.h" 11 #include "platform/network/EncodedFormData.h"
12 #include "wtf/PassRefPtr.h" 12 #include "wtf/PassRefPtr.h"
13 #include "wtf/text/WTFString.h" 13 #include "wtf/text/WTFString.h"
14 14
15 namespace blink { 15 namespace blink {
16 16
17 class ExecutionContext;
18
17 // BytesConsumer represents the "consumer" side of a data pipe. A user 19 // BytesConsumer represents the "consumer" side of a data pipe. A user
18 // can read data from it. 20 // can read data from it.
19 // 21 //
20 // A BytesConsumer is bound to the thread on which it is created. 22 // A BytesConsumer is bound to the thread on which it is created.
21 // BytesConsumer has four states: waiting, readable, closed and errored. Once 23 // BytesConsumer has four states: waiting, readable, closed and errored. Once
22 // the state becomes closed or errored, it will never change. |readable| means 24 // the state becomes closed or errored, it will never change. |readable| means
23 // that the BytesConsumer is ready to read non-empty bytes synchronously. 25 // that the BytesConsumer is ready to read non-empty bytes synchronously.
24 class MODULES_EXPORT BytesConsumer : public GarbageCollectedFinalized<BytesConsu mer> { 26 class MODULES_EXPORT BytesConsumer : public GarbageCollectedFinalized<BytesConsu mer> {
25 public: 27 public:
26 enum class Result { 28 enum class Result {
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 86
85 // Begins a two-phase read. On success, the function stores a buffer 87 // Begins a two-phase read. On success, the function stores a buffer
86 // that contains the read data of length |*available| into |*buffer|. 88 // that contains the read data of length |*available| into |*buffer|.
87 // Returns Ok when readable. 89 // Returns Ok when readable.
88 // Returns ShouldWait when it's waiting. 90 // Returns ShouldWait when it's waiting.
89 // Returns Done when it's closed. 91 // Returns Done when it's closed.
90 // Returns Error when errored. 92 // Returns Error when errored.
91 // When not readable, the caller don't have to (and must not) call 93 // When not readable, the caller don't have to (and must not) call
92 // endRead, because the read session implicitly ends in that case. 94 // endRead, because the read session implicitly ends in that case.
93 // 95 //
96 // |*buffer| will become invalid when this object becomes unreachable,
97 // even if endRead is not called.
98 //
94 // |*buffer| will be set to null and |*available| will be set to 0 if not 99 // |*buffer| will be set to null and |*available| will be set to 0 if not
95 // readable. 100 // readable.
96 virtual Result beginRead(const char** buffer, size_t* available) = 0; 101 virtual Result beginRead(const char** buffer, size_t* available) = 0;
97 102
98 // Ends a two-phase read. 103 // Ends a two-phase read.
99 virtual Result endRead(size_t readSize) = 0; 104 virtual Result endRead(size_t readSize) = 0;
100 105
101 // Drains the data as a BlobDataHandle. 106 // Drains the data as a BlobDataHandle.
102 // When this function returns a non-null value, the returned blob handle 107 // When this function returns a non-null value, the returned blob handle
103 // contains bytes that would be read through read, beginRead and 108 // contains bytes that would be read through read, beginRead and
104 // endRead functions without calling this function. In such a case, this 109 // endRead functions without calling this function. In such a case, this
105 // object becomes closed. 110 // object becomes closed.
106 // When this function returns null value, this function does nothing. 111 // When this function returns null value, this function does nothing.
107 // When |policy| is DisallowBlobWithInvalidSize, this function doesn't 112 // When |policy| is DisallowBlobWithInvalidSize, this function doesn't
108 // return a non-null blob handle with unspecified size. 113 // return a non-null blob handle with unspecified size.
109 // The type of the returned blob handle may not be meaningful. 114 // The type of the returned blob handle may not be meaningful.
110 virtual PassRefPtr<BlobDataHandle> drainAsBlobDataHandle(BlobSizePolicy = Bl obSizePolicy::DisallowBlobWithInvalidSize) { return nullptr; } 115 virtual PassRefPtr<BlobDataHandle> drainAsBlobDataHandle(BlobSizePolicy = Bl obSizePolicy::DisallowBlobWithInvalidSize) { return nullptr; }
111 116
112 // Drains the data as an EncodedFormData. 117 // Drains the data as an EncodedFormData.
113 // When this function returns a non-null value, the returned form data 118 // When this function returns a non-null value, the returned form data
114 // contains bytes that would be read through read, beginRead and 119 // contains bytes that would be read through read, beginRead and
115 // endRead functions without calling this function. In such a case, this 120 // endRead functions without calling this function. In such a case, this
116 // object becomes closed. 121 // object becomes closed.
117 // When this function returns null value, this function does nothing. 122 // When this function returns null value, this function does nothing.
118 // This function returns a non-null form data when the handle is made 123 // This function returns a non-null form data when the handle is made
119 // from an EncodedFormData-convertible value. 124 // from an EncodedFormData-convertible value.
120 virtual PassRefPtr<EncodedFormData> drainAsFormData() { return nullptr; } 125 virtual PassRefPtr<EncodedFormData> drainAsFormData() { return nullptr; }
121 126
122 // Sets a client. 127 // Sets a client. This can be called only when no client is set. When
128 // this object is already closed or errored, this function does nothing.
123 virtual void setClient(Client*) = 0; 129 virtual void setClient(Client*) = 0;
124 // Clears the set client. This can be called only when a client is set. 130 // Clears the set client.
131 // A client will be implicitly cleared when this object gets closed or
132 // errored (after the state change itself is notified).
125 virtual void clearClient() = 0; 133 virtual void clearClient() = 0;
126 134
127 // Cancels this ByteConsumer. This function does nothing when |this| is 135 // Cancels this ByteConsumer. This function does nothing when |this| is
128 // already closed or errored. Otherwise, this object becomes closed. 136 // already closed or errored. Otherwise, this object becomes closed.
137 // This function cannot be called in a two-phase read.
129 virtual void cancel() = 0; 138 virtual void cancel() = 0;
130 139
131 // Returns the current state. 140 // Returns the current state.
132 virtual PublicState getPublicState() const = 0; 141 virtual PublicState getPublicState() const = 0;
133 142
134 // Returns the associated error of this object. This function can be called 143 // Returns the associated error of this object. This function can be called
135 // only when errored. 144 // only when errored.
136 virtual Error getError() const = 0; 145 virtual Error getError() const = 0;
137 146
138 // Each implementation should return a string that represents the 147 // Each implementation should return a string that represents the
139 // implementation for debug purpose. 148 // implementation for debug purpose.
140 virtual String debugName() const = 0; 149 virtual String debugName() const = 0;
141 150
151 // Creates two BytesConsumer both of which represent the data sequence that
152 // would be read from |src| and store them to |*dest1| and |*dest2|.
153 // |src| must not have a client when called.
154 static void tee(ExecutionContext*, BytesConsumer* src, BytesConsumer** dest1 , BytesConsumer** dest2);
155
142 DEFINE_INLINE_VIRTUAL_TRACE() {} 156 DEFINE_INLINE_VIRTUAL_TRACE() {}
143 157
144 protected: 158 protected:
145 // This InternalState directly corresponds to the states in the class 159 // This InternalState directly corresponds to the states in the class
146 // comments. This enum is defined here for subclasses. 160 // comments. This enum is defined here for subclasses.
147 enum class InternalState { 161 enum class InternalState {
148 Readable, 162 Readable,
149 Waiting, 163 Waiting,
150 Closed, 164 Closed,
151 Errored, 165 Errored,
(...skipping 11 matching lines...) Expand all
163 return PublicState::Errored; 177 return PublicState::Errored;
164 } 178 }
165 NOTREACHED(); 179 NOTREACHED();
166 return PublicState::ReadableOrWaiting; 180 return PublicState::ReadableOrWaiting;
167 } 181 }
168 }; 182 };
169 183
170 } // namespace blink 184 } // namespace blink
171 185
172 #endif // BytesConsumer_h 186 #endif // BytesConsumer_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698