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/Vector.h" |
| 11 #include "wtf/text/AtomicString.h" |
| 12 #include "wtf/text/WTFString.h" |
| 13 |
| 14 namespace blink { |
| 15 |
| 16 class CORE_EXPORT EventSourceParser final : public GarbageCollectedFinalized<Eve
ntSourceParser> { |
| 17 public: |
| 18 class CORE_EXPORT Client : public GarbageCollectedMixin { |
| 19 public: |
| 20 virtual ~Client() {} |
| 21 virtual void onMessageEvent(const AtomicString& type, const String& data
, const AtomicString& lastEventId) = 0; |
| 22 virtual void onReconnectionTimeSet(unsigned long long reconnectionTime)
= 0; |
| 23 DEFINE_INLINE_VIRTUAL_TRACE() {} |
| 24 }; |
| 25 |
| 26 EventSourceParser(const AtomicString& lastEventId, Client* client) |
| 27 : m_id(lastEventId) |
| 28 , m_lastEventId(lastEventId) |
| 29 , m_client(client) |
| 30 { |
| 31 } |
| 32 void addBytes(const char*, size_t); |
| 33 const AtomicString& lastEventId() const { return m_lastEventId; } |
| 34 // Stop parsing. This can be called from Client::onMessageEvent. |
| 35 void stop() { m_isStopped = true; } |
| 36 DECLARE_TRACE(); |
| 37 |
| 38 private: |
| 39 void parseLine(); |
| 40 |
| 41 Vector<char> m_line; |
| 42 AtomicString m_event; |
| 43 Vector<char> m_data; |
| 44 // This is used to store the currently processed ID field value. |
| 45 AtomicString m_id; |
| 46 // This is used to store the last dispatched ID field value. |
| 47 AtomicString m_lastEventId; |
| 48 Member<Client> m_client; |
| 49 bool m_isRecognizingCRLF = false; |
| 50 bool m_isRecognizingBOM = true; |
| 51 bool m_isStopped = false; |
| 52 }; |
| 53 |
| 54 } // namespace blink |
| 55 |
| 56 #endif // EventSourceParser_h |
OLD | NEW |