diff options
author | jbates@chromium.org <jbates@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-09 04:23:38 +0000 |
---|---|---|
committer | jbates@chromium.org <jbates@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-09 04:23:38 +0000 |
commit | 350ce870f6da3f4850b99d8567ff469a3e053f62 (patch) | |
tree | 21635083155771a4147b63e6d7e5d0725db833b9 /content | |
parent | c46c92f5a211d688550dd87de9e8e1ad8b011f13 (diff) | |
download | chromium_src-350ce870f6da3f4850b99d8567ff469a3e053f62.zip chromium_src-350ce870f6da3f4850b99d8567ff469a3e053f62.tar.gz chromium_src-350ce870f6da3f4850b99d8567ff469a3e053f62.tar.bz2 |
Fix RenderWidget task leak
R=jamesr
BUG=114914,117195
Review URL: http://codereview.chromium.org/9649014
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@125797 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content')
-rw-r--r-- | content/renderer/render_widget.cc | 47 | ||||
-rw-r--r-- | content/renderer/render_widget.h | 3 |
2 files changed, 23 insertions, 27 deletions
diff --git a/content/renderer/render_widget.cc b/content/renderer/render_widget.cc index ee0f897..b777157 100644 --- a/content/renderer/render_widget.cc +++ b/content/renderer/render_widget.cc @@ -102,7 +102,6 @@ RenderWidget::RenderWidget(WebKit::WebPopupType popup_type, suppress_next_char_events_(false), is_accelerated_compositing_active_(false), animation_update_pending_(false), - animation_task_posted_(false), invalidation_task_posted_(false), screen_info_(screen_info), invert_(false) { @@ -713,7 +712,6 @@ void RenderWidget::PaintDebugBorder(const gfx::Rect& rect, void RenderWidget::AnimationCallback() { TRACE_EVENT0("renderer", "RenderWidget::AnimationCallback"); - animation_task_posted_ = false; if (!animation_update_pending_) { TRACE_EVENT0("renderer", "EarlyOut_NoAnimationUpdatePending"); return; @@ -752,29 +750,27 @@ void RenderWidget::AnimateIfNeeded() { // Set a timer to call us back after animationInterval before // running animation callbacks so that if a callback requests another // we'll be sure to run it at the proper time. - MessageLoop::current()->PostDelayedTask( - FROM_HERE, base::Bind(&RenderWidget::AnimationCallback, this), - animationInterval); - animation_task_posted_ = true; + animation_timer_.Stop(); + animation_timer_.Start(FROM_HERE, animationInterval, this, + &RenderWidget::AnimationCallback); animation_update_pending_ = false; webwidget_->animate(0.0); return; } TRACE_EVENT0("renderer", "EarlyOut_AnimatedTooRecently"); - if (animation_task_posted_) - return; - // This code uses base::Time::Now() to calculate the floor and next fire - // time because javascript's Date object uses base::Time::Now(). The - // message loop uses base::TimeTicks, which on windows can have a - // different granularity than base::Time. - // The upshot of all this is that this function might be called before - // base::Time::Now() has advanced past the animation_floor_time_. To - // avoid exposing this delay to javascript, we keep posting delayed - // tasks until base::Time::Now() has advanced far enough. - base::TimeDelta delay = animation_floor_time_ - now; - animation_task_posted_ = true; - MessageLoop::current()->PostDelayedTask( - FROM_HERE, base::Bind(&RenderWidget::AnimationCallback, this), delay); + if (!animation_timer_.IsRunning()) { + // This code uses base::Time::Now() to calculate the floor and next fire + // time because javascript's Date object uses base::Time::Now(). The + // message loop uses base::TimeTicks, which on windows can have a + // different granularity than base::Time. + // The upshot of all this is that this function might be called before + // base::Time::Now() has advanced past the animation_floor_time_. To + // avoid exposing this delay to javascript, we keep posting delayed + // tasks until base::Time::Now() has advanced far enough. + base::TimeDelta delay = animation_floor_time_ - now; + animation_timer_.Start(FROM_HERE, delay, this, + &RenderWidget::AnimationCallback); + } } bool RenderWidget::IsRenderingVSynced() { @@ -1013,7 +1009,7 @@ void RenderWidget::didInvalidateRect(const WebRect& rect) { // When GPU rendering, combine pending animations and invalidations into // a single update. - if (is_accelerated_compositing_active_ && animation_task_posted_) + if (is_accelerated_compositing_active_ && animation_timer_.IsRunning()) return; // Perform updating asynchronously. This serves two purposes: @@ -1051,7 +1047,7 @@ void RenderWidget::didScrollRect(int dx, int dy, const WebRect& clip_rect) { // When GPU rendering, combine pending animations and invalidations into // a single update. - if (is_accelerated_compositing_active_ && animation_task_posted_) + if (is_accelerated_compositing_active_ && animation_timer_.IsRunning()) return; // Perform updating asynchronously. This serves two purposes: @@ -1149,10 +1145,9 @@ void RenderWidget::scheduleAnimation() { TRACE_EVENT0("gpu", "RenderWidget::scheduleAnimation"); if (!animation_update_pending_) { animation_update_pending_ = true; - if (!animation_task_posted_) { - animation_task_posted_ = true; - MessageLoop::current()->PostTask( - FROM_HERE, base::Bind(&RenderWidget::AnimationCallback, this)); + if (!animation_timer_.IsRunning()) { + animation_timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(0), this, + &RenderWidget::AnimationCallback); } } } diff --git a/content/renderer/render_widget.h b/content/renderer/render_widget.h index 11e4bfa..9aa76f6c 100644 --- a/content/renderer/render_widget.h +++ b/content/renderer/render_widget.h @@ -14,6 +14,7 @@ #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" #include "base/time.h" +#include "base/timer.h" #include "content/common/content_export.h" #include "content/renderer/paint_aggregator.h" #include "ipc/ipc_channel.h" @@ -490,9 +491,9 @@ class CONTENT_EXPORT RenderWidget // compositor. bool is_accelerated_compositing_active_; + base::OneShotTimer<RenderWidget> animation_timer_; base::Time animation_floor_time_; bool animation_update_pending_; - bool animation_task_posted_; bool invalidation_task_posted_; bool has_disable_gpu_vsync_switch_; |