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