| 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" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 // depending on what is already registered: | 26 // depending on what is already registered: |
| 27 // - creating a ServiceWorkerRegistration instance if there isn't | 27 // - creating a ServiceWorkerRegistration instance if there isn't |
| 28 // already something registered | 28 // already something registered |
| 29 // - creating a ServiceWorkerVersion for the new version. | 29 // - creating a ServiceWorkerVersion for the new version. |
| 30 // - starting a worker for the ServiceWorkerVersion | 30 // - starting a worker for the ServiceWorkerVersion |
| 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 // - updating storage | 35 // - updating storage |
| 36 class ServiceWorkerRegisterJob | 36 class ServiceWorkerRegisterJob : public ServiceWorkerRegisterJobBase, |
| 37 : public ServiceWorkerRegisterJobBase, | 37 public EmbeddedWorkerInstance::Listener, |
| 38 public EmbeddedWorkerInstance::Listener { | 38 public ServiceWorkerRegistration::Listener { |
| 39 public: | 39 public: |
| 40 typedef base::Callback<void(ServiceWorkerStatusCode status, | 40 typedef base::Callback<void(ServiceWorkerStatusCode status, |
| 41 ServiceWorkerRegistration* registration, | 41 ServiceWorkerRegistration* registration, |
| 42 ServiceWorkerVersion* version)> | 42 ServiceWorkerVersion* version)> |
| 43 RegistrationCallback; | 43 RegistrationCallback; |
| 44 | 44 |
| 45 // For registration jobs. | 45 // For registration jobs. |
| 46 CONTENT_EXPORT ServiceWorkerRegisterJob( | 46 CONTENT_EXPORT ServiceWorkerRegisterJob( |
| 47 base::WeakPtr<ServiceWorkerContextCore> context, | 47 base::WeakPtr<ServiceWorkerContextCore> context, |
| 48 const GURL& pattern, | 48 const GURL& pattern, |
| (...skipping 18 matching lines...) Expand all Loading... |
| 67 virtual bool Equals(ServiceWorkerRegisterJobBase* job) OVERRIDE; | 67 virtual bool Equals(ServiceWorkerRegisterJobBase* job) OVERRIDE; |
| 68 virtual RegistrationJobType GetType() OVERRIDE; | 68 virtual RegistrationJobType GetType() OVERRIDE; |
| 69 | 69 |
| 70 private: | 70 private: |
| 71 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerProviderHostWaitingVersionTest, | 71 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerProviderHostWaitingVersionTest, |
| 72 AssociateInstallingVersionToDocuments); | 72 AssociateInstallingVersionToDocuments); |
| 73 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerProviderHostWaitingVersionTest, | 73 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerProviderHostWaitingVersionTest, |
| 74 DisassociateVersionFromDocuments); | 74 DisassociateVersionFromDocuments); |
| 75 | 75 |
| 76 enum Phase { | 76 enum Phase { |
| 77 INITIAL, | 77 INITIAL, |
| 78 START, | 78 START, |
| 79 REGISTER, | 79 WAIT_FOR_UNINSTALL, |
| 80 UPDATE, | 80 REGISTER, |
| 81 INSTALL, | 81 UPDATE, |
| 82 STORE, | 82 INSTALL, |
| 83 COMPLETE, | 83 STORE, |
| 84 ABORT, | 84 COMPLETE, |
| 85 ABORT, |
| 85 }; | 86 }; |
| 86 | 87 |
| 87 // Holds internal state of ServiceWorkerRegistrationJob, to compel use of the | 88 // Holds internal state of ServiceWorkerRegistrationJob, to compel use of the |
| 88 // getter/setter functions. | 89 // getter/setter functions. |
| 89 struct Internal { | 90 struct Internal { |
| 90 Internal(); | 91 Internal(); |
| 91 ~Internal(); | 92 ~Internal(); |
| 92 scoped_refptr<ServiceWorkerRegistration> registration; | 93 scoped_refptr<ServiceWorkerRegistration> registration; |
| 93 | 94 |
| 94 // 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', |
| 95 // 'waiting', or 'active' version depending on the phase. | 96 // 'waiting', or 'active' version depending on the phase. |
| 96 scoped_refptr<ServiceWorkerVersion> new_version; | 97 scoped_refptr<ServiceWorkerVersion> new_version; |
| 98 |
| 99 scoped_refptr<ServiceWorkerRegistration> uninstalling_registration; |
| 97 }; | 100 }; |
| 98 | 101 |
| 99 void set_registration(ServiceWorkerRegistration* registration); | 102 void set_registration(ServiceWorkerRegistration* registration); |
| 100 ServiceWorkerRegistration* registration(); | 103 ServiceWorkerRegistration* registration(); |
| 101 void set_new_version(ServiceWorkerVersion* version); | 104 void set_new_version(ServiceWorkerVersion* version); |
| 102 ServiceWorkerVersion* new_version(); | 105 ServiceWorkerVersion* new_version(); |
| 106 void set_uninstalling_registration(ServiceWorkerRegistration* registration); |
| 107 ServiceWorkerRegistration* uninstalling_registration(); |
| 103 | 108 |
| 104 void SetPhase(Phase phase); | 109 void SetPhase(Phase phase); |
| 105 | 110 |
| 106 void ContinueWithRegistration( | 111 void ContinueWithRegistration( |
| 107 ServiceWorkerStatusCode status, | 112 ServiceWorkerStatusCode status, |
| 108 const scoped_refptr<ServiceWorkerRegistration>& registration); | 113 const scoped_refptr<ServiceWorkerRegistration>& registration); |
| 109 void ContinueWithUpdate( | 114 void ContinueWithUpdate( |
| 110 ServiceWorkerStatusCode status, | 115 ServiceWorkerStatusCode status, |
| 111 const scoped_refptr<ServiceWorkerRegistration>& registration); | 116 const scoped_refptr<ServiceWorkerRegistration>& registration); |
| 112 void RegisterAndContinue(ServiceWorkerStatusCode status); | 117 void RegisterAndContinue(ServiceWorkerStatusCode status); |
| 118 void WaitForUninstall( |
| 119 const scoped_refptr<ServiceWorkerRegistration>& registration); |
| 120 void ContinueWithRegistrationForSameScriptUrl( |
| 121 const scoped_refptr<ServiceWorkerRegistration>& existing_registration, |
| 122 ServiceWorkerStatusCode status); |
| 113 void UpdateAndContinue(); | 123 void UpdateAndContinue(); |
| 114 void OnStartWorkerFinished(ServiceWorkerStatusCode status); | 124 void OnStartWorkerFinished(ServiceWorkerStatusCode status); |
| 115 void OnStoreRegistrationComplete(ServiceWorkerStatusCode status); | 125 void OnStoreRegistrationComplete(ServiceWorkerStatusCode status); |
| 116 void InstallAndContinue(); | 126 void InstallAndContinue(); |
| 117 void OnInstallFinished(ServiceWorkerStatusCode status); | 127 void OnInstallFinished(ServiceWorkerStatusCode status); |
| 118 void ActivateAndContinue(); | 128 void ActivateAndContinue(); |
| 119 void OnActivateFinished(ServiceWorkerStatusCode status); | 129 void OnActivateFinished(ServiceWorkerStatusCode status); |
| 120 void Complete(ServiceWorkerStatusCode status); | 130 void Complete(ServiceWorkerStatusCode status); |
| 121 void CompleteInternal(ServiceWorkerStatusCode status); | 131 void CompleteInternal(ServiceWorkerStatusCode status); |
| 122 void ResolvePromise(ServiceWorkerStatusCode status, | 132 void ResolvePromise(ServiceWorkerStatusCode status, |
| 123 ServiceWorkerRegistration* registration, | 133 ServiceWorkerRegistration* registration, |
| 124 ServiceWorkerVersion* version); | 134 ServiceWorkerVersion* version); |
| 125 | 135 |
| 126 // EmbeddedWorkerInstance::Listener override of OnPausedAfterDownload. | 136 // EmbeddedWorkerInstance::Listener override of OnPausedAfterDownload. |
| 127 virtual void OnPausedAfterDownload() OVERRIDE; | 137 virtual void OnPausedAfterDownload() OVERRIDE; |
| 128 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 138 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
| 129 | 139 |
| 140 // ServiceWorkerRegistration::Listener overrides |
| 141 virtual void OnRegistrationFinishedUninstalling( |
| 142 ServiceWorkerRegistration* registration) OVERRIDE; |
| 143 |
| 130 void OnCompareScriptResourcesComplete( | 144 void OnCompareScriptResourcesComplete( |
| 131 ServiceWorkerVersion* most_recent_version, | 145 ServiceWorkerVersion* most_recent_version, |
| 132 ServiceWorkerStatusCode status, | 146 ServiceWorkerStatusCode status, |
| 133 bool are_equal); | 147 bool are_equal); |
| 134 | 148 |
| 135 void AssociateProviderHostsToRegistration( | 149 void AssociateProviderHostsToRegistration( |
| 136 ServiceWorkerRegistration* registration); | 150 ServiceWorkerRegistration* registration); |
| 137 | 151 |
| 138 // The ServiceWorkerContextCore object should always outlive this. | 152 // The ServiceWorkerContextCore object should always outlive this. |
| 139 base::WeakPtr<ServiceWorkerContextCore> context_; | 153 base::WeakPtr<ServiceWorkerContextCore> context_; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 150 scoped_refptr<ServiceWorkerRegistration> promise_resolved_registration_; | 164 scoped_refptr<ServiceWorkerRegistration> promise_resolved_registration_; |
| 151 scoped_refptr<ServiceWorkerVersion> promise_resolved_version_; | 165 scoped_refptr<ServiceWorkerVersion> promise_resolved_version_; |
| 152 base::WeakPtrFactory<ServiceWorkerRegisterJob> weak_factory_; | 166 base::WeakPtrFactory<ServiceWorkerRegisterJob> weak_factory_; |
| 153 | 167 |
| 154 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerRegisterJob); | 168 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerRegisterJob); |
| 155 }; | 169 }; |
| 156 | 170 |
| 157 } // namespace content | 171 } // namespace content |
| 158 | 172 |
| 159 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_REGISTER_JOB_H_ | 173 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_REGISTER_JOB_H_ |
| OLD | NEW |