Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(100)

Side by Side Diff: content/browser/renderer_host/render_process_host_impl.cc

Issue 72203003: Introduce RenderProcessHostObserver, use it in its first client. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixes Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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
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 deletion_callback_called_(false),
362 pending_views_(0), 364 pending_views_(0),
363 visible_widgets_(0), 365 visible_widgets_(0),
364 backgrounded_(true), 366 backgrounded_(true),
365 cached_dibs_cleaner_( 367 cached_dibs_cleaner_(
366 FROM_HERE, base::TimeDelta::FromSeconds(5), 368 FROM_HERE, base::TimeDelta::FromSeconds(5),
367 this, &RenderProcessHostImpl::ClearTransportDIBCache), 369 this, &RenderProcessHostImpl::ClearTransportDIBCache),
368 is_initialized_(false), 370 is_initialized_(false),
369 id_(ChildProcessHostImpl::GenerateChildProcessUniqueId()), 371 id_(ChildProcessHostImpl::GenerateChildProcessUniqueId()),
370 browser_context_(browser_context), 372 browser_context_(browser_context),
371 storage_partition_impl_(storage_partition_impl), 373 storage_partition_impl_(storage_partition_impl),
(...skipping 21 matching lines...) Expand all
393 storage_partition_impl_->GetPath())); 395 storage_partition_impl_->GetPath()));
394 } 396 }
395 397
396 // Note: When we create the RenderProcessHostImpl, it's technically 398 // Note: When we create the RenderProcessHostImpl, it's technically
397 // backgrounded, because it has no visible listeners. But the process 399 // backgrounded, because it has no visible listeners. But the process
398 // doesn't actually exist yet, so we'll Background it later, after 400 // doesn't actually exist yet, so we'll Background it later, after
399 // creation. 401 // creation.
400 } 402 }
401 403
402 RenderProcessHostImpl::~RenderProcessHostImpl() { 404 RenderProcessHostImpl::~RenderProcessHostImpl() {
405 if (!deletion_callback_called_) {
406 FOR_EACH_OBSERVER(RenderProcessHostObserver,
407 observers_,
408 RenderProcessHostDestroyed(this));
409 }
410
403 ChildProcessSecurityPolicyImpl::GetInstance()->Remove(GetID()); 411 ChildProcessSecurityPolicyImpl::GetInstance()->Remove(GetID());
404 412
405 if (gpu_observer_registered_) { 413 if (gpu_observer_registered_) {
406 GpuDataManagerImpl::GetInstance()->RemoveObserver(this); 414 GpuDataManagerImpl::GetInstance()->RemoveObserver(this);
407 gpu_observer_registered_ = false; 415 gpu_observer_registered_ = false;
408 } 416 }
409 417
410 // We may have some unsent messages at this point, but that's OK. 418 // We may have some unsent messages at this point, but that's OK.
411 channel_.reset(); 419 channel_.reset();
412 while (!queued_messages_.empty()) { 420 while (!queued_messages_.empty()) {
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
765 // 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
766 // dumping handles and sends us ChildProcessHostMsg_DumpHandlesDone. 774 // dumping handles and sends us ChildProcessHostMsg_DumpHandlesDone.
767 return; 775 return;
768 } 776 }
769 #endif 777 #endif
770 // Keep the one renderer thread around forever in single process mode. 778 // Keep the one renderer thread around forever in single process mode.
771 if (!run_renderer_in_process()) 779 if (!run_renderer_in_process())
772 Cleanup(); 780 Cleanup();
773 } 781 }
774 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
775 bool RenderProcessHostImpl::WaitForBackingStoreMsg( 792 bool RenderProcessHostImpl::WaitForBackingStoreMsg(
776 int render_widget_id, 793 int render_widget_id,
777 const base::TimeDelta& max_delay, 794 const base::TimeDelta& max_delay,
778 IPC::Message* msg) { 795 IPC::Message* msg) {
779 // 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
780 // 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.
781 if (child_process_launcher_.get() && child_process_launcher_->IsStarting()) 798 if (child_process_launcher_.get() && child_process_launcher_->IsStarting())
782 return false; 799 return false;
783 800
784 return widget_helper_->WaitForBackingStoreMsg(render_widget_id, 801 return widget_helper_->WaitForBackingStoreMsg(render_widget_id,
(...skipping 570 matching lines...) Expand 10 before | Expand all | Expand 10 after
1355 } 1372 }
1356 1373
1357 bool RenderProcessHostImpl::IgnoreInputEvents() const { 1374 bool RenderProcessHostImpl::IgnoreInputEvents() const {
1358 return ignore_input_events_; 1375 return ignore_input_events_;
1359 } 1376 }
1360 1377
1361 void RenderProcessHostImpl::Cleanup() { 1378 void RenderProcessHostImpl::Cleanup() {
1362 // When no other owners of this object, we can delete ourselves 1379 // When no other owners of this object, we can delete ourselves
1363 if (listeners_.IsEmpty()) { 1380 if (listeners_.IsEmpty()) {
1364 DCHECK_EQ(0, pending_views_); 1381 DCHECK_EQ(0, pending_views_);
1382 FOR_EACH_OBSERVER(RenderProcessHostObserver,
1383 observers_,
1384 RenderProcessHostDestroyed(this));
jam 2013/11/15 22:42:23 why isn't this enough, i.e. why do we need to do t
1385 deletion_callback_called_ = true;
1365 NotificationService::current()->Notify( 1386 NotificationService::current()->Notify(
1366 NOTIFICATION_RENDERER_PROCESS_TERMINATED, 1387 NOTIFICATION_RENDERER_PROCESS_TERMINATED,
1367 Source<RenderProcessHost>(this), 1388 Source<RenderProcessHost>(this),
1368 NotificationService::NoDetails()); 1389 NotificationService::NoDetails());
1369 1390
1370 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); 1391 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this);
1371 deleting_soon_ = true; 1392 deleting_soon_ = true;
1372 // It's important not to wait for the DeleteTask to delete the channel 1393 // It's important not to wait for the DeleteTask to delete the channel
1373 // proxy. Kill it off now. That way, in case the profile is going away, the 1394 // proxy. Kill it off now. That way, in case the profile is going away, the
1374 // rest of the objects attached to this RenderProcessHost start going 1395 // rest of the objects attached to this RenderProcessHost start going
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after
1845 // Skip widgets in other processes. 1866 // Skip widgets in other processes.
1846 if (widget->GetProcess()->GetID() != GetID()) 1867 if (widget->GetProcess()->GetID() != GetID())
1847 continue; 1868 continue;
1848 1869
1849 RenderViewHost* rvh = RenderViewHost::From(widget); 1870 RenderViewHost* rvh = RenderViewHost::From(widget);
1850 rvh->UpdateWebkitPreferences(rvh->GetWebkitPreferences()); 1871 rvh->UpdateWebkitPreferences(rvh->GetWebkitPreferences());
1851 } 1872 }
1852 } 1873 }
1853 1874
1854 } // namespace content 1875 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/render_process_host_impl.h ('k') | content/browser/site_instance_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698