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