summaryrefslogtreecommitdiffstats
path: root/chromium/content/child/service_worker/web_service_worker_impl.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/content/child/service_worker/web_service_worker_impl.cc')
-rw-r--r--chromium/content/child/service_worker/web_service_worker_impl.cc91
1 files changed, 90 insertions, 1 deletions
diff --git a/chromium/content/child/service_worker/web_service_worker_impl.cc b/chromium/content/child/service_worker/web_service_worker_impl.cc
index 02d9cf8ca77..685c68cb8ab 100644
--- a/chromium/content/child/service_worker/web_service_worker_impl.cc
+++ b/chromium/content/child/service_worker/web_service_worker_impl.cc
@@ -4,8 +4,97 @@
#include "content/child/service_worker/web_service_worker_impl.h"
+#include "content/child/service_worker/service_worker_dispatcher.h"
+#include "content/child/service_worker/service_worker_handle_reference.h"
+#include "content/child/thread_safe_sender.h"
+#include "content/child/webmessageportchannel_impl.h"
+#include "content/common/service_worker/service_worker_messages.h"
+#include "third_party/WebKit/public/platform/WebServiceWorkerProxy.h"
+#include "third_party/WebKit/public/platform/WebString.h"
+
+using blink::WebMessagePortChannel;
+using blink::WebMessagePortChannelArray;
+using blink::WebMessagePortChannelClient;
+using blink::WebString;
+
namespace content {
-WebServiceWorkerImpl::~WebServiceWorkerImpl() {}
+WebServiceWorkerImpl::WebServiceWorkerImpl(
+ scoped_ptr<ServiceWorkerHandleReference> handle_ref,
+ ThreadSafeSender* thread_safe_sender)
+ : handle_ref_(handle_ref.Pass()),
+ state_(handle_ref_->state()),
+ thread_safe_sender_(thread_safe_sender),
+ proxy_(NULL) {
+ ServiceWorkerDispatcher* dispatcher =
+ ServiceWorkerDispatcher::GetThreadSpecificInstance();
+ DCHECK(dispatcher);
+ dispatcher->AddServiceWorker(handle_ref_->handle_id(), this);
+}
+
+WebServiceWorkerImpl::~WebServiceWorkerImpl() {
+ if (handle_ref_->handle_id() == kInvalidServiceWorkerHandleId)
+ return;
+ ServiceWorkerDispatcher* dispatcher =
+ ServiceWorkerDispatcher::GetThreadSpecificInstance();
+ if (dispatcher)
+ dispatcher->RemoveServiceWorker(handle_ref_->handle_id());
+}
+
+void WebServiceWorkerImpl::OnStateChanged(
+ blink::WebServiceWorkerState new_state) {
+ DCHECK(proxy_);
+ if (proxy_->isReady())
+ ChangeState(new_state);
+ else
+ queued_states_.push_back(new_state);
+}
+
+void WebServiceWorkerImpl::setProxy(blink::WebServiceWorkerProxy* proxy) {
+ proxy_ = proxy;
+}
+
+blink::WebServiceWorkerProxy* WebServiceWorkerImpl::proxy() {
+ return 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 {
+ return handle_ref_->scope();
+}
+
+blink::WebURL WebServiceWorkerImpl::url() const {
+ return handle_ref_->url();
+}
+
+blink::WebServiceWorkerState WebServiceWorkerImpl::state() const {
+ return state_;
+}
+
+void WebServiceWorkerImpl::postMessage(const WebString& message,
+ WebMessagePortChannelArray* channels) {
+ thread_safe_sender_->Send(new ServiceWorkerHostMsg_PostMessageToWorker(
+ handle_ref_->handle_id(),
+ message,
+ WebMessagePortChannelImpl::ExtractMessagePortIDs(channels)));
+}
+
+void WebServiceWorkerImpl::ChangeState(blink::WebServiceWorkerState new_state) {
+ DCHECK(proxy_);
+ DCHECK(proxy_->isReady());
+ state_ = new_state;
+ proxy_->dispatchStateChangeEvent();
+}
} // namespace content