| 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 27 matching lines...) Expand all Loading... |
| 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 // This class is bound with mojom::ServiceWorkerDispatcherHost. All | 46 // This class is bound with mojom::ServiceWorkerDispatcherHost. All |
| 47 // InterfacePtrs on the same render process are bound to the same | 47 // InterfacePtrs on the same render process are bound to the same |
| 48 // content::ServiceWorkerDispatcherHost. This can be overridden only for | 48 // content::ServiceWorkerDispatcherHost. |
| 49 // testing. | |
| 50 class CONTENT_EXPORT ServiceWorkerDispatcherHost | 49 class CONTENT_EXPORT ServiceWorkerDispatcherHost |
| 51 : public mojom::ServiceWorkerDispatcherHost, | 50 : public mojom::ServiceWorkerDispatcherHost, |
| 52 public BrowserMessageFilter { | 51 public BrowserMessageFilter { |
| 53 public: | 52 public: |
| 54 ServiceWorkerDispatcherHost( | 53 ServiceWorkerDispatcherHost( |
| 55 int render_process_id, | 54 int render_process_id, |
| 56 ResourceContext* resource_context); | 55 ResourceContext* resource_context); |
| 57 | 56 |
| 58 void Init(ServiceWorkerContextWrapper* context_wrapper); | 57 void Init(ServiceWorkerContextWrapper* context_wrapper); |
| 59 | 58 |
| 60 // BrowserMessageFilter implementation | 59 // BrowserMessageFilter implementation |
| 61 void OnFilterAdded(IPC::Channel* channel) override; | 60 void OnFilterAdded(IPC::Channel* channel) override; |
| 62 void OnFilterRemoved() override; | 61 void OnFilterRemoved() override; |
| 63 void OnDestruct() const override; | 62 void OnDestruct() const override; |
| 64 bool OnMessageReceived(const IPC::Message& message) override; | 63 bool OnMessageReceived(const IPC::Message& message) override; |
| 65 | 64 |
| 66 // IPC::Sender implementation | 65 // IPC::Sender implementation |
| 67 | 66 |
| 68 // Send() queues the message until the underlying sender is ready. This | 67 // Send() queues the message until the underlying sender is ready. This |
| 69 // class assumes that Send() can only fail after that when the renderer | 68 // class assumes that Send() can only fail after that when the renderer |
| 70 // process has terminated, at which point the whole instance will eventually | 69 // process has terminated, at which point the whole instance will eventually |
| 71 // be destroyed. | 70 // be destroyed. |
| 72 bool Send(IPC::Message* message) override; | 71 bool Send(IPC::Message* message) override; |
| 73 | 72 |
| 74 // Virtual for testing. | 73 void RegisterServiceWorkerHandle(std::unique_ptr<ServiceWorkerHandle> handle); |
| 75 virtual void RegisterServiceWorkerHandle( | 74 void RegisterServiceWorkerRegistrationHandle( |
| 76 std::unique_ptr<ServiceWorkerHandle> handle); | |
| 77 // Virtual for testing. | |
| 78 virtual void RegisterServiceWorkerRegistrationHandle( | |
| 79 std::unique_ptr<ServiceWorkerRegistrationHandle> handle); | 75 std::unique_ptr<ServiceWorkerRegistrationHandle> handle); |
| 80 | 76 |
| 81 ServiceWorkerHandle* FindServiceWorkerHandle(int provider_id, | 77 ServiceWorkerHandle* FindServiceWorkerHandle(int provider_id, |
| 82 int64_t version_id); | 78 int64_t version_id); |
| 83 | 79 |
| 84 // Gets or creates the registration and version handles appropriate for | |
| 85 // representing |registration| inside of |provider_host|. Sets |out_info| and | |
| 86 // |out_attrs| accordingly for these handles. | |
| 87 void GetRegistrationObjectInfoAndVersionAttributes( | |
| 88 base::WeakPtr<ServiceWorkerProviderHost> provider_host, | |
| 89 ServiceWorkerRegistration* registration, | |
| 90 ServiceWorkerRegistrationObjectInfo* out_info, | |
| 91 ServiceWorkerVersionAttributes* out_attrs); | |
| 92 | |
| 93 // Returns the existing registration handle whose reference count is | 80 // Returns the existing registration handle whose reference count is |
| 94 // incremented or a newly created one if it doesn't exist. | 81 // incremented or a newly created one if it doesn't exist. |
| 95 ServiceWorkerRegistrationHandle* GetOrCreateRegistrationHandle( | 82 ServiceWorkerRegistrationHandle* GetOrCreateRegistrationHandle( |
| 96 base::WeakPtr<ServiceWorkerProviderHost> provider_host, | 83 base::WeakPtr<ServiceWorkerProviderHost> provider_host, |
| 97 ServiceWorkerRegistration* registration); | 84 ServiceWorkerRegistration* registration); |
| 98 | 85 |
| 99 protected: | 86 protected: |
| 100 ~ServiceWorkerDispatcherHost() override; | 87 ~ServiceWorkerDispatcherHost() override; |
| 101 | 88 |
| 102 private: | 89 private: |
| 103 friend class BrowserThread; | 90 friend class BrowserThread; |
| 104 friend class base::DeleteHelper<ServiceWorkerDispatcherHost>; | 91 friend class base::DeleteHelper<ServiceWorkerDispatcherHost>; |
| 105 friend class ServiceWorkerDispatcherHostTest; | 92 friend class ServiceWorkerDispatcherHostTest; |
| 106 friend class TestingServiceWorkerDispatcherHost; | 93 friend class TestingServiceWorkerDispatcherHost; |
| 107 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerDispatcherHostTest, | 94 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerDispatcherHostTest, |
| 108 ProviderCreatedAndDestroyed); | 95 ProviderCreatedAndDestroyed); |
| 109 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerDispatcherHostTest, | 96 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerDispatcherHostTest, |
| 110 CleanupOnRendererCrash); | 97 CleanupOnRendererCrash); |
| 111 FRIEND_TEST_ALL_PREFIXES(BackgroundSyncManagerTest, | |
| 112 RegisterWithoutLiveSWRegistration); | |
| 113 | 98 |
| 114 using StatusCallback = base::Callback<void(ServiceWorkerStatusCode status)>; | 99 using StatusCallback = base::Callback<void(ServiceWorkerStatusCode status)>; |
| 115 enum class ProviderStatus { OK, NO_CONTEXT, DEAD_HOST, NO_HOST, NO_URL }; | 100 enum class ProviderStatus { OK, NO_CONTEXT, DEAD_HOST, NO_HOST, NO_URL }; |
| 116 | 101 |
| 117 // Called when mojom::ServiceWorkerDispatcherHostPtr is created on the | 102 // Called when mojom::ServiceWorkerDispatcherHostPtr is created on the |
| 118 // renderer-side. | 103 // renderer-side. |
| 119 void AddMojoBinding(mojo::ScopedInterfaceEndpointHandle handle); | 104 void AddMojoBinding(mojo::ScopedInterfaceEndpointHandle handle); |
| 120 | 105 |
| 121 // mojom::ServiceWorkerDispatcherHost implementation | 106 // mojom::ServiceWorkerDispatcherHost implementation |
| 122 void OnProviderCreated(ServiceWorkerProviderHostInfo info) override; | 107 void OnProviderCreated(ServiceWorkerProviderHostInfo info) override; |
| 108 void OnSetHostedVersionId(int provider_id, |
| 109 int64_t version_id, |
| 110 int embedded_worker_id) override; |
| 123 | 111 |
| 124 // IPC Message handlers | 112 // IPC Message handlers |
| 125 void OnRegisterServiceWorker(int thread_id, | 113 void OnRegisterServiceWorker(int thread_id, |
| 126 int request_id, | 114 int request_id, |
| 127 int provider_id, | 115 int provider_id, |
| 128 const GURL& pattern, | 116 const GURL& pattern, |
| 129 const GURL& script_url); | 117 const GURL& script_url); |
| 130 void OnUpdateServiceWorker(int thread_id, | 118 void OnUpdateServiceWorker(int thread_id, |
| 131 int request_id, | 119 int request_id, |
| 132 int provider_id, | 120 int provider_id, |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 const SourceInfo& source_info, | 189 const SourceInfo& source_info, |
| 202 const StatusCallback& callback, | 190 const StatusCallback& callback, |
| 203 ServiceWorkerStatusCode status); | 191 ServiceWorkerStatusCode status); |
| 204 void ReleaseSourceInfo(const ServiceWorkerClientInfo& source_info); | 192 void ReleaseSourceInfo(const ServiceWorkerClientInfo& source_info); |
| 205 void ReleaseSourceInfo(const ServiceWorkerObjectInfo& source_info); | 193 void ReleaseSourceInfo(const ServiceWorkerObjectInfo& source_info); |
| 206 | 194 |
| 207 ServiceWorkerRegistrationHandle* FindRegistrationHandle( | 195 ServiceWorkerRegistrationHandle* FindRegistrationHandle( |
| 208 int provider_id, | 196 int provider_id, |
| 209 int64_t registration_handle_id); | 197 int64_t registration_handle_id); |
| 210 | 198 |
| 199 void GetRegistrationObjectInfoAndVersionAttributes( |
| 200 base::WeakPtr<ServiceWorkerProviderHost> provider_host, |
| 201 ServiceWorkerRegistration* registration, |
| 202 ServiceWorkerRegistrationObjectInfo* info, |
| 203 ServiceWorkerVersionAttributes* attrs); |
| 204 |
| 211 // Callbacks from ServiceWorkerContextCore | 205 // Callbacks from ServiceWorkerContextCore |
| 212 void RegistrationComplete(int thread_id, | 206 void RegistrationComplete(int thread_id, |
| 213 int provider_id, | 207 int provider_id, |
| 214 int request_id, | 208 int request_id, |
| 215 ServiceWorkerStatusCode status, | 209 ServiceWorkerStatusCode status, |
| 216 const std::string& status_message, | 210 const std::string& status_message, |
| 217 int64_t registration_id); | 211 int64_t registration_id); |
| 218 void UpdateComplete(int thread_id, | 212 void UpdateComplete(int thread_id, |
| 219 int provider_id, | 213 int provider_id, |
| 220 int request_id, | 214 int request_id, |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 mojo::AssociatedBindingSet<mojom::ServiceWorkerDispatcherHost> bindings_; | 272 mojo::AssociatedBindingSet<mojom::ServiceWorkerDispatcherHost> bindings_; |
| 279 | 273 |
| 280 base::WeakPtrFactory<ServiceWorkerDispatcherHost> weak_factory_; | 274 base::WeakPtrFactory<ServiceWorkerDispatcherHost> weak_factory_; |
| 281 | 275 |
| 282 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerDispatcherHost); | 276 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerDispatcherHost); |
| 283 }; | 277 }; |
| 284 | 278 |
| 285 } // namespace content | 279 } // namespace content |
| 286 | 280 |
| 287 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_DISPATCHER_HOST_H_ | 281 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_DISPATCHER_HOST_H_ |
| OLD | NEW |