| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 BodyStreamBuffer_h | 5 #ifndef BodyStreamBuffer_h |
| 6 #define BodyStreamBuffer_h | 6 #define BodyStreamBuffer_h |
| 7 | 7 |
| 8 #include "core/dom/DOMException.h" | 8 #include "core/dom/DOMException.h" |
| 9 #include "core/streams/ReadableByteStream.h" | 9 #include "core/streams/ReadableByteStream.h" |
| 10 #include "core/streams/ReadableByteStreamReader.h" | 10 #include "core/streams/ReadableByteStreamReader.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 USING_GARBAGE_COLLECTED_MIXIN(BodyStreamBuffer); | 27 USING_GARBAGE_COLLECTED_MIXIN(BodyStreamBuffer); |
| 28 public: | 28 public: |
| 29 // |handle| cannot be null and cannot be locked. | 29 // |handle| cannot be null and cannot be locked. |
| 30 explicit BodyStreamBuffer(PassOwnPtr<FetchDataConsumerHandle> /* handle */); | 30 explicit BodyStreamBuffer(PassOwnPtr<FetchDataConsumerHandle> /* handle */); |
| 31 | 31 |
| 32 ReadableByteStream* stream() { return m_stream; } | 32 ReadableByteStream* stream() { return m_stream; } |
| 33 | 33 |
| 34 // Callable only when not locked. | 34 // Callable only when not locked. |
| 35 PassRefPtr<BlobDataHandle> drainAsBlobDataHandle(FetchDataConsumerHandle::Re
ader::BlobSizePolicy); | 35 PassRefPtr<BlobDataHandle> drainAsBlobDataHandle(FetchDataConsumerHandle::Re
ader::BlobSizePolicy); |
| 36 PassRefPtr<EncodedFormData> drainAsFormData(); | 36 PassRefPtr<EncodedFormData> drainAsFormData(); |
| 37 void startLoading(ExecutionContext*, FetchDataLoader*, FetchDataLoader::Clie
nt* /* client */); |
| 37 | 38 |
| 38 // Callable only when not locked. Returns a non-null handle. | 39 // Callable only when not locked. Returns a non-null handle. |
| 39 // Note: There is a case that calling |lock| doesn't make the buffer | 40 // There is no means to "return" the handle to the body buffer: Calling |
| 40 // locked. |unlock| should be called even in such cases when a user finishes | 41 // this function locks, disturbs and closes the stream and no one will |
| 41 // to use the returned handle, in order to maintain hasPendingActivity(). | 42 // not be able to get any information from the stream and this buffer after |
| 42 PassOwnPtr<FetchDataConsumerHandle> lock(ExecutionContext*); | 43 // that. |
| 44 PassOwnPtr<FetchDataConsumerHandle> releaseHandle(ExecutionContext*); |
| 43 | 45 |
| 44 // This function will lock |this| object. |client| cannot be null. | 46 bool hasPendingActivity() const; |
| 45 void startLoading(ExecutionContext*, FetchDataLoader*, FetchDataLoader::Clie
nt* /* client */); | |
| 46 | |
| 47 bool isLocked() const { return m_stream->isLocked(); } | |
| 48 bool hasPendingActivity() const { return isLocked() || m_lockLevel > 0; } | |
| 49 | 47 |
| 50 // UnderlyingSource | 48 // UnderlyingSource |
| 51 void pullSource() override; | 49 void pullSource() override; |
| 52 ScriptPromise cancelSource(ScriptState*, ScriptValue reason) override; | 50 ScriptPromise cancelSource(ScriptState*, ScriptValue reason) override; |
| 53 | 51 |
| 54 // WebDataConsumerHandle::Client | 52 // WebDataConsumerHandle::Client |
| 55 void didGetReadable() override; | 53 void didGetReadable() override; |
| 56 | 54 |
| 57 DEFINE_INLINE_TRACE() | 55 DEFINE_INLINE_TRACE() |
| 58 { | 56 { |
| 59 visitor->trace(m_stream); | 57 visitor->trace(m_stream); |
| 60 visitor->trace(m_streamReader); | 58 visitor->trace(m_loader); |
| 61 visitor->trace(m_loaders); | |
| 62 UnderlyingSource::trace(visitor); | 59 UnderlyingSource::trace(visitor); |
| 63 } | 60 } |
| 64 | 61 |
| 65 private: | 62 private: |
| 66 class LoaderHolder; | 63 class LoaderClient; |
| 67 enum EndLoadingMode { | |
| 68 EndLoadingDone, | |
| 69 EndLoadingErrored, | |
| 70 }; | |
| 71 void close(); | 64 void close(); |
| 72 void error(); | 65 void error(); |
| 73 void processData(); | 66 void processData(); |
| 74 void unlock(); | 67 void endLoading(); |
| 75 void endLoading(FetchDataLoader::Client*, EndLoadingMode); | 68 void stopLoading(); |
| 76 | 69 |
| 77 OwnPtr<FetchDataConsumerHandle> m_handle; | 70 OwnPtr<FetchDataConsumerHandle> m_handle; |
| 78 OwnPtr<FetchDataConsumerHandle::Reader> m_reader; | 71 OwnPtr<FetchDataConsumerHandle::Reader> m_reader; |
| 79 Member<ReadableByteStream> m_stream; | 72 Member<ReadableByteStream> m_stream; |
| 80 Member<ReadableByteStreamReader> m_streamReader; | 73 // We need this member to keep it alive while loading. |
| 81 HeapHashSet<Member<FetchDataLoader::Client>> m_loaders; | 74 Member<FetchDataLoader> m_loader; |
| 82 // We need this variable because we cannot lock closed or erroed stream | |
| 83 // although we should return true for hasPendingActivity() when someone | |
| 84 // calls |startLoading| but the loding is not yet done. | |
| 85 unsigned m_lockLevel; | |
| 86 bool m_streamNeedsMore; | 75 bool m_streamNeedsMore; |
| 87 }; | 76 }; |
| 88 | 77 |
| 89 } // namespace blink | 78 } // namespace blink |
| 90 | 79 |
| 91 #endif // BodyStreamBuffer_h | 80 #endif // BodyStreamBuffer_h |
| OLD | NEW |