summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/dom_ui/new_tab_ui.cc24
-rw-r--r--chrome/browser/dom_ui/new_tab_ui.h5
2 files changed, 20 insertions, 9 deletions
diff --git a/chrome/browser/dom_ui/new_tab_ui.cc b/chrome/browser/dom_ui/new_tab_ui.cc
index 86ebb60..2e44322 100644
--- a/chrome/browser/dom_ui/new_tab_ui.cc
+++ b/chrome/browser/dom_ui/new_tab_ui.cc
@@ -132,8 +132,7 @@ void SetURLTitleAndDirection(DictionaryValue* dictionary,
// messages and wait for the page to stop repainting.
class PaintTimer : public RenderWidgetHost::PaintObserver {
public:
- PaintTimer()
- : ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) {
+ PaintTimer() {
Start();
}
@@ -141,8 +140,9 @@ class PaintTimer : public RenderWidgetHost::PaintObserver {
void Start() {
start_ = base::TimeTicks::Now();
last_paint_ = start_;
- MessageLoop::current()->PostDelayedTask(FROM_HERE,
- method_factory_.NewRunnableMethod(&PaintTimer::Timeout), kTimeoutMs);
+
+ timer_.Start(base::TimeDelta::FromMilliseconds(kTimeoutMs), this,
+ &PaintTimer::Timeout);
}
// A callback that is invoked whenever our RenderWidgetHost paints.
@@ -167,8 +167,8 @@ class PaintTimer : public RenderWidgetHost::PaintObserver {
// Not enough quiet time has elapsed.
// Some more paints must've occurred since we set the timeout.
// Wait some more.
- MessageLoop::current()->PostDelayedTask(FROM_HERE,
- method_factory_.NewRunnableMethod(&PaintTimer::Timeout), kTimeoutMs);
+ timer_.Start(base::TimeDelta::FromMilliseconds(kTimeoutMs), this,
+ &PaintTimer::Timeout);
}
}
@@ -181,7 +181,7 @@ class PaintTimer : public RenderWidgetHost::PaintObserver {
// The last time we got a paint notification.
base::TimeTicks last_paint_;
// Scoping so we can be sure our timeouts don't outlive us.
- ScopedRunnableMethodFactory<PaintTimer> method_factory_;
+ base::OneShotTimer<PaintTimer> timer_;
DISALLOW_COPY_AND_ASSIGN(PaintTimer);
};
@@ -1643,8 +1643,6 @@ NewTabUI::NewTabUI(TabContents* contents)
if (NewTabUI::FirstRunDisabled())
NewTabHTMLSource::set_first_run(false);
- tab_contents()->render_view_host()->set_paint_observer(new PaintTimer);
-
if (GetProfile()->IsOffTheRecord()) {
incognito_ = true;
@@ -1699,6 +1697,14 @@ NewTabUI::NewTabUI(TabContents* contents)
NewTabUI::~NewTabUI() {
}
+void NewTabUI::RenderViewCreated(RenderViewHost* render_view_host) {
+ render_view_host->set_paint_observer(new PaintTimer);
+}
+
+void NewTabUI::RenderViewReused(RenderViewHost* render_view_host) {
+ render_view_host->set_paint_observer(new PaintTimer);
+}
+
void NewTabUI::Observe(NotificationType type,
const NotificationSource& source,
const NotificationDetails& details) {
diff --git a/chrome/browser/dom_ui/new_tab_ui.h b/chrome/browser/dom_ui/new_tab_ui.h
index bc60804..e5d1094 100644
--- a/chrome/browser/dom_ui/new_tab_ui.h
+++ b/chrome/browser/dom_ui/new_tab_ui.h
@@ -23,6 +23,11 @@ class NewTabUI : public DOMUI,
explicit NewTabUI(TabContents* manager);
~NewTabUI();
+ // Override DOMUI methods so we can hook up the paint timer to the render
+ // view host.
+ virtual void RenderViewCreated(RenderViewHost* render_view_host);
+ virtual void RenderViewReused(RenderViewHost* render_view_host);
+
static void RegisterUserPrefs(PrefService* prefs);
// Whether we should use the old new tab page.