| 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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 | 67 |
| 68 if (message.type() != ServiceWorkerHostMsg_InstallEventFinished::ID) { | 68 if (message.type() != ServiceWorkerHostMsg_InstallEventFinished::ID) { |
| 69 NOTREACHED() << "Got unexpected response for InstallEvent: " | 69 NOTREACHED() << "Got unexpected response for InstallEvent: " |
| 70 << message.type(); | 70 << message.type(); |
| 71 callback.Run(SERVICE_WORKER_ERROR_FAILED); | 71 callback.Run(SERVICE_WORKER_ERROR_FAILED); |
| 72 return; | 72 return; |
| 73 } | 73 } |
| 74 callback.Run(SERVICE_WORKER_OK); | 74 callback.Run(SERVICE_WORKER_OK); |
| 75 } | 75 } |
| 76 | 76 |
| 77 void HandleFetchResponse(const ServiceWorkerVersion::FetchCallback& callback, |
| 78 ServiceWorkerStatusCode status, |
| 79 const IPC::Message& message) { |
| 80 Tuple1<ServiceWorkerFetchResponse> response; |
| 81 if (message.type() != ServiceWorkerHostMsg_FetchEventFinished::ID) { |
| 82 NOTREACHED() << "Got unexpected response for FetchEvent: " |
| 83 << message.type(); |
| 84 callback.Run(SERVICE_WORKER_ERROR_FAILED, response.a); |
| 85 return; |
| 86 } |
| 87 ServiceWorkerHostMsg_FetchEventFinished::Read(&message, &response); |
| 88 callback.Run(status, response.a); |
| 89 } |
| 90 |
| 77 } // namespace | 91 } // namespace |
| 78 | 92 |
| 79 ServiceWorkerVersion::ServiceWorkerVersion( | 93 ServiceWorkerVersion::ServiceWorkerVersion( |
| 80 ServiceWorkerRegistration* registration, | 94 ServiceWorkerRegistration* registration, |
| 81 EmbeddedWorkerRegistry* worker_registry, | 95 EmbeddedWorkerRegistry* worker_registry, |
| 82 int64 version_id) | 96 int64 version_id) |
| 83 : version_id_(version_id), | 97 : version_id_(version_id), |
| 84 is_shutdown_(false), | 98 is_shutdown_(false), |
| 85 registration_(registration), | 99 registration_(registration), |
| 86 weak_factory_(this) { | 100 weak_factory_(this) { |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 } | 201 } |
| 188 | 202 |
| 189 void ServiceWorkerVersion::DispatchInstallEvent( | 203 void ServiceWorkerVersion::DispatchInstallEvent( |
| 190 int active_version_embedded_worker_id, | 204 int active_version_embedded_worker_id, |
| 191 const StatusCallback& callback) { | 205 const StatusCallback& callback) { |
| 192 SendMessageAndRegisterCallback( | 206 SendMessageAndRegisterCallback( |
| 193 ServiceWorkerMsg_InstallEvent(active_version_embedded_worker_id), | 207 ServiceWorkerMsg_InstallEvent(active_version_embedded_worker_id), |
| 194 base::Bind(&HandleInstallFinished, callback)); | 208 base::Bind(&HandleInstallFinished, callback)); |
| 195 } | 209 } |
| 196 | 210 |
| 197 bool ServiceWorkerVersion::DispatchFetchEvent( | 211 void ServiceWorkerVersion::DispatchFetchEvent( |
| 198 const ServiceWorkerFetchRequest& request) { | 212 const ServiceWorkerFetchRequest& request, |
| 199 if (status() != RUNNING) | 213 const FetchCallback& callback) { |
| 200 return false; | 214 SendMessageAndRegisterCallback( |
| 201 return embedded_worker_->SendMessage( | 215 ServiceWorkerMsg_FetchEvent(request), |
| 202 kInvalidRequestId, ServiceWorkerMsg_FetchEvent(request)) | 216 base::Bind(&HandleFetchResponse, callback)); |
| 203 == SERVICE_WORKER_OK; | |
| 204 } | 217 } |
| 205 | 218 |
| 206 void ServiceWorkerVersion::AddProcessToWorker(int process_id) { | 219 void ServiceWorkerVersion::AddProcessToWorker(int process_id) { |
| 207 DCHECK(!is_shutdown_); | 220 DCHECK(!is_shutdown_); |
| 208 embedded_worker_->AddProcessReference(process_id); | 221 embedded_worker_->AddProcessReference(process_id); |
| 209 } | 222 } |
| 210 | 223 |
| 211 void ServiceWorkerVersion::RemoveProcessToWorker(int process_id) { | 224 void ServiceWorkerVersion::RemoveProcessToWorker(int process_id) { |
| 212 embedded_worker_->ReleaseProcessReference(process_id); | 225 embedded_worker_->ReleaseProcessReference(process_id); |
| 213 } | 226 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 if (callback) { | 258 if (callback) { |
| 246 callback->Run(SERVICE_WORKER_OK, message); | 259 callback->Run(SERVICE_WORKER_OK, message); |
| 247 message_callbacks_.Remove(request_id); | 260 message_callbacks_.Remove(request_id); |
| 248 return; | 261 return; |
| 249 } | 262 } |
| 250 NOTREACHED() << "Got unexpected message: " << request_id | 263 NOTREACHED() << "Got unexpected message: " << request_id |
| 251 << " " << message.type(); | 264 << " " << message.type(); |
| 252 } | 265 } |
| 253 | 266 |
| 254 } // namespace content | 267 } // namespace content |
| OLD | NEW |