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

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

Issue 2392823002: Remove create[Done|UnexpectedError]DataConsumerHandle (Closed)
Patch Set: fix Created 4 years, 2 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 #include "modules/fetch/BytesConsumer.h" 5 #include "modules/fetch/BytesConsumer.h"
6 6
7 #include "core/dom/ExecutionContext.h" 7 #include "core/dom/ExecutionContext.h"
8 #include "core/dom/TaskRunnerHelper.h" 8 #include "core/dom/TaskRunnerHelper.h"
9 #include "modules/fetch/BlobBytesConsumer.h" 9 #include "modules/fetch/BlobBytesConsumer.h"
10 #include "platform/blob/BlobData.h" 10 #include "platform/blob/BlobData.h"
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 m_destination2->clearChunks(); 291 m_destination2->clearChunks();
292 m_destination1->notify(); 292 m_destination1->notify();
293 m_destination2->notify(); 293 m_destination2->notify();
294 } 294 }
295 295
296 Member<BytesConsumer> m_src; 296 Member<BytesConsumer> m_src;
297 Member<Destination> m_destination1; 297 Member<Destination> m_destination1;
298 Member<Destination> m_destination2; 298 Member<Destination> m_destination2;
299 }; 299 };
300 300
301 class ErroredBytesConsumer final : public BytesConsumer {
302 public:
303 explicit ErroredBytesConsumer(const Error& error) : m_error(error) {}
304
305 Result beginRead(const char** buffer, size_t* available) override {
306 *buffer = nullptr;
307 *available = 0;
308 return Result::Error;
309 }
310 Result endRead(size_t readSize) override {
311 NOTREACHED();
312 return Result::Error;
313 }
314 void setClient(BytesConsumer::Client*) override {}
315 void clearClient() override {}
316
317 void cancel() override {}
318 PublicState getPublicState() const override { return PublicState::Errored; }
319 Error getError() const override { return m_error; }
320 String debugName() const override { return "ErroredBytesConsumer"; }
321
322 private:
323 const Error m_error;
324 };
325
326 class ClosedBytesConsumer final : public BytesConsumer {
327 public:
328 Result beginRead(const char** buffer, size_t* available) override {
329 *buffer = nullptr;
330 *available = 0;
331 return Result::Done;
332 }
333 Result endRead(size_t readSize) override {
334 NOTREACHED();
335 return Result::Error;
336 }
337 void setClient(BytesConsumer::Client*) override {}
338 void clearClient() override {}
339
340 void cancel() override {}
341 PublicState getPublicState() const override { return PublicState::Closed; }
342 Error getError() const override {
343 NOTREACHED();
344 return Error();
345 }
346 String debugName() const override { return "ClosedBytesConsumer"; }
347 };
348
301 } // namespace 349 } // namespace
302 350
303 void BytesConsumer::tee(ExecutionContext* executionContext, 351 void BytesConsumer::tee(ExecutionContext* executionContext,
304 BytesConsumer* src, 352 BytesConsumer* src,
305 BytesConsumer** dest1, 353 BytesConsumer** dest1,
306 BytesConsumer** dest2) { 354 BytesConsumer** dest2) {
307 RefPtr<BlobDataHandle> blobDataHandle = 355 RefPtr<BlobDataHandle> blobDataHandle =
308 src->drainAsBlobDataHandle(BlobSizePolicy::AllowBlobWithInvalidSize); 356 src->drainAsBlobDataHandle(BlobSizePolicy::AllowBlobWithInvalidSize);
309 if (blobDataHandle) { 357 if (blobDataHandle) {
310 // Register a client in order to be consistent. 358 // Register a client in order to be consistent.
311 src->setClient(new NoopClient); 359 src->setClient(new NoopClient);
312 *dest1 = new BlobBytesConsumer(executionContext, blobDataHandle); 360 *dest1 = new BlobBytesConsumer(executionContext, blobDataHandle);
313 *dest2 = new BlobBytesConsumer(executionContext, blobDataHandle); 361 *dest2 = new BlobBytesConsumer(executionContext, blobDataHandle);
314 return; 362 return;
315 } 363 }
316 364
317 Tee* tee = new Tee(executionContext, src); 365 Tee* tee = new Tee(executionContext, src);
318 *dest1 = tee->destination1(); 366 *dest1 = tee->destination1();
319 *dest2 = tee->destination2(); 367 *dest2 = tee->destination2();
320 } 368 }
321 369
370 BytesConsumer* BytesConsumer::createErrored(const BytesConsumer::Error& error) {
371 return new ErroredBytesConsumer(error);
372 }
373
374 BytesConsumer* BytesConsumer::createClosed() {
375 return new ClosedBytesConsumer();
376 }
377
322 } // namespace blink 378 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/modules/fetch/BytesConsumer.h ('k') | third_party/WebKit/Source/modules/fetch/BytesConsumerTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698