| 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/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 10 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
| (...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 427 fetch_callbacks_.Remove(request_id); | 427 fetch_callbacks_.Remove(request_id); |
| 428 RunSoon(base::Bind(&RunErrorFetchCallback, | 428 RunSoon(base::Bind(&RunErrorFetchCallback, |
| 429 fetch_callback, | 429 fetch_callback, |
| 430 SERVICE_WORKER_ERROR_FAILED)); | 430 SERVICE_WORKER_ERROR_FAILED)); |
| 431 } | 431 } |
| 432 } | 432 } |
| 433 | 433 |
| 434 void ServiceWorkerVersion::DispatchSyncEvent(const StatusCallback& callback) { | 434 void ServiceWorkerVersion::DispatchSyncEvent(const StatusCallback& callback) { |
| 435 DCHECK_EQ(ACTIVATED, status()) << status(); | 435 DCHECK_EQ(ACTIVATED, status()) << status(); |
| 436 | 436 |
| 437 if (!CommandLine::ForCurrentProcess()->HasSwitch( | 437 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 438 switches::kEnableServiceWorkerSync)) { | 438 switches::kEnableServiceWorkerSync)) { |
| 439 callback.Run(SERVICE_WORKER_ERROR_ABORT); | 439 callback.Run(SERVICE_WORKER_ERROR_ABORT); |
| 440 return; | 440 return; |
| 441 } | 441 } |
| 442 | 442 |
| 443 if (running_status() != RUNNING) { | 443 if (running_status() != RUNNING) { |
| 444 // Schedule calling this method after starting the worker. | 444 // Schedule calling this method after starting the worker. |
| 445 StartWorker(base::Bind(&RunTaskAfterStartWorker, | 445 StartWorker(base::Bind(&RunTaskAfterStartWorker, |
| 446 weak_factory_.GetWeakPtr(), callback, | 446 weak_factory_.GetWeakPtr(), callback, |
| 447 base::Bind(&self::DispatchSyncEvent, | 447 base::Bind(&self::DispatchSyncEvent, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 458 RunSoon(base::Bind(callback, status)); | 458 RunSoon(base::Bind(callback, status)); |
| 459 } | 459 } |
| 460 } | 460 } |
| 461 | 461 |
| 462 void ServiceWorkerVersion::DispatchNotificationClickEvent( | 462 void ServiceWorkerVersion::DispatchNotificationClickEvent( |
| 463 const StatusCallback& callback, | 463 const StatusCallback& callback, |
| 464 const std::string& notification_id, | 464 const std::string& notification_id, |
| 465 const PlatformNotificationData& notification_data) { | 465 const PlatformNotificationData& notification_data) { |
| 466 DCHECK_EQ(ACTIVATED, status()) << status(); | 466 DCHECK_EQ(ACTIVATED, status()) << status(); |
| 467 | 467 |
| 468 if (!CommandLine::ForCurrentProcess()->HasSwitch( | 468 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 469 switches::kEnableExperimentalWebPlatformFeatures)) { | 469 switches::kEnableExperimentalWebPlatformFeatures)) { |
| 470 callback.Run(SERVICE_WORKER_ERROR_ABORT); | 470 callback.Run(SERVICE_WORKER_ERROR_ABORT); |
| 471 return; | 471 return; |
| 472 } | 472 } |
| 473 | 473 |
| 474 if (running_status() != RUNNING) { | 474 if (running_status() != RUNNING) { |
| 475 // Schedule calling this method after starting the worker. | 475 // Schedule calling this method after starting the worker. |
| 476 StartWorker(base::Bind(&RunTaskAfterStartWorker, | 476 StartWorker(base::Bind(&RunTaskAfterStartWorker, |
| 477 weak_factory_.GetWeakPtr(), callback, | 477 weak_factory_.GetWeakPtr(), callback, |
| 478 base::Bind(&self::DispatchNotificationClickEvent, | 478 base::Bind(&self::DispatchNotificationClickEvent, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 491 if (status != SERVICE_WORKER_OK) { | 491 if (status != SERVICE_WORKER_OK) { |
| 492 notification_click_callbacks_.Remove(request_id); | 492 notification_click_callbacks_.Remove(request_id); |
| 493 RunSoon(base::Bind(callback, status)); | 493 RunSoon(base::Bind(callback, status)); |
| 494 } | 494 } |
| 495 } | 495 } |
| 496 | 496 |
| 497 void ServiceWorkerVersion::DispatchPushEvent(const StatusCallback& callback, | 497 void ServiceWorkerVersion::DispatchPushEvent(const StatusCallback& callback, |
| 498 const std::string& data) { | 498 const std::string& data) { |
| 499 DCHECK_EQ(ACTIVATED, status()) << status(); | 499 DCHECK_EQ(ACTIVATED, status()) << status(); |
| 500 | 500 |
| 501 if (!CommandLine::ForCurrentProcess()->HasSwitch( | 501 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 502 switches::kEnableExperimentalWebPlatformFeatures)) { | 502 switches::kEnableExperimentalWebPlatformFeatures)) { |
| 503 callback.Run(SERVICE_WORKER_ERROR_ABORT); | 503 callback.Run(SERVICE_WORKER_ERROR_ABORT); |
| 504 return; | 504 return; |
| 505 } | 505 } |
| 506 | 506 |
| 507 if (running_status() != RUNNING) { | 507 if (running_status() != RUNNING) { |
| 508 // Schedule calling this method after starting the worker. | 508 // Schedule calling this method after starting the worker. |
| 509 StartWorker(base::Bind(&RunTaskAfterStartWorker, | 509 StartWorker(base::Bind(&RunTaskAfterStartWorker, |
| 510 weak_factory_.GetWeakPtr(), callback, | 510 weak_factory_.GetWeakPtr(), callback, |
| 511 base::Bind(&self::DispatchPushEvent, | 511 base::Bind(&self::DispatchPushEvent, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 523 } | 523 } |
| 524 } | 524 } |
| 525 | 525 |
| 526 void ServiceWorkerVersion::DispatchGeofencingEvent( | 526 void ServiceWorkerVersion::DispatchGeofencingEvent( |
| 527 const StatusCallback& callback, | 527 const StatusCallback& callback, |
| 528 blink::WebGeofencingEventType event_type, | 528 blink::WebGeofencingEventType event_type, |
| 529 const std::string& region_id, | 529 const std::string& region_id, |
| 530 const blink::WebCircularGeofencingRegion& region) { | 530 const blink::WebCircularGeofencingRegion& region) { |
| 531 DCHECK_EQ(ACTIVATED, status()) << status(); | 531 DCHECK_EQ(ACTIVATED, status()) << status(); |
| 532 | 532 |
| 533 if (!CommandLine::ForCurrentProcess()->HasSwitch( | 533 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 534 switches::kEnableExperimentalWebPlatformFeatures)) { | 534 switches::kEnableExperimentalWebPlatformFeatures)) { |
| 535 callback.Run(SERVICE_WORKER_ERROR_ABORT); | 535 callback.Run(SERVICE_WORKER_ERROR_ABORT); |
| 536 return; | 536 return; |
| 537 } | 537 } |
| 538 | 538 |
| 539 if (running_status() != RUNNING) { | 539 if (running_status() != RUNNING) { |
| 540 // Schedule calling this method after starting the worker. | 540 // Schedule calling this method after starting the worker. |
| 541 StartWorker(base::Bind(&RunTaskAfterStartWorker, | 541 StartWorker(base::Bind(&RunTaskAfterStartWorker, |
| 542 weak_factory_.GetWeakPtr(), | 542 weak_factory_.GetWeakPtr(), |
| 543 callback, | 543 callback, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 558 geofencing_callbacks_.Remove(request_id); | 558 geofencing_callbacks_.Remove(request_id); |
| 559 RunSoon(base::Bind(callback, status)); | 559 RunSoon(base::Bind(callback, status)); |
| 560 } | 560 } |
| 561 } | 561 } |
| 562 | 562 |
| 563 void ServiceWorkerVersion::DispatchCrossOriginConnectEvent( | 563 void ServiceWorkerVersion::DispatchCrossOriginConnectEvent( |
| 564 const CrossOriginConnectCallback& callback, | 564 const CrossOriginConnectCallback& callback, |
| 565 const CrossOriginServiceWorkerClient& client) { | 565 const CrossOriginServiceWorkerClient& client) { |
| 566 DCHECK_EQ(ACTIVATED, status()) << status(); | 566 DCHECK_EQ(ACTIVATED, status()) << status(); |
| 567 | 567 |
| 568 if (!CommandLine::ForCurrentProcess()->HasSwitch( | 568 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 569 switches::kEnableExperimentalWebPlatformFeatures)) { | 569 switches::kEnableExperimentalWebPlatformFeatures)) { |
| 570 callback.Run(SERVICE_WORKER_ERROR_ABORT, false); | 570 callback.Run(SERVICE_WORKER_ERROR_ABORT, false); |
| 571 return; | 571 return; |
| 572 } | 572 } |
| 573 | 573 |
| 574 if (running_status() != RUNNING) { | 574 if (running_status() != RUNNING) { |
| 575 // Schedule calling this method after starting the worker. | 575 // Schedule calling this method after starting the worker. |
| 576 StartWorker( | 576 StartWorker( |
| 577 base::Bind(&RunTaskAfterStartWorker, weak_factory_.GetWeakPtr(), | 577 base::Bind(&RunTaskAfterStartWorker, weak_factory_.GetWeakPtr(), |
| 578 base::Bind(&RunErrorCrossOriginConnectCallback, callback), | 578 base::Bind(&RunErrorCrossOriginConnectCallback, callback), |
| (...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1137 SetStatus(REDUNDANT); | 1137 SetStatus(REDUNDANT); |
| 1138 StopWorker(base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); | 1138 StopWorker(base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); |
| 1139 if (!context_) | 1139 if (!context_) |
| 1140 return; | 1140 return; |
| 1141 std::vector<ServiceWorkerDatabase::ResourceRecord> resources; | 1141 std::vector<ServiceWorkerDatabase::ResourceRecord> resources; |
| 1142 script_cache_map_.GetResources(&resources); | 1142 script_cache_map_.GetResources(&resources); |
| 1143 context_->storage()->PurgeResources(resources); | 1143 context_->storage()->PurgeResources(resources); |
| 1144 } | 1144 } |
| 1145 | 1145 |
| 1146 } // namespace content | 1146 } // namespace content |
| OLD | NEW |