ozone: evdev: Sync caps lock LED state to evdev
[chromium-blink-merge.git] / content / browser / service_worker / service_worker_dispatcher_host.h
blobe737a20e41df4178689848c85ef481997e71cce1
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 OnProviderCreated(int provider_id,
96 int render_frame_id,
97 ServiceWorkerProviderType provider_type);
98 void OnProviderDestroyed(int provider_id);
99 void OnSetHostedVersionId(int provider_id, int64 version_id);
100 void OnWorkerReadyForInspection(int embedded_worker_id);
101 void OnWorkerScriptLoaded(int embedded_worker_id,
102 int thread_id,
103 int provider_id);
104 void OnWorkerScriptLoadFailed(int embedded_worker_id);
105 void OnWorkerScriptEvaluated(int embedded_worker_id, bool success);
106 void OnWorkerStarted(int embedded_worker_id);
107 void OnWorkerStopped(int embedded_worker_id);
108 void OnPausedAfterDownload(int embedded_worker_id);
109 void OnReportException(int embedded_worker_id,
110 const base::string16& error_message,
111 int line_number,
112 int column_number,
113 const GURL& source_url);
114 void OnReportConsoleMessage(
115 int embedded_worker_id,
116 const EmbeddedWorkerHostMsg_ReportConsoleMessage_Params& params);
117 void OnIncrementServiceWorkerRefCount(int handle_id);
118 void OnDecrementServiceWorkerRefCount(int handle_id);
119 void OnIncrementRegistrationRefCount(int registration_handle_id);
120 void OnDecrementRegistrationRefCount(int registration_handle_id);
121 void OnPostMessageToWorker(
122 int handle_id,
123 const base::string16& message,
124 const std::vector<TransferredMessagePort>& sent_message_ports);
125 void OnServiceWorkerObjectDestroyed(int handle_id);
126 void OnTerminateWorker(int handle_id);
128 ServiceWorkerRegistrationHandle* FindRegistrationHandle(
129 int provider_id,
130 int64 registration_id);
132 void GetRegistrationObjectInfoAndVersionAttributes(
133 base::WeakPtr<ServiceWorkerProviderHost> provider_host,
134 ServiceWorkerRegistration* registration,
135 ServiceWorkerRegistrationObjectInfo* info,
136 ServiceWorkerVersionAttributes* attrs);
138 // Callbacks from ServiceWorkerContextCore
139 void RegistrationComplete(int thread_id,
140 int provider_id,
141 int request_id,
142 ServiceWorkerStatusCode status,
143 const std::string& status_message,
144 int64 registration_id);
146 void UnregistrationComplete(int thread_id,
147 int request_id,
148 ServiceWorkerStatusCode status);
150 void GetRegistrationComplete(
151 int thread_id,
152 int provider_id,
153 int request_id,
154 ServiceWorkerStatusCode status,
155 const scoped_refptr<ServiceWorkerRegistration>& registration);
157 void SendRegistrationError(int thread_id,
158 int request_id,
159 ServiceWorkerStatusCode status,
160 const std::string& status_message);
162 void SendUnregistrationError(int thread_id,
163 int request_id,
164 ServiceWorkerStatusCode status);
166 void SendGetRegistrationError(int thread_id,
167 int request_id,
168 ServiceWorkerStatusCode status);
170 ServiceWorkerContextCore* GetContext();
172 int render_process_id_;
173 MessagePortMessageFilter* const message_port_message_filter_;
174 ResourceContext* resource_context_;
175 scoped_refptr<ServiceWorkerContextWrapper> context_wrapper_;
177 IDMap<ServiceWorkerHandle, IDMapOwnPointer> handles_;
178 IDMap<ServiceWorkerRegistrationHandle, IDMapOwnPointer> registration_handles_;
180 bool channel_ready_; // True after BrowserMessageFilter::sender_ != NULL.
181 ScopedVector<IPC::Message> pending_messages_;
183 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerDispatcherHost);
186 } // namespace content
188 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_DISPATCHER_HOST_H_