| 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 <vector> | 9 #include <vector> |
| 9 | 10 |
| 10 #include "base/macros.h" | 11 #include "base/macros.h" |
| 11 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 12 #include "content/browser/service_worker/embedded_worker_instance.h" | 13 #include "content/browser/service_worker/embedded_worker_instance.h" |
| 13 #include "content/browser/service_worker/service_worker_register_job_base.h" | 14 #include "content/browser/service_worker/service_worker_register_job_base.h" |
| 14 #include "content/browser/service_worker/service_worker_registration.h" | 15 #include "content/browser/service_worker/service_worker_registration.h" |
| 15 #include "content/common/service_worker/service_worker_status_code.h" | 16 #include "content/common/service_worker/service_worker_status_code.h" |
| 16 #include "url/gurl.h" | 17 #include "url/gurl.h" |
| 17 | 18 |
| 18 namespace content { | 19 namespace content { |
| 19 | 20 |
| 20 class ServiceWorkerJobCoordinator; | 21 class ServiceWorkerJobCoordinator; |
| 21 class ServiceWorkerStorage; | 22 class ServiceWorkerStorage; |
| 22 | 23 |
| 23 // Handles the initial registration of a Service Worker and the | 24 // Handles the initial registration of a Service Worker and the |
| 24 // subsequent update of existing registrations. | 25 // subsequent update of existing registrations. |
| 25 // | 26 // |
| 26 // The control flow includes most or all of the following, | 27 // The control flow includes most or all of the following, |
| 27 // depending on what is already registered: | 28 // depending on what is already registered: |
| 28 // - creating a ServiceWorkerRegistration instance if there isn't | 29 // - creating a ServiceWorkerRegistration instance if there isn't |
| 29 // already something registered | 30 // already something registered |
| 30 // - creating a ServiceWorkerVersion for the new version. | 31 // - creating a ServiceWorkerVersion for the new version. |
| 31 // - starting a worker for the ServiceWorkerVersion | 32 // - starting a worker for the ServiceWorkerVersion |
| 32 // - firing the 'install' event at the ServiceWorkerVersion | 33 // - firing the 'install' event at the ServiceWorkerVersion |
| 33 // - firing the 'activate' event at the ServiceWorkerVersion | 34 // - firing the 'activate' event at the ServiceWorkerVersion |
| 34 // - waiting for older ServiceWorkerVersions to deactivate | 35 // - waiting for older ServiceWorkerVersions to deactivate |
| 35 // - designating the new version to be the 'active' version | 36 // - designating the new version to be the 'active' version |
| 36 // - updating storage | 37 // - updating storage |
| 37 class ServiceWorkerRegisterJob : public ServiceWorkerRegisterJobBase { | 38 class ServiceWorkerRegisterJob : public ServiceWorkerRegisterJobBase, |
| 39 public EmbeddedWorkerInstance::Listener { |
| 38 public: | 40 public: |
| 39 typedef base::Callback<void(ServiceWorkerStatusCode status, | 41 typedef base::Callback<void(ServiceWorkerStatusCode status, |
| 40 const std::string& status_message, | 42 const std::string& status_message, |
| 41 ServiceWorkerRegistration* registration)> | 43 ServiceWorkerRegistration* registration)> |
| 42 RegistrationCallback; | 44 RegistrationCallback; |
| 43 | 45 |
| 44 // For registration jobs. | 46 // For registration jobs. |
| 45 CONTENT_EXPORT ServiceWorkerRegisterJob( | 47 CONTENT_EXPORT ServiceWorkerRegisterJob( |
| 46 base::WeakPtr<ServiceWorkerContextCore> context, | 48 base::WeakPtr<ServiceWorkerContextCore> context, |
| 47 const GURL& pattern, | 49 const GURL& pattern, |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 const std::string& status_message); | 129 const std::string& status_message); |
| 128 void CompleteInternal(ServiceWorkerStatusCode status, | 130 void CompleteInternal(ServiceWorkerStatusCode status, |
| 129 const std::string& status_message); | 131 const std::string& status_message); |
| 130 void ResolvePromise(ServiceWorkerStatusCode status, | 132 void ResolvePromise(ServiceWorkerStatusCode status, |
| 131 const std::string& status_message, | 133 const std::string& status_message, |
| 132 ServiceWorkerRegistration* registration); | 134 ServiceWorkerRegistration* registration); |
| 133 | 135 |
| 134 void AddRegistrationToMatchingProviderHosts( | 136 void AddRegistrationToMatchingProviderHosts( |
| 135 ServiceWorkerRegistration* registration); | 137 ServiceWorkerRegistration* registration); |
| 136 | 138 |
| 139 // EmbeddedWorkerInstance::Listener implementation: |
| 140 void OnScriptLoaded() override; |
| 141 |
| 137 // The ServiceWorkerContextCore object should always outlive this. | 142 // The ServiceWorkerContextCore object should always outlive this. |
| 138 base::WeakPtr<ServiceWorkerContextCore> context_; | 143 base::WeakPtr<ServiceWorkerContextCore> context_; |
| 139 | 144 |
| 140 RegistrationJobType job_type_; | 145 RegistrationJobType job_type_; |
| 141 const GURL pattern_; | 146 const GURL pattern_; |
| 142 const GURL script_url_; | 147 const GURL script_url_; |
| 143 std::vector<RegistrationCallback> callbacks_; | 148 std::vector<RegistrationCallback> callbacks_; |
| 144 Phase phase_; | 149 Phase phase_; |
| 145 Internal internal_; | 150 Internal internal_; |
| 146 bool doom_installing_worker_; | 151 bool doom_installing_worker_; |
| 147 bool is_promise_resolved_; | 152 bool is_promise_resolved_; |
| 148 bool should_uninstall_on_failure_; | 153 bool should_uninstall_on_failure_; |
| 149 bool force_bypass_cache_; | 154 bool force_bypass_cache_; |
| 150 bool skip_script_comparison_; | 155 bool skip_script_comparison_; |
| 151 ServiceWorkerStatusCode promise_resolved_status_; | 156 ServiceWorkerStatusCode promise_resolved_status_; |
| 152 std::string promise_resolved_status_message_; | 157 std::string promise_resolved_status_message_; |
| 153 scoped_refptr<ServiceWorkerRegistration> promise_resolved_registration_; | 158 scoped_refptr<ServiceWorkerRegistration> promise_resolved_registration_; |
| 154 base::WeakPtrFactory<ServiceWorkerRegisterJob> weak_factory_; | 159 base::WeakPtrFactory<ServiceWorkerRegisterJob> weak_factory_; |
| 155 | 160 |
| 156 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerRegisterJob); | 161 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerRegisterJob); |
| 157 }; | 162 }; |
| 158 | 163 |
| 159 } // namespace content | 164 } // namespace content |
| 160 | 165 |
| 161 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_REGISTER_JOB_H_ | 166 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_REGISTER_JOB_H_ |
| OLD | NEW |