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

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, 11 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..03284e2915b00c15b0c6b0340e917c5f50b584fb
--- /dev/null
+++ b/third_party/WebKit/Source/core/page/EventSourceParser.h
@@ -0,0 +1,56 @@
+// 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/Vector.h"
+#include "wtf/text/AtomicString.h"
+#include "wtf/text/WTFString.h"
tyoshino (SeeGerritForStatus) 2016/01/28 07:31:43 Forward.h is enough?
yhirano 2016/01/28 08:45:36 I keep the header because I've just added |fromUTF
+
+namespace blink {
+
+class CORE_EXPORT EventSourceParser final : public GarbageCollectedFinalized<EventSourceParser> {
+public:
+ class 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* client)
+ : m_id(lastEventId)
+ , m_lastEventId(lastEventId)
+ , m_client(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();
+
+ Vector<char> m_line;
tyoshino (SeeGerritForStatus) 2016/01/28 07:31:43 blank line here
yhirano 2016/01/28 08:45:36 Done.
+ AtomicString m_event;
tyoshino (SeeGerritForStatus) 2016/01/28 07:31:43 how about m_eventType?
yhirano 2016/01/28 08:45:36 Done.
+ Vector<char> m_data;
+ // This is used to store the currently processed ID field value.
tyoshino (SeeGerritForStatus) 2016/01/28 07:31:43 as you've chosen not to reset m_id unlike the code
yhirano 2016/01/28 08:45:36 Updated the comment.
+ AtomicString m_id;
+ // This is used to store the last dispatched ID field value.
+ AtomicString m_lastEventId;
tyoshino (SeeGerritForStatus) 2016/01/28 07:31:43 blank line here
yhirano 2016/01/28 08:45:36 Done.
+ Member<Client> m_client;
tyoshino (SeeGerritForStatus) 2016/01/28 07:31:44 blank line here
yhirano 2016/01/28 08:45:36 Done.
+ 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