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 609 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
620 FOR_EACH_OBSERVER(Listener, listeners_, OnNoControllees(this)); | 620 FOR_EACH_OBSERVER(Listener, listeners_, OnNoControllees(this)); |
621 if (is_doomed_) { | 621 if (is_doomed_) { |
622 DoomInternal(); | 622 DoomInternal(); |
623 return; | 623 return; |
624 } | 624 } |
625 // Schedule the stop-worker-timer if it's not running. | 625 // Schedule the stop-worker-timer if it's not running. |
626 if (!stop_worker_timer_.IsRunning()) | 626 if (!stop_worker_timer_.IsRunning()) |
627 ScheduleStopWorker(); | 627 ScheduleStopWorker(); |
628 } | 628 } |
629 | 629 |
| 630 void ServiceWorkerVersion::AddStreamingURLRequestJob( |
| 631 const ServiceWorkerURLRequestJob* request_job) { |
| 632 DCHECK(streaming_url_request_jobs_.find(request_job) == |
| 633 streaming_url_request_jobs_.end()); |
| 634 streaming_url_request_jobs_.insert(request_job); |
| 635 } |
| 636 |
| 637 void ServiceWorkerVersion::RemoveStreamingURLRequestJob( |
| 638 const ServiceWorkerURLRequestJob* request_job) { |
| 639 streaming_url_request_jobs_.erase(request_job); |
| 640 } |
| 641 |
630 void ServiceWorkerVersion::AddListener(Listener* listener) { | 642 void ServiceWorkerVersion::AddListener(Listener* listener) { |
631 listeners_.AddObserver(listener); | 643 listeners_.AddObserver(listener); |
632 } | 644 } |
633 | 645 |
634 void ServiceWorkerVersion::RemoveListener(Listener* listener) { | 646 void ServiceWorkerVersion::RemoveListener(Listener* listener) { |
635 listeners_.RemoveObserver(listener); | 647 listeners_.RemoveObserver(listener); |
636 } | 648 } |
637 | 649 |
638 void ServiceWorkerVersion::Doom() { | 650 void ServiceWorkerVersion::Doom() { |
639 if (is_doomed_) | 651 if (is_doomed_) |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
699 SERVICE_WORKER_ERROR_FAILED); | 711 SERVICE_WORKER_ERROR_FAILED); |
700 RunIDMapCallbacks(&geofencing_callbacks_, | 712 RunIDMapCallbacks(&geofencing_callbacks_, |
701 SERVICE_WORKER_ERROR_FAILED); | 713 SERVICE_WORKER_ERROR_FAILED); |
702 RunIDMapCallbacks(&get_client_info_callbacks_, | 714 RunIDMapCallbacks(&get_client_info_callbacks_, |
703 SERVICE_WORKER_ERROR_FAILED, | 715 SERVICE_WORKER_ERROR_FAILED, |
704 ServiceWorkerClientInfo()); | 716 ServiceWorkerClientInfo()); |
705 RunIDMapCallbacks(&cross_origin_connect_callbacks_, | 717 RunIDMapCallbacks(&cross_origin_connect_callbacks_, |
706 SERVICE_WORKER_ERROR_FAILED, | 718 SERVICE_WORKER_ERROR_FAILED, |
707 false); | 719 false); |
708 | 720 |
| 721 streaming_url_request_jobs_.clear(); |
| 722 |
709 FOR_EACH_OBSERVER(Listener, listeners_, OnWorkerStopped(this)); | 723 FOR_EACH_OBSERVER(Listener, listeners_, OnWorkerStopped(this)); |
710 | 724 |
711 // There should be no more communication from/to a stopped worker. Deleting | 725 // There should be no more communication from/to a stopped worker. Deleting |
712 // the listener prevents any pending completion callbacks from causing | 726 // the listener prevents any pending completion callbacks from causing |
713 // messages to be sent to the stopped worker. | 727 // messages to be sent to the stopped worker. |
714 cache_listener_.reset(); | 728 cache_listener_.reset(); |
715 | 729 |
716 // Restart worker if we have any start callbacks and the worker isn't doomed. | 730 // Restart worker if we have any start callbacks and the worker isn't doomed. |
717 if (should_restart) { | 731 if (should_restart) { |
718 cache_listener_.reset(new ServiceWorkerCacheListener(this, context_)); | 732 cache_listener_.reset(new ServiceWorkerCacheListener(this, context_)); |
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1124 bool ServiceWorkerVersion::HasInflightRequests() const { | 1138 bool ServiceWorkerVersion::HasInflightRequests() const { |
1125 return | 1139 return |
1126 !activate_callbacks_.IsEmpty() || | 1140 !activate_callbacks_.IsEmpty() || |
1127 !install_callbacks_.IsEmpty() || | 1141 !install_callbacks_.IsEmpty() || |
1128 !fetch_callbacks_.IsEmpty() || | 1142 !fetch_callbacks_.IsEmpty() || |
1129 !sync_callbacks_.IsEmpty() || | 1143 !sync_callbacks_.IsEmpty() || |
1130 !notification_click_callbacks_.IsEmpty() || | 1144 !notification_click_callbacks_.IsEmpty() || |
1131 !push_callbacks_.IsEmpty() || | 1145 !push_callbacks_.IsEmpty() || |
1132 !geofencing_callbacks_.IsEmpty() || | 1146 !geofencing_callbacks_.IsEmpty() || |
1133 !get_client_info_callbacks_.IsEmpty() || | 1147 !get_client_info_callbacks_.IsEmpty() || |
1134 !cross_origin_connect_callbacks_.IsEmpty(); | 1148 !cross_origin_connect_callbacks_.IsEmpty() || |
| 1149 !streaming_url_request_jobs_.empty(); |
1135 } | 1150 } |
1136 | 1151 |
1137 void ServiceWorkerVersion::DoomInternal() { | 1152 void ServiceWorkerVersion::DoomInternal() { |
1138 DCHECK(!HasControllee()); | 1153 DCHECK(!HasControllee()); |
1139 SetStatus(REDUNDANT); | 1154 SetStatus(REDUNDANT); |
1140 StopWorker(base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); | 1155 StopWorker(base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); |
1141 if (!context_) | 1156 if (!context_) |
1142 return; | 1157 return; |
1143 std::vector<ServiceWorkerDatabase::ResourceRecord> resources; | 1158 std::vector<ServiceWorkerDatabase::ResourceRecord> resources; |
1144 script_cache_map_.GetResources(&resources); | 1159 script_cache_map_.GetResources(&resources); |
1145 context_->storage()->PurgeResources(resources); | 1160 context_->storage()->PurgeResources(resources); |
1146 } | 1161 } |
1147 | 1162 |
1148 } // namespace content | 1163 } // namespace content |
OLD | NEW |