diff options
author | darin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-09-25 21:35:10 +0000 |
---|---|---|
committer | darin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-09-25 21:35:10 +0000 |
commit | 7e2fa03804bef4bff9c5bb941f2edf09b6d234c0 (patch) | |
tree | 535d81a14867f7b037bec19764bfaa56a53acd33 /chrome/browser/render_widget_host.cc | |
parent | 5f715e9411a0b4b8e207072fdbfad5160f5ad1e2 (diff) | |
download | chromium_src-7e2fa03804bef4bff9c5bb941f2edf09b6d234c0.zip chromium_src-7e2fa03804bef4bff9c5bb941f2edf09b6d234c0.tar.gz chromium_src-7e2fa03804bef4bff9c5bb941f2edf09b6d234c0.tar.bz2 |
Stop spamming delayed tasks on each input event.
R=mbelshe
BUG=2693
Review URL: http://codereview.chromium.org/4262
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@2609 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/render_widget_host.cc')
-rw-r--r-- | chrome/browser/render_widget_host.cc | 43 |
1 files changed, 33 insertions, 10 deletions
diff --git a/chrome/browser/render_widget_host.cc b/chrome/browser/render_widget_host.cc index 34e9c26..449b194 100644 --- a/chrome/browser/render_widget_host.cc +++ b/chrome/browser/render_widget_host.cc @@ -273,7 +273,6 @@ RenderWidgetHost::RenderWidgetHost(RenderProcessHost* process, int routing_id) is_hidden_(false), suppress_view_updating_(false), needs_repainting_on_restore_(false), - hung_renderer_factory_(this), is_unresponsive_(false), view_being_painted_(false), repaint_ack_pending_(false) { @@ -630,7 +629,7 @@ void RenderWidgetHost::ForwardInputEvent(const WebInputEvent& input_event, // any input event cancels a pending mouse move event next_mouse_move_.reset(); - StartHangMonitorTimeout(kHungRendererDelayMs); + StartHangMonitorTimeout(TimeDelta::FromMilliseconds(kHungRendererDelayMs)); } void RenderWidgetHost::Shutdown() { @@ -673,7 +672,19 @@ void RenderWidgetHost::Destroy() { delete this; } -void RenderWidgetHost::RendererIsUnresponsive() { +void RenderWidgetHost::CheckRendererIsUnresponsive() { + // If we received a call to StopHangMonitorTimeout. + if (time_when_considered_hung_.is_null()) + return; + + // If we have not waited long enough, then wait some more. + Time now = Time::Now(); + if (now < time_when_considered_hung_) { + StartHangMonitorTimeout(time_when_considered_hung_ - now); + return; + } + + // OK, looks like we have a hung renderer! NotificationService::current()->Notify(NOTIFY_RENDERER_PROCESS_HANG, Source<RenderWidgetHost>(this), NotificationService::NoDetails()); @@ -788,19 +799,31 @@ void RenderWidgetHost::ScrollRect(HANDLE bitmap, const gfx::Rect& bitmap_rect, } void RenderWidgetHost::RestartHangMonitorTimeout() { - hung_renderer_factory_.RevokeAll(); - StartHangMonitorTimeout(kHungRendererDelayMs); + StartHangMonitorTimeout(TimeDelta::FromMilliseconds(kHungRendererDelayMs)); } void RenderWidgetHost::StopHangMonitorTimeout() { - hung_renderer_factory_.RevokeAll(); + time_when_considered_hung_ = Time(); RendererIsResponsive(); + + // We do not bother to stop the hung_renderer_timer_ here in case it will be + // started again shortly, which happens to be the common use case. } -void RenderWidgetHost::StartHangMonitorTimeout(int delay) { - MessageLoop::current()->PostDelayedTask(FROM_HERE, - hung_renderer_factory_.NewRunnableMethod( - &RenderWidgetHost::RendererIsUnresponsive), delay); +void RenderWidgetHost::StartHangMonitorTimeout(TimeDelta delay) { + time_when_considered_hung_ = Time::Now() + delay; + + // If we already have a timer that will expire at or before the given delay, + // then we have nothing more to do now. + if (hung_renderer_timer_.IsRunning() && + hung_renderer_timer_.GetCurrentDelay() <= delay) + return; + + // Either the timer is not yet running, or we need to adjust the timer to + // fire sooner. + hung_renderer_timer_.Stop(); + hung_renderer_timer_.Start(delay, this, + &RenderWidgetHost::CheckRendererIsUnresponsive); } void RenderWidgetHost::RendererExited() { |