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

Side by Side Diff: components/history/core/browser/top_sites_backend.cc

Issue 1018713002: Record the time to update top sites through db thread to understand if this is low and how slow it … (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments & pretty print histogram xml. Created 5 years, 9 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
« no previous file with comments | « no previous file | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
11 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
12 #include "base/metrics/histogram_macros.h"
12 #include "base/single_thread_task_runner.h" 13 #include "base/single_thread_task_runner.h"
13 #include "base/task/cancelable_task_tracker.h" 14 #include "base/task/cancelable_task_tracker.h"
15 #include "base/trace_event/trace_event.h"
14 #include "components/history/core/browser/top_sites_database.h" 16 #include "components/history/core/browser/top_sites_database.h"
15 #include "sql/connection.h" 17 #include "sql/connection.h"
16 18
17 namespace history { 19 namespace history {
18 20
19 TopSitesBackend::TopSitesBackend( 21 TopSitesBackend::TopSitesBackend(
20 const scoped_refptr<base::SingleThreadTaskRunner>& db_task_runner) 22 const scoped_refptr<base::SingleThreadTaskRunner>& db_task_runner)
21 : db_(new TopSitesDatabase()), db_task_runner_(db_task_runner) { 23 : db_(new TopSitesDatabase()), db_task_runner_(db_task_runner) {
22 DCHECK(db_task_runner_); 24 DCHECK(db_task_runner_);
23 } 25 }
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 scoped_refptr<MostVisitedThumbnails> thumbnails) { 94 scoped_refptr<MostVisitedThumbnails> thumbnails) {
93 DCHECK(db_task_runner_->BelongsToCurrentThread()); 95 DCHECK(db_task_runner_->BelongsToCurrentThread());
94 96
95 if (db_) { 97 if (db_) {
96 db_->GetPageThumbnails(&(thumbnails->most_visited), 98 db_->GetPageThumbnails(&(thumbnails->most_visited),
97 &(thumbnails->url_to_images_map)); 99 &(thumbnails->url_to_images_map));
98 } 100 }
99 } 101 }
100 102
101 void TopSitesBackend::UpdateTopSitesOnDBThread(const TopSitesDelta& delta) { 103 void TopSitesBackend::UpdateTopSitesOnDBThread(const TopSitesDelta& delta) {
104 TRACE_EVENT0("startup", "history::TopSitesBackend::UpdateTopSitesOnDBThread");
105
102 if (!db_) 106 if (!db_)
103 return; 107 return;
104 108
109 // TODO(yiyaoliu): Remove the histogram and related code when crbug/223430 is
110 // fixed.
111 base::Time begin_time = base::Time::Now();
sky 2015/03/20 14:58:22 Shouldn't we use timeticks for this sort of stuff?
yao 2015/03/20 18:06:01 Done.
112
105 for (size_t i = 0; i < delta.deleted.size(); ++i) 113 for (size_t i = 0; i < delta.deleted.size(); ++i)
106 db_->RemoveURL(delta.deleted[i]); 114 db_->RemoveURL(delta.deleted[i]);
107 115
108 for (size_t i = 0; i < delta.added.size(); ++i) 116 for (size_t i = 0; i < delta.added.size(); ++i)
109 db_->SetPageThumbnail(delta.added[i].url, delta.added[i].rank, Images()); 117 db_->SetPageThumbnail(delta.added[i].url, delta.added[i].rank, Images());
110 118
111 for (size_t i = 0; i < delta.moved.size(); ++i) 119 for (size_t i = 0; i < delta.moved.size(); ++i)
112 db_->UpdatePageRank(delta.moved[i].url, delta.moved[i].rank); 120 db_->UpdatePageRank(delta.moved[i].url, delta.moved[i].rank);
121
122 UMA_HISTOGRAM_TIMES("History.UpdateTopSitesOnDBThreadTime",
123 base::Time::Now() - begin_time);
113 } 124 }
114 125
115 void TopSitesBackend::SetPageThumbnailOnDBThread(const MostVisitedURL& url, 126 void TopSitesBackend::SetPageThumbnailOnDBThread(const MostVisitedURL& url,
116 int url_rank, 127 int url_rank,
117 const Images& thumbnail) { 128 const Images& thumbnail) {
118 if (!db_) 129 if (!db_)
119 return; 130 return;
120 131
121 db_->SetPageThumbnail(url, url_rank, thumbnail); 132 db_->SetPageThumbnail(url, url_rank, thumbnail);
122 } 133 }
123 134
124 void TopSitesBackend::ResetDatabaseOnDBThread(const base::FilePath& file_path) { 135 void TopSitesBackend::ResetDatabaseOnDBThread(const base::FilePath& file_path) {
125 DCHECK(db_task_runner_->BelongsToCurrentThread()); 136 DCHECK(db_task_runner_->BelongsToCurrentThread());
126 db_.reset(NULL); 137 db_.reset(NULL);
127 sql::Connection::Delete(db_path_); 138 sql::Connection::Delete(db_path_);
128 db_.reset(new TopSitesDatabase()); 139 db_.reset(new TopSitesDatabase());
129 InitDBOnDBThread(db_path_); 140 InitDBOnDBThread(db_path_);
130 } 141 }
131 142
132 } // namespace history 143 } // namespace history
OLDNEW
« no previous file with comments | « no previous file | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698