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

Side by Side Diff: components/history/core/browser/top_sites_backend.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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "components/history/core/browser/top_sites_backend.h" 5 #include "components/history/core/browser/top_sites_backend.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/location.h" 10 #include "base/location.h"
(...skipping 29 matching lines...) Expand all
40 const GetMostVisitedThumbnailsCallback& callback, 40 const GetMostVisitedThumbnailsCallback& callback,
41 base::CancelableTaskTracker* tracker) { 41 base::CancelableTaskTracker* tracker) {
42 scoped_refptr<MostVisitedThumbnails> thumbnails = new MostVisitedThumbnails(); 42 scoped_refptr<MostVisitedThumbnails> thumbnails = new MostVisitedThumbnails();
43 tracker->PostTaskAndReply( 43 tracker->PostTaskAndReply(
44 db_task_runner_.get(), FROM_HERE, 44 db_task_runner_.get(), FROM_HERE,
45 base::Bind(&TopSitesBackend::GetMostVisitedThumbnailsOnDBThread, this, 45 base::Bind(&TopSitesBackend::GetMostVisitedThumbnailsOnDBThread, this,
46 thumbnails), 46 thumbnails),
47 base::Bind(callback, thumbnails)); 47 base::Bind(callback, thumbnails));
48 } 48 }
49 49
50 void TopSitesBackend::UpdateTopSites(const TopSitesDelta& delta) { 50 void TopSitesBackend::UpdateTopSites(const TopSitesDelta& delta,
51 const TopSitesCalledLocation location) {
51 db_task_runner_->PostTask( 52 db_task_runner_->PostTask(
52 FROM_HERE, 53 FROM_HERE,
53 base::Bind(&TopSitesBackend::UpdateTopSitesOnDBThread, this, delta)); 54 base::Bind(&TopSitesBackend::UpdateTopSitesOnDBThread, this, delta,
55 location));
54 } 56 }
55 57
56 void TopSitesBackend::SetPageThumbnail(const MostVisitedURL& url, 58 void TopSitesBackend::SetPageThumbnail(const MostVisitedURL& url,
57 int url_rank, 59 int url_rank,
58 const Images& thumbnail) { 60 const Images& thumbnail) {
59 db_task_runner_->PostTask( 61 db_task_runner_->PostTask(
60 FROM_HERE, base::Bind(&TopSitesBackend::SetPageThumbnailOnDBThread, this, 62 FROM_HERE, base::Bind(&TopSitesBackend::SetPageThumbnailOnDBThread, this,
61 url, url_rank, thumbnail)); 63 url, url_rank, thumbnail));
62 } 64 }
63 65
(...skipping 30 matching lines...) Expand all
94 void TopSitesBackend::GetMostVisitedThumbnailsOnDBThread( 96 void TopSitesBackend::GetMostVisitedThumbnailsOnDBThread(
95 scoped_refptr<MostVisitedThumbnails> thumbnails) { 97 scoped_refptr<MostVisitedThumbnails> thumbnails) {
96 DCHECK(db_task_runner_->BelongsToCurrentThread()); 98 DCHECK(db_task_runner_->BelongsToCurrentThread());
97 99
98 if (db_) { 100 if (db_) {
99 db_->GetPageThumbnails(&(thumbnails->most_visited), 101 db_->GetPageThumbnails(&(thumbnails->most_visited),
100 &(thumbnails->url_to_images_map)); 102 &(thumbnails->url_to_images_map));
101 } 103 }
102 } 104 }
103 105
104 void TopSitesBackend::UpdateTopSitesOnDBThread(const TopSitesDelta& delta) { 106 void TopSitesBackend::UpdateTopSitesOnDBThread(
107 const TopSitesDelta& delta, const TopSitesCalledLocation location) {
105 TRACE_EVENT0("startup", "history::TopSitesBackend::UpdateTopSitesOnDBThread"); 108 TRACE_EVENT0("startup", "history::TopSitesBackend::UpdateTopSitesOnDBThread");
106 109
107 if (!db_) 110 if (!db_)
108 return; 111 return;
109 112
110 // TODO(yiyaoliu): Remove the histogram and related code when crbug/223430 is 113 // TODO(yiyaoliu): Remove the histogram and related code when crbug/223430 is
111 // fixed. 114 // fixed.
112 base::TimeTicks begin_time = base::TimeTicks::Now(); 115 base::TimeTicks begin_time = base::TimeTicks::Now();
113 116
114 for (size_t i = 0; i < delta.deleted.size(); ++i) 117 for (size_t i = 0; i < delta.deleted.size(); ++i)
115 db_->RemoveURL(delta.deleted[i]); 118 db_->RemoveURL(delta.deleted[i]);
116 119
117 for (size_t i = 0; i < delta.added.size(); ++i) 120 for (size_t i = 0; i < delta.added.size(); ++i)
118 db_->SetPageThumbnail(delta.added[i].url, delta.added[i].rank, Images()); 121 db_->SetPageThumbnail(delta.added[i].url, delta.added[i].rank, Images());
119 122
120 for (size_t i = 0; i < delta.moved.size(); ++i) 123 for (size_t i = 0; i < delta.moved.size(); ++i)
121 db_->UpdatePageRank(delta.moved[i].url, delta.moved[i].rank); 124 db_->UpdatePageRank(delta.moved[i].url, delta.moved[i].rank);
122 125
123 UMA_HISTOGRAM_TIMES("History.UpdateTopSitesOnDBThreadTime", 126 // If this is initiated from TopSitesImpl::OnGotMostVisitedThumbnails, record
124 base::TimeTicks::Now() - begin_time); 127 // the function execution time.
128 if (location == fromOnGotMostVisitedThumbnails) {
129 UMA_HISTOGRAM_TIMES("History.UpdateTopSitesOnDBThread_Startup_Time",
130 base::TimeTicks::Now() - begin_time);
131 }
125 } 132 }
126 133
127 void TopSitesBackend::SetPageThumbnailOnDBThread(const MostVisitedURL& url, 134 void TopSitesBackend::SetPageThumbnailOnDBThread(const MostVisitedURL& url,
128 int url_rank, 135 int url_rank,
129 const Images& thumbnail) { 136 const Images& thumbnail) {
130 if (!db_) 137 if (!db_)
131 return; 138 return;
132 139
133 db_->SetPageThumbnail(url, url_rank, thumbnail); 140 db_->SetPageThumbnail(url, url_rank, thumbnail);
134 } 141 }
135 142
136 void TopSitesBackend::ResetDatabaseOnDBThread(const base::FilePath& file_path) { 143 void TopSitesBackend::ResetDatabaseOnDBThread(const base::FilePath& file_path) {
137 DCHECK(db_task_runner_->BelongsToCurrentThread()); 144 DCHECK(db_task_runner_->BelongsToCurrentThread());
138 db_.reset(NULL); 145 db_.reset(NULL);
139 sql::Connection::Delete(db_path_); 146 sql::Connection::Delete(db_path_);
140 db_.reset(new TopSitesDatabase()); 147 db_.reset(new TopSitesDatabase());
141 InitDBOnDBThread(db_path_); 148 InitDBOnDBThread(db_path_);
142 } 149 }
143 150
144 } // namespace history 151 } // namespace history
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698