| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 12 matching lines...) Expand all Loading... |
| 23 #include "base/debug/trace_event.h" | 23 #include "base/debug/trace_event.h" |
| 24 #include "base/files/file.h" | 24 #include "base/files/file.h" |
| 25 #include "base/lazy_instance.h" | 25 #include "base/lazy_instance.h" |
| 26 #include "base/logging.h" | 26 #include "base/logging.h" |
| 27 #include "base/metrics/field_trial.h" | 27 #include "base/metrics/field_trial.h" |
| 28 #include "base/metrics/histogram.h" | 28 #include "base/metrics/histogram.h" |
| 29 #include "base/numerics/safe_math.h" | 29 #include "base/numerics/safe_math.h" |
| 30 #include "base/path_service.h" | 30 #include "base/path_service.h" |
| 31 #include "base/rand_util.h" | 31 #include "base/rand_util.h" |
| 32 #include "base/stl_util.h" | 32 #include "base/stl_util.h" |
| 33 #include "base/strings/string_number_conversions.h" |
| 33 #include "base/strings/string_util.h" | 34 #include "base/strings/string_util.h" |
| 34 #include "base/supports_user_data.h" | 35 #include "base/supports_user_data.h" |
| 35 #include "base/sys_info.h" | 36 #include "base/sys_info.h" |
| 36 #include "base/threading/thread.h" | 37 #include "base/threading/thread.h" |
| 37 #include "base/threading/thread_restrictions.h" | 38 #include "base/threading/thread_restrictions.h" |
| 38 #include "base/tracked_objects.h" | 39 #include "base/tracked_objects.h" |
| 39 #include "cc/base/switches.h" | 40 #include "cc/base/switches.h" |
| 40 #include "content/browser/appcache/appcache_dispatcher_host.h" | 41 #include "content/browser/appcache/appcache_dispatcher_host.h" |
| 41 #include "content/browser/appcache/chrome_appcache_service.h" | 42 #include "content/browser/appcache/chrome_appcache_service.h" |
| 42 #include "content/browser/battery_status/battery_status_message_filter.h" | 43 #include "content/browser/battery_status/battery_status_message_filter.h" |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 #include "base/win/scoped_com_initializer.h" | 167 #include "base/win/scoped_com_initializer.h" |
| 167 #include "content/common/font_cache_dispatcher_win.h" | 168 #include "content/common/font_cache_dispatcher_win.h" |
| 168 #include "content/common/sandbox_win.h" | 169 #include "content/common/sandbox_win.h" |
| 169 #include "ui/gfx/win/dpi.h" | 170 #include "ui/gfx/win/dpi.h" |
| 170 #endif | 171 #endif |
| 171 | 172 |
| 172 #if defined(ENABLE_WEBRTC) | 173 #if defined(ENABLE_WEBRTC) |
| 173 #include "content/browser/media/webrtc_internals.h" | 174 #include "content/browser/media/webrtc_internals.h" |
| 174 #include "content/browser/renderer_host/media/media_stream_track_metrics_host.h" | 175 #include "content/browser/renderer_host/media/media_stream_track_metrics_host.h" |
| 175 #include "content/browser/renderer_host/media/webrtc_identity_service_host.h" | 176 #include "content/browser/renderer_host/media/webrtc_identity_service_host.h" |
| 177 #include "content/common/media/aec_dump_messages.h" |
| 176 #include "content/common/media/media_stream_messages.h" | 178 #include "content/common/media/media_stream_messages.h" |
| 177 #endif | 179 #endif |
| 178 | 180 |
| 179 extern bool g_exited_main_message_loop; | 181 extern bool g_exited_main_message_loop; |
| 180 | 182 |
| 181 static const char* kSiteProcessMapKeyName = "content_site_process_map"; | 183 static const char* kSiteProcessMapKeyName = "content_site_process_map"; |
| 182 | 184 |
| 183 namespace content { | 185 namespace content { |
| 184 namespace { | 186 namespace { |
| 185 | 187 |
| (...skipping 1175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1361 OnDumpHandlesDone) | 1363 OnDumpHandlesDone) |
| 1362 IPC_MESSAGE_HANDLER(ViewHostMsg_SuddenTerminationChanged, | 1364 IPC_MESSAGE_HANDLER(ViewHostMsg_SuddenTerminationChanged, |
| 1363 SuddenTerminationChanged) | 1365 SuddenTerminationChanged) |
| 1364 IPC_MESSAGE_HANDLER(ViewHostMsg_UserMetricsRecordAction, | 1366 IPC_MESSAGE_HANDLER(ViewHostMsg_UserMetricsRecordAction, |
| 1365 OnUserMetricsRecordAction) | 1367 OnUserMetricsRecordAction) |
| 1366 IPC_MESSAGE_HANDLER(ViewHostMsg_SavedPageAsMHTML, OnSavedPageAsMHTML) | 1368 IPC_MESSAGE_HANDLER(ViewHostMsg_SavedPageAsMHTML, OnSavedPageAsMHTML) |
| 1367 IPC_MESSAGE_HANDLER_DELAY_REPLY( | 1369 IPC_MESSAGE_HANDLER_DELAY_REPLY( |
| 1368 ChildProcessHostMsg_SyncAllocateGpuMemoryBuffer, | 1370 ChildProcessHostMsg_SyncAllocateGpuMemoryBuffer, |
| 1369 OnAllocateGpuMemoryBuffer) | 1371 OnAllocateGpuMemoryBuffer) |
| 1370 IPC_MESSAGE_HANDLER(ViewHostMsg_Close_ACK, OnCloseACK) | 1372 IPC_MESSAGE_HANDLER(ViewHostMsg_Close_ACK, OnCloseACK) |
| 1373 #if defined(ENABLE_WEBRTC) |
| 1374 IPC_MESSAGE_HANDLER(AecDumpMsg_RegisterAecDumpConsumer, |
| 1375 OnRegisterAecDumpConsumer) |
| 1376 IPC_MESSAGE_HANDLER(AecDumpMsg_UnregisterAecDumpConsumer, |
| 1377 OnUnregisterAecDumpConsumer) |
| 1378 #endif |
| 1371 // Adding single handlers for your service here is fine, but once your | 1379 // Adding single handlers for your service here is fine, but once your |
| 1372 // service needs more than one handler, please extract them into a new | 1380 // service needs more than one handler, please extract them into a new |
| 1373 // message filter and add that filter to CreateMessageFilters(). | 1381 // message filter and add that filter to CreateMessageFilters(). |
| 1374 IPC_END_MESSAGE_MAP() | 1382 IPC_END_MESSAGE_MAP() |
| 1375 | 1383 |
| 1376 return true; | 1384 return true; |
| 1377 } | 1385 } |
| 1378 | 1386 |
| 1379 // Dispatch incoming messages to the appropriate IPC::Listener. | 1387 // Dispatch incoming messages to the appropriate IPC::Listener. |
| 1380 IPC::Listener* listener = listeners_.Lookup(msg.routing_id()); | 1388 IPC::Listener* listener = listeners_.Lookup(msg.routing_id()); |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1531 widget_helper_->ResumeRequestsForView(route_id); | 1539 widget_helper_->ResumeRequestsForView(route_id); |
| 1532 } | 1540 } |
| 1533 | 1541 |
| 1534 void RenderProcessHostImpl::FilterURL(bool empty_allowed, GURL* url) { | 1542 void RenderProcessHostImpl::FilterURL(bool empty_allowed, GURL* url) { |
| 1535 FilterURL(this, empty_allowed, url); | 1543 FilterURL(this, empty_allowed, url); |
| 1536 } | 1544 } |
| 1537 | 1545 |
| 1538 #if defined(ENABLE_WEBRTC) | 1546 #if defined(ENABLE_WEBRTC) |
| 1539 void RenderProcessHostImpl::EnableAecDump(const base::FilePath& file) { | 1547 void RenderProcessHostImpl::EnableAecDump(const base::FilePath& file) { |
| 1540 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1548 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 1541 BrowserThread::PostTaskAndReplyWithResult( | 1549 // Enable AEC dump for each registered consumer. |
| 1542 BrowserThread::FILE, FROM_HERE, | 1550 for (std::vector<int>::iterator it = aec_dump_consumers_.begin(); |
| 1543 base::Bind(&CreateAecDumpFileForProcess, file, GetHandle()), | 1551 it != aec_dump_consumers_.end(); ++it) { |
| 1544 base::Bind(&RenderProcessHostImpl::SendAecDumpFileToRenderer, | 1552 EnableAecDumpForId(file, *it); |
| 1545 weak_factory_.GetWeakPtr())); | 1553 } |
| 1546 } | 1554 } |
| 1547 | 1555 |
| 1548 void RenderProcessHostImpl::DisableAecDump() { | 1556 void RenderProcessHostImpl::DisableAecDump() { |
| 1549 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1557 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 1550 // Posting on the FILE thread and then replying back on the UI thread is only | 1558 // Posting on the FILE thread and then replying back on the UI thread is only |
| 1551 // for avoiding races between enable and disable. Nothing is done on the FILE | 1559 // for avoiding races between enable and disable. Nothing is done on the FILE |
| 1552 // thread. | 1560 // thread. |
| 1553 BrowserThread::PostTaskAndReply( | 1561 BrowserThread::PostTaskAndReply( |
| 1554 BrowserThread::FILE, FROM_HERE, | 1562 BrowserThread::FILE, FROM_HERE, |
| 1555 base::Bind(&DisableAecDumpOnFileThread), | 1563 base::Bind(&DisableAecDumpOnFileThread), |
| (...skipping 591 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2147 // Skip widgets in other processes. | 2155 // Skip widgets in other processes. |
| 2148 if (widget->GetProcess()->GetID() != GetID()) | 2156 if (widget->GetProcess()->GetID() != GetID()) |
| 2149 continue; | 2157 continue; |
| 2150 | 2158 |
| 2151 RenderViewHost* rvh = RenderViewHost::From(widget); | 2159 RenderViewHost* rvh = RenderViewHost::From(widget); |
| 2152 rvh->UpdateWebkitPreferences(rvh->GetWebkitPreferences()); | 2160 rvh->UpdateWebkitPreferences(rvh->GetWebkitPreferences()); |
| 2153 } | 2161 } |
| 2154 } | 2162 } |
| 2155 | 2163 |
| 2156 #if defined(ENABLE_WEBRTC) | 2164 #if defined(ENABLE_WEBRTC) |
| 2165 void RenderProcessHostImpl::OnRegisterAecDumpConsumer(int id) { |
| 2166 BrowserThread::PostTask( |
| 2167 BrowserThread::UI, |
| 2168 FROM_HERE, |
| 2169 base::Bind( |
| 2170 &RenderProcessHostImpl::RegisterAecDumpConsumerOnUIThread, |
| 2171 weak_factory_.GetWeakPtr(), |
| 2172 id)); |
| 2173 } |
| 2174 |
| 2175 void RenderProcessHostImpl::OnUnregisterAecDumpConsumer(int id) { |
| 2176 BrowserThread::PostTask( |
| 2177 BrowserThread::UI, |
| 2178 FROM_HERE, |
| 2179 base::Bind( |
| 2180 &RenderProcessHostImpl::UnregisterAecDumpConsumerOnUIThread, |
| 2181 weak_factory_.GetWeakPtr(), |
| 2182 id)); |
| 2183 } |
| 2184 |
| 2185 void RenderProcessHostImpl::RegisterAecDumpConsumerOnUIThread(int id) { |
| 2186 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 2187 aec_dump_consumers_.push_back(id); |
| 2188 if (WebRTCInternals::GetInstance()->aec_dump_enabled()) { |
| 2189 EnableAecDumpForId(WebRTCInternals::GetInstance()->aec_dump_file_path(), |
| 2190 id); |
| 2191 } |
| 2192 } |
| 2193 |
| 2194 void RenderProcessHostImpl::UnregisterAecDumpConsumerOnUIThread(int id) { |
| 2195 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 2196 for (std::vector<int>::iterator it = aec_dump_consumers_.begin(); |
| 2197 it != aec_dump_consumers_.end(); ++it) { |
| 2198 if (*it == id) { |
| 2199 aec_dump_consumers_.erase(it); |
| 2200 break; |
| 2201 } |
| 2202 } |
| 2203 } |
| 2204 |
| 2205 #if defined(OS_WIN) |
| 2206 #define IntToStringType base::IntToString16 |
| 2207 #else |
| 2208 #define IntToStringType base::IntToString |
| 2209 #endif |
| 2210 |
| 2211 void RenderProcessHostImpl::EnableAecDumpForId(const base::FilePath& file, |
| 2212 int id) { |
| 2213 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 2214 base::FilePath unique_file = |
| 2215 file.AddExtension(IntToStringType(GetID())) |
| 2216 .AddExtension(IntToStringType(id)); |
| 2217 BrowserThread::PostTaskAndReplyWithResult( |
| 2218 BrowserThread::FILE, FROM_HERE, |
| 2219 base::Bind(&CreateAecDumpFileForProcess, unique_file, GetHandle()), |
| 2220 base::Bind(&RenderProcessHostImpl::SendAecDumpFileToRenderer, |
| 2221 weak_factory_.GetWeakPtr(), |
| 2222 id)); |
| 2223 } |
| 2224 |
| 2225 #undef IntToStringType |
| 2226 |
| 2157 void RenderProcessHostImpl::SendAecDumpFileToRenderer( | 2227 void RenderProcessHostImpl::SendAecDumpFileToRenderer( |
| 2228 int id, |
| 2158 IPC::PlatformFileForTransit file_for_transit) { | 2229 IPC::PlatformFileForTransit file_for_transit) { |
| 2159 if (file_for_transit == IPC::InvalidPlatformFileForTransit()) | 2230 if (file_for_transit == IPC::InvalidPlatformFileForTransit()) |
| 2160 return; | 2231 return; |
| 2161 Send(new MediaStreamMsg_EnableAecDump(file_for_transit)); | 2232 Send(new AecDumpMsg_EnableAecDump(id, file_for_transit)); |
| 2162 } | 2233 } |
| 2163 | 2234 |
| 2164 void RenderProcessHostImpl::SendDisableAecDumpToRenderer() { | 2235 void RenderProcessHostImpl::SendDisableAecDumpToRenderer() { |
| 2165 Send(new MediaStreamMsg_DisableAecDump()); | 2236 Send(new AecDumpMsg_DisableAecDump()); |
| 2166 } | 2237 } |
| 2167 #endif | 2238 #endif |
| 2168 | 2239 |
| 2169 void RenderProcessHostImpl::IncrementWorkerRefCount() { | 2240 void RenderProcessHostImpl::IncrementWorkerRefCount() { |
| 2170 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 2241 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 2171 ++worker_ref_count_; | 2242 ++worker_ref_count_; |
| 2172 } | 2243 } |
| 2173 | 2244 |
| 2174 void RenderProcessHostImpl::DecrementWorkerRefCount() { | 2245 void RenderProcessHostImpl::DecrementWorkerRefCount() { |
| 2175 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 2246 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2287 void RenderProcessHostImpl::GpuMemoryBufferAllocated( | 2358 void RenderProcessHostImpl::GpuMemoryBufferAllocated( |
| 2288 IPC::Message* reply, | 2359 IPC::Message* reply, |
| 2289 const gfx::GpuMemoryBufferHandle& handle) { | 2360 const gfx::GpuMemoryBufferHandle& handle) { |
| 2290 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 2361 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 2291 ChildProcessHostMsg_SyncAllocateGpuMemoryBuffer::WriteReplyParams(reply, | 2362 ChildProcessHostMsg_SyncAllocateGpuMemoryBuffer::WriteReplyParams(reply, |
| 2292 handle); | 2363 handle); |
| 2293 Send(reply); | 2364 Send(reply); |
| 2294 } | 2365 } |
| 2295 | 2366 |
| 2296 } // namespace content | 2367 } // namespace content |
| OLD | NEW |