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

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: Removes the references when frames are being deleted Created 4 years, 4 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 std::vector<int> remove_pending_instance_list;
461 for (const auto& it : pending_instances_) {
462 it.second->RemoveRequestFromFrame(render_process_id, render_frame_id);
463 if (it.second->requests()->empty())
464 remove_pending_instance_list.push_back(it.first);
465 }
466 for (int to_remove : remove_pending_instance_list)
467 pending_instances_.erase(to_remove);
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 // TODO(alokp): Remove after collecting crash data. 477 // TODO(alokp): Remove after collecting crash data.
450 // Temporary checks to verify that all shared workers are terminated. 478 // Temporary checks to verify that all shared workers are terminated.
451 // It is suspected that shared workers prevent render process hosts 479 // It is suspected that shared workers prevent render process hosts
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
655 UpdateWorkerDependencyFunc new_func) { 683 UpdateWorkerDependencyFunc new_func) {
656 update_worker_dependency_ = new_func; 684 update_worker_dependency_ = new_func;
657 } 685 }
658 686
659 void SharedWorkerServiceImpl::ChangeTryIncrementWorkerRefCountFuncForTesting( 687 void SharedWorkerServiceImpl::ChangeTryIncrementWorkerRefCountFuncForTesting(
660 bool (*new_func)(int)) { 688 bool (*new_func)(int)) {
661 s_try_increment_worker_ref_count_ = new_func; 689 s_try_increment_worker_ref_count_ = new_func;
662 } 690 }
663 691
664 } // namespace content 692 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698