Commit e9374129 authored by falken@chromium.org's avatar falken@chromium.org

ServiceWorker: Queue worker state changes until Blink is ready for them

Chromium-side part of the following:
https://codereview.chromium.org/247263010/
https://codereview.chromium.org/256723002/

BUG=365252

Review URL: https://codereview.chromium.org/255813003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@266544 0039d316-1c4b-4281-b951-d872f2087c98
parent 37dbcfa2
...@@ -198,7 +198,7 @@ void ServiceWorkerDispatcher::OnServiceWorkerStateChanged( ...@@ -198,7 +198,7 @@ void ServiceWorkerDispatcher::OnServiceWorkerStateChanged(
ServiceWorkerMap::iterator found = service_workers_.find(handle_id); ServiceWorkerMap::iterator found = service_workers_.find(handle_id);
if (found == service_workers_.end()) if (found == service_workers_.end())
return; return;
found->second->SetState(state); found->second->OnStateChanged(state);
} }
void ServiceWorkerDispatcher::OnSetCurrentServiceWorker( void ServiceWorkerDispatcher::OnSetCurrentServiceWorker(
......
...@@ -44,17 +44,31 @@ WebServiceWorkerImpl::~WebServiceWorkerImpl() { ...@@ -44,17 +44,31 @@ WebServiceWorkerImpl::~WebServiceWorkerImpl() {
dispatcher->RemoveServiceWorker(handle_id_); dispatcher->RemoveServiceWorker(handle_id_);
} }
void WebServiceWorkerImpl::SetState(blink::WebServiceWorkerState new_state) { void WebServiceWorkerImpl::OnStateChanged(
state_ = new_state; blink::WebServiceWorkerState new_state) {
if (!proxy_) DCHECK(proxy_);
return; if (proxy_->isReady())
proxy_->dispatchStateChangeEvent(); ChangeState(new_state);
else
queued_states_.push_back(new_state);
} }
void WebServiceWorkerImpl::setProxy(blink::WebServiceWorkerProxy* proxy) { void WebServiceWorkerImpl::setProxy(blink::WebServiceWorkerProxy* proxy) {
proxy_ = proxy; proxy_ = proxy;
} }
void WebServiceWorkerImpl::proxyReadyChanged() {
if (!proxy_->isReady())
return;
for (std::vector<blink::WebServiceWorkerState>::iterator it =
queued_states_.begin();
it != queued_states_.end();
++it) {
ChangeState(*it);
}
queued_states_.clear();
}
blink::WebURL WebServiceWorkerImpl::scope() const { blink::WebURL WebServiceWorkerImpl::scope() const {
return scope_; return scope_;
} }
...@@ -75,4 +89,11 @@ void WebServiceWorkerImpl::postMessage(const WebString& message, ...@@ -75,4 +89,11 @@ void WebServiceWorkerImpl::postMessage(const WebString& message,
WebMessagePortChannelImpl::ExtractMessagePortIDs(channels))); WebMessagePortChannelImpl::ExtractMessagePortIDs(channels)));
} }
void WebServiceWorkerImpl::ChangeState(blink::WebServiceWorkerState new_state) {
DCHECK(proxy_);
DCHECK(proxy_->isReady());
state_ = new_state;
proxy_->dispatchStateChangeEvent();
}
} // namespace content } // namespace content
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
#ifndef CONTENT_CHILD_SERVICE_WORKER_WEB_SERVICE_WORKER_IMPL_H_ #ifndef CONTENT_CHILD_SERVICE_WORKER_WEB_SERVICE_WORKER_IMPL_H_
#define CONTENT_CHILD_SERVICE_WORKER_WEB_SERVICE_WORKER_IMPL_H_ #define CONTENT_CHILD_SERVICE_WORKER_WEB_SERVICE_WORKER_IMPL_H_
#include <vector>
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "base/strings/string16.h" #include "base/strings/string16.h"
...@@ -28,9 +30,13 @@ class WebServiceWorkerImpl ...@@ -28,9 +30,13 @@ class WebServiceWorkerImpl
ThreadSafeSender* thread_safe_sender); ThreadSafeSender* thread_safe_sender);
virtual ~WebServiceWorkerImpl(); virtual ~WebServiceWorkerImpl();
void SetState(blink::WebServiceWorkerState new_state); // Notifies that the service worker's state changed. This function may queue
// the state change for later processing, if the proxy is not yet ready to
// handle state changes.
void OnStateChanged(blink::WebServiceWorkerState new_state);
virtual void setProxy(blink::WebServiceWorkerProxy* proxy); virtual void setProxy(blink::WebServiceWorkerProxy* proxy);
virtual void proxyReadyChanged();
virtual blink::WebURL scope() const; virtual blink::WebURL scope() const;
virtual blink::WebURL url() const; virtual blink::WebURL url() const;
virtual blink::WebServiceWorkerState state() const; virtual blink::WebServiceWorkerState state() const;
...@@ -38,12 +44,16 @@ class WebServiceWorkerImpl ...@@ -38,12 +44,16 @@ class WebServiceWorkerImpl
blink::WebMessagePortChannelArray* channels); blink::WebMessagePortChannelArray* channels);
private: private:
// Commits the new state internally and notifies the proxy of the change.
void ChangeState(blink::WebServiceWorkerState new_state);
const int handle_id_; const int handle_id_;
const GURL scope_; const GURL scope_;
const GURL url_; const GURL url_;
blink::WebServiceWorkerState state_; blink::WebServiceWorkerState state_;
scoped_refptr<ThreadSafeSender> thread_safe_sender_; scoped_refptr<ThreadSafeSender> thread_safe_sender_;
blink::WebServiceWorkerProxy* proxy_; blink::WebServiceWorkerProxy* proxy_;
std::vector<blink::WebServiceWorkerState> queued_states_;
DISALLOW_COPY_AND_ASSIGN(WebServiceWorkerImpl); DISALLOW_COPY_AND_ASSIGN(WebServiceWorkerImpl);
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment