Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/history/top_sites_impl.h" | 5 #include "chrome/browser/history/top_sites_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 619 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 630 // since this is almost always where it needs to go, unless the user's local | 630 // since this is almost always where it needs to go, unless the user's local |
| 631 // clock is fiddled with. | 631 // clock is fiddled with. |
| 632 MostVisitedURLList::iterator mid = new_list.begin() + num_forced; | 632 MostVisitedURLList::iterator mid = new_list.begin() + num_forced; |
| 633 new_list.insert(mid, new_url); | 633 new_list.insert(mid, new_url); |
| 634 mid = new_list.begin() + num_forced; // Mid was invalidated. | 634 mid = new_list.begin() + num_forced; // Mid was invalidated. |
| 635 std::inplace_merge(new_list.begin(), mid, mid + 1, ForcedURLComparator); | 635 std::inplace_merge(new_list.begin(), mid, mid + 1, ForcedURLComparator); |
| 636 SetTopSites(new_list); | 636 SetTopSites(new_list); |
| 637 return true; | 637 return true; |
| 638 } | 638 } |
| 639 | 639 |
| 640 Profile* TopSitesImpl::GetProfile() { | |
|
sdefresne
2014/08/04 08:47:18
Remove.
nshaik
2014/08/05 06:38:03
Done.
| |
| 641 return profile_; | |
| 642 } | |
| 643 | |
| 640 bool TopSitesImpl::AddPrepopulatedPages(MostVisitedURLList* urls, | 644 bool TopSitesImpl::AddPrepopulatedPages(MostVisitedURLList* urls, |
| 641 size_t num_forced_urls) { | 645 size_t num_forced_urls) { |
| 642 bool added = false; | 646 bool added = false; |
| 643 MostVisitedURLList prepopulate_urls = GetPrepopulatePages(); | 647 MostVisitedURLList prepopulate_urls = GetPrepopulatePages(); |
| 644 for (size_t i = 0; i < prepopulate_urls.size(); ++i) { | 648 for (size_t i = 0; i < prepopulate_urls.size(); ++i) { |
| 645 if (urls->size() - num_forced_urls < kNonForcedTopSitesNumber && | 649 if (urls->size() - num_forced_urls < kNonForcedTopSitesNumber && |
| 646 IndexOf(*urls, prepopulate_urls[i].url) == -1) { | 650 IndexOf(*urls, prepopulate_urls[i].url) == -1) { |
| 647 urls->push_back(prepopulate_urls[i]); | 651 urls->push_back(prepopulate_urls[i]); |
| 648 added = true; | 652 added = true; |
| 649 } | 653 } |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 867 filtered_urls_nonforced.assign(thread_safe_cache_->top_sites().begin() + | 871 filtered_urls_nonforced.assign(thread_safe_cache_->top_sites().begin() + |
| 868 thread_safe_cache_->GetNumForcedURLs(), | 872 thread_safe_cache_->GetNumForcedURLs(), |
| 869 thread_safe_cache_->top_sites().end()); | 873 thread_safe_cache_->top_sites().end()); |
| 870 pending_callbacks.swap(pending_callbacks_); | 874 pending_callbacks.swap(pending_callbacks_); |
| 871 } | 875 } |
| 872 } | 876 } |
| 873 | 877 |
| 874 for (size_t i = 0; i < pending_callbacks.size(); i++) | 878 for (size_t i = 0; i < pending_callbacks.size(); i++) |
| 875 pending_callbacks[i].Run(filtered_urls_all, filtered_urls_nonforced); | 879 pending_callbacks[i].Run(filtered_urls_all, filtered_urls_nonforced); |
| 876 | 880 |
| 877 content::NotificationService::current()->Notify( | 881 NotifyTopSitesLoaded(); |
| 878 chrome::NOTIFICATION_TOP_SITES_LOADED, | |
| 879 content::Source<Profile>(profile_), | |
| 880 content::Details<TopSites>(this)); | |
| 881 } | 882 } |
| 882 | 883 |
| 883 void TopSitesImpl::ResetThreadSafeCache() { | 884 void TopSitesImpl::ResetThreadSafeCache() { |
| 884 base::AutoLock lock(lock_); | 885 base::AutoLock lock(lock_); |
| 885 MostVisitedURLList cached; | 886 MostVisitedURLList cached; |
| 886 ApplyBlacklist(cache_->top_sites(), &cached); | 887 ApplyBlacklist(cache_->top_sites(), &cached); |
| 887 thread_safe_cache_->SetTopSites(cached); | 888 thread_safe_cache_->SetTopSites(cached); |
| 888 } | 889 } |
| 889 | 890 |
| 890 void TopSitesImpl::ResetThreadSafeImageCache() { | 891 void TopSitesImpl::ResetThreadSafeImageCache() { |
| 891 base::AutoLock lock(lock_); | 892 base::AutoLock lock(lock_); |
| 892 thread_safe_cache_->SetThumbnails(cache_->images()); | 893 thread_safe_cache_->SetThumbnails(cache_->images()); |
| 893 } | 894 } |
| 894 | 895 |
| 895 void TopSitesImpl::NotifyTopSitesChanged() { | |
| 896 content::NotificationService::current()->Notify( | |
| 897 chrome::NOTIFICATION_TOP_SITES_CHANGED, | |
| 898 content::Source<TopSites>(this), | |
| 899 content::NotificationService::NoDetails()); | |
| 900 } | |
| 901 | |
| 902 void TopSitesImpl::RestartQueryForTopSitesTimer(base::TimeDelta delta) { | 896 void TopSitesImpl::RestartQueryForTopSitesTimer(base::TimeDelta delta) { |
| 903 if (timer_.IsRunning() && ((timer_start_time_ + timer_.GetCurrentDelay()) < | 897 if (timer_.IsRunning() && ((timer_start_time_ + timer_.GetCurrentDelay()) < |
| 904 (base::TimeTicks::Now() + delta))) { | 898 (base::TimeTicks::Now() + delta))) { |
| 905 return; | 899 return; |
| 906 } | 900 } |
| 907 | 901 |
| 908 timer_start_time_ = base::TimeTicks::Now(); | 902 timer_start_time_ = base::TimeTicks::Now(); |
| 909 timer_.Stop(); | 903 timer_.Stop(); |
| 910 timer_.Start(FROM_HERE, delta, this, &TopSitesImpl::TimerFired); | 904 timer_.Start(FROM_HERE, delta, this, &TopSitesImpl::TimerFired); |
| 911 } | 905 } |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 929 base::TimeDelta::FromSeconds(kUpdateIntervalSecs)); | 923 base::TimeDelta::FromSeconds(kUpdateIntervalSecs)); |
| 930 } | 924 } |
| 931 | 925 |
| 932 void TopSitesImpl::OnTopSitesAvailableFromHistory( | 926 void TopSitesImpl::OnTopSitesAvailableFromHistory( |
| 933 const MostVisitedURLList* pages) { | 927 const MostVisitedURLList* pages) { |
| 934 DCHECK(pages); | 928 DCHECK(pages); |
| 935 SetTopSites(*pages); | 929 SetTopSites(*pages); |
| 936 } | 930 } |
| 937 | 931 |
| 938 } // namespace history | 932 } // namespace history |
| OLD | NEW |