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