Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(72)

Side by Side Diff: chrome/browser/history/top_sites_impl.cc

Issue 1005873011: Only record the execution time during startup. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments. Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 607 matching lines...) Expand 10 before | Expand all | Expand 10 after
618 new_url.redirects.push_back(url); 618 new_url.redirects.push_back(url);
619 } 619 }
620 new_url.last_forced_time = time; 620 new_url.last_forced_time = time;
621 // Add forced URLs and sort. Added to the end of the list of forced URLs 621 // Add forced URLs and sort. Added to the end of the list of forced URLs
622 // since this is almost always where it needs to go, unless the user's local 622 // since this is almost always where it needs to go, unless the user's local
623 // clock is fiddled with. 623 // clock is fiddled with.
624 MostVisitedURLList::iterator mid = new_list.begin() + num_forced; 624 MostVisitedURLList::iterator mid = new_list.begin() + num_forced;
625 new_list.insert(mid, new_url); 625 new_list.insert(mid, new_url);
626 mid = new_list.begin() + num_forced; // Mid was invalidated. 626 mid = new_list.begin() + num_forced; // Mid was invalidated.
627 std::inplace_merge(new_list.begin(), mid, mid + 1, ForcedURLComparator); 627 std::inplace_merge(new_list.begin(), mid, mid + 1, ForcedURLComparator);
628 SetTopSites(new_list); 628 SetTopSites(new_list, TopSitesBackend::fomOtherPlaces);
629 return true; 629 return true;
630 } 630 }
631 631
632 bool TopSitesImpl::AddPrepopulatedPages(MostVisitedURLList* urls, 632 bool TopSitesImpl::AddPrepopulatedPages(MostVisitedURLList* urls,
633 size_t num_forced_urls) { 633 size_t num_forced_urls) {
634 bool added = false; 634 bool added = false;
635 for (const auto& prepopulated_page : prepopulated_pages_) { 635 for (const auto& prepopulated_page : prepopulated_pages_) {
636 if (urls->size() - num_forced_urls < kNonForcedTopSitesNumber && 636 if (urls->size() - num_forced_urls < kNonForcedTopSitesNumber &&
637 IndexOf(*urls, prepopulated_page.most_visited.url) == -1) { 637 IndexOf(*urls, prepopulated_page.most_visited.url) == -1) {
638 urls->push_back(prepopulated_page.most_visited); 638 urls->push_back(prepopulated_page.most_visited);
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
745 return; 745 return;
746 const GURL& url = load_details->entry->GetURL(); 746 const GURL& url = load_details->entry->GetURL();
747 if (!cache_->IsKnownURL(url) && CanAddURLToHistory(url)) { 747 if (!cache_->IsKnownURL(url) && CanAddURLToHistory(url)) {
748 // To avoid slamming history we throttle requests when the url updates. 748 // To avoid slamming history we throttle requests when the url updates.
749 // To do otherwise negatively impacts perf tests. 749 // To do otherwise negatively impacts perf tests.
750 RestartQueryForTopSitesTimer(GetUpdateDelay()); 750 RestartQueryForTopSitesTimer(GetUpdateDelay());
751 } 751 }
752 } 752 }
753 } 753 }
754 754
755 void TopSitesImpl::SetTopSites(const MostVisitedURLList& new_top_sites) { 755 void TopSitesImpl::SetTopSites(
756 const MostVisitedURLList& new_top_sites,
757 const TopSitesBackend::TopSitesCalledLocation location) {
756 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 758 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
757 759
758 MostVisitedURLList top_sites(new_top_sites); 760 MostVisitedURLList top_sites(new_top_sites);
759 size_t num_forced_urls = MergeCachedForcedURLs(&top_sites); 761 size_t num_forced_urls = MergeCachedForcedURLs(&top_sites);
760 AddPrepopulatedPages(&top_sites, num_forced_urls); 762 AddPrepopulatedPages(&top_sites, num_forced_urls);
761 763
762 TopSitesDelta delta; 764 TopSitesDelta delta;
763 DiffMostVisited(cache_->top_sites(), top_sites, &delta); 765 DiffMostVisited(cache_->top_sites(), top_sites, &delta);
764 if (!delta.deleted.empty() || !delta.added.empty() || !delta.moved.empty()) { 766 if (!delta.deleted.empty() || !delta.added.empty() || !delta.moved.empty()) {
765 backend_->UpdateTopSites(delta); 767 backend_->UpdateTopSites(delta, location);
768 }
769
770 // Record the delta size into a histogram if this function is called from
771 // function OnGotMostVisitedThumbnails.
772 if (location == TopSitesBackend::fromOnGotMostVisitedThumbnails) {
773 size_t delta_size =
774 delta.deleted.size() + delta.added.size() + delta.moved.size();
775 UMA_HISTOGRAM_COUNTS_100(
776 "History.UpdateTopSitesOnDBThread_Startup_DeltaSize", delta_size);
sky 2015/04/01 22:51:48 The name seems to indicate you want this only at s
yao 2015/04/02 17:20:31 Right, I guess we could get the number of profiles
sky 2015/04/02 18:22:18 What about a static?
yao 2015/04/02 19:37:30 Like a static class member, that indicates whether
766 } 777 }
767 778
768 last_num_urls_changed_ = delta.added.size() + delta.moved.size(); 779 last_num_urls_changed_ = delta.added.size() + delta.moved.size();
769 780
770 // We always do the following steps (setting top sites in cache, and resetting 781 // We always do the following steps (setting top sites in cache, and resetting
771 // thread safe cache ...) as this method is invoked during startup at which 782 // thread safe cache ...) as this method is invoked during startup at which
772 // point the caches haven't been updated yet. 783 // point the caches haven't been updated yet.
773 cache_->SetTopSites(top_sites); 784 cache_->SetTopSites(top_sites);
774 785
775 // See if we have any tmp thumbnails for the new sites. 786 // See if we have any tmp thumbnails for the new sites.
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
872 timer_.Start(FROM_HERE, delta, this, &TopSitesImpl::TimerFired); 883 timer_.Start(FROM_HERE, delta, this, &TopSitesImpl::TimerFired);
873 } 884 }
874 885
875 void TopSitesImpl::OnGotMostVisitedThumbnails( 886 void TopSitesImpl::OnGotMostVisitedThumbnails(
876 const scoped_refptr<MostVisitedThumbnails>& thumbnails) { 887 const scoped_refptr<MostVisitedThumbnails>& thumbnails) {
877 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 888 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
878 889
879 // Set the top sites directly in the cache so that SetTopSites diffs 890 // Set the top sites directly in the cache so that SetTopSites diffs
880 // correctly. 891 // correctly.
881 cache_->SetTopSites(thumbnails->most_visited); 892 cache_->SetTopSites(thumbnails->most_visited);
882 SetTopSites(thumbnails->most_visited); 893 SetTopSites(thumbnails->most_visited,
894 TopSitesBackend::fromOnGotMostVisitedThumbnails);
883 cache_->SetThumbnails(thumbnails->url_to_images_map); 895 cache_->SetThumbnails(thumbnails->url_to_images_map);
884 896
885 ResetThreadSafeImageCache(); 897 ResetThreadSafeImageCache();
886 898
887 MoveStateToLoaded(); 899 MoveStateToLoaded();
888 900
889 // Start a timer that refreshes top sites from history. 901 // Start a timer that refreshes top sites from history.
890 RestartQueryForTopSitesTimer( 902 RestartQueryForTopSitesTimer(
891 base::TimeDelta::FromSeconds(kUpdateIntervalSecs)); 903 base::TimeDelta::FromSeconds(kUpdateIntervalSecs));
892 } 904 }
893 905
894 void TopSitesImpl::OnTopSitesAvailableFromHistory( 906 void TopSitesImpl::OnTopSitesAvailableFromHistory(
895 const MostVisitedURLList* pages) { 907 const MostVisitedURLList* pages) {
896 DCHECK(pages); 908 DCHECK(pages);
897 SetTopSites(*pages); 909 SetTopSites(*pages, TopSitesBackend::fomOtherPlaces);
898 } 910 }
899 911
900 void TopSitesImpl::OnURLsDeleted(HistoryService* history_service, 912 void TopSitesImpl::OnURLsDeleted(HistoryService* history_service,
901 bool all_history, 913 bool all_history,
902 bool expired, 914 bool expired,
903 const URLRows& deleted_rows, 915 const URLRows& deleted_rows,
904 const std::set<GURL>& favicon_urls) { 916 const std::set<GURL>& favicon_urls) {
905 if (!loaded_) 917 if (!loaded_)
906 return; 918 return;
907 919
908 if (all_history) { 920 if (all_history) {
909 SetTopSites(MostVisitedURLList()); 921 SetTopSites(MostVisitedURLList(), TopSitesBackend::fomOtherPlaces);
910 backend_->ResetDatabase(); 922 backend_->ResetDatabase();
911 } else { 923 } else {
912 std::set<size_t> indices_to_delete; // Indices into top_sites_. 924 std::set<size_t> indices_to_delete; // Indices into top_sites_.
913 for (const auto& row : deleted_rows) { 925 for (const auto& row : deleted_rows) {
914 if (cache_->IsKnownURL(row.url())) 926 if (cache_->IsKnownURL(row.url()))
915 indices_to_delete.insert(cache_->GetURLIndex(row.url())); 927 indices_to_delete.insert(cache_->GetURLIndex(row.url()));
916 } 928 }
917 929
918 if (indices_to_delete.empty()) 930 if (indices_to_delete.empty())
919 return; 931 return;
920 932
921 MostVisitedURLList new_top_sites(cache_->top_sites()); 933 MostVisitedURLList new_top_sites(cache_->top_sites());
922 for (std::set<size_t>::reverse_iterator i = indices_to_delete.rbegin(); 934 for (std::set<size_t>::reverse_iterator i = indices_to_delete.rbegin();
923 i != indices_to_delete.rend(); i++) { 935 i != indices_to_delete.rend(); i++) {
924 new_top_sites.erase(new_top_sites.begin() + *i); 936 new_top_sites.erase(new_top_sites.begin() + *i);
925 } 937 }
926 SetTopSites(new_top_sites); 938 SetTopSites(new_top_sites, TopSitesBackend::fomOtherPlaces);
927 } 939 }
928 StartQueryForMostVisited(); 940 StartQueryForMostVisited();
929 } 941 }
930 942
931 void TopSitesImpl::HistoryServiceBeingDeleted(HistoryService* history_service) { 943 void TopSitesImpl::HistoryServiceBeingDeleted(HistoryService* history_service) {
932 history_service_observer_.Remove(history_service); 944 history_service_observer_.Remove(history_service);
933 } 945 }
934 946
935 } // namespace history 947 } // namespace history
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698