Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / content / browser / service_worker / service_worker_dispatcher_host.h
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.
4
5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_DISPATCHER_HOST_H_
6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_DISPATCHER_HOST_H_
7
8 #include "base/memory/weak_ptr.h"
9 #include "content/browser/service_worker/service_worker_registration_status.h"
10 #include "content/public/browser/browser_message_filter.h"
11
12 class GURL;
13
14 namespace content {
15
16 class ServiceWorkerContextCore;
17 class ServiceWorkerContextWrapper;
18 class ServiceWorkerProviderHost;
19
20 class CONTENT_EXPORT ServiceWorkerDispatcherHost : public BrowserMessageFilter {
21  public:
22   explicit ServiceWorkerDispatcherHost(int render_process_id);
23
24   void Init(ServiceWorkerContextWrapper* context_wrapper);
25
26   // BrowserIOMessageFilter implementation
27   virtual void OnDestruct() const OVERRIDE;
28   virtual bool OnMessageReceived(const IPC::Message& message,
29                                  bool* message_was_ok) OVERRIDE;
30
31  protected:
32   virtual ~ServiceWorkerDispatcherHost();
33
34  private:
35   friend class BrowserThread;
36   friend class base::DeleteHelper<ServiceWorkerDispatcherHost>;
37   friend class TestingServiceWorkerDispatcherHost;
38
39   // IPC Message handlers
40   void OnRegisterServiceWorker(int32 thread_id,
41                                int32 request_id,
42                                const GURL& pattern,
43                                const GURL& script_url);
44   void OnUnregisterServiceWorker(int32 thread_id,
45                                  int32 request_id,
46                                  const GURL& pattern);
47   void OnProviderCreated(int provider_id);
48   void OnProviderDestroyed(int provider_id);
49   void OnWorkerStarted(int thread_id,
50                        int embedded_worker_id);
51   void OnWorkerStopped(int embedded_worker_id);
52   void OnSendMessageToBrowser(int embedded_worker_id,
53                               int request_id,
54                               const IPC::Message& message);
55
56   // Callbacks from ServiceWorkerContextCore
57   void RegistrationComplete(int32 thread_id,
58                             int32 request_id,
59                             ServiceWorkerStatusCode status,
60                             int64 registration_id);
61
62   void UnregistrationComplete(int32 thread_id,
63                               int32 request_id,
64                               ServiceWorkerStatusCode status);
65
66   void SendRegistrationError(int32 thread_id,
67                              int32 request_id,
68                              ServiceWorkerStatusCode status);
69   int render_process_id_;
70   base::WeakPtr<ServiceWorkerContextCore> context_;
71 };
72
73 }  // namespace content
74
75 #endif  // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_DISPATCHER_HOST_H_