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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 #include "content/common/child_process_messages.h" | 110 #include "content/common/child_process_messages.h" |
111 #include "content/common/gpu/gpu_messages.h" | 111 #include "content/common/gpu/gpu_messages.h" |
112 #include "content/common/resource_messages.h" | 112 #include "content/common/resource_messages.h" |
113 #include "content/common/view_messages.h" | 113 #include "content/common/view_messages.h" |
114 #include "content/port/browser/render_widget_host_view_frame_subscriber.h" | 114 #include "content/port/browser/render_widget_host_view_frame_subscriber.h" |
115 #include "content/public/browser/browser_context.h" | 115 #include "content/public/browser/browser_context.h" |
116 #include "content/public/browser/content_browser_client.h" | 116 #include "content/public/browser/content_browser_client.h" |
117 #include "content/public/browser/notification_service.h" | 117 #include "content/public/browser/notification_service.h" |
118 #include "content/public/browser/notification_types.h" | 118 #include "content/public/browser/notification_types.h" |
119 #include "content/public/browser/render_process_host_factory.h" | 119 #include "content/public/browser/render_process_host_factory.h" |
| 120 #include "content/public/browser/render_process_host_observer.h" |
120 #include "content/public/browser/render_widget_host.h" | 121 #include "content/public/browser/render_widget_host.h" |
121 #include "content/public/browser/render_widget_host_iterator.h" | 122 #include "content/public/browser/render_widget_host_iterator.h" |
122 #include "content/public/browser/resource_context.h" | 123 #include "content/public/browser/resource_context.h" |
123 #include "content/public/browser/user_metrics.h" | 124 #include "content/public/browser/user_metrics.h" |
124 #include "content/public/common/content_constants.h" | 125 #include "content/public/common/content_constants.h" |
125 #include "content/public/common/content_switches.h" | 126 #include "content/public/common/content_switches.h" |
126 #include "content/public/common/process_type.h" | 127 #include "content/public/common/process_type.h" |
127 #include "content/public/common/result_codes.h" | 128 #include "content/public/common/result_codes.h" |
128 #include "content/public/common/url_constants.h" | 129 #include "content/public/common/url_constants.h" |
129 #include "gpu/command_buffer/service/gpu_switches.h" | 130 #include "gpu/command_buffer/service/gpu_switches.h" |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 g_max_renderer_count_override = count; | 353 g_max_renderer_count_override = count; |
353 } | 354 } |
354 | 355 |
355 RenderProcessHostImpl::RenderProcessHostImpl( | 356 RenderProcessHostImpl::RenderProcessHostImpl( |
356 BrowserContext* browser_context, | 357 BrowserContext* browser_context, |
357 StoragePartitionImpl* storage_partition_impl, | 358 StoragePartitionImpl* storage_partition_impl, |
358 bool supports_browser_plugin, | 359 bool supports_browser_plugin, |
359 bool is_guest) | 360 bool is_guest) |
360 : fast_shutdown_started_(false), | 361 : fast_shutdown_started_(false), |
361 deleting_soon_(false), | 362 deleting_soon_(false), |
| 363 #ifndef NDEBUG |
| 364 is_self_deleted_(false), |
| 365 #endif |
362 pending_views_(0), | 366 pending_views_(0), |
363 visible_widgets_(0), | 367 visible_widgets_(0), |
364 backgrounded_(true), | 368 backgrounded_(true), |
365 cached_dibs_cleaner_( | 369 cached_dibs_cleaner_( |
366 FROM_HERE, base::TimeDelta::FromSeconds(5), | 370 FROM_HERE, base::TimeDelta::FromSeconds(5), |
367 this, &RenderProcessHostImpl::ClearTransportDIBCache), | 371 this, &RenderProcessHostImpl::ClearTransportDIBCache), |
368 is_initialized_(false), | 372 is_initialized_(false), |
369 id_(ChildProcessHostImpl::GenerateChildProcessUniqueId()), | 373 id_(ChildProcessHostImpl::GenerateChildProcessUniqueId()), |
370 browser_context_(browser_context), | 374 browser_context_(browser_context), |
371 storage_partition_impl_(storage_partition_impl), | 375 storage_partition_impl_(storage_partition_impl), |
(...skipping 20 matching lines...) Expand all Loading... |
392 base::Bind(&CacheShaderInfo, GetID(), | 396 base::Bind(&CacheShaderInfo, GetID(), |
393 storage_partition_impl_->GetPath())); | 397 storage_partition_impl_->GetPath())); |
394 } | 398 } |
395 | 399 |
396 // Note: When we create the RenderProcessHostImpl, it's technically | 400 // Note: When we create the RenderProcessHostImpl, it's technically |
397 // backgrounded, because it has no visible listeners. But the process | 401 // backgrounded, because it has no visible listeners. But the process |
398 // doesn't actually exist yet, so we'll Background it later, after | 402 // doesn't actually exist yet, so we'll Background it later, after |
399 // creation. | 403 // creation. |
400 } | 404 } |
401 | 405 |
| 406 // static |
| 407 void RenderProcessHostImpl::ShutDownInProcessRenderer() { |
| 408 DCHECK(g_run_renderer_in_process_); |
| 409 |
| 410 switch (g_all_hosts.Pointer()->size()) { |
| 411 case 0: |
| 412 return; |
| 413 case 1: { |
| 414 RenderProcessHostImpl* host = static_cast<RenderProcessHostImpl*>( |
| 415 AllHostsIterator().GetCurrentValue()); |
| 416 FOR_EACH_OBSERVER(RenderProcessHostObserver, |
| 417 host->observers_, |
| 418 RenderProcessHostDestroyed(host)); |
| 419 #ifndef NDEBUG |
| 420 host->is_self_deleted_ = true; |
| 421 #endif |
| 422 delete host; |
| 423 return; |
| 424 } |
| 425 default: |
| 426 NOTREACHED() << "There should be only one RenderProcessHost when running " |
| 427 << "in-process."; |
| 428 } |
| 429 } |
| 430 |
402 RenderProcessHostImpl::~RenderProcessHostImpl() { | 431 RenderProcessHostImpl::~RenderProcessHostImpl() { |
| 432 #ifndef NDEBUG |
| 433 DCHECK(is_self_deleted_) |
| 434 << "RenderProcessHostImpl is destroyed by something other than itself"; |
| 435 #endif |
| 436 |
403 ChildProcessSecurityPolicyImpl::GetInstance()->Remove(GetID()); | 437 ChildProcessSecurityPolicyImpl::GetInstance()->Remove(GetID()); |
404 | 438 |
405 if (gpu_observer_registered_) { | 439 if (gpu_observer_registered_) { |
406 GpuDataManagerImpl::GetInstance()->RemoveObserver(this); | 440 GpuDataManagerImpl::GetInstance()->RemoveObserver(this); |
407 gpu_observer_registered_ = false; | 441 gpu_observer_registered_ = false; |
408 } | 442 } |
409 | 443 |
410 // We may have some unsent messages at this point, but that's OK. | 444 // We may have some unsent messages at this point, but that's OK. |
411 channel_.reset(); | 445 channel_.reset(); |
412 while (!queued_messages_.empty()) { | 446 while (!queued_messages_.empty()) { |
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
764 // We wait to close the channels until the child process has finished | 798 // We wait to close the channels until the child process has finished |
765 // dumping handles and sends us ChildProcessHostMsg_DumpHandlesDone. | 799 // dumping handles and sends us ChildProcessHostMsg_DumpHandlesDone. |
766 return; | 800 return; |
767 } | 801 } |
768 #endif | 802 #endif |
769 // Keep the one renderer thread around forever in single process mode. | 803 // Keep the one renderer thread around forever in single process mode. |
770 if (!run_renderer_in_process()) | 804 if (!run_renderer_in_process()) |
771 Cleanup(); | 805 Cleanup(); |
772 } | 806 } |
773 | 807 |
| 808 void RenderProcessHostImpl::AddObserver(RenderProcessHostObserver* observer) { |
| 809 observers_.AddObserver(observer); |
| 810 } |
| 811 |
| 812 void RenderProcessHostImpl::RemoveObserver( |
| 813 RenderProcessHostObserver* observer) { |
| 814 observers_.RemoveObserver(observer); |
| 815 } |
| 816 |
774 bool RenderProcessHostImpl::WaitForBackingStoreMsg( | 817 bool RenderProcessHostImpl::WaitForBackingStoreMsg( |
775 int render_widget_id, | 818 int render_widget_id, |
776 const base::TimeDelta& max_delay, | 819 const base::TimeDelta& max_delay, |
777 IPC::Message* msg) { | 820 IPC::Message* msg) { |
778 // The post task to this thread with the process id could be in queue, and we | 821 // The post task to this thread with the process id could be in queue, and we |
779 // don't want to dispatch a message before then since it will need the handle. | 822 // don't want to dispatch a message before then since it will need the handle. |
780 if (child_process_launcher_.get() && child_process_launcher_->IsStarting()) | 823 if (child_process_launcher_.get() && child_process_launcher_->IsStarting()) |
781 return false; | 824 return false; |
782 | 825 |
783 return widget_helper_->WaitForBackingStoreMsg(render_widget_id, | 826 return widget_helper_->WaitForBackingStoreMsg(render_widget_id, |
(...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1351 | 1394 |
1352 void RenderProcessHostImpl::SetIgnoreInputEvents(bool ignore_input_events) { | 1395 void RenderProcessHostImpl::SetIgnoreInputEvents(bool ignore_input_events) { |
1353 ignore_input_events_ = ignore_input_events; | 1396 ignore_input_events_ = ignore_input_events; |
1354 } | 1397 } |
1355 | 1398 |
1356 bool RenderProcessHostImpl::IgnoreInputEvents() const { | 1399 bool RenderProcessHostImpl::IgnoreInputEvents() const { |
1357 return ignore_input_events_; | 1400 return ignore_input_events_; |
1358 } | 1401 } |
1359 | 1402 |
1360 void RenderProcessHostImpl::Cleanup() { | 1403 void RenderProcessHostImpl::Cleanup() { |
1361 // When no other owners of this object, we can delete ourselves | 1404 // When there are no other owners of this object, we can delete ourselves. |
1362 if (listeners_.IsEmpty()) { | 1405 if (listeners_.IsEmpty()) { |
1363 DCHECK_EQ(0, pending_views_); | 1406 DCHECK_EQ(0, pending_views_); |
| 1407 FOR_EACH_OBSERVER(RenderProcessHostObserver, |
| 1408 observers_, |
| 1409 RenderProcessHostDestroyed(this)); |
1364 NotificationService::current()->Notify( | 1410 NotificationService::current()->Notify( |
1365 NOTIFICATION_RENDERER_PROCESS_TERMINATED, | 1411 NOTIFICATION_RENDERER_PROCESS_TERMINATED, |
1366 Source<RenderProcessHost>(this), | 1412 Source<RenderProcessHost>(this), |
1367 NotificationService::NoDetails()); | 1413 NotificationService::NoDetails()); |
1368 | 1414 |
| 1415 #ifndef NDEBUG |
| 1416 is_self_deleted_ = true; |
| 1417 #endif |
1369 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); | 1418 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); |
1370 deleting_soon_ = true; | 1419 deleting_soon_ = true; |
1371 // It's important not to wait for the DeleteTask to delete the channel | 1420 // It's important not to wait for the DeleteTask to delete the channel |
1372 // proxy. Kill it off now. That way, in case the profile is going away, the | 1421 // proxy. Kill it off now. That way, in case the profile is going away, the |
1373 // rest of the objects attached to this RenderProcessHost start going | 1422 // rest of the objects attached to this RenderProcessHost start going |
1374 // away first, since deleting the channel proxy will post a | 1423 // away first, since deleting the channel proxy will post a |
1375 // OnChannelClosed() to IPC::ChannelProxy::Context on the IO thread. | 1424 // OnChannelClosed() to IPC::ChannelProxy::Context on the IO thread. |
1376 channel_.reset(); | 1425 channel_.reset(); |
1377 gpu_message_filter_ = NULL; | 1426 gpu_message_filter_ = NULL; |
1378 message_port_message_filter_ = NULL; | 1427 message_port_message_filter_ = NULL; |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1507 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 1556 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
1508 if (value && !command_line->HasSwitch(switches::kLang)) { | 1557 if (value && !command_line->HasSwitch(switches::kLang)) { |
1509 // Modify the current process' command line to include the browser locale, | 1558 // Modify the current process' command line to include the browser locale, |
1510 // as the renderer expects this flag to be set. | 1559 // as the renderer expects this flag to be set. |
1511 const std::string locale = | 1560 const std::string locale = |
1512 GetContentClient()->browser()->GetApplicationLocale(); | 1561 GetContentClient()->browser()->GetApplicationLocale(); |
1513 command_line->AppendSwitchASCII(switches::kLang, locale); | 1562 command_line->AppendSwitchASCII(switches::kLang, locale); |
1514 } | 1563 } |
1515 } | 1564 } |
1516 | 1565 |
| 1566 // static |
1517 RenderProcessHost::iterator RenderProcessHost::AllHostsIterator() { | 1567 RenderProcessHost::iterator RenderProcessHost::AllHostsIterator() { |
1518 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1568 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1519 return iterator(g_all_hosts.Pointer()); | 1569 return iterator(g_all_hosts.Pointer()); |
1520 } | 1570 } |
1521 | 1571 |
1522 // static | 1572 // static |
1523 RenderProcessHost* RenderProcessHost::FromID(int render_process_id) { | 1573 RenderProcessHost* RenderProcessHost::FromID(int render_process_id) { |
1524 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1574 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1525 return g_all_hosts.Get().Lookup(render_process_id); | 1575 return g_all_hosts.Get().Lookup(render_process_id); |
1526 } | 1576 } |
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1844 // Skip widgets in other processes. | 1894 // Skip widgets in other processes. |
1845 if (widget->GetProcess()->GetID() != GetID()) | 1895 if (widget->GetProcess()->GetID() != GetID()) |
1846 continue; | 1896 continue; |
1847 | 1897 |
1848 RenderViewHost* rvh = RenderViewHost::From(widget); | 1898 RenderViewHost* rvh = RenderViewHost::From(widget); |
1849 rvh->UpdateWebkitPreferences(rvh->GetWebkitPreferences()); | 1899 rvh->UpdateWebkitPreferences(rvh->GetWebkitPreferences()); |
1850 } | 1900 } |
1851 } | 1901 } |
1852 | 1902 |
1853 } // namespace content | 1903 } // namespace content |
OLD | NEW |