cc: Make picture pile base thread safe.
[chromium-blink-merge.git] / content / browser / service_worker / service_worker_dispatcher_host.h
blobc3140c4c67c294cb692421014642e83c2c570e04
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 ResourceContext;
23 class ServiceWorkerContextCore;
24 class ServiceWorkerContextWrapper;
25 class ServiceWorkerHandle;
26 class ServiceWorkerProviderHost;
27 class ServiceWorkerRegistration;
28 class ServiceWorkerRegistrationHandle;
29 struct ServiceWorkerRegistrationObjectInfo;
30 struct ServiceWorkerVersionAttributes;
32 class CONTENT_EXPORT ServiceWorkerDispatcherHost : public BrowserMessageFilter {
33 public:
34 ServiceWorkerDispatcherHost(
35 int render_process_id,
36 MessagePortMessageFilter* message_port_message_filter,
37 ResourceContext* resource_context);
39 void Init(ServiceWorkerContextWrapper* context_wrapper);
41 // BrowserMessageFilter implementation
42 void OnFilterAdded(IPC::Sender* sender) override;
43 void OnDestruct() const override;
44 bool OnMessageReceived(const IPC::Message& message) override;
46 // IPC::Sender implementation
48 // Send() queues the message until the underlying sender is ready. This
49 // class assumes that Send() can only fail after that when the renderer
50 // process has terminated, at which point the whole instance will eventually
51 // be destroyed.
52 bool Send(IPC::Message* message) override;
54 // Returns the existing registration handle whose reference count is
55 // incremented or newly created one if it doesn't exist.
56 ServiceWorkerRegistrationHandle* GetOrCreateRegistrationHandle(
57 int provider_id,
58 ServiceWorkerRegistration* registration);
60 void RegisterServiceWorkerHandle(scoped_ptr<ServiceWorkerHandle> handle);
61 void RegisterServiceWorkerRegistrationHandle(
62 scoped_ptr<ServiceWorkerRegistrationHandle> handle);
64 MessagePortMessageFilter* message_port_message_filter() {
65 return message_port_message_filter_;
68 protected:
69 ~ServiceWorkerDispatcherHost() override;
71 private:
72 friend class BrowserThread;
73 friend class base::DeleteHelper<ServiceWorkerDispatcherHost>;
74 friend class TestingServiceWorkerDispatcherHost;
76 // IPC Message handlers
77 void OnRegisterServiceWorker(int thread_id,
78 int request_id,
79 int provider_id,
80 const GURL& pattern,
81 const GURL& script_url);
82 void OnUnregisterServiceWorker(int thread_id,
83 int request_id,
84 int provider_id,
85 const GURL& pattern);
86 void OnGetRegistration(int thread_id,
87 int request_id,
88 int provider_id,
89 const GURL& document_url);
90 void OnProviderCreated(int provider_id);
91 void OnProviderDestroyed(int provider_id);
92 void OnSetHostedVersionId(int provider_id, int64 version_id);
93 void OnWorkerReadyForInspection(int embedded_worker_id);
94 void OnWorkerScriptLoaded(int embedded_worker_id, int thread_id);
95 void OnWorkerScriptLoadFailed(int embedded_worker_id);
96 void OnWorkerStarted(int embedded_worker_id);
97 void OnWorkerStopped(int embedded_worker_id);
98 void OnPausedAfterDownload(int embedded_worker_id);
99 void OnReportException(int embedded_worker_id,
100 const base::string16& error_message,
101 int line_number,
102 int column_number,
103 const GURL& source_url);
104 void OnReportConsoleMessage(
105 int embedded_worker_id,
106 const EmbeddedWorkerHostMsg_ReportConsoleMessage_Params& params);
107 void OnPostMessage(int handle_id,
108 const base::string16& message,
109 const std::vector<int>& sent_message_port_ids);
110 void OnIncrementServiceWorkerRefCount(int handle_id);
111 void OnDecrementServiceWorkerRefCount(int handle_id);
112 void OnIncrementRegistrationRefCount(int registration_handle_id);
113 void OnDecrementRegistrationRefCount(int registration_handle_id);
114 void OnPostMessageToWorker(int handle_id,
115 const base::string16& message,
116 const std::vector<int>& sent_message_port_ids);
117 void OnServiceWorkerObjectDestroyed(int handle_id);
119 ServiceWorkerRegistrationHandle* FindRegistrationHandle(
120 int provider_id,
121 int64 registration_id);
123 void GetRegistrationObjectInfoAndVersionAttributes(
124 int provider_id,
125 ServiceWorkerRegistration* registration,
126 ServiceWorkerRegistrationObjectInfo* info,
127 ServiceWorkerVersionAttributes* attrs);
129 // Callbacks from ServiceWorkerContextCore
130 void RegistrationComplete(int thread_id,
131 int provider_id,
132 int request_id,
133 ServiceWorkerStatusCode status,
134 int64 registration_id);
136 void UnregistrationComplete(int thread_id,
137 int request_id,
138 ServiceWorkerStatusCode status);
140 void GetRegistrationComplete(
141 int thread_id,
142 int provider_id,
143 int request_id,
144 ServiceWorkerStatusCode status,
145 const scoped_refptr<ServiceWorkerRegistration>& registration);
147 void SendRegistrationError(int thread_id,
148 int request_id,
149 ServiceWorkerStatusCode status);
151 void SendUnregistrationError(int thread_id,
152 int request_id,
153 ServiceWorkerStatusCode status);
155 void SendGetRegistrationError(int thread_id,
156 int request_id,
157 ServiceWorkerStatusCode status);
159 ServiceWorkerContextCore* GetContext();
161 int render_process_id_;
162 MessagePortMessageFilter* const message_port_message_filter_;
163 ResourceContext* resource_context_;
164 scoped_refptr<ServiceWorkerContextWrapper> context_wrapper_;
166 IDMap<ServiceWorkerHandle, IDMapOwnPointer> handles_;
167 IDMap<ServiceWorkerRegistrationHandle, IDMapOwnPointer> registration_handles_;
169 bool channel_ready_; // True after BrowserMessageFilter::sender_ != NULL.
170 ScopedVector<IPC::Message> pending_messages_;
172 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerDispatcherHost);
175 } // namespace content
177 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_DISPATCHER_HOST_H_