Battery Status API: add UMA logging for Linux.
[chromium-blink-merge.git] / content / browser / service_worker / service_worker_dispatcher_host.h
blob9ea4296b1e63773ea4597a693377f4b221b1a6a1
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_BROWSER_SERVICE_WORKER_SERVICE_WORKER_DISPATCHER_HOST_H_
6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_DISPATCHER_HOST_H_
8 #include <vector>
10 #include "base/id_map.h"
11 #include "base/memory/weak_ptr.h"
12 #include "base/strings/string16.h"
13 #include "content/browser/service_worker/service_worker_registration_status.h"
14 #include "content/public/browser/browser_message_filter.h"
16 class GURL;
17 struct EmbeddedWorkerHostMsg_ReportConsoleMessage_Params;
19 namespace content {
21 class MessagePortMessageFilter;
22 class ServiceWorkerContextCore;
23 class ServiceWorkerContextWrapper;
24 class ServiceWorkerHandle;
25 class ServiceWorkerProviderHost;
26 class ServiceWorkerRegistration;
27 class ServiceWorkerRegistrationHandle;
29 class CONTENT_EXPORT ServiceWorkerDispatcherHost : public BrowserMessageFilter {
30 public:
31 ServiceWorkerDispatcherHost(
32 int render_process_id,
33 MessagePortMessageFilter* message_port_message_filter);
35 void Init(ServiceWorkerContextWrapper* context_wrapper);
37 // BrowserMessageFilter implementation
38 virtual void OnFilterAdded(IPC::Sender* sender) OVERRIDE;
39 virtual void OnDestruct() const OVERRIDE;
40 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
42 // IPC::Sender implementation
44 // Send() queues the message until the underlying sender is ready. This
45 // class assumes that Send() can only fail after that when the renderer
46 // process has terminated, at which point the whole instance will eventually
47 // be destroyed.
48 virtual bool Send(IPC::Message* message) OVERRIDE;
50 void RegisterServiceWorkerHandle(scoped_ptr<ServiceWorkerHandle> handle);
51 void RegisterServiceWorkerRegistrationHandle(
52 scoped_ptr<ServiceWorkerRegistrationHandle> handle);
54 MessagePortMessageFilter* message_port_message_filter() {
55 return message_port_message_filter_;
58 protected:
59 virtual ~ServiceWorkerDispatcherHost();
61 private:
62 friend class BrowserThread;
63 friend class base::DeleteHelper<ServiceWorkerDispatcherHost>;
64 friend class TestingServiceWorkerDispatcherHost;
66 // IPC Message handlers
67 void OnRegisterServiceWorker(int thread_id,
68 int request_id,
69 int provider_id,
70 const GURL& pattern,
71 const GURL& script_url);
72 void OnUnregisterServiceWorker(int thread_id,
73 int request_id,
74 int provider_id,
75 const GURL& pattern);
76 void OnProviderCreated(int provider_id);
77 void OnProviderDestroyed(int provider_id);
78 void OnSetHostedVersionId(int provider_id, int64 version_id);
79 void OnWorkerReadyForInspection(int embedded_worker_id);
80 void OnWorkerScriptLoaded(int embedded_worker_id, int thread_id);
81 void OnWorkerScriptLoadFailed(int embedded_worker_id);
82 void OnWorkerStarted(int embedded_worker_id);
83 void OnWorkerStopped(int embedded_worker_id);
84 void OnPausedAfterDownload(int embedded_worker_id);
85 void OnReportException(int embedded_worker_id,
86 const base::string16& error_message,
87 int line_number,
88 int column_number,
89 const GURL& source_url);
90 void OnReportConsoleMessage(
91 int embedded_worker_id,
92 const EmbeddedWorkerHostMsg_ReportConsoleMessage_Params& params);
93 void OnPostMessage(int handle_id,
94 const base::string16& message,
95 const std::vector<int>& sent_message_port_ids);
96 void OnIncrementServiceWorkerRefCount(int handle_id);
97 void OnDecrementServiceWorkerRefCount(int handle_id);
98 void OnIncrementRegistrationRefCount(int registration_handle_id);
99 void OnDecrementRegistrationRefCount(int registration_handle_id);
100 void OnPostMessageToWorker(int handle_id,
101 const base::string16& message,
102 const std::vector<int>& sent_message_port_ids);
103 void OnServiceWorkerObjectDestroyed(int handle_id);
105 ServiceWorkerRegistrationHandle* FindRegistrationHandle(
106 int provider_id,
107 int64 registration_id);
109 // Callbacks from ServiceWorkerContextCore
110 void RegistrationComplete(int thread_id,
111 int provider_id,
112 int request_id,
113 ServiceWorkerStatusCode status,
114 int64 registration_id,
115 int64 version_id);
117 void UnregistrationComplete(int thread_id,
118 int request_id,
119 ServiceWorkerStatusCode status);
121 void SendRegistrationError(int thread_id,
122 int request_id,
123 ServiceWorkerStatusCode status);
125 ServiceWorkerContextCore* GetContext();
127 int render_process_id_;
128 MessagePortMessageFilter* const message_port_message_filter_;
129 scoped_refptr<ServiceWorkerContextWrapper> context_wrapper_;
131 IDMap<ServiceWorkerHandle, IDMapOwnPointer> handles_;
132 IDMap<ServiceWorkerRegistrationHandle, IDMapOwnPointer> registration_handles_;
134 bool channel_ready_; // True after BrowserMessageFilter::sender_ != NULL.
135 ScopedVector<IPC::Message> pending_messages_;
137 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerDispatcherHost);
140 } // namespace content
142 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_DISPATCHER_HOST_H_