| 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 // process to create the Service Worker instance. If there are no existing | 50 // process to create the Service Worker instance. If there are no existing |
| 51 // clients, a new RenderProcessHost will be created. | 51 // clients, a new RenderProcessHost will be created. |
| 52 void AddCallback(const RegistrationCallback& callback, int process_id); | 52 void AddCallback(const RegistrationCallback& callback, int process_id); |
| 53 | 53 |
| 54 // ServiceWorkerRegisterJobBase implementation: | 54 // ServiceWorkerRegisterJobBase implementation: |
| 55 virtual void Start() OVERRIDE; | 55 virtual void Start() OVERRIDE; |
| 56 virtual bool Equals(ServiceWorkerRegisterJobBase* job) OVERRIDE; | 56 virtual bool Equals(ServiceWorkerRegisterJobBase* job) OVERRIDE; |
| 57 virtual RegistrationJobType GetType() OVERRIDE; | 57 virtual RegistrationJobType GetType() OVERRIDE; |
| 58 | 58 |
| 59 private: | 59 private: |
| 60 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerProviderHostPendingVersionTest, | 60 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerProviderHostWaitingVersionTest, |
| 61 AssociatePendingVersionToDocuments); | 61 AssociateWaitingVersionToDocuments); |
| 62 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerProviderHostPendingVersionTest, | 62 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerProviderHostWaitingVersionTest, |
| 63 DisassociatePendingVersionFromDocuments); | 63 DisassociateWaitingVersionFromDocuments); |
| 64 | 64 |
| 65 enum Phase { | 65 enum Phase { |
| 66 INITIAL, | 66 INITIAL, |
| 67 START, | 67 START, |
| 68 REGISTER, | 68 REGISTER, |
| 69 UPDATE, | 69 UPDATE, |
| 70 INSTALL, | 70 INSTALL, |
| 71 STORE, | 71 STORE, |
| 72 ACTIVATE, | 72 ACTIVATE, |
| 73 COMPLETE | 73 COMPLETE |
| 74 }; | 74 }; |
| 75 | 75 |
| 76 // Holds internal state of ServiceWorkerRegistrationJob, to compel use of the | 76 // Holds internal state of ServiceWorkerRegistrationJob, to compel use of the |
| 77 // getter/setter functions. | 77 // getter/setter functions. |
| 78 struct Internal { | 78 struct Internal { |
| 79 Internal(); | 79 Internal(); |
| 80 ~Internal(); | 80 ~Internal(); |
| 81 scoped_refptr<ServiceWorkerRegistration> registration; | 81 scoped_refptr<ServiceWorkerRegistration> registration; |
| 82 |
| 83 // Holds 'installing' or 'waiting' version depending on the phase. |
| 82 scoped_refptr<ServiceWorkerVersion> pending_version; | 84 scoped_refptr<ServiceWorkerVersion> pending_version; |
| 83 }; | 85 }; |
| 84 | 86 |
| 85 void set_registration(ServiceWorkerRegistration* registration); | 87 void set_registration(ServiceWorkerRegistration* registration); |
| 86 ServiceWorkerRegistration* registration(); | 88 ServiceWorkerRegistration* registration(); |
| 87 void set_pending_version(ServiceWorkerVersion* version); | 89 void set_pending_version(ServiceWorkerVersion* version); |
| 88 ServiceWorkerVersion* pending_version(); | 90 ServiceWorkerVersion* pending_version(); |
| 89 | 91 |
| 90 void SetPhase(Phase phase); | 92 void SetPhase(Phase phase); |
| 91 | 93 |
| 92 void HandleExistingRegistrationAndContinue( | 94 void HandleExistingRegistrationAndContinue( |
| 93 ServiceWorkerStatusCode status, | 95 ServiceWorkerStatusCode status, |
| 94 const scoped_refptr<ServiceWorkerRegistration>& registration); | 96 const scoped_refptr<ServiceWorkerRegistration>& registration); |
| 95 void RegisterAndContinue(ServiceWorkerStatusCode status); | 97 void RegisterAndContinue(ServiceWorkerStatusCode status); |
| 96 void UpdateAndContinue(ServiceWorkerStatusCode status); | 98 void UpdateAndContinue(ServiceWorkerStatusCode status); |
| 97 void OnStartWorkerFinished(ServiceWorkerStatusCode status); | 99 void OnStartWorkerFinished(ServiceWorkerStatusCode status); |
| 98 void OnStoreRegistrationComplete(ServiceWorkerStatusCode status); | 100 void OnStoreRegistrationComplete(ServiceWorkerStatusCode status); |
| 99 void InstallAndContinue(); | 101 void InstallAndContinue(); |
| 100 void OnInstallFinished(ServiceWorkerStatusCode status); | 102 void OnInstallFinished(ServiceWorkerStatusCode status); |
| 101 void ActivateAndContinue(); | 103 void ActivateAndContinue(); |
| 102 void OnActivateFinished(ServiceWorkerStatusCode status); | 104 void OnActivateFinished(ServiceWorkerStatusCode status); |
| 103 void Complete(ServiceWorkerStatusCode status); | 105 void Complete(ServiceWorkerStatusCode status); |
| 104 | 106 |
| 105 void ResolvePromise(ServiceWorkerStatusCode status, | 107 void ResolvePromise(ServiceWorkerStatusCode status, |
| 106 ServiceWorkerRegistration* registration, | 108 ServiceWorkerRegistration* registration, |
| 107 ServiceWorkerVersion* version); | 109 ServiceWorkerVersion* version); |
| 108 | 110 |
| 109 // Associates a pending version to documents matched with a scope of the | 111 // Associates a waiting version to documents matched with a scope of the |
| 110 // version. | 112 // version. |
| 111 CONTENT_EXPORT static void AssociatePendingVersionToDocuments( | 113 CONTENT_EXPORT static void AssociateWaitingVersionToDocuments( |
| 112 base::WeakPtr<ServiceWorkerContextCore> context, | 114 base::WeakPtr<ServiceWorkerContextCore> context, |
| 113 ServiceWorkerVersion* version); | 115 ServiceWorkerVersion* version); |
| 114 | 116 |
| 115 // Disassociates a pending version specified by |version_id| from documents. | 117 // Disassociates a waiting version specified by |version_id| from documents. |
| 116 CONTENT_EXPORT static void DisassociatePendingVersionFromDocuments( | 118 CONTENT_EXPORT static void DisassociateWaitingVersionFromDocuments( |
| 117 base::WeakPtr<ServiceWorkerContextCore> context, | 119 base::WeakPtr<ServiceWorkerContextCore> context, |
| 118 int64 version_id); | 120 int64 version_id); |
| 119 | 121 |
| 120 // The ServiceWorkerContextCore object should always outlive this. | 122 // The ServiceWorkerContextCore object should always outlive this. |
| 121 base::WeakPtr<ServiceWorkerContextCore> context_; | 123 base::WeakPtr<ServiceWorkerContextCore> context_; |
| 122 | 124 |
| 123 const GURL pattern_; | 125 const GURL pattern_; |
| 124 const GURL script_url_; | 126 const GURL script_url_; |
| 125 std::vector<RegistrationCallback> callbacks_; | 127 std::vector<RegistrationCallback> callbacks_; |
| 126 std::vector<int> pending_process_ids_; | 128 std::vector<int> pending_process_ids_; |
| 127 Phase phase_; | 129 Phase phase_; |
| 128 Internal internal_; | 130 Internal internal_; |
| 129 bool is_promise_resolved_; | 131 bool is_promise_resolved_; |
| 130 ServiceWorkerStatusCode promise_resolved_status_; | 132 ServiceWorkerStatusCode promise_resolved_status_; |
| 131 scoped_refptr<ServiceWorkerRegistration> promise_resolved_registration_; | 133 scoped_refptr<ServiceWorkerRegistration> promise_resolved_registration_; |
| 132 scoped_refptr<ServiceWorkerVersion> promise_resolved_version_; | 134 scoped_refptr<ServiceWorkerVersion> promise_resolved_version_; |
| 133 base::WeakPtrFactory<ServiceWorkerRegisterJob> weak_factory_; | 135 base::WeakPtrFactory<ServiceWorkerRegisterJob> weak_factory_; |
| 134 | 136 |
| 135 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerRegisterJob); | 137 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerRegisterJob); |
| 136 }; | 138 }; |
| 137 | 139 |
| 138 } // namespace content | 140 } // namespace content |
| 139 | 141 |
| 140 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_REGISTER_JOB_H_ | 142 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_REGISTER_JOB_H_ |
| OLD | NEW |