Simplify ChildProcessLauncher
[chromium-blink-merge.git] / content / browser / service_worker / service_worker_dispatcher_host.h
blob201935382ad4ada19b8f707f9e90dc4e97df33ae
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 ServiceWorkerRegistrationObjectInfo;
33 struct ServiceWorkerVersionAttributes;
34 struct TransferredMessagePort;
36 class CONTENT_EXPORT ServiceWorkerDispatcherHost : public BrowserMessageFilter {
37 public:
38 ServiceWorkerDispatcherHost(
39 int render_process_id,
40 MessagePortMessageFilter* message_port_message_filter,
41 ResourceContext* resource_context);
43 void Init(ServiceWorkerContextWrapper* context_wrapper);
45 // BrowserMessageFilter implementation
46 void OnFilterAdded(IPC::Sender* sender) override;
47 void OnFilterRemoved() override;
48 void OnDestruct() const override;
49 bool OnMessageReceived(const IPC::Message& message) override;
51 // IPC::Sender implementation
53 // Send() queues the message until the underlying sender is ready. This
54 // class assumes that Send() can only fail after that when the renderer
55 // process has terminated, at which point the whole instance will eventually
56 // be destroyed.
57 bool Send(IPC::Message* message) override;
59 void RegisterServiceWorkerHandle(scoped_ptr<ServiceWorkerHandle> handle);
60 void RegisterServiceWorkerRegistrationHandle(
61 scoped_ptr<ServiceWorkerRegistrationHandle> handle);
63 // Returns the existing registration handle whose reference count is
64 // incremented or newly created one if it doesn't exist.
65 ServiceWorkerRegistrationHandle* GetOrCreateRegistrationHandle(
66 base::WeakPtr<ServiceWorkerProviderHost> provider_host,
67 ServiceWorkerRegistration* registration);
69 MessagePortMessageFilter* message_port_message_filter() {
70 return message_port_message_filter_;
73 protected:
74 ~ServiceWorkerDispatcherHost() override;
76 private:
77 friend class BrowserThread;
78 friend class base::DeleteHelper<ServiceWorkerDispatcherHost>;
79 friend class TestingServiceWorkerDispatcherHost;
81 // IPC Message handlers
82 void OnRegisterServiceWorker(int thread_id,
83 int request_id,
84 int provider_id,
85 const GURL& pattern,
86 const GURL& script_url);
87 void OnUnregisterServiceWorker(int thread_id,
88 int request_id,
89 int provider_id,
90 const GURL& pattern);
91 void OnGetRegistration(int thread_id,
92 int request_id,
93 int provider_id,
94 const GURL& document_url);
95 void OnGetRegistrationForReady(int thread_id,
96 int request_id,
97 int provider_id);
98 void OnProviderCreated(int provider_id,
99 int render_frame_id,
100 ServiceWorkerProviderType provider_type);
101 void OnProviderDestroyed(int provider_id);
102 void OnSetHostedVersionId(int provider_id, int64 version_id);
103 void OnWorkerReadyForInspection(int embedded_worker_id);
104 void OnWorkerScriptLoaded(int embedded_worker_id,
105 int thread_id,
106 int provider_id);
107 void OnWorkerScriptLoadFailed(int embedded_worker_id);
108 void OnWorkerScriptEvaluated(int embedded_worker_id, bool success);
109 void OnWorkerStarted(int embedded_worker_id);
110 void OnWorkerStopped(int embedded_worker_id);
111 void OnPausedAfterDownload(int embedded_worker_id);
112 void OnReportException(int embedded_worker_id,
113 const base::string16& error_message,
114 int line_number,
115 int column_number,
116 const GURL& source_url);
117 void OnReportConsoleMessage(
118 int embedded_worker_id,
119 const EmbeddedWorkerHostMsg_ReportConsoleMessage_Params& params);
120 void OnIncrementServiceWorkerRefCount(int handle_id);
121 void OnDecrementServiceWorkerRefCount(int handle_id);
122 void OnIncrementRegistrationRefCount(int registration_handle_id);
123 void OnDecrementRegistrationRefCount(int registration_handle_id);
124 void OnPostMessageToWorker(
125 int handle_id,
126 const base::string16& message,
127 const std::vector<TransferredMessagePort>& sent_message_ports);
128 void OnServiceWorkerObjectDestroyed(int handle_id);
129 void OnTerminateWorker(int handle_id);
131 ServiceWorkerRegistrationHandle* FindRegistrationHandle(
132 int provider_id,
133 int64 registration_id);
135 void GetRegistrationObjectInfoAndVersionAttributes(
136 base::WeakPtr<ServiceWorkerProviderHost> provider_host,
137 ServiceWorkerRegistration* registration,
138 ServiceWorkerRegistrationObjectInfo* info,
139 ServiceWorkerVersionAttributes* attrs);
141 // Callbacks from ServiceWorkerContextCore
142 void RegistrationComplete(int thread_id,
143 int provider_id,
144 int request_id,
145 ServiceWorkerStatusCode status,
146 const std::string& status_message,
147 int64 registration_id);
149 void UnregistrationComplete(int thread_id,
150 int request_id,
151 ServiceWorkerStatusCode status);
153 void GetRegistrationComplete(
154 int thread_id,
155 int provider_id,
156 int request_id,
157 ServiceWorkerStatusCode status,
158 const scoped_refptr<ServiceWorkerRegistration>& registration);
160 void GetRegistrationForReadyComplete(
161 int thread_id,
162 int request_id,
163 base::WeakPtr<ServiceWorkerProviderHost> provider_host,
164 ServiceWorkerRegistration* registration);
166 void SendRegistrationError(int thread_id,
167 int request_id,
168 ServiceWorkerStatusCode status,
169 const std::string& status_message);
171 void SendUnregistrationError(int thread_id,
172 int request_id,
173 ServiceWorkerStatusCode status);
175 void SendGetRegistrationError(int thread_id,
176 int request_id,
177 ServiceWorkerStatusCode status);
179 ServiceWorkerContextCore* GetContext();
181 int render_process_id_;
182 MessagePortMessageFilter* const message_port_message_filter_;
183 ResourceContext* resource_context_;
184 scoped_refptr<ServiceWorkerContextWrapper> context_wrapper_;
186 IDMap<ServiceWorkerHandle, IDMapOwnPointer> handles_;
187 IDMap<ServiceWorkerRegistrationHandle, IDMapOwnPointer> registration_handles_;
189 bool channel_ready_; // True after BrowserMessageFilter::sender_ != NULL.
190 ScopedVector<IPC::Message> pending_messages_;
192 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerDispatcherHost);
195 } // namespace content
197 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_DISPATCHER_HOST_H_