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 #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 "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "content/browser/service_worker/service_worker_job_coordinator.h" | 10 #include "content/browser/service_worker/service_worker_job_coordinator.h" |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 104 ServiceWorkerStatusCode status) { | 104 ServiceWorkerStatusCode status) { |
| 105 DCHECK(registration_); | 105 DCHECK(registration_); |
| 106 if (registration_->active_version()) { | 106 if (registration_->active_version()) { |
| 107 // We have an active version, so we can complete immediately, even | 107 // We have an active version, so we can complete immediately, even |
| 108 // if the service worker isn't running. | 108 // if the service worker isn't running. |
| 109 callback.Run(SERVICE_WORKER_OK); | 109 callback.Run(SERVICE_WORKER_OK); |
| 110 return; | 110 return; |
| 111 } | 111 } |
| 112 | 112 |
| 113 pending_version_ = new ServiceWorkerVersion( | 113 pending_version_ = new ServiceWorkerVersion( |
| 114 registration_, worker_registry_, registration_->next_version_id()); | 114 registration_, worker_registry_, |
| 115 storage_->NewVersionId(), | |
| 116 ServiceWorkerVersion::NEW); | |
| 115 for (std::vector<int>::const_iterator it = pending_process_ids_.begin(); | 117 for (std::vector<int>::const_iterator it = pending_process_ids_.begin(); |
| 116 it != pending_process_ids_.end(); | 118 it != pending_process_ids_.end(); |
| 117 ++it) | 119 ++it) |
| 118 pending_version_->AddProcessToWorker(*it); | 120 pending_version_->AddProcessToWorker(*it); |
| 119 | 121 |
| 120 // The callback to watch "installation" actually fires as soon as | 122 // The callback to watch "installation" actually fires as soon as |
| 121 // the worker is up and running, just before the install event is | 123 // the worker is up and running, just before the install event is |
| 122 // dispatched. The job will continue to run even though the main | 124 // dispatched. The job will continue to run even though the main |
| 123 // callback has executed. | 125 // callback has executed. |
| 124 pending_version_->StartWorker(callback); | 126 pending_version_->StartWorker(callback); |
| 125 | 127 |
| 126 // TODO(alecflett): Don't set the active version until just before | 128 // TODO(alecflett): Don't set the active version until just before |
| 127 // the activate event is dispatched. | 129 // the install/activate event is dispatched. |
|
alecflett
2014/03/06 19:10:24
I don't think adding "install/" is right - we want
michaeln
2014/03/06 19:49:54
Regarding setting before, what if activate fails?
kinuko
2014/03/10 10:36:56
I overlooked the 'just before' phrasing, just want
| |
| 130 pending_version_->set_status(ServiceWorkerVersion::ACTIVE); | |
| 128 registration_->set_active_version(pending_version_); | 131 registration_->set_active_version(pending_version_); |
| 129 } | 132 } |
| 130 | 133 |
| 131 void ServiceWorkerRegisterJob::RegisterPatternAndContinue( | 134 void ServiceWorkerRegisterJob::RegisterPatternAndContinue( |
| 132 const StatusCallback& callback, | 135 const StatusCallback& callback, |
| 133 ServiceWorkerStatusCode previous_status) { | 136 ServiceWorkerStatusCode previous_status) { |
| 134 if (previous_status == SERVICE_WORKER_ERROR_EXISTS) { | 137 if (previous_status == SERVICE_WORKER_ERROR_EXISTS) { |
| 135 // Registration already exists, call to the next step. | 138 // Registration already exists, call to the next step. |
| 136 RunSoon(base::Bind(callback, SERVICE_WORKER_OK)); | 139 RunSoon(base::Bind(callback, SERVICE_WORKER_OK)); |
| 137 return; | 140 return; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 183 void ServiceWorkerRegisterJob::Complete(ServiceWorkerStatusCode status) { | 186 void ServiceWorkerRegisterJob::Complete(ServiceWorkerStatusCode status) { |
| 184 for (std::vector<RegistrationCallback>::iterator it = callbacks_.begin(); | 187 for (std::vector<RegistrationCallback>::iterator it = callbacks_.begin(); |
| 185 it != callbacks_.end(); | 188 it != callbacks_.end(); |
| 186 ++it) { | 189 ++it) { |
| 187 it->Run(status, registration_); | 190 it->Run(status, registration_); |
| 188 } | 191 } |
| 189 coordinator_->FinishJob(pattern_, this); | 192 coordinator_->FinishJob(pattern_, this); |
| 190 } | 193 } |
| 191 | 194 |
| 192 } // namespace content | 195 } // namespace content |
| OLD | NEW |