1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CONTENT_CHILD_SERVICE_WORKER_SERVICE_WORKER_DISPATCHER_H_
6 #define CONTENT_CHILD_SERVICE_WORKER_SERVICE_WORKER_DISPATCHER_H_
8 #include "base/id_map.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/strings/string16.h"
11 #include "third_party/WebKit/public/platform/WebServiceWorkerProvider.h"
12 #include "webkit/child/worker_task_runner.h"
25 class ServiceWorkerMessageFilter;
26 class ThreadSafeSender;
27 class WebServiceWorkerImpl;
29 // This class manages communication with the browser process about
30 // registration of the service worker, exposed to renderer and worker
31 // scripts through methods like navigator.registerServiceWorker().
32 class ServiceWorkerDispatcher : public webkit_glue::WorkerTaskRunner::Observer {
34 explicit ServiceWorkerDispatcher(ThreadSafeSender* thread_safe_sender);
35 virtual ~ServiceWorkerDispatcher();
37 void OnMessageReceived(const IPC::Message& msg);
38 bool Send(IPC::Message* msg);
40 // Corresponds to navigator.registerServiceWorker()
41 void RegisterServiceWorker(
43 const GURL& script_url,
44 WebKit::WebServiceWorkerProvider::WebServiceWorkerCallbacks* callbacks);
45 // Corresponds to navigator.unregisterServiceWorker()
46 void UnregisterServiceWorker(
48 WebKit::WebServiceWorkerProvider::WebServiceWorkerCallbacks* callbacks);
50 // |thread_safe_sender| needs to be passed in because if the call leads to
51 // construction it will be needed.
52 static ServiceWorkerDispatcher* ThreadSpecificInstance(
53 ThreadSafeSender* thread_safe_sender);
56 // webkit_glue::WorkerTaskRunner::Observer implementation.
57 virtual void OnWorkerRunLoopStopped() OVERRIDE;
59 // The asynchronous success response to RegisterServiceWorker.
60 void OnServiceWorkerRegistered(int32 thread_id,
62 int64 service_worker_id);
63 // The asynchronous success response to UregisterServiceWorker.
64 void OnServiceWorkerUnregistered(int32 thread_id, int32 request_id);
66 IDMap<WebKit::WebServiceWorkerProvider::WebServiceWorkerCallbacks,
67 IDMapOwnPointer> pending_callbacks_;
69 scoped_refptr<ThreadSafeSender> thread_safe_sender_;
71 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerDispatcher);
74 } // namespace content
76 #endif // CONTENT_CHILD_SERVICE_WORKER_SERVICE_WORKER_DISPATCHER_H_