Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(240)

Unified Diff: third_party/WebKit/Source/core/page/EventSourceParser.h

Issue 1642563002: Introduce EventSourceParser (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@event-source-retry-fix
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/page/EventSourceParser.h
diff --git a/third_party/WebKit/Source/core/page/EventSourceParser.h b/third_party/WebKit/Source/core/page/EventSourceParser.h
new file mode 100644
index 0000000000000000000000000000000000000000..7629b6843c7ef5ce0e1e725802f7a1161a3781f5
--- /dev/null
+++ b/third_party/WebKit/Source/core/page/EventSourceParser.h
@@ -0,0 +1,61 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef EventSourceParser_h
+#define EventSourceParser_h
+
+#include "core/CoreExport.h"
+#include "platform/heap/Handle.h"
+#include "wtf/OwnPtr.h"
+#include "wtf/Vector.h"
+#include "wtf/text/AtomicString.h"
+#include "wtf/text/TextCodec.h"
+#include "wtf/text/WTFString.h"
+
+namespace blink {
+
+class CORE_EXPORT EventSourceParser final : public GarbageCollectedFinalized<EventSourceParser> {
+public:
+ class CORE_EXPORT Client : public GarbageCollectedMixin {
+ public:
+ virtual ~Client() {}
+ virtual void onMessageEvent(const AtomicString& type, const String& data, const AtomicString& lastEventId) = 0;
+ virtual void onReconnectionTimeSet(unsigned long long reconnectionTime) = 0;
+ DEFINE_INLINE_VIRTUAL_TRACE() {}
+ };
+
+ EventSourceParser(const AtomicString& lastEventId, Client*);
+
+ void addBytes(const char*, size_t);
+ const AtomicString& lastEventId() const { return m_lastEventId; }
+ // Stop parsing. This can be called from Client::onMessageEvent.
+ void stop() { m_isStopped = true; }
+ DECLARE_TRACE();
+
+private:
+ void parseLine();
+ String fromUTF8(const char* bytes, size_t);
+
+ Vector<char> m_line;
+
+ AtomicString m_eventType;
+ Vector<char> m_data;
+ // This variable corresponds to "last event ID buffer" in the spec. The
+ // value can be discarded when a connection is disconnected while
+ // parsing an event.
+ AtomicString m_id;
+ // This variable corresponds to "last event ID string" in the spec.
+ AtomicString m_lastEventId;
+
+ Member<Client> m_client;
+ OwnPtr<TextCodec> m_codec;
+
+ bool m_isRecognizingCRLF = false;
+ bool m_isRecognizingBOM = true;
+ bool m_isStopped = false;
+};
+
+} // namespace blink
+
+#endif // EventSourceParser_h

Powered by Google App Engine
This is Rietveld 408576698