| OLD | NEW |
| 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/BytesConsumerForDataConsumerHandle.h" | 5 #include "modules/fetch/BytesConsumerForDataConsumerHandle.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 "public/platform/WebTaskRunner.h" | 9 #include "public/platform/WebTaskRunner.h" |
| 10 #include "public/platform/WebTraceLocation.h" | 10 #include "public/platform/WebTraceLocation.h" |
| 11 #include "wtf/Functional.h" | 11 #include "wtf/Functional.h" |
| 12 | 12 |
| 13 #include <algorithm> | 13 #include <algorithm> |
| 14 #include <string.h> | 14 #include <string.h> |
| 15 | 15 |
| 16 namespace blink { | 16 namespace blink { |
| 17 | 17 |
| 18 BytesConsumerForDataConsumerHandle::BytesConsumerForDataConsumerHandle(Execution
Context* executionContext, std::unique_ptr<FetchDataConsumerHandle> handle) | 18 BytesConsumerForDataConsumerHandle::BytesConsumerForDataConsumerHandle(Execution
Context* executionContext, std::unique_ptr<FetchDataConsumerHandle> handle) |
| 19 : m_executionContext(executionContext) | 19 : m_executionContext(executionContext) |
| 20 , m_reader(handle->obtainFetchDataReader(this)) | 20 , m_reader(handle->obtainFetchDataReader(this)) |
| 21 { | 21 { |
| 22 } | 22 } |
| 23 | 23 |
| 24 BytesConsumerForDataConsumerHandle::~BytesConsumerForDataConsumerHandle() | 24 BytesConsumerForDataConsumerHandle::~BytesConsumerForDataConsumerHandle() |
| 25 { | 25 { |
| 26 } | 26 } |
| 27 | 27 |
| 28 BytesConsumer::Result BytesConsumerForDataConsumerHandle::read(char* buffer, siz
e_t size, size_t* readSize) | |
| 29 { | |
| 30 DCHECK(!m_isInTwoPhaseRead); | |
| 31 *readSize = 0; | |
| 32 if (m_state == InternalState::Closed) | |
| 33 return Result::Done; | |
| 34 if (m_state == InternalState::Errored) | |
| 35 return Result::Error; | |
| 36 | |
| 37 WebDataConsumerHandle::Result r = m_reader->read(buffer, size, WebDataConsum
erHandle::FlagNone, readSize); | |
| 38 switch (r) { | |
| 39 case WebDataConsumerHandle::Ok: | |
| 40 return Result::Ok; | |
| 41 case WebDataConsumerHandle::ShouldWait: | |
| 42 return Result::ShouldWait; | |
| 43 case WebDataConsumerHandle::Done: | |
| 44 close(); | |
| 45 return Result::Done; | |
| 46 case WebDataConsumerHandle::Busy: | |
| 47 case WebDataConsumerHandle::ResourceExhausted: | |
| 48 case WebDataConsumerHandle::UnexpectedError: | |
| 49 error(); | |
| 50 return Result::Error; | |
| 51 } | |
| 52 NOTREACHED(); | |
| 53 return Result::Error; | |
| 54 } | |
| 55 | |
| 56 BytesConsumer::Result BytesConsumerForDataConsumerHandle::beginRead(const char**
buffer, size_t* available) | 28 BytesConsumer::Result BytesConsumerForDataConsumerHandle::beginRead(const char**
buffer, size_t* available) |
| 57 { | 29 { |
| 58 DCHECK(!m_isInTwoPhaseRead); | 30 DCHECK(!m_isInTwoPhaseRead); |
| 59 *buffer = nullptr; | 31 *buffer = nullptr; |
| 60 *available = 0; | 32 *available = 0; |
| 61 if (m_state == InternalState::Closed) | 33 if (m_state == InternalState::Closed) |
| 62 return Result::Done; | 34 return Result::Done; |
| 63 if (m_state == InternalState::Errored) | 35 if (m_state == InternalState::Errored) |
| 64 return Result::Error; | 36 return Result::Error; |
| 65 | 37 |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 } | 195 } |
| 224 | 196 |
| 225 void BytesConsumerForDataConsumerHandle::notify() | 197 void BytesConsumerForDataConsumerHandle::notify() |
| 226 { | 198 { |
| 227 if (m_state == InternalState::Closed || m_state == InternalState::Errored) | 199 if (m_state == InternalState::Closed || m_state == InternalState::Errored) |
| 228 return; | 200 return; |
| 229 didGetReadable(); | 201 didGetReadable(); |
| 230 } | 202 } |
| 231 | 203 |
| 232 } // namespace blink | 204 } // namespace blink |
| OLD | NEW |