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/WebServiceWorkerError.h"
12 #include "third_party/WebKit/public/platform/WebServiceWorkerProvider.h"
13 #include "webkit/child/worker_task_runner.h"
26 class ServiceWorkerMessageFilter
;
27 class ThreadSafeSender
;
28 class WebServiceWorkerImpl
;
30 // This class manages communication with the browser process about
31 // registration of the service worker, exposed to renderer and worker
32 // scripts through methods like navigator.registerServiceWorker().
33 class ServiceWorkerDispatcher
: public webkit_glue::WorkerTaskRunner::Observer
{
35 explicit ServiceWorkerDispatcher(ThreadSafeSender
* thread_safe_sender
);
36 virtual ~ServiceWorkerDispatcher();
38 void OnMessageReceived(const IPC::Message
& msg
);
39 bool Send(IPC::Message
* msg
);
41 // Corresponds to navigator.registerServiceWorker()
42 void RegisterServiceWorker(
44 const GURL
& script_url
,
45 blink::WebServiceWorkerProvider::WebServiceWorkerCallbacks
* callbacks
);
46 // Corresponds to navigator.unregisterServiceWorker()
47 void UnregisterServiceWorker(
49 blink::WebServiceWorkerProvider::WebServiceWorkerCallbacks
* callbacks
);
51 // |thread_safe_sender| needs to be passed in because if the call leads to
52 // construction it will be needed.
53 static ServiceWorkerDispatcher
* ThreadSpecificInstance(
54 ThreadSafeSender
* thread_safe_sender
);
57 // webkit_glue::WorkerTaskRunner::Observer implementation.
58 virtual void OnWorkerRunLoopStopped() OVERRIDE
;
60 // The asynchronous success response to RegisterServiceWorker.
61 void OnRegistered(int32 thread_id
, int32 request_id
, int64 registration_id
);
62 // The asynchronous success response to UregisterServiceWorker.
63 void OnUnregistered(int32 thread_id
,
65 void OnRegistrationError(int32 thread_id
,
67 blink::WebServiceWorkerError::ErrorType error_type
,
68 const base::string16
& message
);
70 IDMap
<blink::WebServiceWorkerProvider::WebServiceWorkerCallbacks
,
71 IDMapOwnPointer
> pending_callbacks_
;
73 scoped_refptr
<ThreadSafeSender
> thread_safe_sender_
;
75 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerDispatcher
);
78 } // namespace content
80 #endif // CONTENT_CHILD_SERVICE_WORKER_SERVICE_WORKER_DISPATCHER_H_