Chromium Code Reviews| Index: chrome/browser/history/top_sites_impl.cc |
| diff --git a/chrome/browser/history/top_sites_impl.cc b/chrome/browser/history/top_sites_impl.cc |
| index 9eb3a00694f7a060f98cdb30e5dfadc134aca212..40f78fce1bd49afb2299049a584dc73725f7eefb 100644 |
| --- a/chrome/browser/history/top_sites_impl.cc |
| +++ b/chrome/browser/history/top_sites_impl.cc |
| @@ -607,6 +607,39 @@ bool TopSitesImpl::loaded() const { |
| return loaded_; |
| } |
| +bool TopSitesImpl::AddForcedURL(const GURL& url, const base::Time& time) { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + size_t num_forced = cache_->GetNumForcedURLs(); |
| + MostVisitedURLList new_list(cache_->top_sites()); |
| + MostVisitedURL new_url; |
| + |
| + if (cache_->IsKnownURL(url)) { |
| + size_t index = cache_->GetURLIndex(url); |
| + // Do nothing if we currently have that URL as non-forced. |
| + if (new_list[index].last_forced_time.is_null()) |
|
brettw
2013/11/19 06:38:09
Non-forced URLs might move around a lot. Will this
beaudoin
2013/11/19 11:59:46
I've thought about that. I don't think it will be
|
| + return false; |
| + |
| + // Update the |last_forced_time| of the already existing URL. Delete it and |
| + // reinsert it at the right location. |
| + new_url = new_list[index]; |
| + new_list.erase(new_list.begin() + index); |
| + num_forced--; |
| + } else { |
| + new_url.url = url; |
| + new_url.redirects.push_back(url); |
| + } |
| + new_url.last_forced_time = time; |
| + // Add forced URLs and sort. Added to the end of the list of forced URLs |
| + // since this is almost always where it needs to go, unless the user's local |
| + // clock is fiddled with. |
| + MostVisitedURLList::iterator mid = new_list.begin() + num_forced; |
| + new_list.insert(mid, new_url); |
| + mid = new_list.begin() + num_forced; // Mid was invalidated. |
| + std::inplace_merge(new_list.begin(), mid, mid + 1, ForcedURLComparator); |
| + SetTopSites(new_list); |
| + return true; |
| +} |
| + |
| bool TopSitesImpl::AddPrepopulatedPages(MostVisitedURLList* urls, |
| size_t num_forced_urls) { |
| bool added = false; |