| 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_version.h" | 5 #include "content/browser/service_worker/service_worker_version.h" |
| 6 | 6 |
| 7 #include "base/stl_util.h" | 7 #include "base/stl_util.h" |
| 8 #include "content/browser/service_worker/embedded_worker_instance.h" | 8 #include "content/browser/service_worker/embedded_worker_instance.h" |
| 9 #include "content/browser/service_worker/embedded_worker_registry.h" | 9 #include "content/browser/service_worker/embedded_worker_registry.h" |
| 10 #include "content/browser/service_worker/service_worker_context_core.h" | 10 #include "content/browser/service_worker/service_worker_context_core.h" |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 | 123 |
| 124 void ServiceWorkerVersion::StartWorker(const StatusCallback& callback) { | 124 void ServiceWorkerVersion::StartWorker(const StatusCallback& callback) { |
| 125 DCHECK(!is_shutdown_); | 125 DCHECK(!is_shutdown_); |
| 126 DCHECK(registration_); | 126 DCHECK(registration_); |
| 127 DCHECK(!observer_); | 127 DCHECK(!observer_); |
| 128 if (status() == RUNNING) { | 128 if (status() == RUNNING) { |
| 129 RunSoon(base::Bind(callback, SERVICE_WORKER_OK)); | 129 RunSoon(base::Bind(callback, SERVICE_WORKER_OK)); |
| 130 return; | 130 return; |
| 131 } | 131 } |
| 132 observer_.reset(new StartObserver(this, callback)); | 132 observer_.reset(new StartObserver(this, callback)); |
| 133 const bool started = embedded_worker_->Start( | 133 ServiceWorkerStatusCode status = embedded_worker_->Start( |
| 134 version_id_, | 134 version_id_, |
| 135 registration_->script_url()); | 135 registration_->script_url()); |
| 136 if (!started) { | 136 if (status != SERVICE_WORKER_OK) { |
| 137 observer_.reset(); | 137 observer_.reset(); |
| 138 RunSoon(base::Bind(callback, SERVICE_WORKER_ERROR_START_WORKER_FAILED)); | 138 RunSoon(base::Bind(callback, status)); |
| 139 } | 139 } |
| 140 } | 140 } |
| 141 | 141 |
| 142 void ServiceWorkerVersion::StopWorker(const StatusCallback& callback) { | 142 void ServiceWorkerVersion::StopWorker(const StatusCallback& callback) { |
| 143 DCHECK(!is_shutdown_); | 143 DCHECK(!is_shutdown_); |
| 144 DCHECK(!observer_); | 144 DCHECK(!observer_); |
| 145 if (status() == STOPPED) { | 145 if (status() == STOPPED) { |
| 146 RunSoon(base::Bind(callback, SERVICE_WORKER_OK)); | 146 RunSoon(base::Bind(callback, SERVICE_WORKER_OK)); |
| 147 return; | 147 return; |
| 148 } | 148 } |
| 149 observer_.reset(new StopObserver(this, callback)); | 149 observer_.reset(new StopObserver(this, callback)); |
| 150 const bool stopped = embedded_worker_->Stop(); | 150 ServiceWorkerStatusCode status = embedded_worker_->Stop(); |
| 151 if (!stopped) { | 151 if (status != SERVICE_WORKER_OK) { |
| 152 observer_.reset(); | 152 observer_.reset(); |
| 153 RunSoon(base::Bind(callback, SERVICE_WORKER_ERROR_FAILED)); | 153 RunSoon(base::Bind(callback, status)); |
| 154 } | 154 } |
| 155 } | 155 } |
| 156 | 156 |
| 157 bool ServiceWorkerVersion::DispatchFetchEvent( | 157 bool ServiceWorkerVersion::DispatchFetchEvent( |
| 158 const ServiceWorkerFetchRequest& request) { | 158 const ServiceWorkerFetchRequest& request) { |
| 159 if (status() != RUNNING) | 159 if (status() != RUNNING) |
| 160 return false; | 160 return false; |
| 161 return embedded_worker_->SendMessage( | 161 return embedded_worker_->SendMessage( |
| 162 ServiceWorkerMsg_FetchEvent(request)); | 162 ServiceWorkerMsg_FetchEvent(request)) == SERVICE_WORKER_OK; |
| 163 } | 163 } |
| 164 | 164 |
| 165 void ServiceWorkerVersion::AddProcessToWorker(int process_id) { | 165 void ServiceWorkerVersion::AddProcessToWorker(int process_id) { |
| 166 DCHECK(!is_shutdown_); | 166 DCHECK(!is_shutdown_); |
| 167 embedded_worker_->AddProcessReference(process_id); | 167 embedded_worker_->AddProcessReference(process_id); |
| 168 } | 168 } |
| 169 | 169 |
| 170 void ServiceWorkerVersion::RemoveProcessToWorker(int process_id) { | 170 void ServiceWorkerVersion::RemoveProcessToWorker(int process_id) { |
| 171 embedded_worker_->ReleaseProcessReference(process_id); | 171 embedded_worker_->ReleaseProcessReference(process_id); |
| 172 } | 172 } |
| 173 | 173 |
| 174 } // namespace content | 174 } // namespace content |
| OLD | NEW |