Chromium Code Reviews| 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 "platform/blob/BlobData.h" | 9 #include "platform/blob/BlobData.h" |
| 10 #include "platform/heap/Heap.h" | 10 #include "platform/heap/Heap.h" |
| 11 #include "wtf/Deque.h" | 11 #include "wtf/Deque.h" |
| 12 #include "wtf/RefPtr.h" | 12 #include "wtf/RefPtr.h" |
| 13 #include "wtf/text/WTFString.h" | |
| 13 | 14 |
| 14 namespace blink { | 15 namespace blink { |
| 15 | 16 |
| 16 class DOMArrayBuffer; | 17 class DOMArrayBuffer; |
| 17 | 18 |
| 18 class BodyStreamBuffer final : public GarbageCollectedFinalized<BodyStreamBuffer > { | 19 class BodyStreamBuffer final : public GarbageCollectedFinalized<BodyStreamBuffer > { |
| 19 public: | 20 public: |
| 20 class Observer : public GarbageCollectedFinalized<Observer> { | 21 class Observer : public GarbageCollectedFinalized<Observer> { |
| 21 public: | 22 public: |
| 22 virtual ~Observer() { } | 23 virtual ~Observer() { } |
| 23 virtual void onWrite() = 0; | 24 virtual void onWrite() = 0; |
| 24 virtual void onClose() = 0; | 25 virtual void onClose() = 0; |
| 25 virtual void onError() = 0; | 26 virtual void onError() = 0; |
| 26 virtual void trace(Visitor*) { } | 27 virtual void trace(Visitor*) { } |
| 27 }; | 28 }; |
| 28 class BlobHandleCreatorClient : public GarbageCollectedFinalized<BlobHandleC reatorClient> { | 29 class BlobHandleCreatorClient : public GarbageCollectedFinalized<BlobHandleC reatorClient> { |
| 29 public: | 30 public: |
| 30 virtual ~BlobHandleCreatorClient() { } | 31 virtual ~BlobHandleCreatorClient() { } |
| 31 virtual void didCreateBlobHandle(PassRefPtr<BlobDataHandle>) = 0; | 32 virtual void didCreateBlobHandle(PassRefPtr<BlobDataHandle>) = 0; |
| 32 virtual void didFail(PassRefPtrWillBeRawPtr<DOMException>) = 0; | 33 virtual void didFail(PassRefPtrWillBeRawPtr<DOMException>) = 0; |
| 33 virtual void trace(Visitor*) { } | 34 virtual void trace(Visitor*) { } |
| 34 }; | 35 }; |
| 35 BodyStreamBuffer(); | 36 explicit BodyStreamBuffer(const String& contentType); |
|
yhirano
2014/12/11 03:44:18
The specified content type takes effect only when
horo
2014/12/11 04:48:56
Done.
| |
| 36 ~BodyStreamBuffer() { } | 37 ~BodyStreamBuffer() { } |
| 37 | 38 |
| 38 PassRefPtr<DOMArrayBuffer> read(); | 39 PassRefPtr<DOMArrayBuffer> read(); |
| 39 bool isClosed() const { return m_isClosed; } | 40 bool isClosed() const { return m_isClosed; } |
| 40 bool hasError() const { return m_exception; } | 41 bool hasError() const { return m_exception; } |
| 41 PassRefPtrWillBeRawPtr<DOMException> exception() const { return m_exception; } | 42 PassRefPtrWillBeRawPtr<DOMException> exception() const { return m_exception; } |
| 43 const String contentType() const { return m_contentType; } | |
| 42 | 44 |
| 43 // Can't call after close() or error() was called. | 45 // Can't call after close() or error() was called. |
| 44 void write(PassRefPtr<DOMArrayBuffer>); | 46 void write(PassRefPtr<DOMArrayBuffer>); |
| 45 // Can't call after close() or error() was called. | 47 // Can't call after close() or error() was called. |
| 46 void close(); | 48 void close(); |
| 47 // Can't call after close() or error() was called. | 49 // Can't call after close() or error() was called. |
| 48 void error(PassRefPtrWillBeRawPtr<DOMException>); | 50 void error(PassRefPtrWillBeRawPtr<DOMException>); |
| 49 | 51 |
| 50 // This function registers an observer so it fails and returns false when an | 52 // This function registers an observer so it fails and returns false when an |
| 51 // observer was already registered | 53 // observer was already registered |
| 52 bool readAllAndCreateBlobHandle(BlobHandleCreatorClient*); | 54 bool readAllAndCreateBlobHandle(BlobHandleCreatorClient*); |
| 53 | 55 |
| 54 // When an observer was registered this function fails and returns false. | 56 // When an observer was registered this function fails and returns false. |
| 55 bool registerObserver(Observer*); | 57 bool registerObserver(Observer*); |
| 56 void unregisterObserver(); | 58 void unregisterObserver(); |
| 57 bool isObserverRegistered() const { return m_observer.get(); } | 59 bool isObserverRegistered() const { return m_observer.get(); } |
| 58 void trace(Visitor*); | 60 void trace(Visitor*); |
| 59 | 61 |
| 60 private: | 62 private: |
| 61 Deque<RefPtr<DOMArrayBuffer> > m_queue; | 63 Deque<RefPtr<DOMArrayBuffer> > m_queue; |
| 64 const String m_contentType; | |
| 62 bool m_isClosed; | 65 bool m_isClosed; |
| 63 RefPtrWillBeMember<DOMException> m_exception; | 66 RefPtrWillBeMember<DOMException> m_exception; |
| 64 Member<Observer> m_observer; | 67 Member<Observer> m_observer; |
| 65 }; | 68 }; |
| 66 | 69 |
| 67 } // namespace blink | 70 } // namespace blink |
| 68 | 71 |
| 69 #endif // BodyStreamBuffer_h | 72 #endif // BodyStreamBuffer_h |
| OLD | NEW |