diff options
author | tony@chromium.org <tony@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-02 17:18:46 +0000 |
---|---|---|
committer | tony@chromium.org <tony@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-02 17:18:46 +0000 |
commit | c81202a0eff6e02942740f92944265e32f411376 (patch) | |
tree | 4c7066278167b14d6cddd82e1335e6ca3cd46774 /chrome/browser | |
parent | c28d7d66e345f8e87660200231998daaf4653622 (diff) | |
download | chromium_src-c81202a0eff6e02942740f92944265e32f411376.zip chromium_src-c81202a0eff6e02942740f92944265e32f411376.tar.gz chromium_src-c81202a0eff6e02942740f92944265e32f411376.tar.bz2 |
Fix the NewTabUI load UMA metric.
We were attaching the paint observer to the a RenderWidgetHost that
was getting immediately swapped out when the new tab page started
to load. Instead, wait and use the DOM UI callback methods which
happen right after NewTabUI is created.
Review URL: http://codereview.chromium.org/242115
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@27850 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r-- | chrome/browser/dom_ui/new_tab_ui.cc | 24 | ||||
-rw-r--r-- | chrome/browser/dom_ui/new_tab_ui.h | 5 |
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. |