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

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

Issue 2351643004: BytesConsumer::endRead can return Done (Closed)
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 #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/BytesConsumerForDataConsumerHandle.h" 9 #include "modules/fetch/BytesConsumerForDataConsumerHandle.h"
10 #include "modules/fetch/FetchBlobDataConsumerHandle.h" 10 #include "modules/fetch/FetchBlobDataConsumerHandle.h"
(...skipping 30 matching lines...) Expand all
41 41
42 void onStateChange() override 42 void onStateChange() override
43 { 43 {
44 bool destination1WasEmpty = m_destination1->isEmpty(); 44 bool destination1WasEmpty = m_destination1->isEmpty();
45 bool destination2WasEmpty = m_destination2->isEmpty(); 45 bool destination2WasEmpty = m_destination2->isEmpty();
46 bool hasEnqueued = false; 46 bool hasEnqueued = false;
47 47
48 while (true) { 48 while (true) {
49 const char* buffer = nullptr; 49 const char* buffer = nullptr;
50 size_t available = 0; 50 size_t available = 0;
51 switch (m_src->beginRead(&buffer, &available)) { 51 auto result = m_src->beginRead(&buffer, &available);
52 case Result::Ok: { 52 if (result == Result::ShouldWait) {
53 Chunk* chunk = new Chunk(buffer, available);
54 if (m_src->endRead(available) != Result::Ok) {
55 clearAndNotify();
56 return;
57 }
58 m_destination1->enqueue(chunk);
59 m_destination2->enqueue(chunk);
60 hasEnqueued = true;
61 break;
62 }
63 case Result::ShouldWait:
64 if (hasEnqueued && destination1WasEmpty) 53 if (hasEnqueued && destination1WasEmpty)
65 m_destination1->notify(); 54 m_destination1->notify();
66 if (hasEnqueued && destination2WasEmpty) 55 if (hasEnqueued && destination2WasEmpty)
67 m_destination2->notify(); 56 m_destination2->notify();
68 return; 57 return;
58 }
59 Chunk* chunk = nullptr;
60 if (result == Result::Ok) {
61 chunk = new Chunk(buffer, available);
62 result = m_src->endRead(available);
63 }
64 switch (result) {
65 case Result::Ok:
66 DCHECK(chunk);
67 m_destination1->enqueue(chunk);
68 m_destination2->enqueue(chunk);
69 hasEnqueued = true;
70 break;
71 case Result::ShouldWait:
72 NOTREACHED();
73 return;
69 case Result::Done: 74 case Result::Done:
70 if (destination1WasEmpty) 75 if (destination1WasEmpty)
71 m_destination1->notify(); 76 m_destination1->notify();
72 if (destination2WasEmpty) 77 if (destination2WasEmpty)
73 m_destination2->notify(); 78 m_destination2->notify();
74 return; 79 return;
75 case Result::Error: 80 case Result::Error:
76 clearAndNotify(); 81 clearAndNotify();
77 return; 82 return;
78 } 83 }
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 *dest2 = new BytesConsumerForDataConsumerHandle(executionContext, FetchB lobDataConsumerHandle::create(executionContext, blobDataHandle)); 329 *dest2 = new BytesConsumerForDataConsumerHandle(executionContext, FetchB lobDataConsumerHandle::create(executionContext, blobDataHandle));
325 return; 330 return;
326 } 331 }
327 332
328 Tee* tee = new Tee(executionContext, src); 333 Tee* tee = new Tee(executionContext, src);
329 *dest1 = tee->destination1(); 334 *dest1 = tee->destination1();
330 *dest2 = tee->destination2(); 335 *dest2 = tee->destination2();
331 } 336 }
332 337
333 } // namespace blink 338 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698