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

Side by Side Diff: components/precache/core/precache_database.cc

Issue 2586813004: Report downloaded resources at most once (Closed)
Patch Set: Improved tests Created 4 years 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 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 "components/precache/core/precache_database.h" 5 #include "components/precache/core/precache_database.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "base/metrics/histogram_macros.h" 10 #include "base/metrics/histogram_macros.h"
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 126
127 PrecacheReferrerHostEntry PrecacheDatabase::GetReferrerHost( 127 PrecacheReferrerHostEntry PrecacheDatabase::GetReferrerHost(
128 const std::string& referrer_host) { 128 const std::string& referrer_host) {
129 DCHECK(thread_checker_.CalledOnValidThread()); 129 DCHECK(thread_checker_.CalledOnValidThread());
130 return precache_referrer_host_table_.GetReferrerHost(referrer_host); 130 return precache_referrer_host_table_.GetReferrerHost(referrer_host);
131 } 131 }
132 132
133 void PrecacheDatabase::GetURLListForReferrerHost( 133 void PrecacheDatabase::GetURLListForReferrerHost(
134 int64_t referrer_host_id, 134 int64_t referrer_host_id,
135 std::vector<GURL>* used_urls, 135 std::vector<GURL>* used_urls,
136 std::vector<GURL>* unused_urls) { 136 std::vector<GURL>* downloaded_urls) {
137 DCHECK(thread_checker_.CalledOnValidThread()); 137 DCHECK(thread_checker_.CalledOnValidThread());
138 DCHECK_NE(PrecacheReferrerHostEntry::kInvalidId, referrer_host_id); 138 DCHECK_NE(PrecacheReferrerHostEntry::kInvalidId, referrer_host_id);
139 139
140 // Flush any pending writes to the URL and referrer host tables. 140 // Flush any pending writes to the URL and referrer host tables.
141 Flush(); 141 Flush();
142 142
143 precache_url_table_.GetURLListForReferrerHost(referrer_host_id, used_urls, 143 precache_url_table_.GetURLListForReferrerHost(referrer_host_id, used_urls,
144 unused_urls); 144 downloaded_urls);
145 precache_url_table_.SetDownloadReported(referrer_host_id);
145 } 146 }
146 147
147 void PrecacheDatabase::RecordURLPrefetchMetrics( 148 void PrecacheDatabase::RecordURLPrefetchMetrics(
148 const net::HttpResponseInfo& info, 149 const net::HttpResponseInfo& info,
149 const base::TimeDelta& latency) { 150 const base::TimeDelta& latency) {
150 DCHECK(thread_checker_.CalledOnValidThread()); 151 DCHECK(thread_checker_.CalledOnValidThread());
151 152
152 UMA_HISTOGRAM_TIMES("Precache.Latency.Prefetch", latency); 153 UMA_HISTOGRAM_TIMES("Precache.Latency.Prefetch", latency);
153 154
154 DCHECK(info.headers) << "The headers are required to get the freshness."; 155 DCHECK(info.headers) << "The headers are required to get the freshness.";
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 } 190 }
190 191
191 // Use the URL table to keep track of URLs. URLs that are fetched via network 192 // Use the URL table to keep track of URLs. URLs that are fetched via network
192 // or already in the cache due to prior precaching are recorded as 193 // or already in the cache due to prior precaching are recorded as
193 // precache-motivated. URLs that came from the cache and not recorded as 194 // precache-motivated. URLs that came from the cache and not recorded as
194 // precached previously, were already in the cache because of user browsing. 195 // precached previously, were already in the cache because of user browsing.
195 // Therefore, this precache will not be considered as precache-motivated, 196 // Therefore, this precache will not be considered as precache-motivated,
196 // since it had no significant effect (besides a possible revalidation and a 197 // since it had no significant effect (besides a possible revalidation and a
197 // change in the cache LRU priority). If a row for the URL already exists, 198 // change in the cache LRU priority). If a row for the URL already exists,
198 // then the timestamp is updated. 199 // then the timestamp is updated.
199 buffered_writes_.push_back(base::Bind( 200 const PrecacheURLInfo info = precache_url_table_.GetURLInfo(url);
200 &PrecacheDatabase::RecordURLPrefetchInternal, GetWeakPtr(), url, 201 bool is_download_reported = info.is_download_reported;
201 referrer_host, 202 if (info.is_precached && !was_cached) {
202 !was_cached || precache_url_table_.GetURLInfo(url).is_precached, 203 is_download_reported = false;
203 fetch_time)); 204 }
205 buffered_writes_.push_back(
206 base::Bind(&PrecacheDatabase::RecordURLPrefetchInternal, GetWeakPtr(),
207 url, referrer_host, !was_cached || info.is_precached,
208 fetch_time, is_download_reported));
204 buffered_urls_.insert(url.spec()); 209 buffered_urls_.insert(url.spec());
205 MaybePostFlush(); 210 MaybePostFlush();
206 } 211 }
207 212
208 void PrecacheDatabase::RecordURLPrefetchInternal( 213 void PrecacheDatabase::RecordURLPrefetchInternal(
209 const GURL& url, 214 const GURL& url,
210 const std::string& referrer_host, 215 const std::string& referrer_host,
211 bool is_precached, 216 bool is_precached,
212 const base::Time& fetch_time) { 217 const base::Time& fetch_time,
218 bool is_download_reported) {
213 int64_t referrer_host_id = 219 int64_t referrer_host_id =
214 precache_referrer_host_table_.GetReferrerHost(referrer_host).id; 220 precache_referrer_host_table_.GetReferrerHost(referrer_host).id;
215 if (referrer_host_id == PrecacheReferrerHostEntry::kInvalidId) { 221 if (referrer_host_id == PrecacheReferrerHostEntry::kInvalidId) {
216 referrer_host_id = precache_referrer_host_table_.UpdateReferrerHost( 222 referrer_host_id = precache_referrer_host_table_.UpdateReferrerHost(
217 referrer_host, 0, fetch_time); 223 referrer_host, 0, fetch_time);
218 } 224 }
219 DCHECK_NE(referrer_host_id, PrecacheReferrerHostEntry::kInvalidId); 225 DCHECK_NE(referrer_host_id, PrecacheReferrerHostEntry::kInvalidId);
220 precache_url_table_.AddURL(url, referrer_host_id, is_precached, fetch_time); 226 precache_url_table_.AddURL(url, referrer_host_id, is_precached, fetch_time,
227 is_download_reported);
221 } 228 }
222 229
223 void PrecacheDatabase::RecordURLNonPrefetch(const GURL& url, 230 void PrecacheDatabase::RecordURLNonPrefetch(const GURL& url,
224 const base::TimeDelta& latency, 231 const base::TimeDelta& latency,
225 const base::Time& fetch_time, 232 const base::Time& fetch_time,
226 const net::HttpResponseInfo& info, 233 const net::HttpResponseInfo& info,
227 int64_t size, 234 int64_t size,
228 int host_rank, 235 int host_rank,
229 bool is_connection_cellular) { 236 bool is_connection_cellular) {
230 UMA_HISTOGRAM_TIMES("Precache.Latency.NonPrefetch", latency); 237 UMA_HISTOGRAM_TIMES("Precache.Latency.NonPrefetch", latency);
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 GetWeakPtr(), hostname, manifest_id, fetch_time)); 337 GetWeakPtr(), hostname, manifest_id, fetch_time));
331 MaybePostFlush(); 338 MaybePostFlush();
332 } 339 }
333 340
334 void PrecacheDatabase::UpdatePrecacheReferrerHostInternal( 341 void PrecacheDatabase::UpdatePrecacheReferrerHostInternal(
335 const std::string& hostname, 342 const std::string& hostname,
336 int64_t manifest_id, 343 int64_t manifest_id,
337 const base::Time& fetch_time) { 344 const base::Time& fetch_time) {
338 int64_t referrer_host_id = precache_referrer_host_table_.UpdateReferrerHost( 345 int64_t referrer_host_id = precache_referrer_host_table_.UpdateReferrerHost(
339 hostname, manifest_id, fetch_time); 346 hostname, manifest_id, fetch_time);
347
340 if (referrer_host_id != PrecacheReferrerHostEntry::kInvalidId) { 348 if (referrer_host_id != PrecacheReferrerHostEntry::kInvalidId) {
341 precache_url_table_.ClearAllForReferrerHost(referrer_host_id); 349 precache_url_table_.ClearAllForReferrerHost(referrer_host_id);
342 } 350 }
343 } 351 }
344 352
345 void PrecacheDatabase::RecordTimeSinceLastPrecache( 353 void PrecacheDatabase::RecordTimeSinceLastPrecache(
346 const base::Time& fetch_time) { 354 const base::Time& fetch_time) {
347 const base::Time& last_precache_timestamp = GetLastPrecacheTimestamp(); 355 const base::Time& last_precache_timestamp = GetLastPrecacheTimestamp();
348 // It could still be null if the DB was not accessible. 356 // It could still be null if the DB was not accessible.
349 if (!last_precache_timestamp.is_null()) { 357 if (!last_precache_timestamp.is_null()) {
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 453
446 PrecacheQuota PrecacheDatabase::GetQuota() { 454 PrecacheQuota PrecacheDatabase::GetQuota() {
447 return precache_session_table_.GetQuota(); 455 return precache_session_table_.GetQuota();
448 } 456 }
449 457
450 base::WeakPtr<PrecacheDatabase> PrecacheDatabase::GetWeakPtr() { 458 base::WeakPtr<PrecacheDatabase> PrecacheDatabase::GetWeakPtr() {
451 return weak_factory_.GetWeakPtr(); 459 return weak_factory_.GetWeakPtr();
452 } 460 }
453 461
454 } // namespace precache 462 } // namespace precache
OLDNEW
« no previous file with comments | « components/precache/core/precache_database.h ('k') | components/precache/core/precache_database_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698