Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1004)

Side by Side Diff: content/browser/shared_worker/shared_worker_service_impl.cc

Issue 2249173003: Removes the references to shared workers from the all documents in being deleted frames (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: incorporated nhiroki's comment Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/shared_worker/shared_worker_service_impl.h" 5 #include "content/browser/shared_worker/shared_worker_service_impl.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <iterator> 10 #include <iterator>
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 150
151 void RemoveRequest(int process_id) { 151 void RemoveRequest(int process_id) {
152 auto to_remove = std::remove_if( 152 auto to_remove = std::remove_if(
153 requests_.begin(), requests_.end(), 153 requests_.begin(), requests_.end(),
154 [process_id](const std::unique_ptr<SharedWorkerPendingRequest>& r) { 154 [process_id](const std::unique_ptr<SharedWorkerPendingRequest>& r) {
155 return r->render_process_id == process_id; 155 return r->render_process_id == process_id;
156 }); 156 });
157 requests_.erase(to_remove, requests_.end()); 157 requests_.erase(to_remove, requests_.end());
158 } 158 }
159 159
160 void RemoveRequestFromFrame(int process_id, int frame_id) {
161 auto to_remove = std::remove_if(
162 requests_.begin(), requests_.end(),
163 [process_id,
164 frame_id](const std::unique_ptr<SharedWorkerPendingRequest>& r) {
165 return r->render_process_id == process_id &&
166 r->render_frame_route_id == frame_id;
167 });
168 requests_.erase(to_remove, requests_.end());
169 }
170
160 void RegisterToSharedWorkerHost(SharedWorkerHost* host) { 171 void RegisterToSharedWorkerHost(SharedWorkerHost* host) {
161 for (const auto& request : requests_) { 172 for (const auto& request : requests_) {
162 host->AddFilter(request->filter, request->route_id); 173 host->AddFilter(request->filter, request->route_id);
163 host->worker_document_set()->Add(request->filter, 174 host->worker_document_set()->Add(request->filter,
164 request->document_id, 175 request->document_id,
165 request->render_process_id, 176 request->render_process_id,
166 request->render_frame_route_id); 177 request->render_frame_route_id);
167 } 178 }
168 } 179 }
169 180
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 std::vector<int> remove_pending_instance_list; 443 std::vector<int> remove_pending_instance_list;
433 for (const auto& it : pending_instances_) { 444 for (const auto& it : pending_instances_) {
434 it.second->RemoveRequest(filter->render_process_id()); 445 it.second->RemoveRequest(filter->render_process_id());
435 if (it.second->requests()->empty()) 446 if (it.second->requests()->empty())
436 remove_pending_instance_list.push_back(it.first); 447 remove_pending_instance_list.push_back(it.first);
437 } 448 }
438 for (int to_remove : remove_pending_instance_list) 449 for (int to_remove : remove_pending_instance_list)
439 pending_instances_.erase(to_remove); 450 pending_instances_.erase(to_remove);
440 } 451 }
441 452
453 void SharedWorkerServiceImpl::RenderFrameDetached(int render_process_id,
454 int render_frame_id) {
455 ScopedWorkerDependencyChecker checker(this);
456 for (const auto& it : worker_hosts_) {
457 it.second->RenderFrameDetached(render_process_id, render_frame_id);
458 }
459
460 auto it = pending_instances_.begin();
461 while (it != pending_instances_.end()) {
462 it->second->RemoveRequestFromFrame(render_process_id, render_frame_id);
463 if (it->second->requests()->empty())
464 it = pending_instances_.erase(it);
465 else
466 ++it;
467 }
468 }
469
442 void SharedWorkerServiceImpl::NotifyWorkerDestroyed(int worker_process_id, 470 void SharedWorkerServiceImpl::NotifyWorkerDestroyed(int worker_process_id,
443 int worker_route_id) { 471 int worker_route_id) {
444 FOR_EACH_OBSERVER(WorkerServiceObserver, 472 FOR_EACH_OBSERVER(WorkerServiceObserver,
445 observers_, 473 observers_,
446 WorkerDestroyed(worker_process_id, worker_route_id)); 474 WorkerDestroyed(worker_process_id, worker_route_id));
447 } 475 }
448 476
449 blink::WebWorkerCreationError 477 blink::WebWorkerCreationError
450 SharedWorkerServiceImpl::ReserveRenderProcessToCreateWorker( 478 SharedWorkerServiceImpl::ReserveRenderProcessToCreateWorker(
451 std::unique_ptr<SharedWorkerPendingInstance> pending_instance) { 479 std::unique_ptr<SharedWorkerPendingInstance> pending_instance) {
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
646 UpdateWorkerDependencyFunc new_func) { 674 UpdateWorkerDependencyFunc new_func) {
647 update_worker_dependency_ = new_func; 675 update_worker_dependency_ = new_func;
648 } 676 }
649 677
650 void SharedWorkerServiceImpl::ChangeTryIncrementWorkerRefCountFuncForTesting( 678 void SharedWorkerServiceImpl::ChangeTryIncrementWorkerRefCountFuncForTesting(
651 bool (*new_func)(int)) { 679 bool (*new_func)(int)) {
652 s_try_increment_worker_ref_count_ = new_func; 680 s_try_increment_worker_ref_count_ = new_func;
653 } 681 }
654 682
655 } // namespace content 683 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/shared_worker/shared_worker_service_impl.h ('k') | content/browser/shared_worker/worker_document_set.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698