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_REGISTER_JOB_H_ | 5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_REGISTER_JOB_H_ |
| 6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_REGISTER_JOB_H_ | 6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_REGISTER_JOB_H_ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
| 11 #include "content/browser/service_worker/embedded_worker_instance.h" | 11 #include "content/browser/service_worker/embedded_worker_instance.h" |
| 12 #include "content/browser/service_worker/service_worker_register_job_base.h" | 12 #include "content/browser/service_worker/service_worker_register_job_base.h" |
| 13 #include "content/browser/service_worker/service_worker_registration.h" | 13 #include "content/browser/service_worker/service_worker_registration.h" |
| 14 #include "content/common/service_worker/service_worker_status_code.h" | 14 #include "content/common/service_worker/service_worker_status_code.h" |
| 15 #include "url/gurl.h" | 15 #include "url/gurl.h" |
| 16 | 16 |
| 17 namespace content { | 17 namespace content { |
| 18 | 18 |
| 19 class ServiceWorkerJobCoordinator; | 19 class ServiceWorkerJobCoordinator; |
| 20 class ServiceWorkerStorage; | 20 class ServiceWorkerStorage; |
| 21 | 21 |
| 22 // Handles the registration of a Service Worker. | 22 // Handles the registration of a Service Worker. |
|
falken
2014/07/10 03:45:32
we'll have to update this documentation
| |
| 23 // | 23 // |
| 24 // The registration flow includes most or all of the following, | 24 // The registration flow includes most or all of the following, |
| 25 // depending on what is already registered: | 25 // depending on what is already registered: |
| 26 // - creating a ServiceWorkerRegistration instance if there isn't | 26 // - creating a ServiceWorkerRegistration instance if there isn't |
| 27 // already something registered | 27 // already something registered |
| 28 // - creating a ServiceWorkerVersion for the new registration instance. | 28 // - creating a ServiceWorkerVersion for the new registration instance. |
| 29 // - starting a worker for the ServiceWorkerVersion | 29 // - starting a worker for the ServiceWorkerVersion |
| 30 // - telling the Version to evaluate the script | 30 // - telling the Version to evaluate the script |
| 31 // - firing the 'install' event at the ServiceWorkerVersion | 31 // - firing the 'install' event at the ServiceWorkerVersion |
| 32 // - firing the 'activate' event at the ServiceWorkerVersion | 32 // - firing the 'activate' event at the ServiceWorkerVersion |
| 33 // - waiting for older ServiceWorkerVersions to deactivate | 33 // - waiting for older ServiceWorkerVersions to deactivate |
| 34 // - designating the new version to be the 'active' version | 34 // - designating the new version to be the 'active' version |
| 35 class ServiceWorkerRegisterJob | 35 class ServiceWorkerRegisterJob |
| 36 : public ServiceWorkerRegisterJobBase, | 36 : public ServiceWorkerRegisterJobBase, |
| 37 public EmbeddedWorkerInstance::Listener { | 37 public EmbeddedWorkerInstance::Listener { |
| 38 public: | 38 public: |
| 39 typedef base::Callback<void(ServiceWorkerStatusCode status, | 39 typedef base::Callback<void(ServiceWorkerStatusCode status, |
| 40 ServiceWorkerRegistration* registration, | 40 ServiceWorkerRegistration* registration, |
| 41 ServiceWorkerVersion* version)> | 41 ServiceWorkerVersion* version)> |
| 42 RegistrationCallback; | 42 RegistrationCallback; |
| 43 | 43 |
| 44 // For registration jobs. | |
| 44 CONTENT_EXPORT ServiceWorkerRegisterJob( | 45 CONTENT_EXPORT ServiceWorkerRegisterJob( |
| 45 base::WeakPtr<ServiceWorkerContextCore> context, | 46 base::WeakPtr<ServiceWorkerContextCore> context, |
| 46 const GURL& pattern, | 47 const GURL& pattern, |
| 47 const GURL& script_url); | 48 const GURL& script_url); |
| 49 | |
| 50 // For update jobs. | |
| 51 CONTENT_EXPORT ServiceWorkerRegisterJob( | |
| 52 base::WeakPtr<ServiceWorkerContextCore> context, | |
| 53 ServiceWorkerRegistration* registration); | |
| 48 virtual ~ServiceWorkerRegisterJob(); | 54 virtual ~ServiceWorkerRegisterJob(); |
| 49 | 55 |
| 50 // Registers a callback to be called when the promise would resolve (whether | 56 // Registers a callback to be called when the promise would resolve (whether |
| 51 // successfully or not). Multiple callbacks may be registered. If |process_id| | 57 // successfully or not). Multiple callbacks may be registered. If |process_id| |
| 52 // is not -1, it's added to the existing clients when deciding in which | 58 // is not -1, it's added to the existing clients when deciding in which |
| 53 // process to create the Service Worker instance. If there are no existing | 59 // process to create the Service Worker instance. If there are no existing |
| 54 // clients, a new RenderProcessHost will be created. | 60 // clients, a new RenderProcessHost will be created. |
| 55 void AddCallback(const RegistrationCallback& callback, int process_id); | 61 void AddCallback(const RegistrationCallback& callback, int process_id); |
| 56 | 62 |
| 57 // ServiceWorkerRegisterJobBase implementation: | 63 // ServiceWorkerRegisterJobBase implementation: |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 89 scoped_refptr<ServiceWorkerVersion> new_version; | 95 scoped_refptr<ServiceWorkerVersion> new_version; |
| 90 }; | 96 }; |
| 91 | 97 |
| 92 void set_registration(ServiceWorkerRegistration* registration); | 98 void set_registration(ServiceWorkerRegistration* registration); |
| 93 ServiceWorkerRegistration* registration(); | 99 ServiceWorkerRegistration* registration(); |
| 94 void set_new_version(ServiceWorkerVersion* version); | 100 void set_new_version(ServiceWorkerVersion* version); |
| 95 ServiceWorkerVersion* new_version(); | 101 ServiceWorkerVersion* new_version(); |
| 96 | 102 |
| 97 void SetPhase(Phase phase); | 103 void SetPhase(Phase phase); |
| 98 | 104 |
| 99 void HandleExistingRegistrationAndContinue( | 105 void ContinueWithRegistration( |
| 106 ServiceWorkerStatusCode status, | |
| 107 const scoped_refptr<ServiceWorkerRegistration>& registration); | |
| 108 void ContinueWithUpdate( | |
| 100 ServiceWorkerStatusCode status, | 109 ServiceWorkerStatusCode status, |
| 101 const scoped_refptr<ServiceWorkerRegistration>& registration); | 110 const scoped_refptr<ServiceWorkerRegistration>& registration); |
| 102 void RegisterAndContinue(ServiceWorkerStatusCode status); | 111 void RegisterAndContinue(ServiceWorkerStatusCode status); |
| 103 void UpdateAndContinue(ServiceWorkerStatusCode status); | 112 void UpdateAndContinue(ServiceWorkerStatusCode status); |
| 104 void OnStartWorkerFinished(ServiceWorkerStatusCode status); | 113 void OnStartWorkerFinished(ServiceWorkerStatusCode status); |
| 105 void OnStoreRegistrationComplete(ServiceWorkerStatusCode status); | 114 void OnStoreRegistrationComplete(ServiceWorkerStatusCode status); |
| 106 void InstallAndContinue(); | 115 void InstallAndContinue(); |
| 107 void OnInstallFinished(ServiceWorkerStatusCode status); | 116 void OnInstallFinished(ServiceWorkerStatusCode status); |
| 108 void ActivateAndContinue(); | 117 void ActivateAndContinue(); |
| 109 void OnActivateFinished(ServiceWorkerStatusCode status); | 118 void OnActivateFinished(ServiceWorkerStatusCode status); |
| 110 void Complete(ServiceWorkerStatusCode status); | 119 void Complete(ServiceWorkerStatusCode status); |
| 111 void CompleteInternal(ServiceWorkerStatusCode status); | 120 void CompleteInternal(ServiceWorkerStatusCode status); |
| 112 | |
| 113 void ResolvePromise(ServiceWorkerStatusCode status, | 121 void ResolvePromise(ServiceWorkerStatusCode status, |
| 114 ServiceWorkerRegistration* registration, | 122 ServiceWorkerRegistration* registration, |
| 115 ServiceWorkerVersion* version); | 123 ServiceWorkerVersion* version); |
| 116 | 124 |
| 117 // EmbeddedWorkerInstance::Listener override of OnPausedAfterDownload. | 125 // EmbeddedWorkerInstance::Listener override of OnPausedAfterDownload. |
| 118 virtual void OnPausedAfterDownload() OVERRIDE; | 126 virtual void OnPausedAfterDownload() OVERRIDE; |
| 119 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 127 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
| 120 | 128 |
| 129 void OnCompareScriptResourcesComplete( | |
| 130 ServiceWorkerVersion* current_version, | |
| 131 ServiceWorkerStatusCode status, | |
| 132 int compare_result); | |
| 133 | |
| 121 // Associates an installing version to documents matched with a scope of the | 134 // Associates an installing version to documents matched with a scope of the |
| 122 // version. | 135 // version. |
| 123 CONTENT_EXPORT static void AssociateInstallingVersionToDocuments( | 136 CONTENT_EXPORT static void AssociateInstallingVersionToDocuments( |
| 124 base::WeakPtr<ServiceWorkerContextCore> context, | 137 base::WeakPtr<ServiceWorkerContextCore> context, |
| 125 ServiceWorkerVersion* version); | 138 ServiceWorkerVersion* version); |
| 126 | 139 |
| 127 // Associates a waiting version to documents matched with a scope of the | 140 // Associates a waiting version to documents matched with a scope of the |
| 128 // version. | 141 // version. |
| 129 static void AssociateWaitingVersionToDocuments( | 142 static void AssociateWaitingVersionToDocuments( |
| 130 base::WeakPtr<ServiceWorkerContextCore> context, | 143 base::WeakPtr<ServiceWorkerContextCore> context, |
| 131 ServiceWorkerVersion* version); | 144 ServiceWorkerVersion* version); |
| 132 | 145 |
| 133 // Associates an active version to documents matched with a scope of the | 146 // Associates an active version to documents matched with a scope of the |
| 134 // version. | 147 // version. |
| 135 static void AssociateActiveVersionToDocuments( | 148 static void AssociateActiveVersionToDocuments( |
| 136 base::WeakPtr<ServiceWorkerContextCore> context, | 149 base::WeakPtr<ServiceWorkerContextCore> context, |
| 137 ServiceWorkerVersion* version); | 150 ServiceWorkerVersion* version); |
| 138 | 151 |
| 139 // Disassociates a version specified by |version_id| from documents. | 152 // Disassociates a version specified by |version_id| from documents. |
| 140 CONTENT_EXPORT static void DisassociateVersionFromDocuments( | 153 CONTENT_EXPORT static void DisassociateVersionFromDocuments( |
| 141 base::WeakPtr<ServiceWorkerContextCore> context, | 154 base::WeakPtr<ServiceWorkerContextCore> context, |
| 142 ServiceWorkerVersion* version); | 155 ServiceWorkerVersion* version); |
| 143 | 156 |
| 144 // The ServiceWorkerContextCore object should always outlive this. | 157 // The ServiceWorkerContextCore object should always outlive this. |
| 145 base::WeakPtr<ServiceWorkerContextCore> context_; | 158 base::WeakPtr<ServiceWorkerContextCore> context_; |
| 146 | 159 |
| 160 RegistrationJobType job_type_; | |
| 147 const GURL pattern_; | 161 const GURL pattern_; |
| 148 const GURL script_url_; | 162 const GURL script_url_; |
| 149 std::vector<RegistrationCallback> callbacks_; | 163 std::vector<RegistrationCallback> callbacks_; |
| 150 std::vector<int> pending_process_ids_; | 164 std::vector<int> pending_process_ids_; |
| 151 Phase phase_; | 165 Phase phase_; |
| 152 Internal internal_; | 166 Internal internal_; |
| 153 bool is_promise_resolved_; | 167 bool is_promise_resolved_; |
| 154 ServiceWorkerStatusCode promise_resolved_status_; | 168 ServiceWorkerStatusCode promise_resolved_status_; |
| 155 scoped_refptr<ServiceWorkerRegistration> promise_resolved_registration_; | 169 scoped_refptr<ServiceWorkerRegistration> promise_resolved_registration_; |
| 156 scoped_refptr<ServiceWorkerVersion> promise_resolved_version_; | 170 scoped_refptr<ServiceWorkerVersion> promise_resolved_version_; |
| 157 base::WeakPtrFactory<ServiceWorkerRegisterJob> weak_factory_; | 171 base::WeakPtrFactory<ServiceWorkerRegisterJob> weak_factory_; |
| 158 | 172 |
| 159 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerRegisterJob); | 173 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerRegisterJob); |
| 160 }; | 174 }; |
| 161 | 175 |
| 162 } // namespace content | 176 } // namespace content |
| 163 | 177 |
| 164 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_REGISTER_JOB_H_ | 178 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_REGISTER_JOB_H_ |
| OLD | NEW |