| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_DISPATCHER_HOST_H_ | 5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_DISPATCHER_HOST_H_ |
| 6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_DISPATCHER_HOST_H_ | 6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_DISPATCHER_HOST_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 | 23 |
| 24 class GURL; | 24 class GURL; |
| 25 struct EmbeddedWorkerHostMsg_ReportConsoleMessage_Params; | 25 struct EmbeddedWorkerHostMsg_ReportConsoleMessage_Params; |
| 26 | 26 |
| 27 namespace url { | 27 namespace url { |
| 28 class Origin; | 28 class Origin; |
| 29 } // namespace url | 29 } // namespace url |
| 30 | 30 |
| 31 namespace content { | 31 namespace content { |
| 32 | 32 |
| 33 class MessagePortMessageFilter; | 33 class MessagePort; |
| 34 class ResourceContext; | 34 class ResourceContext; |
| 35 class ServiceWorkerContextCore; | 35 class ServiceWorkerContextCore; |
| 36 class ServiceWorkerContextWrapper; | 36 class ServiceWorkerContextWrapper; |
| 37 class ServiceWorkerHandle; | 37 class ServiceWorkerHandle; |
| 38 class ServiceWorkerProviderHost; | 38 class ServiceWorkerProviderHost; |
| 39 class ServiceWorkerRegistration; | 39 class ServiceWorkerRegistration; |
| 40 class ServiceWorkerRegistrationHandle; | 40 class ServiceWorkerRegistrationHandle; |
| 41 class ServiceWorkerVersion; | 41 class ServiceWorkerVersion; |
| 42 struct ServiceWorkerObjectInfo; | 42 struct ServiceWorkerObjectInfo; |
| 43 struct ServiceWorkerRegistrationObjectInfo; | 43 struct ServiceWorkerRegistrationObjectInfo; |
| 44 struct ServiceWorkerVersionAttributes; | 44 struct ServiceWorkerVersionAttributes; |
| 45 | 45 |
| 46 class CONTENT_EXPORT ServiceWorkerDispatcherHost | 46 class CONTENT_EXPORT ServiceWorkerDispatcherHost |
| 47 : public mojom::ServiceWorkerDispatcherHost, | 47 : public mojom::ServiceWorkerDispatcherHost, |
| 48 public BrowserMessageFilter { | 48 public BrowserMessageFilter { |
| 49 public: | 49 public: |
| 50 ServiceWorkerDispatcherHost( | 50 ServiceWorkerDispatcherHost( |
| 51 int render_process_id, | 51 int render_process_id, |
| 52 MessagePortMessageFilter* message_port_message_filter, | |
| 53 ResourceContext* resource_context); | 52 ResourceContext* resource_context); |
| 54 | 53 |
| 55 void Init(ServiceWorkerContextWrapper* context_wrapper); | 54 void Init(ServiceWorkerContextWrapper* context_wrapper); |
| 56 | 55 |
| 57 // BrowserMessageFilter implementation | 56 // BrowserMessageFilter implementation |
| 58 void OnFilterAdded(IPC::Channel* channel) override; | 57 void OnFilterAdded(IPC::Channel* channel) override; |
| 59 void OnFilterRemoved() override; | 58 void OnFilterRemoved() override; |
| 60 void OnDestruct() const override; | 59 void OnDestruct() const override; |
| 61 bool OnMessageReceived(const IPC::Message& message) override; | 60 bool OnMessageReceived(const IPC::Message& message) override; |
| 62 | 61 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 74 | 73 |
| 75 ServiceWorkerHandle* FindServiceWorkerHandle(int provider_id, | 74 ServiceWorkerHandle* FindServiceWorkerHandle(int provider_id, |
| 76 int64_t version_id); | 75 int64_t version_id); |
| 77 | 76 |
| 78 // Returns the existing registration handle whose reference count is | 77 // Returns the existing registration handle whose reference count is |
| 79 // incremented or a newly created one if it doesn't exist. | 78 // incremented or a newly created one if it doesn't exist. |
| 80 ServiceWorkerRegistrationHandle* GetOrCreateRegistrationHandle( | 79 ServiceWorkerRegistrationHandle* GetOrCreateRegistrationHandle( |
| 81 base::WeakPtr<ServiceWorkerProviderHost> provider_host, | 80 base::WeakPtr<ServiceWorkerProviderHost> provider_host, |
| 82 ServiceWorkerRegistration* registration); | 81 ServiceWorkerRegistration* registration); |
| 83 | 82 |
| 84 MessagePortMessageFilter* message_port_message_filter() { | |
| 85 return message_port_message_filter_; | |
| 86 } | |
| 87 | |
| 88 protected: | 83 protected: |
| 89 ~ServiceWorkerDispatcherHost() override; | 84 ~ServiceWorkerDispatcherHost() override; |
| 90 | 85 |
| 91 private: | 86 private: |
| 92 friend class BrowserThread; | 87 friend class BrowserThread; |
| 93 friend class base::DeleteHelper<ServiceWorkerDispatcherHost>; | 88 friend class base::DeleteHelper<ServiceWorkerDispatcherHost>; |
| 94 friend class ServiceWorkerDispatcherHostTest; | 89 friend class ServiceWorkerDispatcherHostTest; |
| 95 friend class TestingServiceWorkerDispatcherHost; | 90 friend class TestingServiceWorkerDispatcherHost; |
| 96 | 91 |
| 97 using StatusCallback = base::Callback<void(ServiceWorkerStatusCode status)>; | 92 using StatusCallback = base::Callback<void(ServiceWorkerStatusCode status)>; |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 int line_number, | 157 int line_number, |
| 163 int column_number, | 158 int column_number, |
| 164 const GURL& source_url); | 159 const GURL& source_url); |
| 165 void OnReportConsoleMessage( | 160 void OnReportConsoleMessage( |
| 166 int embedded_worker_id, | 161 int embedded_worker_id, |
| 167 const EmbeddedWorkerHostMsg_ReportConsoleMessage_Params& params); | 162 const EmbeddedWorkerHostMsg_ReportConsoleMessage_Params& params); |
| 168 void OnIncrementServiceWorkerRefCount(int handle_id); | 163 void OnIncrementServiceWorkerRefCount(int handle_id); |
| 169 void OnDecrementServiceWorkerRefCount(int handle_id); | 164 void OnDecrementServiceWorkerRefCount(int handle_id); |
| 170 void OnIncrementRegistrationRefCount(int registration_handle_id); | 165 void OnIncrementRegistrationRefCount(int registration_handle_id); |
| 171 void OnDecrementRegistrationRefCount(int registration_handle_id); | 166 void OnDecrementRegistrationRefCount(int registration_handle_id); |
| 172 void OnPostMessageToWorker(int handle_id, | 167 void OnPostMessageToWorker( |
| 173 int provider_id, | 168 int handle_id, |
| 174 const base::string16& message, | 169 int provider_id, |
| 175 const url::Origin& source_origin, | 170 const base::string16& message, |
| 176 const std::vector<int>& sent_message_ports); | 171 const url::Origin& source_origin, |
| 172 const std::vector<MessagePort>& sent_message_ports); |
| 177 | 173 |
| 178 void OnTerminateWorker(int handle_id); | 174 void OnTerminateWorker(int handle_id); |
| 179 | 175 |
| 180 void DispatchExtendableMessageEvent( | 176 void DispatchExtendableMessageEvent( |
| 181 scoped_refptr<ServiceWorkerVersion> worker, | 177 scoped_refptr<ServiceWorkerVersion> worker, |
| 182 const base::string16& message, | 178 const base::string16& message, |
| 183 const url::Origin& source_origin, | 179 const url::Origin& source_origin, |
| 184 const std::vector<int>& sent_message_ports, | 180 const std::vector<MessagePort>& sent_message_ports, |
| 185 ServiceWorkerProviderHost* sender_provider_host, | 181 ServiceWorkerProviderHost* sender_provider_host, |
| 186 const StatusCallback& callback); | 182 const StatusCallback& callback); |
| 187 template <typename SourceInfo> | 183 template <typename SourceInfo> |
| 188 void DispatchExtendableMessageEventInternal( | 184 void DispatchExtendableMessageEventInternal( |
| 189 scoped_refptr<ServiceWorkerVersion> worker, | 185 scoped_refptr<ServiceWorkerVersion> worker, |
| 190 const base::string16& message, | 186 const base::string16& message, |
| 191 const url::Origin& source_origin, | 187 const url::Origin& source_origin, |
| 192 const std::vector<int>& sent_message_ports, | 188 const std::vector<MessagePort>& sent_message_ports, |
| 193 const base::Optional<base::TimeDelta>& timeout, | 189 const base::Optional<base::TimeDelta>& timeout, |
| 194 const StatusCallback& callback, | 190 const StatusCallback& callback, |
| 195 const SourceInfo& source_info); | 191 const SourceInfo& source_info); |
| 196 void DispatchExtendableMessageEventAfterStartWorker( | 192 void DispatchExtendableMessageEventAfterStartWorker( |
| 197 scoped_refptr<ServiceWorkerVersion> worker, | 193 scoped_refptr<ServiceWorkerVersion> worker, |
| 198 const base::string16& message, | 194 const base::string16& message, |
| 199 const url::Origin& source_origin, | 195 const url::Origin& source_origin, |
| 200 const std::vector<int>& sent_message_ports, | 196 const std::vector<MessagePort>& sent_message_ports, |
| 201 const ExtendableMessageEventSource& source, | 197 const ExtendableMessageEventSource& source, |
| 202 const base::Optional<base::TimeDelta>& timeout, | 198 const base::Optional<base::TimeDelta>& timeout, |
| 203 const StatusCallback& callback); | 199 const StatusCallback& callback); |
| 204 template <typename SourceInfo> | 200 template <typename SourceInfo> |
| 205 void DidFailToDispatchExtendableMessageEvent( | 201 void DidFailToDispatchExtendableMessageEvent( |
| 206 const std::vector<int>& sent_message_ports, | 202 const std::vector<MessagePort>& sent_message_ports, |
| 207 const SourceInfo& source_info, | 203 const SourceInfo& source_info, |
| 208 const StatusCallback& callback, | 204 const StatusCallback& callback, |
| 209 ServiceWorkerStatusCode status); | 205 ServiceWorkerStatusCode status); |
| 210 void ReleaseSourceInfo(const ServiceWorkerClientInfo& source_info); | 206 void ReleaseSourceInfo(const ServiceWorkerClientInfo& source_info); |
| 211 void ReleaseSourceInfo(const ServiceWorkerObjectInfo& source_info); | 207 void ReleaseSourceInfo(const ServiceWorkerObjectInfo& source_info); |
| 212 | 208 |
| 213 ServiceWorkerRegistrationHandle* FindRegistrationHandle( | 209 ServiceWorkerRegistrationHandle* FindRegistrationHandle( |
| 214 int provider_id, | 210 int provider_id, |
| 215 int64_t registration_handle_id); | 211 int64_t registration_handle_id); |
| 216 | 212 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 int registration_id, | 264 int registration_id, |
| 269 bool enable, | 265 bool enable, |
| 270 ServiceWorkerStatusCode status); | 266 ServiceWorkerStatusCode status); |
| 271 void DidUpdateNavigationPreloadHeader(int thread_id, | 267 void DidUpdateNavigationPreloadHeader(int thread_id, |
| 272 int request_id, | 268 int request_id, |
| 273 int registration_id, | 269 int registration_id, |
| 274 const std::string& value, | 270 const std::string& value, |
| 275 ServiceWorkerStatusCode status); | 271 ServiceWorkerStatusCode status); |
| 276 | 272 |
| 277 const int render_process_id_; | 273 const int render_process_id_; |
| 278 MessagePortMessageFilter* const message_port_message_filter_; | |
| 279 ResourceContext* resource_context_; | 274 ResourceContext* resource_context_; |
| 280 scoped_refptr<ServiceWorkerContextWrapper> context_wrapper_; | 275 scoped_refptr<ServiceWorkerContextWrapper> context_wrapper_; |
| 281 | 276 |
| 282 IDMap<std::unique_ptr<ServiceWorkerHandle>> handles_; | 277 IDMap<std::unique_ptr<ServiceWorkerHandle>> handles_; |
| 283 | 278 |
| 284 using RegistrationHandleMap = | 279 using RegistrationHandleMap = |
| 285 IDMap<std::unique_ptr<ServiceWorkerRegistrationHandle>>; | 280 IDMap<std::unique_ptr<ServiceWorkerRegistrationHandle>>; |
| 286 RegistrationHandleMap registration_handles_; | 281 RegistrationHandleMap registration_handles_; |
| 287 | 282 |
| 288 bool channel_ready_; // True after BrowserMessageFilter::sender_ != NULL. | 283 bool channel_ready_; // True after BrowserMessageFilter::sender_ != NULL. |
| 289 std::vector<std::unique_ptr<IPC::Message>> pending_messages_; | 284 std::vector<std::unique_ptr<IPC::Message>> pending_messages_; |
| 290 | 285 |
| 291 mojo::AssociatedBindingSet<mojom::ServiceWorkerDispatcherHost> bindings_; | 286 mojo::AssociatedBindingSet<mojom::ServiceWorkerDispatcherHost> bindings_; |
| 292 | 287 |
| 293 base::WeakPtrFactory<ServiceWorkerDispatcherHost> weak_factory_; | 288 base::WeakPtrFactory<ServiceWorkerDispatcherHost> weak_factory_; |
| 294 | 289 |
| 295 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerDispatcherHost); | 290 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerDispatcherHost); |
| 296 }; | 291 }; |
| 297 | 292 |
| 298 } // namespace content | 293 } // namespace content |
| 299 | 294 |
| 300 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_DISPATCHER_HOST_H_ | 295 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_DISPATCHER_HOST_H_ |
| OLD | NEW |