Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / content / browser / service_worker / service_worker_dispatcher_host.h
index 7b99255..7301eee 100644 (file)
@@ -5,17 +5,21 @@
 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_DISPATCHER_HOST_H_
 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_DISPATCHER_HOST_H_
 
+#include "base/id_map.h"
 #include "base/memory/weak_ptr.h"
+#include "base/strings/string16.h"
 #include "content/browser/service_worker/service_worker_registration_status.h"
 #include "content/public/browser/browser_message_filter.h"
 
 class GURL;
+struct EmbeddedWorkerHostMsg_ReportConsoleMessage_Params;
 
 namespace content {
 
 class MessagePortMessageFilter;
 class ServiceWorkerContextCore;
 class ServiceWorkerContextWrapper;
+class ServiceWorkerHandle;
 class ServiceWorkerProviderHost;
 class ServiceWorkerRegistration;
 
@@ -27,11 +31,26 @@ class CONTENT_EXPORT ServiceWorkerDispatcherHost : public BrowserMessageFilter {
 
   void Init(ServiceWorkerContextWrapper* context_wrapper);
 
-  // BrowserIOMessageFilter implementation
+  // BrowserMessageFilter implementation
+  virtual void OnFilterAdded(IPC::Channel* channel) OVERRIDE;
   virtual void OnDestruct() const OVERRIDE;
   virtual bool OnMessageReceived(const IPC::Message& message,
                                  bool* message_was_ok) OVERRIDE;
 
+  // IPC::Sender implementation
+
+  // Send() queues the message until the underlying channel is ready.  This
+  // class assumes that Send() can only fail after that when the renderer
+  // process has terminated, at which point the whole instance will eventually
+  // be destroyed.
+  virtual bool Send(IPC::Message* message) OVERRIDE;
+
+  void RegisterServiceWorkerHandle(scoped_ptr<ServiceWorkerHandle> handle);
+
+  MessagePortMessageFilter* message_port_message_filter() {
+    return message_port_message_filter_;
+  }
+
  protected:
   virtual ~ServiceWorkerDispatcherHost();
 
@@ -41,52 +60,66 @@ class CONTENT_EXPORT ServiceWorkerDispatcherHost : public BrowserMessageFilter {
   friend class TestingServiceWorkerDispatcherHost;
 
   // IPC Message handlers
-  void OnRegisterServiceWorker(int32 thread_id,
-                               int32 request_id,
+  void OnRegisterServiceWorker(int thread_id,
+                               int request_id,
+                               int provider_id,
                                const GURL& pattern,
                                const GURL& script_url);
-  void OnUnregisterServiceWorker(int32 thread_id,
-                                 int32 request_id,
+  void OnUnregisterServiceWorker(int thread_id,
+                                 int request_id,
+                                 int provider_id,
                                  const GURL& pattern);
   void OnProviderCreated(int provider_id);
   void OnProviderDestroyed(int provider_id);
-  void OnAddScriptClient(int thread_id, int provider_id);
-  void OnRemoveScriptClient(int thread_id, int provider_id);
+  void OnSetHostedVersionId(int provider_id, int64 version_id);
+  void OnWorkerScriptLoaded(int embedded_worker_id);
+  void OnWorkerScriptLoadFailed(int embedded_worker_id);
   void OnWorkerStarted(int thread_id,
                        int embedded_worker_id);
   void OnWorkerStopped(int embedded_worker_id);
-  void OnSendMessageToBrowser(int embedded_worker_id,
-                              int request_id,
-                              const IPC::Message& message);
-  void OnPostMessage(int64 registration_id,
+  void OnReportException(int embedded_worker_id,
+                         const base::string16& error_message,
+                         int line_number,
+                         int column_number,
+                         const GURL& source_url);
+  void OnReportConsoleMessage(
+      int embedded_worker_id,
+      const EmbeddedWorkerHostMsg_ReportConsoleMessage_Params& params);
+  void OnPostMessage(int handle_id,
                      const base::string16& message,
                      const std::vector<int>& sent_message_port_ids);
-
-  static void PostMessageFoundRegistration(
-      const base::string16& message,
-      const std::vector<int>& sent_message_port_ids,
-      const std::vector<int>& new_routing_ids,
-      ServiceWorkerStatusCode status,
-      const scoped_refptr<ServiceWorkerRegistration>& result);
+  void OnIncrementServiceWorkerRefCount(int handle_id);
+  void OnDecrementServiceWorkerRefCount(int handle_id);
+  void OnPostMessageToWorker(int handle_id,
+                             const base::string16& message,
+                             const std::vector<int>& sent_message_port_ids);
+  void OnServiceWorkerObjectDestroyed(int handle_id);
 
   // Callbacks from ServiceWorkerContextCore
-  void RegistrationComplete(int32 thread_id,
-                            int32 request_id,
+  void RegistrationComplete(int thread_id,
+                            int request_id,
                             ServiceWorkerStatusCode status,
-                            int64 registration_id);
+                            int64 registration_id,
+                            int64 version_id);
 
-  void UnregistrationComplete(int32 thread_id,
-                              int32 request_id,
+  void UnregistrationComplete(int thread_id,
+                              int request_id,
                               ServiceWorkerStatusCode status);
 
-  void SendRegistrationError(int32 thread_id,
-                             int32 request_id,
+  void SendRegistrationError(int thread_id,
+                             int request_id,
                              ServiceWorkerStatusCode status);
 
   int render_process_id_;
   MessagePortMessageFilter* const message_port_message_filter_;
-
   base::WeakPtr<ServiceWorkerContextCore> context_;
+
+  IDMap<ServiceWorkerHandle, IDMapOwnPointer> handles_;
+
+  bool channel_ready_;  // True after BrowserMessageFilter::channel_ != NULL.
+  ScopedVector<IPC::Message> pending_messages_;
+
+  DISALLOW_COPY_AND_ASSIGN(ServiceWorkerDispatcherHost);
 };
 
 }  // namespace content