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 /chrome/browser/dom_ui/new_tab_ui.cc | |
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
Diffstat (limited to 'chrome/browser/dom_ui/new_tab_ui.cc')
-rw-r--r-- | chrome/browser/dom_ui/new_tab_ui.cc | 36 |
1 files changed, 19 insertions, 17 deletions
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_); } |