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 "base/memory/weak_ptr.h" | 8 #include "base/memory/weak_ptr.h" |
| 9 #include "content/browser/service_worker/service_worker_registration_status.h" | 9 #include "content/browser/service_worker/service_worker_registration_status.h" |
| 10 #include "content/browser/service_worker/service_worker_storage.h" | 10 #include "content/browser/service_worker/service_worker_storage.h" |
| 11 | 11 |
| 12 namespace content { | 12 namespace content { |
| 13 | 13 |
| 14 class ServiceWorkerJobCoordinator; | |
| 15 | |
| 14 // A ServiceWorkerRegisterJob lives only for the lifetime of a single | 16 // A ServiceWorkerRegisterJob lives only for the lifetime of a single |
| 15 // registration or unregistration. | 17 // registration or unregistration. |
| 16 class ServiceWorkerRegisterJob { | 18 class ServiceWorkerRegisterJob { |
| 17 public: | 19 public: |
| 20 enum RegistrationType { | |
| 21 REGISTER, | |
| 22 UNREGISTER, | |
| 23 }; | |
| 24 | |
| 18 typedef base::Callback<void(ServiceWorkerRegistrationStatus status, | 25 typedef base::Callback<void(ServiceWorkerRegistrationStatus status, |
| 19 const scoped_refptr<ServiceWorkerRegistration>& | 26 const scoped_refptr<ServiceWorkerRegistration>& |
| 20 registration)> RegistrationCallback; | 27 registration)> RegistrationCallback; |
| 21 typedef base::Callback<void(ServiceWorkerRegistrationStatus status)> | 28 typedef base::Callback<void(ServiceWorkerRegistrationStatus status)> |
| 22 UnregistrationCallback; | 29 UnregistrationCallback; |
| 23 | 30 |
| 24 typedef base::Callback<void( | 31 typedef base::Callback<void( |
| 25 ServiceWorkerRegisterJob* job, | 32 ServiceWorkerRegisterJob* job, |
| 26 ServiceWorkerRegistrationStatus status, | 33 ServiceWorkerRegistrationStatus status, |
| 27 ServiceWorkerRegistration* registration)> RegistrationCompleteCallback; | 34 ServiceWorkerRegistration* registration)> RegistrationCompleteCallback; |
| 28 | 35 |
| 29 // All type of jobs (Register and Unregister) complete through a | 36 // All type of jobs (Register and Unregister) complete through a |
| 30 // single call to this callback on the IO thread. | 37 // single call to this callback on the IO thread. |
| 31 ServiceWorkerRegisterJob(const base::WeakPtr<ServiceWorkerStorage>& storage, | 38 ServiceWorkerRegisterJob(const base::WeakPtr<ServiceWorkerStorage>& storage, |
| 32 const RegistrationCompleteCallback& callback); | 39 ServiceWorkerJobCoordinator* coordinator, |
| 40 const GURL& pattern, | |
| 41 const GURL& script_url, | |
| 42 RegistrationType type); | |
| 33 ~ServiceWorkerRegisterJob(); | 43 ~ServiceWorkerRegisterJob(); |
| 34 | 44 |
| 45 void AddCallback(const RegistrationCompleteCallback& callback); | |
| 46 | |
| 47 // hack for now. Could be virtual | |
| 48 void Start() { | |
| 49 if (type_ == REGISTER) | |
| 50 StartRegister(); | |
| 51 else | |
| 52 StartUnregister(); | |
| 53 running_ = true; | |
| 54 } | |
|
kinuko
2014/01/08 08:38:36
Can you move this to .cc ?
alecflett
2014/01/08 23:59:16
oops! meant to do that before uploading. Done.
| |
| 55 | |
| 56 const GURL& pattern() const { return pattern_; } | |
| 57 const GURL& script_url() const { | |
| 58 DCHECK(type_ == REGISTER); | |
|
kinuko
2014/01/08 08:38:36
We seem to call this for UNREGISTER case too?
alecflett
2014/01/08 23:59:16
the && short-circuits this call)
But we never sho
| |
| 59 return script_url_; | |
| 60 } | |
| 61 RegistrationType type() const { return type_; } | |
| 62 bool is_running() const { return running_; } | |
|
kinuko
2014/01/08 08:38:36
This doesn't seem to be used, or relying on this f
alecflett
2014/01/08 23:59:16
this is mainly for tests - I thought I had an EXPE
| |
| 63 | |
| 64 private: | |
| 35 // The Registration flow includes most or all of the following, | 65 // The Registration flow includes most or all of the following, |
| 36 // depending on what is already registered: | 66 // depending on what is already registered: |
| 37 // - creating a ServiceWorkerRegistration instance if there isn't | 67 // - creating a ServiceWorkerRegistration instance if there isn't |
| 38 // already something registered | 68 // already something registered |
| 39 // - creating a ServiceWorkerVersion for the new registration instance. | 69 // - creating a ServiceWorkerVersion for the new registration instance. |
| 40 // - starting a worker for the ServiceWorkerVersion | 70 // - starting a worker for the ServiceWorkerVersion |
| 41 // - telling the Version to evaluate the script | 71 // - telling the Version to evaluate the script |
| 42 // - firing the 'install' event at the ServiceWorkerVersion | 72 // - firing the 'install' event at the ServiceWorkerVersion |
| 43 // - firing the 'activate' event at the ServiceWorkerVersion | 73 // - firing the 'activate' event at the ServiceWorkerVersion |
| 44 // - Waiting for older ServiceWorkerVersions to deactivate | 74 // - Waiting for older ServiceWorkerVersions to deactivate |
| 45 // - designating the new version to be the 'active' version | 75 // - designating the new version to be the 'active' version |
| 46 // This method should be called once and only once per job. | 76 // This method should be called once and only once per job. |
| 47 void StartRegister(const GURL& pattern, const GURL& script_url); | 77 void StartRegister(); |
| 48 | 78 |
| 49 // The Unregistration process is primarily cleanup, removing | 79 // The Unregistration process is primarily cleanup, removing |
| 50 // everything that was created during the Registration process, | 80 // everything that was created during the Registration process, |
| 51 // including the ServiceWorkerRegistration itself. | 81 // including the ServiceWorkerRegistration itself. |
| 52 // This method should be called once and only once per job. | 82 // This method should be called once and only once per job. |
| 53 void StartUnregister(const GURL& pattern); | 83 void StartUnregister(); |
| 54 | 84 |
| 55 private: | |
| 56 // These are all steps in the registration and unregistration pipeline. | 85 // These are all steps in the registration and unregistration pipeline. |
| 57 void RegisterPatternAndContinue( | 86 void RegisterPatternAndContinue( |
| 58 const GURL& pattern, | |
| 59 const GURL& script_url, | |
| 60 const RegistrationCallback& callback, | 87 const RegistrationCallback& callback, |
| 61 ServiceWorkerRegistrationStatus previous_status); | 88 ServiceWorkerRegistrationStatus previous_status); |
| 62 | 89 |
| 63 void UnregisterPatternAndContinue( | 90 void UnregisterPatternAndContinue( |
| 64 const GURL& pattern, | |
| 65 const GURL& script_url, | |
| 66 const UnregistrationCallback& callback, | 91 const UnregistrationCallback& callback, |
| 67 bool found, | 92 bool found, |
| 68 ServiceWorkerRegistrationStatus previous_status, | 93 ServiceWorkerRegistrationStatus previous_status, |
| 69 const scoped_refptr<ServiceWorkerRegistration>& previous_registration); | 94 const scoped_refptr<ServiceWorkerRegistration>& previous_registration); |
| 70 | 95 |
| 71 // These methods are the last internal callback in the callback | 96 // These methods are the last internal callback in the callback |
| 72 // chain, and ultimately call callback_. | 97 // chain, and ultimately call callback_. |
| 73 void UnregisterComplete(ServiceWorkerRegistrationStatus status); | 98 void UnregisterComplete(ServiceWorkerRegistrationStatus status); |
| 74 void RegisterComplete( | 99 void RegisterComplete( |
| 75 ServiceWorkerRegistrationStatus status, | 100 ServiceWorkerRegistrationStatus status, |
| 76 const scoped_refptr<ServiceWorkerRegistration>& registration); | 101 const scoped_refptr<ServiceWorkerRegistration>& registration); |
| 77 | 102 |
| 103 void RunCallbacks( | |
| 104 ServiceWorkerRegistrationStatus status, | |
| 105 const scoped_refptr<ServiceWorkerRegistration>& registration); | |
| 106 | |
| 78 const base::WeakPtr<ServiceWorkerStorage> storage_; | 107 const base::WeakPtr<ServiceWorkerStorage> storage_; |
| 79 const RegistrationCompleteCallback callback_; | 108 ServiceWorkerJobCoordinator* coordinator_; |
| 109 const GURL pattern_; | |
| 110 GURL script_url_; // should be unset for register case | |
| 111 std::vector<RegistrationCompleteCallback> callbacks_; | |
| 80 base::WeakPtrFactory<ServiceWorkerRegisterJob> weak_factory_; | 112 base::WeakPtrFactory<ServiceWorkerRegisterJob> weak_factory_; |
| 113 const RegistrationType type_; | |
| 114 bool running_; | |
| 81 | 115 |
| 82 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerRegisterJob); | 116 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerRegisterJob); |
| 83 }; | 117 }; |
| 84 } // namespace content | 118 } // namespace content |
| 85 | 119 |
| 86 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_REGISTER_JOB_H_ | 120 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_REGISTER_JOB_H_ |
| OLD | NEW |