| 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/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
| 9 #include "base/strings/string16.h" | 9 #include "base/strings/string16.h" |
| 10 #include "content/browser/service_worker/embedded_worker_instance.h" | 10 #include "content/browser/service_worker/embedded_worker_instance.h" |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 base::Bind(&self::DispatchActivateEventAfterStartWorker, | 282 base::Bind(&self::DispatchActivateEventAfterStartWorker, |
| 283 weak_factory_.GetWeakPtr(), | 283 weak_factory_.GetWeakPtr(), |
| 284 callback))); | 284 callback))); |
| 285 } else { | 285 } else { |
| 286 DispatchActivateEventAfterStartWorker(callback); | 286 DispatchActivateEventAfterStartWorker(callback); |
| 287 } | 287 } |
| 288 } | 288 } |
| 289 | 289 |
| 290 void ServiceWorkerVersion::DispatchFetchEvent( | 290 void ServiceWorkerVersion::DispatchFetchEvent( |
| 291 const ServiceWorkerFetchRequest& request, | 291 const ServiceWorkerFetchRequest& request, |
| 292 const FetchCallback& callback) { | 292 const base::Closure& prepare_callback, |
| 293 const FetchCallback& fetch_callback) { |
| 293 DCHECK_EQ(ACTIVATED, status()) << status(); | 294 DCHECK_EQ(ACTIVATED, status()) << status(); |
| 294 | 295 |
| 295 if (running_status() != RUNNING) { | 296 if (running_status() != RUNNING) { |
| 296 // Schedule calling this method after starting the worker. | 297 // Schedule calling this method after starting the worker. |
| 297 StartWorker(base::Bind(&RunTaskAfterStartWorker, | 298 StartWorker(base::Bind(&RunTaskAfterStartWorker, |
| 298 weak_factory_.GetWeakPtr(), | 299 weak_factory_.GetWeakPtr(), |
| 299 base::Bind(&RunErrorFetchCallback, callback), | 300 base::Bind(&RunErrorFetchCallback, fetch_callback), |
| 300 base::Bind(&self::DispatchFetchEvent, | 301 base::Bind(&self::DispatchFetchEvent, |
| 301 weak_factory_.GetWeakPtr(), | 302 weak_factory_.GetWeakPtr(), |
| 302 request, callback))); | 303 request, |
| 304 prepare_callback, |
| 305 fetch_callback))); |
| 303 return; | 306 return; |
| 304 } | 307 } |
| 305 | 308 |
| 306 int request_id = fetch_callbacks_.Add(new FetchCallback(callback)); | 309 prepare_callback.Run(); |
| 310 |
| 311 int request_id = fetch_callbacks_.Add(new FetchCallback(fetch_callback)); |
| 307 ServiceWorkerStatusCode status = embedded_worker_->SendMessage( | 312 ServiceWorkerStatusCode status = embedded_worker_->SendMessage( |
| 308 ServiceWorkerMsg_FetchEvent(request_id, request)); | 313 ServiceWorkerMsg_FetchEvent(request_id, request)); |
| 309 if (status != SERVICE_WORKER_OK) { | 314 if (status != SERVICE_WORKER_OK) { |
| 310 fetch_callbacks_.Remove(request_id); | 315 fetch_callbacks_.Remove(request_id); |
| 311 RunSoon(base::Bind(&RunErrorFetchCallback, | 316 RunSoon(base::Bind(&RunErrorFetchCallback, |
| 312 callback, | 317 fetch_callback, |
| 313 SERVICE_WORKER_ERROR_FAILED)); | 318 SERVICE_WORKER_ERROR_FAILED)); |
| 314 } | 319 } |
| 315 } | 320 } |
| 316 | 321 |
| 317 void ServiceWorkerVersion::DispatchSyncEvent(const StatusCallback& callback) { | 322 void ServiceWorkerVersion::DispatchSyncEvent(const StatusCallback& callback) { |
| 318 DCHECK_EQ(ACTIVATED, status()) << status(); | 323 DCHECK_EQ(ACTIVATED, status()) << status(); |
| 319 | 324 |
| 320 if (!CommandLine::ForCurrentProcess()->HasSwitch( | 325 if (!CommandLine::ForCurrentProcess()->HasSwitch( |
| 321 switches::kEnableServiceWorkerSync)) { | 326 switches::kEnableServiceWorkerSync)) { |
| 322 callback.Run(SERVICE_WORKER_ERROR_ABORT); | 327 callback.Run(SERVICE_WORKER_ERROR_ABORT); |
| (...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 692 SetStatus(REDUNDANT); | 697 SetStatus(REDUNDANT); |
| 693 StopWorker(base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); | 698 StopWorker(base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); |
| 694 if (!context_) | 699 if (!context_) |
| 695 return; | 700 return; |
| 696 std::vector<ServiceWorkerDatabase::ResourceRecord> resources; | 701 std::vector<ServiceWorkerDatabase::ResourceRecord> resources; |
| 697 script_cache_map_.GetResources(&resources); | 702 script_cache_map_.GetResources(&resources); |
| 698 context_->storage()->PurgeResources(resources); | 703 context_->storage()->PurgeResources(resources); |
| 699 } | 704 } |
| 700 | 705 |
| 701 } // namespace content | 706 } // namespace content |
| OLD | NEW |