| 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 <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 13 #include "base/time/time.h" | 13 #include "base/time/time.h" |
| 14 #include "content/browser/service_worker/embedded_worker_instance.h" | 14 #include "content/browser/service_worker/embedded_worker_instance.h" |
| 15 #include "content/browser/service_worker/service_worker_register_job_base.h" | 15 #include "content/browser/service_worker/service_worker_register_job_base.h" |
| 16 #include "content/browser/service_worker/service_worker_registration.h" | 16 #include "content/browser/service_worker/service_worker_registration.h" |
| 17 #include "content/common/service_worker/service_worker_event_dispatcher.mojom.h" |
| 17 #include "content/common/service_worker/service_worker_status_code.h" | 18 #include "content/common/service_worker/service_worker_status_code.h" |
| 19 #include "mojo/public/cpp/bindings/associated_binding.h" |
| 18 #include "url/gurl.h" | 20 #include "url/gurl.h" |
| 19 | 21 |
| 20 namespace content { | 22 namespace content { |
| 21 | 23 |
| 22 // Handles the initial registration of a Service Worker and the | 24 // Handles the initial registration of a Service Worker and the |
| 23 // subsequent update of existing registrations. | 25 // subsequent update of existing registrations. |
| 24 // | 26 // |
| 25 // The control flow includes most or all of the following, | 27 // The control flow includes most or all of the following, |
| 26 // depending on what is already registered: | 28 // depending on what is already registered: |
| 27 // - creating a ServiceWorkerRegistration instance if there isn't | 29 // - creating a ServiceWorkerRegistration instance if there isn't |
| 28 // already something registered | 30 // already something registered |
| 29 // - creating a ServiceWorkerVersion for the new version. | 31 // - creating a ServiceWorkerVersion for the new version. |
| 30 // - starting a worker for the ServiceWorkerVersion | 32 // - starting a worker for the ServiceWorkerVersion |
| 31 // - firing the 'install' event at the ServiceWorkerVersion | 33 // - firing the 'install' event at the ServiceWorkerVersion |
| 32 // - firing the 'activate' event at the ServiceWorkerVersion | 34 // - firing the 'activate' event at the ServiceWorkerVersion |
| 33 // - waiting for older ServiceWorkerVersions to deactivate | 35 // - waiting for older ServiceWorkerVersions to deactivate |
| 34 // - designating the new version to be the 'active' version | 36 // - designating the new version to be the 'active' version |
| 35 // - updating storage | 37 // - updating storage |
| 36 class ServiceWorkerRegisterJob : public ServiceWorkerRegisterJobBase, | 38 class ServiceWorkerRegisterJob : public ServiceWorkerRegisterJobBase, |
| 37 public EmbeddedWorkerInstance::Listener { | 39 public EmbeddedWorkerInstance::Listener, |
| 40 public mojom::InstallEventMethod { |
| 38 public: | 41 public: |
| 39 typedef base::Callback<void(ServiceWorkerStatusCode status, | 42 typedef base::Callback<void(ServiceWorkerStatusCode status, |
| 40 const std::string& status_message, | 43 const std::string& status_message, |
| 41 ServiceWorkerRegistration* registration)> | 44 ServiceWorkerRegistration* registration)> |
| 42 RegistrationCallback; | 45 RegistrationCallback; |
| 43 | 46 |
| 44 // For registration jobs. | 47 // For registration jobs. |
| 45 CONTENT_EXPORT ServiceWorkerRegisterJob( | 48 CONTENT_EXPORT ServiceWorkerRegisterJob( |
| 46 base::WeakPtr<ServiceWorkerContextCore> context, | 49 base::WeakPtr<ServiceWorkerContextCore> context, |
| 47 const GURL& pattern, | 50 const GURL& pattern, |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 // Holds the version created by this job. It can be the 'installing', | 95 // Holds the version created by this job. It can be the 'installing', |
| 93 // 'waiting', or 'active' version depending on the phase. | 96 // 'waiting', or 'active' version depending on the phase. |
| 94 scoped_refptr<ServiceWorkerVersion> new_version; | 97 scoped_refptr<ServiceWorkerVersion> new_version; |
| 95 }; | 98 }; |
| 96 | 99 |
| 97 void set_registration(scoped_refptr<ServiceWorkerRegistration> registration); | 100 void set_registration(scoped_refptr<ServiceWorkerRegistration> registration); |
| 98 ServiceWorkerRegistration* registration(); | 101 ServiceWorkerRegistration* registration(); |
| 99 void set_new_version(ServiceWorkerVersion* version); | 102 void set_new_version(ServiceWorkerVersion* version); |
| 100 ServiceWorkerVersion* new_version(); | 103 ServiceWorkerVersion* new_version(); |
| 101 | 104 |
| 105 // mojom::InstallEventMethod implementation. |
| 106 void Register(const std::vector<GURL>& sub_scopes, |
| 107 const std::vector<url::Origin>& origins) override; |
| 108 |
| 102 void SetPhase(Phase phase); | 109 void SetPhase(Phase phase); |
| 103 | 110 |
| 104 void StartImpl(); | 111 void StartImpl(); |
| 105 void ContinueWithRegistration( | 112 void ContinueWithRegistration( |
| 106 ServiceWorkerStatusCode status, | 113 ServiceWorkerStatusCode status, |
| 107 scoped_refptr<ServiceWorkerRegistration> registration); | 114 scoped_refptr<ServiceWorkerRegistration> registration); |
| 108 void ContinueWithUpdate( | 115 void ContinueWithUpdate( |
| 109 ServiceWorkerStatusCode status, | 116 ServiceWorkerStatusCode status, |
| 110 scoped_refptr<ServiceWorkerRegistration> registration); | 117 scoped_refptr<ServiceWorkerRegistration> registration); |
| 111 void RegisterAndContinue(); | 118 void RegisterAndContinue(); |
| 112 void ContinueWithUninstallingRegistration( | 119 void ContinueWithUninstallingRegistration( |
| 113 scoped_refptr<ServiceWorkerRegistration> existing_registration, | 120 scoped_refptr<ServiceWorkerRegistration> existing_registration, |
| 114 ServiceWorkerStatusCode status); | 121 ServiceWorkerStatusCode status); |
| 115 void ContinueWithRegistrationForSameScriptUrl( | 122 void ContinueWithRegistrationForSameScriptUrl( |
| 116 scoped_refptr<ServiceWorkerRegistration> existing_registration, | 123 scoped_refptr<ServiceWorkerRegistration> existing_registration, |
| 117 ServiceWorkerStatusCode status); | 124 ServiceWorkerStatusCode status); |
| 118 void UpdateAndContinue(); | 125 void UpdateAndContinue(); |
| 119 void OnStartWorkerFinished(ServiceWorkerStatusCode status); | 126 void OnStartWorkerFinished(ServiceWorkerStatusCode status); |
| 120 void OnStoreRegistrationComplete(ServiceWorkerStatusCode status); | 127 void OnStoreRegistrationComplete(ServiceWorkerStatusCode status); |
| 121 void InstallAndContinue(); | 128 void InstallAndContinue(); |
| 122 void DispatchInstallEvent(); | 129 void DispatchInstallEvent(); |
| 123 void OnInstallFinished(int request_id, | 130 void OnInstallFinished(int request_id, |
| 124 blink::WebServiceWorkerEventResult result, | 131 ServiceWorkerStatusCode status, |
| 125 bool has_fetch_handler, | 132 bool has_fetch_handler, |
| 126 base::Time dispatch_event_time); | 133 base::Time dispatch_event_time); |
| 127 void OnInstallFailed(ServiceWorkerStatusCode status); | 134 void OnInstallFailed(ServiceWorkerStatusCode status); |
| 128 void Complete(ServiceWorkerStatusCode status); | 135 void Complete(ServiceWorkerStatusCode status); |
| 129 void Complete(ServiceWorkerStatusCode status, | 136 void Complete(ServiceWorkerStatusCode status, |
| 130 const std::string& status_message); | 137 const std::string& status_message); |
| 131 void CompleteInternal(ServiceWorkerStatusCode status, | 138 void CompleteInternal(ServiceWorkerStatusCode status, |
| 132 const std::string& status_message); | 139 const std::string& status_message); |
| 133 void ResolvePromise(ServiceWorkerStatusCode status, | 140 void ResolvePromise(ServiceWorkerStatusCode status, |
| 134 const std::string& status_message, | 141 const std::string& status_message, |
| 135 ServiceWorkerRegistration* registration); | 142 ServiceWorkerRegistration* registration); |
| 136 | 143 |
| 137 void AddRegistrationToMatchingProviderHosts( | 144 void AddRegistrationToMatchingProviderHosts( |
| 138 ServiceWorkerRegistration* registration); | 145 ServiceWorkerRegistration* registration); |
| 139 | 146 |
| 140 // EmbeddedWorkerInstance::Listener implementation: | 147 // EmbeddedWorkerInstance::Listener implementation: |
| 141 void OnScriptLoaded() override; | 148 void OnScriptLoaded() override; |
| 142 | 149 |
| 143 void BumpLastUpdateCheckTimeIfNeeded(); | 150 void BumpLastUpdateCheckTimeIfNeeded(); |
| 144 | 151 |
| 145 // The ServiceWorkerContextCore object should always outlive this. | 152 // The ServiceWorkerContextCore object should always outlive this. |
| 146 base::WeakPtr<ServiceWorkerContextCore> context_; | 153 base::WeakPtr<ServiceWorkerContextCore> context_; |
| 147 | 154 |
| 155 // Binding for InstallEventMethod. |
| 156 mojo::AssociatedBinding<InstallEventMethod> install_method_binding_; |
| 157 |
| 148 RegistrationJobType job_type_; | 158 RegistrationJobType job_type_; |
| 149 const GURL pattern_; | 159 const GURL pattern_; |
| 150 GURL script_url_; | 160 GURL script_url_; |
| 151 std::vector<RegistrationCallback> callbacks_; | 161 std::vector<RegistrationCallback> callbacks_; |
| 152 Phase phase_; | 162 Phase phase_; |
| 153 Internal internal_; | 163 Internal internal_; |
| 154 bool doom_installing_worker_; | 164 bool doom_installing_worker_; |
| 155 bool is_promise_resolved_; | 165 bool is_promise_resolved_; |
| 156 bool should_uninstall_on_failure_; | 166 bool should_uninstall_on_failure_; |
| 157 bool force_bypass_cache_; | 167 bool force_bypass_cache_; |
| 158 bool skip_script_comparison_; | 168 bool skip_script_comparison_; |
| 159 ServiceWorkerStatusCode promise_resolved_status_; | 169 ServiceWorkerStatusCode promise_resolved_status_; |
| 160 std::string promise_resolved_status_message_; | 170 std::string promise_resolved_status_message_; |
| 161 scoped_refptr<ServiceWorkerRegistration> promise_resolved_registration_; | 171 scoped_refptr<ServiceWorkerRegistration> promise_resolved_registration_; |
| 162 base::WeakPtrFactory<ServiceWorkerRegisterJob> weak_factory_; | 172 base::WeakPtrFactory<ServiceWorkerRegisterJob> weak_factory_; |
| 163 | 173 |
| 164 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerRegisterJob); | 174 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerRegisterJob); |
| 165 }; | 175 }; |
| 166 | 176 |
| 167 } // namespace content | 177 } // namespace content |
| 168 | 178 |
| 169 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_REGISTER_JOB_H_ | 179 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_REGISTER_JOB_H_ |
| OLD | NEW |