Commit e6a7869b authored by tburkard@chromium.org's avatar tburkard@chromium.org

B0;136;0cRe-enable TopSites in PrerenderManager, this time duplicating the invariant

observed in NTP (browser must have started).
R=sky, cbentzel
Review URL: http://codereview.chromium.org/7828023

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@99741 0039d316-1c4b-4281-b951-d872f2087c98
parent 27dec6f8
...@@ -164,6 +164,8 @@ TopSites::TopSites(Profile* profile) ...@@ -164,6 +164,8 @@ TopSites::TopSites(Profile* profile)
profile_->GetPrefs()->GetDictionary(prefs::kNTPMostVisitedURLsBlacklist); profile_->GetPrefs()->GetDictionary(prefs::kNTPMostVisitedURLsBlacklist);
pinned_urls_ = pinned_urls_ =
profile_->GetPrefs()->GetDictionary(prefs::kNTPMostVisitedPinnedURLs); profile_->GetPrefs()->GetDictionary(prefs::kNTPMostVisitedPinnedURLs);
DCHECK(blacklist_ != NULL);
DCHECK(pinned_urls_ != NULL);
} }
void TopSites::Init(const FilePath& db_name) { void TopSites::Init(const FilePath& db_name) {
......
...@@ -173,19 +173,6 @@ class PrerenderManager::MostVisitedSites : public NotificationObserver { ...@@ -173,19 +173,6 @@ class PrerenderManager::MostVisitedSites : public NotificationObserver {
public: public:
explicit MostVisitedSites(Profile* profile) : explicit MostVisitedSites(Profile* profile) :
profile_(profile) { profile_(profile) {
// If TopSites is already loaded, we will want to use it right away.
// Otherwise, wait for three seconds to avoid race conditions.
// This is a hack to ensure unit tests don't fail.
// See http://crbug.com/94654
if (profile && profile->GetTopSitesWithoutCreating()) {
Init();
} else {
timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(3), this,
&prerender::PrerenderManager::MostVisitedSites::Init);
}
}
void Init() {
history::TopSites* top_sites = GetTopSites(); history::TopSites* top_sites = GetTopSites();
if (top_sites) { if (top_sites) {
registrar_.Add(this, chrome::NOTIFICATION_TOP_SITES_CHANGED, registrar_.Add(this, chrome::NOTIFICATION_TOP_SITES_CHANGED,
...@@ -234,11 +221,12 @@ class PrerenderManager::MostVisitedSites : public NotificationObserver { ...@@ -234,11 +221,12 @@ class PrerenderManager::MostVisitedSites : public NotificationObserver {
Profile* profile_; Profile* profile_;
NotificationRegistrar registrar_; NotificationRegistrar registrar_;
std::set<GURL> urls_; std::set<GURL> urls_;
base::OneShotTimer<prerender::PrerenderManager::MostVisitedSites> timer_;
}; };
bool PrerenderManager::IsTopSite(const GURL& url) const { bool PrerenderManager::IsTopSite(const GURL& url) {
return most_visited_.get() && most_visited_->IsTopSite(url); if (!most_visited_.get())
most_visited_.reset(new MostVisitedSites(profile_));
return most_visited_->IsTopSite(url);
} }
PrerenderManager::PrerenderManager(Profile* profile, PrerenderManager::PrerenderManager(Profile* profile,
......
...@@ -204,7 +204,7 @@ class PrerenderManager : public base::SupportsWeakPtr<PrerenderManager>, ...@@ -204,7 +204,7 @@ class PrerenderManager : public base::SupportsWeakPtr<PrerenderManager>,
// Adds a condition. This is owned by the PrerenderManager. // Adds a condition. This is owned by the PrerenderManager.
void AddCondition(const PrerenderCondition* condition); void AddCondition(const PrerenderCondition* condition);
bool IsTopSite(const GURL& url) const; bool IsTopSite(const GURL& url);
protected: protected:
// Test that needs needs access to internal functions. // Test that needs needs access to internal functions.
......
...@@ -310,7 +310,7 @@ void PrerenderTabHelper::MaybeLogCurrentHover(bool was_used) { ...@@ -310,7 +310,7 @@ void PrerenderTabHelper::MaybeLogCurrentHover(bool was_used) {
current_hover_url_ = GURL(); current_hover_url_ = GURL();
} }
bool PrerenderTabHelper::IsTopSite(const GURL& url) const { bool PrerenderTabHelper::IsTopSite(const GURL& url) {
PrerenderManager* pm = MaybeGetPrerenderManager(); PrerenderManager* pm = MaybeGetPrerenderManager();
return (pm && pm->IsTopSite(url)); return (pm && pm->IsTopSite(url));
} }
......
...@@ -61,7 +61,7 @@ class PrerenderTabHelper : public TabContentsObserver { ...@@ -61,7 +61,7 @@ class PrerenderTabHelper : public TabContentsObserver {
// Also resets the hover to no hover. // Also resets the hover to no hover.
void MaybeLogCurrentHover(bool was_used); void MaybeLogCurrentHover(bool was_used);
bool IsTopSite(const GURL& url) const; bool IsTopSite(const GURL& url);
// TabContentsWrapper we're created for. // TabContentsWrapper we're created for.
TabContentsWrapper* tab_; TabContentsWrapper* tab_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment