OLD | NEW |
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 1352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1363 | 1363 |
1364 const base::TimeTicks& RenderProcessHostImpl::GetInitTimeForNavigationMetrics() | 1364 const base::TimeTicks& RenderProcessHostImpl::GetInitTimeForNavigationMetrics() |
1365 const { | 1365 const { |
1366 return init_time_; | 1366 return init_time_; |
1367 } | 1367 } |
1368 | 1368 |
1369 bool RenderProcessHostImpl::IsProcessBackgrounded() const { | 1369 bool RenderProcessHostImpl::IsProcessBackgrounded() const { |
1370 return is_process_backgrounded_; | 1370 return is_process_backgrounded_; |
1371 } | 1371 } |
1372 | 1372 |
| 1373 size_t RenderProcessHostImpl::GetWorkerRefCount() const { |
| 1374 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 1375 return service_worker_ref_count_ + shared_worker_ref_count_; |
| 1376 } |
| 1377 |
1373 void RenderProcessHostImpl::IncrementServiceWorkerRefCount() { | 1378 void RenderProcessHostImpl::IncrementServiceWorkerRefCount() { |
1374 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1379 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
1375 DCHECK(!is_worker_ref_count_disabled_); | 1380 DCHECK(!is_worker_ref_count_disabled_); |
1376 ++service_worker_ref_count_; | 1381 ++service_worker_ref_count_; |
1377 if (worker_ref_count() > max_worker_count_) | 1382 if (GetWorkerRefCount() > max_worker_count_) |
1378 max_worker_count_ = worker_ref_count(); | 1383 max_worker_count_ = GetWorkerRefCount(); |
1379 } | 1384 } |
1380 | 1385 |
1381 void RenderProcessHostImpl::DecrementServiceWorkerRefCount() { | 1386 void RenderProcessHostImpl::DecrementServiceWorkerRefCount() { |
1382 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1387 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
1383 DCHECK(!is_worker_ref_count_disabled_); | 1388 DCHECK(!is_worker_ref_count_disabled_); |
1384 DCHECK_GT(worker_ref_count(), 0U); | 1389 DCHECK_GT(GetWorkerRefCount(), 0U); |
1385 --service_worker_ref_count_; | 1390 --service_worker_ref_count_; |
1386 if (worker_ref_count() == 0) | 1391 if (GetWorkerRefCount() == 0) |
1387 Cleanup(); | 1392 Cleanup(); |
1388 } | 1393 } |
1389 | 1394 |
1390 void RenderProcessHostImpl::IncrementSharedWorkerRefCount() { | 1395 void RenderProcessHostImpl::IncrementSharedWorkerRefCount() { |
1391 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1396 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
1392 DCHECK(!is_worker_ref_count_disabled_); | 1397 DCHECK(!is_worker_ref_count_disabled_); |
1393 ++shared_worker_ref_count_; | 1398 ++shared_worker_ref_count_; |
1394 if (worker_ref_count() > max_worker_count_) | 1399 if (GetWorkerRefCount() > max_worker_count_) |
1395 max_worker_count_ = worker_ref_count(); | 1400 max_worker_count_ = GetWorkerRefCount(); |
1396 } | 1401 } |
1397 | 1402 |
1398 void RenderProcessHostImpl::DecrementSharedWorkerRefCount() { | 1403 void RenderProcessHostImpl::DecrementSharedWorkerRefCount() { |
1399 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1404 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
1400 DCHECK(!is_worker_ref_count_disabled_); | 1405 DCHECK(!is_worker_ref_count_disabled_); |
1401 DCHECK_GT(worker_ref_count(), 0U); | 1406 DCHECK_GT(GetWorkerRefCount(), 0U); |
1402 --shared_worker_ref_count_; | 1407 --shared_worker_ref_count_; |
1403 if (worker_ref_count() == 0) | 1408 if (GetWorkerRefCount() == 0) |
1404 Cleanup(); | 1409 Cleanup(); |
1405 } | 1410 } |
1406 | 1411 |
1407 void RenderProcessHostImpl::ForceReleaseWorkerRefCounts() { | 1412 void RenderProcessHostImpl::ForceReleaseWorkerRefCounts() { |
1408 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1413 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
1409 DCHECK(!is_worker_ref_count_disabled_); | 1414 DCHECK(!is_worker_ref_count_disabled_); |
1410 is_worker_ref_count_disabled_ = true; | 1415 is_worker_ref_count_disabled_ = true; |
1411 if (!worker_ref_count()) | 1416 if (!GetWorkerRefCount()) |
1412 return; | 1417 return; |
1413 service_worker_ref_count_ = 0; | 1418 service_worker_ref_count_ = 0; |
1414 shared_worker_ref_count_ = 0; | 1419 shared_worker_ref_count_ = 0; |
1415 Cleanup(); | 1420 Cleanup(); |
1416 } | 1421 } |
1417 | 1422 |
1418 bool RenderProcessHostImpl::IsWorkerRefCountDisabled() { | 1423 bool RenderProcessHostImpl::IsWorkerRefCountDisabled() { |
1419 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1424 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
1420 return is_worker_ref_count_disabled_; | 1425 return is_worker_ref_count_disabled_; |
1421 } | 1426 } |
(...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1927 return false; // Render process hasn't started or is probably crashed. | 1932 return false; // Render process hasn't started or is probably crashed. |
1928 | 1933 |
1929 // Test if there's an unload listener. | 1934 // Test if there's an unload listener. |
1930 // NOTE: It's possible that an onunload listener may be installed | 1935 // NOTE: It's possible that an onunload listener may be installed |
1931 // while we're shutting down, so there's a small race here. Given that | 1936 // while we're shutting down, so there's a small race here. Given that |
1932 // the window is small, it's unlikely that the web page has much | 1937 // the window is small, it's unlikely that the web page has much |
1933 // state that will be lost by not calling its unload handlers properly. | 1938 // state that will be lost by not calling its unload handlers properly. |
1934 if (!SuddenTerminationAllowed()) | 1939 if (!SuddenTerminationAllowed()) |
1935 return false; | 1940 return false; |
1936 | 1941 |
1937 if (worker_ref_count() != 0) { | 1942 if (GetWorkerRefCount() != 0) { |
1938 if (survive_for_worker_start_time_.is_null()) | 1943 if (survive_for_worker_start_time_.is_null()) |
1939 survive_for_worker_start_time_ = base::TimeTicks::Now(); | 1944 survive_for_worker_start_time_ = base::TimeTicks::Now(); |
1940 return false; | 1945 return false; |
1941 } | 1946 } |
1942 | 1947 |
1943 // Set this before ProcessDied() so observers can tell if the render process | 1948 // Set this before ProcessDied() so observers can tell if the render process |
1944 // died due to fast shutdown versus another cause. | 1949 // died due to fast shutdown versus another cause. |
1945 fast_shutdown_started_ = true; | 1950 fast_shutdown_started_ = true; |
1946 | 1951 |
1947 ProcessDied(false /* already_dead */, nullptr); | 1952 ProcessDied(false /* already_dead */, nullptr); |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2105 // delay the destruction until all of the observer callbacks have been made, | 2110 // delay the destruction until all of the observer callbacks have been made, |
2106 // and guarantee that the RenderProcessHostDestroyed observer callback is | 2111 // and guarantee that the RenderProcessHostDestroyed observer callback is |
2107 // always the last callback fired. | 2112 // always the last callback fired. |
2108 if (within_process_died_observer_) { | 2113 if (within_process_died_observer_) { |
2109 delayed_cleanup_needed_ = true; | 2114 delayed_cleanup_needed_ = true; |
2110 return; | 2115 return; |
2111 } | 2116 } |
2112 delayed_cleanup_needed_ = false; | 2117 delayed_cleanup_needed_ = false; |
2113 | 2118 |
2114 // Records the time when the process starts surviving for workers for UMA. | 2119 // Records the time when the process starts surviving for workers for UMA. |
2115 if (listeners_.IsEmpty() && worker_ref_count() > 0 && | 2120 if (listeners_.IsEmpty() && GetWorkerRefCount() > 0 && |
2116 survive_for_worker_start_time_.is_null()) { | 2121 survive_for_worker_start_time_.is_null()) { |
2117 survive_for_worker_start_time_ = base::TimeTicks::Now(); | 2122 survive_for_worker_start_time_ = base::TimeTicks::Now(); |
2118 } | 2123 } |
2119 | 2124 |
2120 // Until there are no other owners of this object, we can't delete ourselves. | 2125 // Until there are no other owners of this object, we can't delete ourselves. |
2121 if (!listeners_.IsEmpty() || worker_ref_count() != 0) | 2126 if (!listeners_.IsEmpty() || GetWorkerRefCount() != 0) |
2122 return; | 2127 return; |
2123 | 2128 |
2124 #if BUILDFLAG(ENABLE_WEBRTC) | 2129 #if BUILDFLAG(ENABLE_WEBRTC) |
2125 if (is_initialized_) | 2130 if (is_initialized_) |
2126 ClearWebRtcLogMessageCallback(); | 2131 ClearWebRtcLogMessageCallback(); |
2127 #endif | 2132 #endif |
2128 | 2133 |
2129 if (!survive_for_worker_start_time_.is_null()) { | 2134 if (!survive_for_worker_start_time_.is_null()) { |
2130 UMA_HISTOGRAM_LONG_TIMES( | 2135 UMA_HISTOGRAM_LONG_TIMES( |
2131 "SharedWorker.RendererSurviveForWorkerTime", | 2136 "SharedWorker.RendererSurviveForWorkerTime", |
(...skipping 870 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3002 LOG(ERROR) << "Terminating render process for bad Mojo message: " << error; | 3007 LOG(ERROR) << "Terminating render process for bad Mojo message: " << error; |
3003 | 3008 |
3004 // The ReceivedBadMessage call below will trigger a DumpWithoutCrashing. | 3009 // The ReceivedBadMessage call below will trigger a DumpWithoutCrashing. |
3005 // Capture the error message in a crash key value. | 3010 // Capture the error message in a crash key value. |
3006 base::debug::ScopedCrashKey error_key_value("mojo-message-error", error); | 3011 base::debug::ScopedCrashKey error_key_value("mojo-message-error", error); |
3007 bad_message::ReceivedBadMessage(render_process_id, | 3012 bad_message::ReceivedBadMessage(render_process_id, |
3008 bad_message::RPH_MOJO_PROCESS_ERROR); | 3013 bad_message::RPH_MOJO_PROCESS_ERROR); |
3009 } | 3014 } |
3010 | 3015 |
3011 } // namespace content | 3016 } // namespace content |
OLD | NEW |