| Index: chrome/browser/history/top_sites.cc
|
| diff --git a/chrome/browser/history/top_sites.cc b/chrome/browser/history/top_sites.cc
|
| index a95b71b66b54d019108f35b73202ef717e72f976..e6416dc6b5f3d5743c81268aa60f80eb0ef9568a 100644
|
| --- a/chrome/browser/history/top_sites.cc
|
| +++ b/chrome/browser/history/top_sites.cc
|
| @@ -141,7 +141,6 @@ TopSites::TopSites(Profile* profile)
|
| thread_safe_cache_(new TopSitesCache()),
|
| profile_(profile),
|
| last_num_urls_changed_(0),
|
| - pinned_urls_(NULL),
|
| history_state_(HISTORY_LOADING),
|
| top_sites_state_(TOP_SITES_LOADING),
|
| loaded_(false) {
|
| @@ -156,17 +155,6 @@ TopSites::TopSites(Profile* profile)
|
| registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED,
|
| content::NotificationService::AllSources());
|
| }
|
| -
|
| - // We create update objects here to be sure that dictionaries are created
|
| - // in the user preferences.
|
| - DictionaryPrefUpdate(profile_->GetPrefs(),
|
| - prefs::kNtpMostVisitedPinnedURLs).Get();
|
| -
|
| - // Now the dictionaries are guaranteed to exist and we can cache pointers
|
| - // to them.
|
| - pinned_urls_ =
|
| - profile_->GetPrefs()->GetDictionary(prefs::kNtpMostVisitedPinnedURLs);
|
| - DCHECK(pinned_urls_ != NULL);
|
| }
|
|
|
| void TopSites::Init(const FilePath& db_name) {
|
| @@ -314,7 +302,6 @@ void TopSites::MigrateFromHistory() {
|
| this,
|
| num_results_to_request_from_history()),
|
| &history_consumer_);
|
| - MigratePinnedURLs();
|
| }
|
|
|
| void TopSites::FinishHistoryMigration(const ThumbnailMigration& data) {
|
| @@ -388,7 +375,6 @@ bool TopSites::HasBlacklistedItems() const {
|
| void TopSites::AddBlacklistedURL(const GURL& url) {
|
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
|
|
| - RemovePinnedURL(url);
|
| Value* dummy = Value::CreateNullValue();
|
| {
|
| DictionaryPrefUpdate update(profile_->GetPrefs(),
|
| @@ -432,62 +418,6 @@ void TopSites::ClearBlacklistedURLs() {
|
| NotifyTopSitesChanged();
|
| }
|
|
|
| -void TopSites::AddPinnedURL(const GURL& url, size_t pinned_index) {
|
| - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| -
|
| - GURL old;
|
| - if (GetPinnedURLAtIndex(pinned_index, &old))
|
| - RemovePinnedURL(old);
|
| -
|
| - if (IsURLPinned(url))
|
| - RemovePinnedURL(url);
|
| -
|
| - Value* index = Value::CreateIntegerValue(pinned_index);
|
| -
|
| - {
|
| - DictionaryPrefUpdate update(profile_->GetPrefs(),
|
| - prefs::kNtpMostVisitedPinnedURLs);
|
| - DictionaryValue* pinned_urls = update.Get();
|
| - pinned_urls->SetWithoutPathExpansion(GetURLString(url), index);
|
| - }
|
| -
|
| - ResetThreadSafeCache();
|
| - NotifyTopSitesChanged();
|
| -}
|
| -
|
| -bool TopSites::IsURLPinned(const GURL& url) {
|
| - int tmp;
|
| - return pinned_urls_->GetIntegerWithoutPathExpansion(GetURLString(url), &tmp);
|
| -}
|
| -
|
| -void TopSites::RemovePinnedURL(const GURL& url) {
|
| - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| -
|
| - {
|
| - DictionaryPrefUpdate update(profile_->GetPrefs(),
|
| - prefs::kNtpMostVisitedPinnedURLs);
|
| - DictionaryValue* pinned_urls = update.Get();
|
| - pinned_urls->RemoveWithoutPathExpansion(GetURLString(url), NULL);
|
| - }
|
| -
|
| - ResetThreadSafeCache();
|
| - NotifyTopSitesChanged();
|
| -}
|
| -
|
| -bool TopSites::GetPinnedURLAtIndex(size_t index, GURL* url) {
|
| - for (DictionaryValue::key_iterator it = pinned_urls_->begin_keys();
|
| - it != pinned_urls_->end_keys(); ++it) {
|
| - int current_index;
|
| - if (pinned_urls_->GetIntegerWithoutPathExpansion(*it, ¤t_index)) {
|
| - if (static_cast<size_t>(current_index) == index) {
|
| - *url = GURL(*it);
|
| - return true;
|
| - }
|
| - }
|
| - }
|
| - return false;
|
| -}
|
| -
|
| void TopSites::Shutdown() {
|
| profile_ = NULL;
|
| // Cancel all requests so that the service doesn't callback to us after we've
|
| @@ -698,84 +628,11 @@ bool TopSites::AddPrepopulatedPages(MostVisitedURLList* urls) {
|
| return added;
|
| }
|
|
|
| -void TopSites::MigratePinnedURLs() {
|
| - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| -
|
| - std::map<GURL, size_t> tmp_map;
|
| - for (DictionaryValue::key_iterator it = pinned_urls_->begin_keys();
|
| - it != pinned_urls_->end_keys(); ++it) {
|
| - Value* value;
|
| - if (!pinned_urls_->GetWithoutPathExpansion(*it, &value))
|
| - continue;
|
| -
|
| - if (value->IsType(DictionaryValue::TYPE_DICTIONARY)) {
|
| - DictionaryValue* dict = static_cast<DictionaryValue*>(value);
|
| - std::string url_string;
|
| - int index;
|
| - if (dict->GetString("url", &url_string) &&
|
| - dict->GetInteger("index", &index))
|
| - tmp_map[GURL(url_string)] = index;
|
| - }
|
| - }
|
| -
|
| - {
|
| - DictionaryPrefUpdate update(profile_->GetPrefs(),
|
| - prefs::kNtpMostVisitedPinnedURLs);
|
| - DictionaryValue* pinned_urls = update.Get();
|
| - pinned_urls->Clear();
|
| - }
|
| -
|
| - for (std::map<GURL, size_t>::iterator it = tmp_map.begin();
|
| - it != tmp_map.end(); ++it)
|
| - AddPinnedURL(it->first, it->second);
|
| -}
|
| -
|
| -void TopSites::ApplyBlacklistAndPinnedURLs(const MostVisitedURLList& urls,
|
| - MostVisitedURLList* out) {
|
| - MostVisitedURLList urls_copy;
|
| - for (size_t i = 0; i < urls.size(); i++) {
|
| +void TopSites::ApplyBlacklist(const MostVisitedURLList& urls,
|
| + MostVisitedURLList* out) {
|
| + for (size_t i = 0; i < urls.size() && i < kTopSitesNumber; ++i) {
|
| if (!IsBlacklisted(urls[i].url))
|
| - urls_copy.push_back(urls[i]);
|
| - }
|
| -
|
| - for (size_t pinned_index = 0; pinned_index < kTopSitesNumber;
|
| - pinned_index++) {
|
| - GURL url;
|
| - bool found = GetPinnedURLAtIndex(pinned_index, &url);
|
| - if (!found)
|
| - continue;
|
| -
|
| - DCHECK(!url.is_empty());
|
| - int cur_index = IndexOf(urls_copy, url);
|
| - MostVisitedURL tmp;
|
| - if (cur_index < 0) {
|
| - // Pinned URL not in urls.
|
| - tmp.url = url;
|
| - } else {
|
| - tmp = urls_copy[cur_index];
|
| - urls_copy.erase(urls_copy.begin() + cur_index);
|
| - }
|
| - if (pinned_index > out->size())
|
| - out->resize(pinned_index); // Add empty URLs as fillers.
|
| - out->insert(out->begin() + pinned_index, tmp);
|
| - }
|
| -
|
| - // Add non-pinned URLs in the empty spots.
|
| - size_t current_url = 0; // Index into the remaining URLs in urls_copy.
|
| - for (size_t i = 0; i < kTopSitesNumber && current_url < urls_copy.size();
|
| - i++) {
|
| - if (i == out->size()) {
|
| - out->push_back(urls_copy[current_url]);
|
| - current_url++;
|
| - } else if (i < out->size()) {
|
| - if ((*out)[i].url.is_empty()) {
|
| - // Replace the filler
|
| - (*out)[i] = urls_copy[current_url];
|
| - current_url++;
|
| - }
|
| - } else {
|
| - NOTREACHED();
|
| - }
|
| + out->push_back(urls[i]);
|
| }
|
| }
|
|
|
| @@ -837,9 +694,7 @@ void TopSites::Observe(int type,
|
| MostVisitedURLList new_top_sites(cache_->top_sites());
|
| for (std::set<size_t>::reverse_iterator i = indices_to_delete.rbegin();
|
| i != indices_to_delete.rend(); i++) {
|
| - size_t index = *i;
|
| - RemovePinnedURL(new_top_sites[index].url);
|
| - new_top_sites.erase(new_top_sites.begin() + index);
|
| + new_top_sites.erase(new_top_sites.begin() + *i);
|
| }
|
| SetTopSites(new_top_sites);
|
| }
|
| @@ -954,7 +809,7 @@ void TopSites::MoveStateToLoaded() {
|
| void TopSites::ResetThreadSafeCache() {
|
| base::AutoLock lock(lock_);
|
| MostVisitedURLList cached;
|
| - ApplyBlacklistAndPinnedURLs(cache_->top_sites(), &cached);
|
| + ApplyBlacklist(cache_->top_sites(), &cached);
|
| thread_safe_cache_->SetTopSites(cached);
|
| }
|
|
|
|
|