summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authordarin@google.com <darin@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-08-07 06:31:41 +0000
committerdarin@google.com <darin@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-08-07 06:31:41 +0000
commitaeab4c7449f26ac71546c1419c524c0870bc155a (patch)
treeba7549cb86473478921b14e00d5ef8e701f7c7f8 /chrome/browser
parentba7f857605d7d088dff38e6ceab868dd90fc108b (diff)
downloadchromium_src-aeab4c7449f26ac71546c1419c524c0870bc155a.zip
chromium_src-aeab4c7449f26ac71546c1419c524c0870bc155a.tar.gz
chromium_src-aeab4c7449f26ac71546c1419c524c0870bc155a.tar.bz2
Revised r408 such that we no longer sometimes fail MetricsServiceTest.CrashRenderers.
That test showed that we were exiting the browser process without noticing that a child process had crashed. I fixed that by simply adding a check to see if the child process is still around before initiating the normal close of the child process. This corresponds to the case where the browser decides to close a renderer. As a result, the race for the MessageLoop to receive a Task notifying the RenderProcessHost of a crashed renderer is removed from the picture. The bulk of this CL is just re-landing r408, which jar reviewed. git-svn-id: svn://svn.chromium.org/chrome/trunk/src@498 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/plugin_process_host.cc4
-rw-r--r--chrome/browser/plugin_process_host.h15
-rw-r--r--chrome/browser/render_process_host.cc26
-rw-r--r--chrome/browser/render_process_host.h16
-rw-r--r--chrome/browser/render_widget_host.cc5
5 files changed, 35 insertions, 31 deletions
diff --git a/chrome/browser/plugin_process_host.cc b/chrome/browser/plugin_process_host.cc
index 7ee3015..f64af9d 100644
--- a/chrome/browser/plugin_process_host.cc
+++ b/chrome/browser/plugin_process_host.cc
@@ -329,7 +329,7 @@ PluginProcessHost::PluginProcessHost(PluginService* plugin_service)
PluginProcessHost::~PluginProcessHost() {
if (process_.handle()) {
- MessageLoop::current()->WatchObject(process_.handle(), NULL);
+ watcher_.StopWatching();
ProcessWatcher::EnsureProcessTerminated(process_.handle());
}
}
@@ -461,7 +461,7 @@ bool PluginProcessHost::Init(const std::wstring& dll,
process_.set_handle(process);
}
- MessageLoop::current()->WatchObject(process_.handle(), this);
+ watcher_.StartWatching(process_.handle(), this);
// Give all plugins "background" priority. See http://b/issue?id=1280317.
process_.SetProcessBackgrounded(true);
diff --git a/chrome/browser/plugin_process_host.h b/chrome/browser/plugin_process_host.h
index f4cf06b..e9ea4c5 100644
--- a/chrome/browser/plugin_process_host.h
+++ b/chrome/browser/plugin_process_host.h
@@ -27,14 +27,14 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#ifndef CHROME_BROWSER_PLUGIN_PROCESS_HOST_H__
-#define CHROME_BROWSER_PLUGIN_PROCESS_HOST_H__
+#ifndef CHROME_BROWSER_PLUGIN_PROCESS_HOST_H_
+#define CHROME_BROWSER_PLUGIN_PROCESS_HOST_H_
#include <vector>
#include "base/basictypes.h"
#include "base/id_map.h"
-#include "base/message_loop.h"
+#include "base/object_watcher.h"
#include "base/process.h"
#include "base/scoped_ptr.h"
#include "base/task.h"
@@ -59,7 +59,7 @@ class GURL;
// the renderer and plugin processes.
class PluginProcessHost : public IPC::Channel::Listener,
public IPC::Message::Sender,
- public MessageLoop::Watcher {
+ public base::ObjectWatcher::Delegate {
public:
PluginProcessHost(PluginService* plugin_service);
~PluginProcessHost();
@@ -75,7 +75,7 @@ class PluginProcessHost : public IPC::Channel::Listener,
// IPC::Message::Sender implementation:
virtual bool Send(IPC::Message* msg);
- // MessageLoop watcher callback
+ // ObjectWatcher::Delegate implementation:
virtual void OnObjectSignaled(HANDLE object);
// IPC::Channel::Listener implementation:
@@ -159,6 +159,9 @@ class PluginProcessHost : public IPC::Channel::Listener,
// The handle to our plugin process.
Process process_;
+ // Used to watch the plugin process handle.
+ base::ObjectWatcher watcher_;
+
// true while we're waiting the channel to be opened. In the meantime,
// plugin instance requests will be buffered.
bool opening_channel_;
@@ -179,4 +182,4 @@ class PluginProcessHost : public IPC::Channel::Listener,
DISALLOW_EVIL_CONSTRUCTORS(PluginProcessHost);
};
-#endif // CHROME_BROWSER_PLUGIN_PROCESS_HOST_H__
+#endif // CHROME_BROWSER_PLUGIN_PROCESS_HOST_H_
diff --git a/chrome/browser/render_process_host.cc b/chrome/browser/render_process_host.cc
index 43ebb64..3dea5c0 100644
--- a/chrome/browser/render_process_host.cc
+++ b/chrome/browser/render_process_host.cc
@@ -202,7 +202,7 @@ RenderProcessHost::~RenderProcessHost() {
channel_.reset();
if (process_.handle() && !run_renderer_in_process_) {
- MessageLoop::current()->WatchObject(process_.handle(), NULL);
+ watcher_.StopWatching();
ProcessWatcher::EnsureProcessTerminated(process_.handle());
}
@@ -420,7 +420,7 @@ bool RenderProcessHost::Init() {
process_.set_handle(process);
}
- MessageLoop::current()->WatchObject(process_.handle(), this);
+ watcher_.StartWatching(process_.handle(), this);
}
}
@@ -459,16 +459,18 @@ void RenderProcessHost::Release(int listener_id) {
DCHECK(listeners_.Lookup(listener_id) != NULL);
listeners_.Remove(listener_id);
- // make sure that all associated resource requests are stopped.
+ // Make sure that all associated resource requests are stopped.
widget_helper_->CancelResourceRequests(listener_id);
- // when no other owners of this object, we can delete ourselves
+ // When there are no other owners of this object, we can delete ourselves.
if (listeners_.IsEmpty()) {
if (!notified_termination_) {
- bool close_expected = true;
+ // It is possible that the renderer died already even though we haven't
+ // broken the pipe yet. We should take care to count this as unexpected.
+ bool clean_shutdown = !process_util::DidProcessCrash(process_.handle());
NotificationService::current()->Notify(NOTIFY_RENDERER_PROCESS_TERMINATED,
Source<RenderProcessHost>(this),
- Details<bool>(&close_expected));
+ Details<bool>(&clean_shutdown));
notified_termination_ = true;
}
Unregister();
@@ -506,8 +508,8 @@ bool RenderProcessHost::FastShutdownIfPossible() {
return false;
}
}
- // Otherwise, call TerminateProcess. Using exit code 0 means that UMA won't
- // treat this as a renderer crash.
+ // Otherwise, call TerminateProcess. Using NORMAL_EXIT here means that UMA
+ // won't treat this as a renderer crash.
::TerminateProcess(proc, ResultCodes::NORMAL_EXIT);
return true;
}
@@ -576,7 +578,7 @@ void RenderProcessHost::OnChannelConnected(int32 peer_pid) {
// returned by CreateProcess() has to the process object.
process_.set_handle(OpenProcess(MAXIMUM_ALLOWED, FALSE, peer_pid));
DCHECK(process_.handle());
- MessageLoop::current()->WatchObject(process_.handle(), this);
+ watcher_.StartWatching(process_.handle(), this);
}
} else {
// Need to verify that the peer_pid is actually the process we know, if
@@ -591,8 +593,6 @@ void RenderProcessHost::OnObjectSignaled(HANDLE object) {
DCHECK(channel_.get());
DCHECK_EQ(object, process_.handle());
- MessageLoop::current()->WatchObject(object, NULL);
-
bool clean_shutdown = !process_util::DidProcessCrash(object);
process_.Close();
@@ -600,8 +600,8 @@ void RenderProcessHost::OnObjectSignaled(HANDLE object) {
channel_.reset();
if (!notified_termination_) {
- // If |close_expected| is false, it means the renderer process went away
- // before the web views expected it; count it as a crash.
+ // If |clean_shutdown| is false, it means the renderer process went away
+ // before we expected it; count it as a crash.
NotificationService::current()->Notify(NOTIFY_RENDERER_PROCESS_TERMINATED,
Source<RenderProcessHost>(this),
Details<bool>(&clean_shutdown));
diff --git a/chrome/browser/render_process_host.h b/chrome/browser/render_process_host.h
index 117ad55..e64b8fe 100644
--- a/chrome/browser/render_process_host.h
+++ b/chrome/browser/render_process_host.h
@@ -27,14 +27,15 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#ifndef CHROME_BROWSER_RENDER_PROCESS_HOST_H__
-#define CHROME_BROWSER_RENDER_PROCESS_HOST_H__
+#ifndef CHROME_BROWSER_RENDER_PROCESS_HOST_H_
+#define CHROME_BROWSER_RENDER_PROCESS_HOST_H_
+#include <set>
#include <vector>
#include <windows.h>
#include "base/id_map.h"
-#include "base/message_loop.h"
+#include "base/object_watcher.h"
#include "base/process.h"
#include "base/ref_counted.h"
#include "base/scoped_ptr.h"
@@ -61,8 +62,8 @@ class WebContents;
// are correlated with IDs. This way, the Views and the corresponding ViewHosts
// communicate through the two process objects.
class RenderProcessHost : public IPC::Channel::Listener,
- public MessageLoop::Watcher,
public IPC::Channel::Sender,
+ public base::ObjectWatcher::Delegate,
public NotificationObserver {
public:
// Returns the RenderProcessHost given its ID. Returns NULL if the ID does
@@ -155,7 +156,7 @@ class RenderProcessHost : public IPC::Channel::Listener,
virtual void OnMessageReceived(const IPC::Message& msg);
virtual void OnChannelConnected(int32 peer_pid);
- // MessageLoop watcher callback
+ // ObjectWatcher::Delegate
virtual void OnObjectSignaled(HANDLE object);
// IPC::Channel::Sender callback
@@ -244,6 +245,9 @@ class RenderProcessHost : public IPC::Channel::Listener,
// Our renderer process.
Process process_;
+ // Used to watch the renderer process handle.
+ base::ObjectWatcher watcher_;
+
// The profile associated with this renderer process.
Profile* profile_;
@@ -289,4 +293,4 @@ inline std::wstring GenerateRandomChannelID(void* instance) {
}
-#endif // CHROME_BROWSER_RENDER_PROCESS_HOST_H__
+#endif // CHROME_BROWSER_RENDER_PROCESS_HOST_H_
diff --git a/chrome/browser/render_widget_host.cc b/chrome/browser/render_widget_host.cc
index 542f903..8f48a51 100644
--- a/chrome/browser/render_widget_host.cc
+++ b/chrome/browser/render_widget_host.cc
@@ -29,11 +29,8 @@
#include "chrome/browser/render_widget_host.h"
-#include <atlbase.h>
-#include <atlapp.h>
-
#include "base/gfx/bitmap_header.h"
-#include "base/histogram.h"
+#include "base/message_loop.h"
#include "chrome/app/chrome_dll_resource.h"
#include "chrome/browser/render_process_host.h"
#include "chrome/browser/render_widget_helper.h"