| Index: Source/core/page/EventSource.cpp
|
| diff --git a/Source/core/page/EventSource.cpp b/Source/core/page/EventSource.cpp
|
| index 8f893ca29f11ef93ffa3666fd82eee0ac7adba90..d4636cb1e1b798ad3d57f3c3659968e073d9a98c 100644
|
| --- a/Source/core/page/EventSource.cpp
|
| +++ b/Source/core/page/EventSource.cpp
|
| @@ -69,7 +69,6 @@ inline EventSource::EventSource(ExecutionContext* context, const KURL& url, cons
|
| , m_decoder(TextResourceDecoder::create("text/plain", "UTF-8"))
|
| , m_connectTimer(this, &EventSource::connectTimerFired)
|
| , m_discardTrailingNewline(false)
|
| - , m_requestInFlight(false)
|
| , m_reconnectDelay(defaultReconnectDelay)
|
| {
|
| }
|
| @@ -104,13 +103,13 @@ EventSource* EventSource::create(ExecutionContext* context, const String& url, c
|
| EventSource::~EventSource()
|
| {
|
| ASSERT(m_state == CLOSED);
|
| - ASSERT(!m_requestInFlight);
|
| + ASSERT(!m_loader);
|
| }
|
|
|
| void EventSource::scheduleInitialConnect()
|
| {
|
| ASSERT(m_state == CONNECTING);
|
| - ASSERT(!m_requestInFlight);
|
| + ASSERT(!m_loader);
|
|
|
| m_connectTimer.startOneShot(0, FROM_HERE);
|
| }
|
| @@ -118,7 +117,7 @@ void EventSource::scheduleInitialConnect()
|
| void EventSource::connect()
|
| {
|
| ASSERT(m_state == CONNECTING);
|
| - ASSERT(!m_requestInFlight);
|
| + ASSERT(!m_loader);
|
| ASSERT(executionContext());
|
|
|
| ExecutionContext& executionContext = *this->executionContext();
|
| @@ -145,20 +144,15 @@ void EventSource::connect()
|
|
|
| InspectorInstrumentation::willSendEventSourceRequest(&executionContext, this);
|
| // InspectorInstrumentation::documentThreadableLoaderStartedLoadingForClient will be called synchronously.
|
| - m_loader = ThreadableLoader::create(executionContext, this, request, options, resourceLoaderOptions);
|
| -
|
| - if (m_loader)
|
| - m_requestInFlight = true;
|
| + m_loader = ThreadableLoader::create(executionContext, this, options, resourceLoaderOptions);
|
| + m_loader->start(request);
|
| }
|
|
|
| void EventSource::networkRequestEnded()
|
| {
|
| - if (!m_requestInFlight)
|
| - return;
|
| -
|
| InspectorInstrumentation::didFinishEventSourceRequest(executionContext(), this);
|
|
|
| - m_requestInFlight = false;
|
| + m_loader = nullptr;
|
|
|
| if (m_state != CLOSED)
|
| scheduleReconnect();
|
| @@ -194,7 +188,7 @@ EventSource::State EventSource::readyState() const
|
| void EventSource::close()
|
| {
|
| if (m_state == CLOSED) {
|
| - ASSERT(!m_requestInFlight);
|
| + ASSERT(!m_loader);
|
| return;
|
| }
|
|
|
| @@ -203,8 +197,10 @@ void EventSource::close()
|
| m_connectTimer.stop();
|
| }
|
|
|
| - if (m_requestInFlight)
|
| + if (m_loader) {
|
| m_loader->cancel();
|
| + m_loader = nullptr;
|
| + }
|
|
|
| m_state = CLOSED;
|
| }
|
| @@ -223,7 +219,7 @@ void EventSource::didReceiveResponse(unsigned long, const ResourceResponse& resp
|
| {
|
| ASSERT_UNUSED(handle, !handle);
|
| ASSERT(m_state == CONNECTING);
|
| - ASSERT(m_requestInFlight);
|
| + ASSERT(m_loader);
|
|
|
| m_eventStreamOrigin = SecurityOrigin::create(response.url())->toString();
|
| int statusCode = response.httpStatusCode();
|
| @@ -265,7 +261,7 @@ void EventSource::didReceiveResponse(unsigned long, const ResourceResponse& resp
|
| void EventSource::didReceiveData(const char* data, unsigned length)
|
| {
|
| ASSERT(m_state == OPEN);
|
| - ASSERT(m_requestInFlight);
|
| + ASSERT(m_loader);
|
|
|
| append(m_receiveBuf, m_decoder->decode(data, length));
|
| parseEventStream();
|
| @@ -274,7 +270,7 @@ void EventSource::didReceiveData(const char* data, unsigned length)
|
| void EventSource::didFinishLoading(unsigned long, double)
|
| {
|
| ASSERT(m_state == OPEN);
|
| - ASSERT(m_requestInFlight);
|
| + ASSERT(m_loader);
|
|
|
| if (m_receiveBuf.size() > 0 || m_data.size() > 0) {
|
| parseEventStream();
|
| @@ -291,7 +287,7 @@ void EventSource::didFinishLoading(unsigned long, double)
|
| void EventSource::didFail(const ResourceError& error)
|
| {
|
| ASSERT(m_state != CLOSED);
|
| - ASSERT(m_requestInFlight);
|
| + ASSERT(m_loader);
|
|
|
| if (error.isCancellation())
|
| m_state = CLOSED;
|
| @@ -315,13 +311,9 @@ void EventSource::abortConnectionAttempt()
|
| {
|
| ASSERT(m_state == CONNECTING);
|
|
|
| - if (m_requestInFlight) {
|
| - m_loader->cancel();
|
| - } else {
|
| - m_state = CLOSED;
|
| - }
|
| -
|
| - ASSERT(m_state == CLOSED);
|
| + m_loader = nullptr;
|
| + m_state = CLOSED;
|
| + networkRequestEnded();
|
| dispatchEvent(Event::create(EventTypeNames::error));
|
| }
|
|
|
| @@ -423,13 +415,6 @@ void EventSource::parseEventStreamLine(unsigned bufPos, int fieldLength, int lin
|
| void EventSource::stop()
|
| {
|
| close();
|
| -
|
| - // (Non)Oilpan: In order to make Worker shutdowns clean,
|
| - // deref the loader. This will in turn deref its
|
| - // RefPtr<WorkerGlobalScope>.
|
| - //
|
| - // Worth doing regardless, it is no longer of use.
|
| - m_loader = nullptr;
|
| }
|
|
|
| bool EventSource::hasPendingActivity() const
|
|
|