OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef EventSourceParser_h |
| 6 #define EventSourceParser_h |
| 7 |
| 8 #include "core/CoreExport.h" |
| 9 #include "platform/heap/Handle.h" |
| 10 #include "wtf/OwnPtr.h" |
| 11 #include "wtf/Vector.h" |
| 12 #include "wtf/text/AtomicString.h" |
| 13 #include "wtf/text/TextCodec.h" |
| 14 #include "wtf/text/WTFString.h" |
| 15 |
| 16 namespace blink { |
| 17 |
| 18 class CORE_EXPORT EventSourceParser final : public GarbageCollectedFinalized<Eve
ntSourceParser> { |
| 19 public: |
| 20 class CORE_EXPORT Client : public GarbageCollectedMixin { |
| 21 public: |
| 22 virtual ~Client() {} |
| 23 virtual void onMessageEvent(const AtomicString& type, const String& data
, const AtomicString& lastEventId) = 0; |
| 24 virtual void onReconnectionTimeSet(unsigned long long reconnectionTime)
= 0; |
| 25 DEFINE_INLINE_VIRTUAL_TRACE() {} |
| 26 }; |
| 27 |
| 28 EventSourceParser(const AtomicString& lastEventId, Client*); |
| 29 |
| 30 void addBytes(const char*, size_t); |
| 31 const AtomicString& lastEventId() const { return m_lastEventId; } |
| 32 // Stop parsing. This can be called from Client::onMessageEvent. |
| 33 void stop() { m_isStopped = true; } |
| 34 DECLARE_TRACE(); |
| 35 |
| 36 private: |
| 37 void parseLine(); |
| 38 String fromUTF8(const char* bytes, size_t); |
| 39 |
| 40 Vector<char> m_line; |
| 41 |
| 42 AtomicString m_eventType; |
| 43 Vector<char> m_data; |
| 44 // This variable corresponds to "last event ID buffer" in the spec. The |
| 45 // value can be discarded when a connection is disconnected while |
| 46 // parsing an event. |
| 47 AtomicString m_id; |
| 48 // This variable corresponds to "last event ID string" in the spec. |
| 49 AtomicString m_lastEventId; |
| 50 |
| 51 Member<Client> m_client; |
| 52 OwnPtr<TextCodec> m_codec; |
| 53 |
| 54 bool m_isRecognizingCRLF = false; |
| 55 bool m_isRecognizingBOM = true; |
| 56 bool m_isStopped = false; |
| 57 }; |
| 58 |
| 59 } // namespace blink |
| 60 |
| 61 #endif // EventSourceParser_h |
OLD | NEW |