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

Side by Side Diff: third_party/WebKit/Source/core/page/EventSource.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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2009, 2012 Ericsson AB. All rights reserved. 2 * Copyright (C) 2009, 2012 Ericsson AB. All rights reserved.
3 * Copyright (C) 2010 Apple Inc. All rights reserved. 3 * Copyright (C) 2010 Apple Inc. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 8 *
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 17 matching lines...) Expand all
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32 #ifndef EventSource_h 32 #ifndef EventSource_h
33 #define EventSource_h 33 #define EventSource_h
34 34
35 #include "core/dom/ActiveDOMObject.h" 35 #include "core/dom/ActiveDOMObject.h"
36 #include "core/events/EventTarget.h" 36 #include "core/events/EventTarget.h"
37 #include "core/loader/ThreadableLoaderClient.h" 37 #include "core/loader/ThreadableLoaderClient.h"
38 #include "core/page/EventSourceParser.h"
38 #include "platform/Timer.h" 39 #include "platform/Timer.h"
39 #include "platform/heap/Handle.h" 40 #include "platform/heap/Handle.h"
40 #include "platform/weborigin/KURL.h" 41 #include "platform/weborigin/KURL.h"
41 #include "wtf/RefPtr.h" 42 #include "wtf/RefPtr.h"
tyoshino (SeeGerritForStatus) 2016/01/28 07:31:43 add wtf/Forward.h for AtomicString
yhirano 2016/01/28 08:45:36 Done.
42 #include "wtf/Vector.h"
43 43
44 namespace blink { 44 namespace blink {
45 45
46 class EventSourceInit; 46 class EventSourceInit;
47 class ExceptionState; 47 class ExceptionState;
48 class MessageEvent;
49 class ResourceResponse; 48 class ResourceResponse;
50 class TextResourceDecoder;
51 class ThreadableLoader; 49 class ThreadableLoader;
52 50
53 class CORE_EXPORT EventSource final : public RefCountedGarbageCollectedEventTarg etWithInlineData<EventSource>, private ThreadableLoaderClient, public ActiveDOMO bject { 51 class CORE_EXPORT EventSource final : public RefCountedGarbageCollectedEventTarg etWithInlineData<EventSource>, private ThreadableLoaderClient, public ActiveDOMO bject, public EventSourceParser::Client {
54 DEFINE_WRAPPERTYPEINFO(); 52 DEFINE_WRAPPERTYPEINFO();
55 REFCOUNTED_GARBAGE_COLLECTED_EVENT_TARGET(EventSource); 53 REFCOUNTED_GARBAGE_COLLECTED_EVENT_TARGET(EventSource);
56 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(EventSource); 54 USING_GARBAGE_COLLECTED_MIXIN(EventSource);
57 public: 55 public:
58 static EventSource* create(ExecutionContext*, const String& url, const Event SourceInit&, ExceptionState&); 56 static EventSource* create(ExecutionContext*, const String& url, const Event SourceInit&, ExceptionState&);
59 ~EventSource() override; 57 ~EventSource() override;
60 58
61 static const unsigned long long defaultReconnectDelay; 59 static const unsigned long long defaultReconnectDelay;
62 60
63 String url() const; 61 String url() const;
64 bool withCredentials() const; 62 bool withCredentials() const;
65 63
66 enum State : unsigned short { 64 enum State : unsigned short {
(...skipping 18 matching lines...) Expand all
85 // Note: suspend() is noop since ScopedPageLoadDeferrer calls 83 // Note: suspend() is noop since ScopedPageLoadDeferrer calls
86 // Page::setDefersLoading() and it defers delivery of events from the 84 // Page::setDefersLoading() and it defers delivery of events from the
87 // loader, and therefore the methods of this class for receiving 85 // loader, and therefore the methods of this class for receiving
88 // asynchronous events from the loader won't be invoked. 86 // asynchronous events from the loader won't be invoked.
89 void stop() override; 87 void stop() override;
90 88
91 bool hasPendingActivity() const override; 89 bool hasPendingActivity() const override;
92 90
93 DECLARE_VIRTUAL_TRACE(); 91 DECLARE_VIRTUAL_TRACE();
94 92
95 void setStateForTest(State state) { m_state = state; }
96 void setRequestInFlightForTest(bool b) { m_requestInFlight = b; }
97 ThreadableLoaderClient* asThreadableLoaderClientForTest() { return this; }
98 unsigned long long reconnectDelayForTest() const { return m_reconnectDelay; }
99
100 private: 93 private:
101 EventSource(ExecutionContext*, const KURL&, const EventSourceInit&); 94 EventSource(ExecutionContext*, const KURL&, const EventSourceInit&);
102 95
103 void didReceiveResponse(unsigned long, const ResourceResponse&, PassOwnPtr<W ebDataConsumerHandle>) override; 96 void didReceiveResponse(unsigned long, const ResourceResponse&, PassOwnPtr<W ebDataConsumerHandle>) override;
104 void didReceiveData(const char*, unsigned) override; 97 void didReceiveData(const char*, unsigned) override;
105 void didFinishLoading(unsigned long, double) override; 98 void didFinishLoading(unsigned long, double) override;
106 void didFail(const ResourceError&) override; 99 void didFail(const ResourceError&) override;
107 void didFailAccessControlCheck(const ResourceError&) override; 100 void didFailAccessControlCheck(const ResourceError&) override;
108 void didFailRedirectCheck() override; 101 void didFailRedirectCheck() override;
109 102
103 void onMessageEvent(const AtomicString& event, const String& data, const Ato micString& id) override;
104 void onReconnectionTimeSet(unsigned long long reconnectionTime) override;
105
110 void scheduleInitialConnect(); 106 void scheduleInitialConnect();
111 void connect(); 107 void connect();
112 void networkRequestEnded(); 108 void networkRequestEnded();
113 void scheduleReconnect(); 109 void scheduleReconnect();
114 void connectTimerFired(Timer<EventSource>*); 110 void connectTimerFired(Timer<EventSource>*);
115 void abortConnectionAttempt(); 111 void abortConnectionAttempt();
116 void parseEventStream();
117 void parseEventStreamLine(unsigned pos, int fieldLength, int lineLength);
118 PassRefPtrWillBeRawPtr<MessageEvent> createMessageEvent();
119 112
120 KURL m_url; 113 KURL m_url;
121 bool m_withCredentials; 114 bool m_withCredentials;
122 State m_state; 115 State m_state;
123 116
124 OwnPtr<TextResourceDecoder> m_decoder; 117 Member<EventSourceParser> m_parser;
125 RefPtr<ThreadableLoader> m_loader; 118 RefPtr<ThreadableLoader> m_loader;
126 Timer<EventSource> m_connectTimer; 119 Timer<EventSource> m_connectTimer;
127 Vector<UChar> m_receiveBuf;
128 bool m_discardTrailingNewline;
129 bool m_requestInFlight; 120 bool m_requestInFlight;
130
131 AtomicString m_eventName;
132 Vector<UChar> m_data;
133 AtomicString m_currentlyParsedEventId;
134 AtomicString m_lastEventId;
135 unsigned long long m_reconnectDelay; 121 unsigned long long m_reconnectDelay;
136 String m_eventStreamOrigin; 122 String m_eventStreamOrigin;
137 }; 123 };
138 124
139 } // namespace blink 125 } // namespace blink
140 126
141 #endif // EventSource_h 127 #endif // EventSource_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698