diff options
author | tony@chromium.org <tony@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-24 01:32:22 +0000 |
---|---|---|
committer | tony@chromium.org <tony@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-24 01:32:22 +0000 |
commit | d7b720c248a214a987f57a3a9fb304c1b01f9f4c (patch) | |
tree | 7e785909050586a774bcf6bf069d5da87ac5ee23 | |
parent | 3400467bb7612df3a77de94e6acca532f85abd5c (diff) | |
download | chromium_src-d7b720c248a214a987f57a3a9fb304c1b01f9f4c.zip chromium_src-d7b720c248a214a987f57a3a9fb304c1b01f9f4c.tar.gz chromium_src-d7b720c248a214a987f57a3a9fb304c1b01f9f4c.tar.bz2 |
Move the NTP HTML generation to early so we can avoid an extra
trip to the UI thread later. Not sure if this will make a
difference.
Move the NTP and CSS handler init to after adding the MostVistedHandler.
This should allow an earlier db fetch for the cases when the HTML/CSS
are not in the cache (e.g., browser startup).
Review URL: http://codereview.chromium.org/439013
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@32899 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/dom_ui/dom_ui_theme_source.cc | 2 | ||||
-rw-r--r-- | chrome/browser/dom_ui/new_tab_ui.cc | 36 | ||||
-rw-r--r-- | chrome/browser/dom_ui/new_tab_ui.h | 5 |
3 files changed, 23 insertions, 20 deletions
diff --git a/chrome/browser/dom_ui/dom_ui_theme_source.cc b/chrome/browser/dom_ui/dom_ui_theme_source.cc index bc3a0aa..3640c40 100644 --- a/chrome/browser/dom_ui/dom_ui_theme_source.cc +++ b/chrome/browser/dom_ui/dom_ui_theme_source.cc @@ -28,7 +28,7 @@ static std::string StripQueryParams(const std::string& path) { DOMUIThemeSource::DOMUIThemeSource(Profile* profile) : DataSource(chrome::kChromeUIThemePath, MessageLoop::current()), - profile_(profile) { + profile_(profile->GetOriginalProfile()) { css_bytes_ = profile_->GetNTPResourceCache()->GetNewTabCSS( profile->IsOffTheRecord()); } diff --git a/chrome/browser/dom_ui/new_tab_ui.cc b/chrome/browser/dom_ui/new_tab_ui.cc index a69a4ba..9e7ae52 100644 --- a/chrome/browser/dom_ui/new_tab_ui.cc +++ b/chrome/browser/dom_ui/new_tab_ui.cc @@ -480,16 +480,6 @@ NewTabUI::NewTabUI(TabContents* contents) if (NewTabUI::FirstRunDisabled()) NewTabHTMLSource::set_first_run(false); - InitializeCSSCaches(); - NewTabHTMLSource* html_source = - new NewTabHTMLSource(GetProfile()->GetOriginalProfile()); - ChromeThread::PostTask( - ChromeThread::IO, FROM_HERE, - NewRunnableMethod( - Singleton<ChromeURLDataManager>::get(), - &ChromeURLDataManager::AddDataSource, - make_scoped_refptr(html_source))); - if (!GetProfile()->IsOffTheRecord()) { AddMessageHandler((new ShownSectionsHandler())->Attach(this)); AddMessageHandler((new MostVisitedHandler())->Attach(this)); @@ -505,6 +495,19 @@ NewTabUI::NewTabUI(TabContents* contents) AddMessageHandler((new PromotionalMessageHandler())->Attach(this)); } + // Initializing the CSS and HTML can require some CPU, so do it after + // we've hooked up the most visited handler. This allows the DB query + // for the new tab thumbs to happen earlier. + InitializeCSSCaches(); + NewTabHTMLSource* html_source = + new NewTabHTMLSource(GetProfile()); + ChromeThread::PostTask( + ChromeThread::IO, FROM_HERE, + NewRunnableMethod( + Singleton<ChromeURLDataManager>::get(), + &ChromeURLDataManager::AddDataSource, + make_scoped_refptr(html_source))); + // Listen for theme installation. registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED, NotificationService::AllSources()); @@ -649,8 +652,7 @@ void NewTabUI::SetURLTitleAndDirection(DictionaryValue* dictionary, bool NewTabUI::NewTabHTMLSource::first_run_ = true; NewTabUI::NewTabHTMLSource::NewTabHTMLSource(Profile* profile) - : DataSource(chrome::kChromeUINewTabHost, MessageLoop::current()), - profile_(profile) { + : DataSource(chrome::kChromeUINewTabHost, NULL) { static bool first_view = true; if (first_view) { // Decrement ntp promo counters; the default values are specified in @@ -661,11 +663,14 @@ NewTabUI::NewTabHTMLSource::NewTabHTMLSource(Profile* profile) profile->GetPrefs()->GetInteger(prefs::kNTPPromoImageRemaining) - 1); first_view = false; } + + html_bytes_ = profile->GetNTPResourceCache()->GetNewTabHTML( + profile->IsOffTheRecord()); } void NewTabUI::NewTabHTMLSource::StartDataRequest(const std::string& path, bool is_off_the_record, int request_id) { - DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); if (!path.empty()) { // A path under new-tab was requested; it's likely a bad relative // URL from the new tab page, but in any case it's an error. @@ -673,8 +678,5 @@ void NewTabUI::NewTabHTMLSource::StartDataRequest(const std::string& path, return; } - scoped_refptr<RefCountedBytes> html_bytes = - profile_->GetNTPResourceCache()->GetNewTabHTML(is_off_the_record); - - SendResponse(request_id, html_bytes); + SendResponse(request_id, html_bytes_); } diff --git a/chrome/browser/dom_ui/new_tab_ui.h b/chrome/browser/dom_ui/new_tab_ui.h index d612dd9..6d73f85 100644 --- a/chrome/browser/dom_ui/new_tab_ui.h +++ b/chrome/browser/dom_ui/new_tab_ui.h @@ -73,8 +73,9 @@ class NewTabUI : public DOMUI, // Whether this is the first run. static bool first_run_; - // Pointer back to the original profile. - Profile* profile_; + // We grab the HTML eagerly so we don't have to go back to the UI thread + // later. + scoped_refptr<RefCountedBytes> html_bytes_; DISALLOW_COPY_AND_ASSIGN(NewTabHTMLSource); }; |