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 21 matching lines...) Expand all Loading... | |
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 |
402 RenderProcessHostImpl::~RenderProcessHostImpl() { | 406 RenderProcessHostImpl::~RenderProcessHostImpl() { |
407 #ifndef NDEBUG | |
408 DCHECK(is_self_deleted_) | |
409 << "RenderProcessHostImpl is destroyed by something other than itself"; | |
410 #endif | |
411 | |
403 ChildProcessSecurityPolicyImpl::GetInstance()->Remove(GetID()); | 412 ChildProcessSecurityPolicyImpl::GetInstance()->Remove(GetID()); |
404 | 413 |
405 if (gpu_observer_registered_) { | 414 if (gpu_observer_registered_) { |
406 GpuDataManagerImpl::GetInstance()->RemoveObserver(this); | 415 GpuDataManagerImpl::GetInstance()->RemoveObserver(this); |
407 gpu_observer_registered_ = false; | 416 gpu_observer_registered_ = false; |
408 } | 417 } |
409 | 418 |
410 // We may have some unsent messages at this point, but that's OK. | 419 // We may have some unsent messages at this point, but that's OK. |
411 channel_.reset(); | 420 channel_.reset(); |
412 while (!queued_messages_.empty()) { | 421 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 | 773 // We wait to close the channels until the child process has finished |
765 // dumping handles and sends us ChildProcessHostMsg_DumpHandlesDone. | 774 // dumping handles and sends us ChildProcessHostMsg_DumpHandlesDone. |
766 return; | 775 return; |
767 } | 776 } |
768 #endif | 777 #endif |
769 // Keep the one renderer thread around forever in single process mode. | 778 // Keep the one renderer thread around forever in single process mode. |
770 if (!run_renderer_in_process()) | 779 if (!run_renderer_in_process()) |
771 Cleanup(); | 780 Cleanup(); |
772 } | 781 } |
773 | 782 |
783 void RenderProcessHostImpl::AddObserver(RenderProcessHostObserver* observer) { | |
784 observers_.AddObserver(observer); | |
785 } | |
786 | |
787 void RenderProcessHostImpl::RemoveObserver( | |
788 RenderProcessHostObserver* observer) { | |
789 observers_.RemoveObserver(observer); | |
790 } | |
791 | |
774 bool RenderProcessHostImpl::WaitForBackingStoreMsg( | 792 bool RenderProcessHostImpl::WaitForBackingStoreMsg( |
775 int render_widget_id, | 793 int render_widget_id, |
776 const base::TimeDelta& max_delay, | 794 const base::TimeDelta& max_delay, |
777 IPC::Message* msg) { | 795 IPC::Message* msg) { |
778 // The post task to this thread with the process id could be in queue, and we | 796 // 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. | 797 // 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()) | 798 if (child_process_launcher_.get() && child_process_launcher_->IsStarting()) |
781 return false; | 799 return false; |
782 | 800 |
783 return widget_helper_->WaitForBackingStoreMsg(render_widget_id, | 801 return widget_helper_->WaitForBackingStoreMsg(render_widget_id, |
(...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1351 | 1369 |
1352 void RenderProcessHostImpl::SetIgnoreInputEvents(bool ignore_input_events) { | 1370 void RenderProcessHostImpl::SetIgnoreInputEvents(bool ignore_input_events) { |
1353 ignore_input_events_ = ignore_input_events; | 1371 ignore_input_events_ = ignore_input_events; |
1354 } | 1372 } |
1355 | 1373 |
1356 bool RenderProcessHostImpl::IgnoreInputEvents() const { | 1374 bool RenderProcessHostImpl::IgnoreInputEvents() const { |
1357 return ignore_input_events_; | 1375 return ignore_input_events_; |
1358 } | 1376 } |
1359 | 1377 |
1360 void RenderProcessHostImpl::Cleanup() { | 1378 void RenderProcessHostImpl::Cleanup() { |
1361 // When no other owners of this object, we can delete ourselves | 1379 // When there are no other owners of this object, we can delete ourselves. |
1362 if (listeners_.IsEmpty()) { | 1380 if (listeners_.IsEmpty()) { |
1363 DCHECK_EQ(0, pending_views_); | 1381 DCHECK_EQ(0, pending_views_); |
1382 FOR_EACH_OBSERVER(RenderProcessHostObserver, | |
1383 observers_, | |
1384 RenderProcessHostDestroyed(this)); | |
1364 NotificationService::current()->Notify( | 1385 NotificationService::current()->Notify( |
1365 NOTIFICATION_RENDERER_PROCESS_TERMINATED, | 1386 NOTIFICATION_RENDERER_PROCESS_TERMINATED, |
1366 Source<RenderProcessHost>(this), | 1387 Source<RenderProcessHost>(this), |
1367 NotificationService::NoDetails()); | 1388 NotificationService::NoDetails()); |
1368 | 1389 |
1390 #ifndef NDEBUG | |
1391 is_self_deleted_ = true; | |
1392 #endif | |
1369 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); | 1393 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); |
1370 deleting_soon_ = true; | 1394 deleting_soon_ = true; |
1371 // It's important not to wait for the DeleteTask to delete the channel | 1395 // 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 | 1396 // 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 | 1397 // rest of the objects attached to this RenderProcessHost start going |
1374 // away first, since deleting the channel proxy will post a | 1398 // away first, since deleting the channel proxy will post a |
1375 // OnChannelClosed() to IPC::ChannelProxy::Context on the IO thread. | 1399 // OnChannelClosed() to IPC::ChannelProxy::Context on the IO thread. |
1376 channel_.reset(); | 1400 channel_.reset(); |
1377 gpu_message_filter_ = NULL; | 1401 gpu_message_filter_ = NULL; |
1378 message_port_message_filter_ = NULL; | 1402 message_port_message_filter_ = NULL; |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1507 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 1531 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
1508 if (value && !command_line->HasSwitch(switches::kLang)) { | 1532 if (value && !command_line->HasSwitch(switches::kLang)) { |
1509 // Modify the current process' command line to include the browser locale, | 1533 // Modify the current process' command line to include the browser locale, |
1510 // as the renderer expects this flag to be set. | 1534 // as the renderer expects this flag to be set. |
1511 const std::string locale = | 1535 const std::string locale = |
1512 GetContentClient()->browser()->GetApplicationLocale(); | 1536 GetContentClient()->browser()->GetApplicationLocale(); |
1513 command_line->AppendSwitchASCII(switches::kLang, locale); | 1537 command_line->AppendSwitchASCII(switches::kLang, locale); |
1514 } | 1538 } |
1515 } | 1539 } |
1516 | 1540 |
1541 // static | |
1542 void RenderProcessHost::ShutDownInProcessRenderer() { | |
1543 DCHECK(g_run_renderer_in_process_); | |
1544 | |
1545 switch (g_all_hosts.Pointer()->size()) { | |
jam
2013/11/18 19:16:20
nit: isn't size() always == 1? can you just make t
Avi (use Gerrit)
2013/11/18 19:22:21
Is it? It's valid to shut down even if there never
| |
1546 case 0: | |
1547 return; | |
1548 case 1: { | |
1549 RenderProcessHostImpl* host = static_cast<RenderProcessHostImpl*>( | |
1550 AllHostsIterator().GetCurrentValue()); | |
1551 FOR_EACH_OBSERVER(RenderProcessHostObserver, | |
1552 host->observers_, | |
1553 RenderProcessHostDestroyed(host)); | |
1554 #ifndef NDEBUG | |
1555 host->is_self_deleted_ = true; | |
1556 #endif | |
1557 delete host; | |
1558 return; | |
1559 } | |
1560 default: | |
1561 NOTREACHED() << "There should be only one RenderProcessHost when running " | |
1562 << "in-process."; | |
1563 } | |
1564 } | |
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 |