| 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 #include "content/browser/service_worker/service_worker_register_job.h" | 5 #include "content/browser/service_worker/service_worker_register_job.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "content/browser/service_worker/service_worker_job_coordinator.h" | 9 #include "content/browser/service_worker/service_worker_job_coordinator.h" |
| 10 #include "content/browser/service_worker/service_worker_registration.h" | 10 #include "content/browser/service_worker/service_worker_registration.h" |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 ServiceWorkerStorage::FindRegistrationCallback unregister( | 75 ServiceWorkerStorage::FindRegistrationCallback unregister( |
| 76 base::Bind(&ServiceWorkerRegisterJob::UnregisterPatternAndContinue, | 76 base::Bind(&ServiceWorkerRegisterJob::UnregisterPatternAndContinue, |
| 77 weak_factory_.GetWeakPtr(), | 77 weak_factory_.GetWeakPtr(), |
| 78 finish_unregistration)); | 78 finish_unregistration)); |
| 79 | 79 |
| 80 storage_->FindRegistrationForPattern(pattern_, unregister); | 80 storage_->FindRegistrationForPattern(pattern_, unregister); |
| 81 } | 81 } |
| 82 | 82 |
| 83 void ServiceWorkerRegisterJob::RegisterPatternAndContinue( | 83 void ServiceWorkerRegisterJob::RegisterPatternAndContinue( |
| 84 const RegistrationCallback& callback, | 84 const RegistrationCallback& callback, |
| 85 ServiceWorkerRegistrationStatus previous_status) { | 85 ServiceWorkerStatusCode previous_status) { |
| 86 if (previous_status != REGISTRATION_OK) { | 86 if (previous_status != SERVICE_WORKER_OK) { |
| 87 BrowserThread::PostTask( | 87 BrowserThread::PostTask( |
| 88 BrowserThread::IO, | 88 BrowserThread::IO, |
| 89 FROM_HERE, | 89 FROM_HERE, |
| 90 base::Bind(callback, | 90 base::Bind(callback, |
| 91 previous_status, | 91 previous_status, |
| 92 scoped_refptr<ServiceWorkerRegistration>())); | 92 scoped_refptr<ServiceWorkerRegistration>())); |
| 93 return; | 93 return; |
| 94 } | 94 } |
| 95 | 95 |
| 96 // TODO: Eventually RegisterInternal will be replaced by an asynchronous | 96 // TODO: Eventually RegisterInternal will be replaced by an asynchronous |
| 97 // operation. Pass its resulting status through 'callback'. | 97 // operation. Pass its resulting status through 'callback'. |
| 98 scoped_refptr<ServiceWorkerRegistration> registration = | 98 scoped_refptr<ServiceWorkerRegistration> registration = |
| 99 storage_->RegisterInternal(pattern_, script_url_); | 99 storage_->RegisterInternal(pattern_, script_url_); |
| 100 BrowserThread::PostTask(BrowserThread::IO, | 100 BrowserThread::PostTask(BrowserThread::IO, |
| 101 FROM_HERE, | 101 FROM_HERE, |
| 102 base::Bind(callback, REGISTRATION_OK, registration)); | 102 base::Bind(callback, SERVICE_WORKER_OK, |
| 103 registration)); |
| 103 } | 104 } |
| 104 | 105 |
| 105 void ServiceWorkerRegisterJob::UnregisterPatternAndContinue( | 106 void ServiceWorkerRegisterJob::UnregisterPatternAndContinue( |
| 106 const UnregistrationCallback& callback, | 107 const UnregistrationCallback& callback, |
| 107 bool found, | 108 bool found, |
| 108 ServiceWorkerRegistrationStatus previous_status, | 109 ServiceWorkerStatusCode previous_status, |
| 109 const scoped_refptr<ServiceWorkerRegistration>& previous_registration) { | 110 const scoped_refptr<ServiceWorkerRegistration>& previous_registration) { |
| 110 | 111 |
| 111 // The previous registration may not exist, which is ok. | 112 // The previous registration may not exist, which is ok. |
| 112 if (previous_status == REGISTRATION_OK && found && | 113 if (previous_status == SERVICE_WORKER_OK && found && |
| 113 (script_url_.is_empty() || | 114 (script_url_.is_empty() || |
| 114 previous_registration->script_url() != script_url_)) { | 115 previous_registration->script_url() != script_url_)) { |
| 115 // TODO: Eventually UnregisterInternal will be replaced by an | 116 // TODO: Eventually UnregisterInternal will be replaced by an |
| 116 // asynchronous operation. Pass its resulting status though | 117 // asynchronous operation. Pass its resulting status though |
| 117 // 'callback'. | 118 // 'callback'. |
| 118 storage_->UnregisterInternal(pattern_); | 119 storage_->UnregisterInternal(pattern_); |
| 119 DCHECK(previous_registration->is_shutdown()); | 120 DCHECK(previous_registration->is_shutdown()); |
| 120 } | 121 } |
| 121 BrowserThread::PostTask( | 122 BrowserThread::PostTask( |
| 122 BrowserThread::IO, FROM_HERE, base::Bind(callback, previous_status)); | 123 BrowserThread::IO, FROM_HERE, base::Bind(callback, previous_status)); |
| 123 } | 124 } |
| 124 | 125 |
| 125 void ServiceWorkerRegisterJob::RunCallbacks( | 126 void ServiceWorkerRegisterJob::RunCallbacks( |
| 126 ServiceWorkerRegistrationStatus status, | 127 ServiceWorkerStatusCode status, |
| 127 const scoped_refptr<ServiceWorkerRegistration>& registration) { | 128 const scoped_refptr<ServiceWorkerRegistration>& registration) { |
| 128 for (std::vector<RegistrationCallback>::iterator it = callbacks_.begin(); | 129 for (std::vector<RegistrationCallback>::iterator it = callbacks_.begin(); |
| 129 it != callbacks_.end(); | 130 it != callbacks_.end(); |
| 130 ++it) { | 131 ++it) { |
| 131 it->Run(status, registration); | 132 it->Run(status, registration); |
| 132 } | 133 } |
| 133 } | 134 } |
| 134 void ServiceWorkerRegisterJob::RegisterComplete( | 135 void ServiceWorkerRegisterJob::RegisterComplete( |
| 135 ServiceWorkerRegistrationStatus status, | 136 ServiceWorkerStatusCode status, |
| 136 const scoped_refptr<ServiceWorkerRegistration>& registration) { | 137 const scoped_refptr<ServiceWorkerRegistration>& registration) { |
| 137 RunCallbacks(status, registration); | 138 RunCallbacks(status, registration); |
| 138 coordinator_->FinishJob(pattern_, this); | 139 coordinator_->FinishJob(pattern_, this); |
| 139 } | 140 } |
| 140 | 141 |
| 141 void ServiceWorkerRegisterJob::UnregisterComplete( | 142 void ServiceWorkerRegisterJob::UnregisterComplete( |
| 142 ServiceWorkerRegistrationStatus status) { | 143 ServiceWorkerStatusCode status) { |
| 143 RunCallbacks(status, NULL); | 144 RunCallbacks(status, NULL); |
| 144 coordinator_->FinishJob(pattern_, this); | 145 coordinator_->FinishJob(pattern_, this); |
| 145 } | 146 } |
| 146 | 147 |
| 147 } // namespace content | 148 } // namespace content |
| OLD | NEW |