Use multiline attribute to check for IA2_STATE_MULTILINE.
[chromium-blink-merge.git] / content / browser / service_worker / service_worker_dispatcher_host.h
blobd121e6bafa5c9f067fd7e2a6b7d705a8fb1650a4
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 ServiceWorkerHandle* FindServiceWorkerHandle(int provider_id,
64 int64 version_id);
66 // Returns the existing registration handle whose reference count is
67 // incremented or newly created one if it doesn't exist.
68 ServiceWorkerRegistrationHandle* GetOrCreateRegistrationHandle(
69 base::WeakPtr<ServiceWorkerProviderHost> provider_host,
70 ServiceWorkerRegistration* registration);
72 MessagePortMessageFilter* message_port_message_filter() {
73 return message_port_message_filter_;
76 protected:
77 ~ServiceWorkerDispatcherHost() override;
79 private:
80 friend class BrowserThread;
81 friend class base::DeleteHelper<ServiceWorkerDispatcherHost>;
82 friend class TestingServiceWorkerDispatcherHost;
84 // IPC Message handlers
85 void OnRegisterServiceWorker(int thread_id,
86 int request_id,
87 int provider_id,
88 const GURL& pattern,
89 const GURL& script_url);
90 void OnUnregisterServiceWorker(int thread_id,
91 int request_id,
92 int provider_id,
93 const GURL& pattern);
94 void OnGetRegistration(int thread_id,
95 int request_id,
96 int provider_id,
97 const GURL& document_url);
98 void OnGetRegistrationForReady(int thread_id,
99 int request_id,
100 int provider_id);
101 void OnProviderCreated(int provider_id,
102 int render_frame_id,
103 ServiceWorkerProviderType provider_type);
104 void OnProviderDestroyed(int provider_id);
105 void OnSetHostedVersionId(int provider_id, int64 version_id);
106 void OnWorkerReadyForInspection(int embedded_worker_id);
107 void OnWorkerScriptLoaded(int embedded_worker_id,
108 int thread_id,
109 int provider_id);
110 void OnWorkerScriptLoadFailed(int embedded_worker_id);
111 void OnWorkerScriptEvaluated(int embedded_worker_id, bool success);
112 void OnWorkerStarted(int embedded_worker_id);
113 void OnWorkerStopped(int embedded_worker_id);
114 void OnPausedAfterDownload(int embedded_worker_id);
115 void OnReportException(int embedded_worker_id,
116 const base::string16& error_message,
117 int line_number,
118 int column_number,
119 const GURL& source_url);
120 void OnReportConsoleMessage(
121 int embedded_worker_id,
122 const EmbeddedWorkerHostMsg_ReportConsoleMessage_Params& params);
123 void OnIncrementServiceWorkerRefCount(int handle_id);
124 void OnDecrementServiceWorkerRefCount(int handle_id);
125 void OnIncrementRegistrationRefCount(int registration_handle_id);
126 void OnDecrementRegistrationRefCount(int registration_handle_id);
127 void OnPostMessageToWorker(
128 int handle_id,
129 const base::string16& message,
130 const std::vector<TransferredMessagePort>& sent_message_ports);
131 void OnServiceWorkerObjectDestroyed(int handle_id);
132 void OnTerminateWorker(int handle_id);
134 ServiceWorkerRegistrationHandle* FindRegistrationHandle(
135 int provider_id,
136 int64 registration_id);
138 void GetRegistrationObjectInfoAndVersionAttributes(
139 base::WeakPtr<ServiceWorkerProviderHost> provider_host,
140 ServiceWorkerRegistration* registration,
141 ServiceWorkerRegistrationObjectInfo* info,
142 ServiceWorkerVersionAttributes* attrs);
144 // Callbacks from ServiceWorkerContextCore
145 void RegistrationComplete(int thread_id,
146 int provider_id,
147 int request_id,
148 ServiceWorkerStatusCode status,
149 const std::string& status_message,
150 int64 registration_id);
152 void UnregistrationComplete(int thread_id,
153 int request_id,
154 ServiceWorkerStatusCode status);
156 void GetRegistrationComplete(
157 int thread_id,
158 int provider_id,
159 int request_id,
160 ServiceWorkerStatusCode status,
161 const scoped_refptr<ServiceWorkerRegistration>& registration);
163 void GetRegistrationForReadyComplete(
164 int thread_id,
165 int request_id,
166 base::WeakPtr<ServiceWorkerProviderHost> provider_host,
167 ServiceWorkerRegistration* registration);
169 void SendRegistrationError(int thread_id,
170 int request_id,
171 ServiceWorkerStatusCode status,
172 const std::string& status_message);
174 void SendUnregistrationError(int thread_id,
175 int request_id,
176 ServiceWorkerStatusCode status);
178 void SendGetRegistrationError(int thread_id,
179 int request_id,
180 ServiceWorkerStatusCode status);
182 ServiceWorkerContextCore* GetContext();
184 int render_process_id_;
185 MessagePortMessageFilter* const message_port_message_filter_;
186 ResourceContext* resource_context_;
187 scoped_refptr<ServiceWorkerContextWrapper> context_wrapper_;
189 IDMap<ServiceWorkerHandle, IDMapOwnPointer> handles_;
190 IDMap<ServiceWorkerRegistrationHandle, IDMapOwnPointer> registration_handles_;
192 bool channel_ready_; // True after BrowserMessageFilter::sender_ != NULL.
193 ScopedVector<IPC::Message> pending_messages_;
195 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerDispatcherHost);
198 } // namespace content
200 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_DISPATCHER_HOST_H_