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

Side by Side Diff: content/browser/renderer_host/render_process_host_impl.cc

Issue 2312633002: For debugging, split worker ref count into service worker and shared worker counts (Closed)
Patch Set: size_t 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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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 // Represents the browser side of the browser <--> renderer communication 5 // Represents the browser side of the browser <--> renderer communication
6 // channel. There will be one RenderProcessHost per renderer process. 6 // channel. There will be one RenderProcessHost per renderer process.
7 7
8 #include "content/browser/renderer_host/render_process_host_impl.h" 8 #include "content/browser/renderer_host/render_process_host_impl.h"
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 654 matching lines...) Expand 10 before | Expand all | Expand 10 after
665 BrowserContext* browser_context, 665 BrowserContext* browser_context,
666 StoragePartitionImpl* storage_partition_impl, 666 StoragePartitionImpl* storage_partition_impl,
667 bool is_for_guests_only) 667 bool is_for_guests_only)
668 : fast_shutdown_started_(false), 668 : fast_shutdown_started_(false),
669 deleting_soon_(false), 669 deleting_soon_(false),
670 #ifndef NDEBUG 670 #ifndef NDEBUG
671 is_self_deleted_(false), 671 is_self_deleted_(false),
672 #endif 672 #endif
673 pending_views_(0), 673 pending_views_(0),
674 child_token_(mojo::edk::GenerateRandomToken()), 674 child_token_(mojo::edk::GenerateRandomToken()),
675 service_worker_ref_count_(0),
676 shared_worker_ref_count_(0),
675 visible_widgets_(0), 677 visible_widgets_(0),
676 is_process_backgrounded_(false), 678 is_process_backgrounded_(false),
677 is_initialized_(false), 679 is_initialized_(false),
678 id_(ChildProcessHostImpl::GenerateChildProcessUniqueId()), 680 id_(ChildProcessHostImpl::GenerateChildProcessUniqueId()),
679 browser_context_(browser_context), 681 browser_context_(browser_context),
680 storage_partition_impl_(storage_partition_impl), 682 storage_partition_impl_(storage_partition_impl),
681 sudden_termination_allowed_(true), 683 sudden_termination_allowed_(true),
682 ignore_input_events_(false), 684 ignore_input_events_(false),
683 is_for_guests_only_(is_for_guests_only), 685 is_for_guests_only_(is_for_guests_only),
684 gpu_observer_registered_(false), 686 gpu_observer_registered_(false),
685 delayed_cleanup_needed_(false), 687 delayed_cleanup_needed_(false),
686 within_process_died_observer_(false), 688 within_process_died_observer_(false),
687 power_monitor_broadcaster_(this), 689 power_monitor_broadcaster_(this),
688 #if defined(ENABLE_WEBRTC) 690 #if defined(ENABLE_WEBRTC)
689 webrtc_eventlog_host_(id_), 691 webrtc_eventlog_host_(id_),
690 #endif 692 #endif
691 worker_ref_count_(0),
692 max_worker_count_(0), 693 max_worker_count_(0),
693 permission_service_context_(new PermissionServiceContext(this)), 694 permission_service_context_(new PermissionServiceContext(this)),
694 channel_connected_(false), 695 channel_connected_(false),
695 sent_render_process_ready_(false), 696 sent_render_process_ready_(false),
696 #if defined(OS_ANDROID) 697 #if defined(OS_ANDROID)
697 never_signaled_(base::WaitableEvent::ResetPolicy::MANUAL, 698 never_signaled_(base::WaitableEvent::ResetPolicy::MANUAL,
698 base::WaitableEvent::InitialState::NOT_SIGNALED), 699 base::WaitableEvent::InitialState::NOT_SIGNALED),
699 #endif 700 #endif
700 instance_weak_factory_( 701 instance_weak_factory_(
701 new base::WeakPtrFactory<RenderProcessHostImpl>(this)), 702 new base::WeakPtrFactory<RenderProcessHostImpl>(this)),
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
792 // static 793 // static
793 // TODO(alokp): Remove after collecting crash data. 794 // TODO(alokp): Remove after collecting crash data.
794 // Temporary checks to verify that all shared workers are terminated. 795 // Temporary checks to verify that all shared workers are terminated.
795 // It is suspected that shared workers prevent render process hosts 796 // It is suspected that shared workers prevent render process hosts
796 // from shutting down: crbug.com/608049 797 // from shutting down: crbug.com/608049
797 void RenderProcessHostImpl::CheckAllWorkersTerminated() { 798 void RenderProcessHostImpl::CheckAllWorkersTerminated() {
798 iterator iter(AllHostsIterator()); 799 iterator iter(AllHostsIterator());
799 while (!iter.IsAtEnd()) { 800 while (!iter.IsAtEnd()) {
800 RenderProcessHostImpl* host = 801 RenderProcessHostImpl* host =
801 static_cast<RenderProcessHostImpl*>(iter.GetCurrentValue()); 802 static_cast<RenderProcessHostImpl*>(iter.GetCurrentValue());
802 CHECK_EQ(0, host->worker_ref_count_); 803 if (host->worker_ref_count() != 0) {
804 std::string message = base::StringPrintf(
805 "%zu service workers, %zu shared workers",
806 host->service_worker_ref_count_, host->shared_worker_ref_count_);
807 // Use separate CHECKs for better crash report readability.
808 CHECK(host->service_worker_ref_count_ == 0 ||
809 host->shared_worker_ref_count_ == 0)
810 << message;
811 CHECK_EQ(0UL, host->service_worker_ref_count_) << message;
812 CHECK_EQ(0UL, host->shared_worker_ref_count_) << message;
813 }
814
815 iter.Advance();
803 } 816 }
804 } 817 }
805 818
806 RenderProcessHostImpl::~RenderProcessHostImpl() { 819 RenderProcessHostImpl::~RenderProcessHostImpl() {
807 DCHECK_CURRENTLY_ON(BrowserThread::UI); 820 DCHECK_CURRENTLY_ON(BrowserThread::UI);
808 #ifndef NDEBUG 821 #ifndef NDEBUG
809 DCHECK(is_self_deleted_) 822 DCHECK(is_self_deleted_)
810 << "RenderProcessHostImpl is destroyed by something other than itself"; 823 << "RenderProcessHostImpl is destroyed by something other than itself";
811 #endif 824 #endif
812 825
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after
1316 if (!manager) 1329 if (!manager)
1317 return nullptr; 1330 return nullptr;
1318 return manager->GetCdm(render_frame_id, cdm_id); 1331 return manager->GetCdm(render_frame_id, cdm_id);
1319 } 1332 }
1320 #endif 1333 #endif
1321 1334
1322 bool RenderProcessHostImpl::IsProcessBackgrounded() const { 1335 bool RenderProcessHostImpl::IsProcessBackgrounded() const {
1323 return is_process_backgrounded_; 1336 return is_process_backgrounded_;
1324 } 1337 }
1325 1338
1326 void RenderProcessHostImpl::IncrementWorkerRefCount() { 1339 void RenderProcessHostImpl::IncrementServiceWorkerRefCount() {
1327 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1340 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1328 ++worker_ref_count_; 1341 ++service_worker_ref_count_;
1329 if (worker_ref_count_ > max_worker_count_) 1342 if (worker_ref_count() > max_worker_count_)
1330 max_worker_count_ = worker_ref_count_; 1343 max_worker_count_ = worker_ref_count();
1331 } 1344 }
1332 1345
1333 void RenderProcessHostImpl::DecrementWorkerRefCount() { 1346 void RenderProcessHostImpl::DecrementServiceWorkerRefCount() {
1334 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1347 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1335 DCHECK_GT(worker_ref_count_, 0); 1348 DCHECK_GT(worker_ref_count(), 0UL);
1336 --worker_ref_count_; 1349 --service_worker_ref_count_;
1337 if (worker_ref_count_ == 0) 1350 if (worker_ref_count() == 0)
1338 Cleanup(); 1351 Cleanup();
1339 } 1352 }
1340 1353
1354 void RenderProcessHostImpl::IncrementSharedWorkerRefCount() {
1355 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1356 ++shared_worker_ref_count_;
1357 if (worker_ref_count() > max_worker_count_)
1358 max_worker_count_ = worker_ref_count();
1359 }
1360
1361 void RenderProcessHostImpl::DecrementSharedWorkerRefCount() {
1362 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1363 DCHECK_GT(worker_ref_count(), 0UL);
1364 --shared_worker_ref_count_;
1365 if (worker_ref_count() == 0)
1366 Cleanup();
1367 }
1368
1341 void RenderProcessHostImpl::PurgeAndSuspend() { 1369 void RenderProcessHostImpl::PurgeAndSuspend() {
1342 Send(new ChildProcessMsg_PurgeAndSuspend()); 1370 Send(new ChildProcessMsg_PurgeAndSuspend());
1343 } 1371 }
1344 1372
1345 void RenderProcessHostImpl::AddRoute(int32_t routing_id, 1373 void RenderProcessHostImpl::AddRoute(int32_t routing_id,
1346 IPC::Listener* listener) { 1374 IPC::Listener* listener) {
1347 CHECK(!listeners_.Lookup(routing_id)) << "Found Routing ID Conflict: " 1375 CHECK(!listeners_.Lookup(routing_id)) << "Found Routing ID Conflict: "
1348 << routing_id; 1376 << routing_id;
1349 listeners_.AddWithID(listener, routing_id); 1377 listeners_.AddWithID(listener, routing_id);
1350 } 1378 }
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after
1832 return false; // Render process hasn't started or is probably crashed. 1860 return false; // Render process hasn't started or is probably crashed.
1833 1861
1834 // Test if there's an unload listener. 1862 // Test if there's an unload listener.
1835 // NOTE: It's possible that an onunload listener may be installed 1863 // NOTE: It's possible that an onunload listener may be installed
1836 // while we're shutting down, so there's a small race here. Given that 1864 // while we're shutting down, so there's a small race here. Given that
1837 // the window is small, it's unlikely that the web page has much 1865 // the window is small, it's unlikely that the web page has much
1838 // state that will be lost by not calling its unload handlers properly. 1866 // state that will be lost by not calling its unload handlers properly.
1839 if (!SuddenTerminationAllowed()) 1867 if (!SuddenTerminationAllowed())
1840 return false; 1868 return false;
1841 1869
1842 if (worker_ref_count_ != 0) { 1870 if (worker_ref_count() != 0) {
1843 if (survive_for_worker_start_time_.is_null()) 1871 if (survive_for_worker_start_time_.is_null())
1844 survive_for_worker_start_time_ = base::TimeTicks::Now(); 1872 survive_for_worker_start_time_ = base::TimeTicks::Now();
1845 return false; 1873 return false;
1846 } 1874 }
1847 1875
1848 // Set this before ProcessDied() so observers can tell if the render process 1876 // Set this before ProcessDied() so observers can tell if the render process
1849 // died due to fast shutdown versus another cause. 1877 // died due to fast shutdown versus another cause.
1850 fast_shutdown_started_ = true; 1878 fast_shutdown_started_ = true;
1851 1879
1852 ProcessDied(false /* already_dead */, nullptr); 1880 ProcessDied(false /* already_dead */, nullptr);
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
2018 // delay the destruction until all of the observer callbacks have been made, 2046 // delay the destruction until all of the observer callbacks have been made,
2019 // and guarantee that the RenderProcessHostDestroyed observer callback is 2047 // and guarantee that the RenderProcessHostDestroyed observer callback is
2020 // always the last callback fired. 2048 // always the last callback fired.
2021 if (within_process_died_observer_) { 2049 if (within_process_died_observer_) {
2022 delayed_cleanup_needed_ = true; 2050 delayed_cleanup_needed_ = true;
2023 return; 2051 return;
2024 } 2052 }
2025 delayed_cleanup_needed_ = false; 2053 delayed_cleanup_needed_ = false;
2026 2054
2027 // Records the time when the process starts surviving for workers for UMA. 2055 // Records the time when the process starts surviving for workers for UMA.
2028 if (listeners_.IsEmpty() && worker_ref_count_ > 0 && 2056 if (listeners_.IsEmpty() && worker_ref_count() > 0 &&
2029 survive_for_worker_start_time_.is_null()) { 2057 survive_for_worker_start_time_.is_null()) {
2030 survive_for_worker_start_time_ = base::TimeTicks::Now(); 2058 survive_for_worker_start_time_ = base::TimeTicks::Now();
2031 } 2059 }
2032 2060
2033 // Until there are no other owners of this object, we can't delete ourselves. 2061 // Until there are no other owners of this object, we can't delete ourselves.
2034 if (!listeners_.IsEmpty() || worker_ref_count_ != 0) 2062 if (!listeners_.IsEmpty() || worker_ref_count() != 0)
2035 return; 2063 return;
2036 2064
2037 #if defined(ENABLE_WEBRTC) 2065 #if defined(ENABLE_WEBRTC)
2038 if (is_initialized_) 2066 if (is_initialized_)
2039 ClearWebRtcLogMessageCallback(); 2067 ClearWebRtcLogMessageCallback();
2040 #endif 2068 #endif
2041 2069
2042 if (!survive_for_worker_start_time_.is_null()) { 2070 if (!survive_for_worker_start_time_.is_null()) {
2043 UMA_HISTOGRAM_LONG_TIMES( 2071 UMA_HISTOGRAM_LONG_TIMES(
2044 "SharedWorker.RendererSurviveForWorkerTime", 2072 "SharedWorker.RendererSurviveForWorkerTime",
(...skipping 889 matching lines...) Expand 10 before | Expand all | Expand 10 after
2934 LOG(ERROR) << "Terminating render process for bad Mojo message: " << error; 2962 LOG(ERROR) << "Terminating render process for bad Mojo message: " << error;
2935 2963
2936 // The ReceivedBadMessage call below will trigger a DumpWithoutCrashing. Alias 2964 // The ReceivedBadMessage call below will trigger a DumpWithoutCrashing. Alias
2937 // enough information here so that we can determine what the bad message was. 2965 // enough information here so that we can determine what the bad message was.
2938 base::debug::Alias(&error); 2966 base::debug::Alias(&error);
2939 bad_message::ReceivedBadMessage(process.get(), 2967 bad_message::ReceivedBadMessage(process.get(),
2940 bad_message::RPH_MOJO_PROCESS_ERROR); 2968 bad_message::RPH_MOJO_PROCESS_ERROR);
2941 } 2969 }
2942 2970
2943 } // namespace content 2971 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698