Add long running gmail memory benchmark for background tab.
[chromium-blink-merge.git] / content / browser / service_worker / service_worker_dispatcher_host.h
blobc2e5c25b3e74027a2afceed88c14745ab54d3565
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/common/service_worker/service_worker_types.h"
15 #include "content/public/browser/browser_message_filter.h"
17 class GURL;
18 struct EmbeddedWorkerHostMsg_ReportConsoleMessage_Params;
20 namespace content {
22 class MessagePortMessageFilter;
23 class ResourceContext;
24 class ServiceWorkerContextCore;
25 class ServiceWorkerContextWrapper;
26 class ServiceWorkerHandle;
27 class ServiceWorkerProviderHost;
28 class ServiceWorkerRegistration;
29 class ServiceWorkerRegistrationHandle;
30 class ServiceWorkerVersion;
31 struct ServiceWorkerObjectInfo;
32 struct ServiceWorkerRegistrationInfo;
33 struct ServiceWorkerRegistrationObjectInfo;
34 struct ServiceWorkerVersionAttributes;
35 struct TransferredMessagePort;
37 class CONTENT_EXPORT ServiceWorkerDispatcherHost : public BrowserMessageFilter {
38 public:
39 ServiceWorkerDispatcherHost(
40 int render_process_id,
41 MessagePortMessageFilter* message_port_message_filter,
42 ResourceContext* resource_context);
44 void Init(ServiceWorkerContextWrapper* context_wrapper);
46 // BrowserMessageFilter implementation
47 void OnFilterAdded(IPC::Sender* sender) override;
48 void OnFilterRemoved() override;
49 void OnDestruct() const override;
50 bool OnMessageReceived(const IPC::Message& message) override;
52 // IPC::Sender implementation
54 // Send() queues the message until the underlying sender is ready. This
55 // class assumes that Send() can only fail after that when the renderer
56 // process has terminated, at which point the whole instance will eventually
57 // be destroyed.
58 bool Send(IPC::Message* message) override;
60 void RegisterServiceWorkerHandle(scoped_ptr<ServiceWorkerHandle> handle);
61 void RegisterServiceWorkerRegistrationHandle(
62 scoped_ptr<ServiceWorkerRegistrationHandle> handle);
64 ServiceWorkerHandle* FindServiceWorkerHandle(int provider_id,
65 int64 version_id);
67 // Returns the existing registration handle whose reference count is
68 // incremented or newly created one if it doesn't exist.
69 ServiceWorkerRegistrationHandle* GetOrCreateRegistrationHandle(
70 base::WeakPtr<ServiceWorkerProviderHost> provider_host,
71 ServiceWorkerRegistration* registration);
73 MessagePortMessageFilter* message_port_message_filter() {
74 return message_port_message_filter_;
77 protected:
78 ~ServiceWorkerDispatcherHost() override;
80 private:
81 friend class BrowserThread;
82 friend class base::DeleteHelper<ServiceWorkerDispatcherHost>;
83 friend class TestingServiceWorkerDispatcherHost;
85 // IPC Message handlers
86 void OnRegisterServiceWorker(int thread_id,
87 int request_id,
88 int provider_id,
89 const GURL& pattern,
90 const GURL& script_url);
91 void OnUpdateServiceWorker(int provider_id, int64 registration_id);
92 void OnUnregisterServiceWorker(int thread_id,
93 int request_id,
94 int provider_id,
95 int64 registration_id);
96 void OnGetRegistration(int thread_id,
97 int request_id,
98 int provider_id,
99 const GURL& document_url);
100 void OnGetRegistrations(int thread_id, int request_id, int provider_id);
101 void OnGetRegistrationForReady(int thread_id,
102 int request_id,
103 int provider_id);
104 void OnProviderCreated(int provider_id,
105 int route_id,
106 ServiceWorkerProviderType provider_type);
107 void OnProviderDestroyed(int provider_id);
108 void OnSetHostedVersionId(int provider_id, int64 version_id);
109 void OnWorkerReadyForInspection(int embedded_worker_id);
110 void OnWorkerScriptLoaded(int embedded_worker_id,
111 int thread_id,
112 int provider_id);
113 void OnWorkerScriptLoadFailed(int embedded_worker_id);
114 void OnWorkerScriptEvaluated(int embedded_worker_id, bool success);
115 void OnWorkerStarted(int embedded_worker_id);
116 void OnWorkerStopped(int embedded_worker_id);
117 void OnReportException(int embedded_worker_id,
118 const base::string16& error_message,
119 int line_number,
120 int column_number,
121 const GURL& source_url);
122 void OnReportConsoleMessage(
123 int embedded_worker_id,
124 const EmbeddedWorkerHostMsg_ReportConsoleMessage_Params& params);
125 void OnIncrementServiceWorkerRefCount(int handle_id);
126 void OnDecrementServiceWorkerRefCount(int handle_id);
127 void OnIncrementRegistrationRefCount(int registration_handle_id);
128 void OnDecrementRegistrationRefCount(int registration_handle_id);
129 void OnPostMessageToWorker(
130 int handle_id,
131 const base::string16& message,
132 const std::vector<TransferredMessagePort>& sent_message_ports);
133 void OnServiceWorkerObjectDestroyed(int handle_id);
134 void OnTerminateWorker(int handle_id);
136 ServiceWorkerRegistrationHandle* FindRegistrationHandle(
137 int provider_id,
138 int64 registration_id);
140 void GetRegistrationObjectInfoAndVersionAttributes(
141 base::WeakPtr<ServiceWorkerProviderHost> provider_host,
142 ServiceWorkerRegistration* registration,
143 ServiceWorkerRegistrationObjectInfo* info,
144 ServiceWorkerVersionAttributes* attrs);
146 // Callbacks from ServiceWorkerContextCore
147 void RegistrationComplete(int thread_id,
148 int provider_id,
149 int request_id,
150 ServiceWorkerStatusCode status,
151 const std::string& status_message,
152 int64 registration_id);
154 void UnregistrationComplete(int thread_id,
155 int request_id,
156 ServiceWorkerStatusCode status);
158 void GetRegistrationComplete(
159 int thread_id,
160 int provider_id,
161 int request_id,
162 ServiceWorkerStatusCode status,
163 const scoped_refptr<ServiceWorkerRegistration>& registration);
165 void GetRegistrationsComplete(
166 int thread_id,
167 int provider_id,
168 int request_id,
169 const std::vector<scoped_refptr<ServiceWorkerRegistration>>&
170 registrations);
172 void GetRegistrationForReadyComplete(
173 int thread_id,
174 int request_id,
175 base::WeakPtr<ServiceWorkerProviderHost> provider_host,
176 ServiceWorkerRegistration* registration);
178 void SendRegistrationError(int thread_id,
179 int request_id,
180 ServiceWorkerStatusCode status,
181 const std::string& status_message);
183 void SendUnregistrationError(int thread_id,
184 int request_id,
185 ServiceWorkerStatusCode status);
187 void SendGetRegistrationError(int thread_id,
188 int request_id,
189 ServiceWorkerStatusCode status);
191 void SendGetRegistrationsError(int thread_id,
192 int request_id,
193 ServiceWorkerStatusCode status);
195 ServiceWorkerContextCore* GetContext();
197 int render_process_id_;
198 MessagePortMessageFilter* const message_port_message_filter_;
199 ResourceContext* resource_context_;
200 scoped_refptr<ServiceWorkerContextWrapper> context_wrapper_;
202 IDMap<ServiceWorkerHandle, IDMapOwnPointer> handles_;
203 IDMap<ServiceWorkerRegistrationHandle, IDMapOwnPointer> registration_handles_;
205 bool channel_ready_; // True after BrowserMessageFilter::sender_ != NULL.
206 ScopedVector<IPC::Message> pending_messages_;
208 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerDispatcherHost);
211 } // namespace content
213 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_DISPATCHER_HOST_H_