OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 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. |
| 4 |
| 5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_NAVIGATION_HANDLE_H_ |
| 6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_NAVIGATION_HANDLE_H_ |
| 7 |
| 8 #include "base/macros.h" |
| 9 #include "base/memory/weak_ptr.h" |
| 10 |
| 11 namespace content { |
| 12 |
| 13 class ServiceWorkerContextWrapper; |
| 14 class ServiceWorkerNavigationHandleCore; |
| 15 |
| 16 // This class is used to manage the lifetime of ServiceWorkerProviderHosts |
| 17 // created during navigation. This is a UI thread class, with a pendant class |
| 18 // on the IO thread, the ServiceWorkerNavigationHandleCore. |
| 19 // |
| 20 // The lifetime of the ServiceWorkerNavigationHandle, the |
| 21 // ServiceWorkerNavigationHandleCore and the ServiceWorkerProviderHost are the |
| 22 // following : |
| 23 // 1) We create a ServiceWorkerNavigationHandle on the UI thread with a |
| 24 // service worker provider id of -1. This also leads to the creation of a |
| 25 // ServiceWorkerNavigationHandleCore with an id of -1. |
| 26 // |
| 27 // 2) When the navigation request is sent to the IO thread, we include a |
| 28 // pointer to the ServiceWorkerNavigationHandleCore. |
| 29 // |
| 30 // 3) If we pre-create a ServiceWorkerProviderHost for this navigation, its |
| 31 // ownershipped is passed to the ServiceWorkerNavigationHandleCore. The |
| 32 // ServiceWorkerNavigationHandleCore id is updated. |
| 33 // |
| 34 // 4) The ServiceWorkerNavigationHandleCore informs the |
| 35 // ServiceWorkerNavigationHandle on the UI that the service worker provider |
| 36 // id was updated. |
| 37 // |
| 38 // 5) When the navigation is ready to commit, the NavigationRequest will |
| 39 // update the RequestNavigationParams based on the id from the |
| 40 // ServiceWorkerNavigationHandle. |
| 41 // |
| 42 // 6) If the commit leads to the creation of a ServiceWorkerNetworkProvider |
| 43 // in the renderer, a ServiceWorkerHostMsg_ProviderCreated will be received |
| 44 // in the browser. The ServiceWorkerDispatcherHost will retrieve the |
| 45 // ServiceWorkerProviderHost from the ServiceWorkerNavigationHandleCore and |
| 46 // put it in the ServiceWorkerContextCore map of ServiceWorkerProviderHosts. |
| 47 // |
| 48 // 7) When the navigation finishes, the ServiceWorkerNavigationHandle is |
| 49 // destroyed. The destructor of the ServiceWorkerNavigationHandle posts a |
| 50 // task to destroy the ServiceWorkerNavigationHandleCore on the IO thread. |
| 51 // This in turn leads to the destruction of an unclaimed |
| 52 // ServiceWorkerProviderHost. |
| 53 class ServiceWorkerNavigationHandle { |
| 54 public: |
| 55 explicit ServiceWorkerNavigationHandle( |
| 56 ServiceWorkerContextWrapper* context_wrapper); |
| 57 ~ServiceWorkerNavigationHandle(); |
| 58 |
| 59 int service_worker_provider_host_id() const { |
| 60 return service_worker_provider_host_id_; |
| 61 } |
| 62 ServiceWorkerNavigationHandleCore* core() const { return core_; } |
| 63 |
| 64 // Called after a ServiceWorkerProviderHost with id |
| 65 // |service_worker_provider_host_id| was pre-created for the navigation on the |
| 66 // IO thread. |
| 67 void DidCreateServiceWorkerProviderHost(int service_worker_provider_host_id); |
| 68 |
| 69 private: |
| 70 int service_worker_provider_host_id_; |
| 71 ServiceWorkerNavigationHandleCore* core_; |
| 72 base::WeakPtrFactory<ServiceWorkerNavigationHandle> weak_factory_; |
| 73 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerNavigationHandle); |
| 74 }; |
| 75 |
| 76 } // namespace content |
| 77 |
| 78 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_NAVIGATION_HANDLE_H_ |
OLD | NEW |