Chromium Code Reviews| Index: components/precache/core/precache_database.cc |
| diff --git a/components/precache/core/precache_database.cc b/components/precache/core/precache_database.cc |
| index 8650262a405707f64b27a55199c29dec8995cdb6..b742796d36c5abd97f872266842be487aef87e65 100644 |
| --- a/components/precache/core/precache_database.cc |
| +++ b/components/precache/core/precache_database.cc |
| @@ -133,7 +133,7 @@ PrecacheReferrerHostEntry PrecacheDatabase::GetReferrerHost( |
| void PrecacheDatabase::GetURLListForReferrerHost( |
| int64_t referrer_host_id, |
| std::vector<GURL>* used_urls, |
| - std::vector<GURL>* unused_urls) { |
| + std::vector<GURL>* downloaded_urls) { |
| DCHECK(thread_checker_.CalledOnValidThread()); |
| DCHECK_NE(PrecacheReferrerHostEntry::kInvalidId, referrer_host_id); |
| @@ -141,7 +141,8 @@ void PrecacheDatabase::GetURLListForReferrerHost( |
| Flush(); |
| precache_url_table_.GetURLListForReferrerHost(referrer_host_id, used_urls, |
| - unused_urls); |
| + downloaded_urls); |
| + precache_url_table_.SetDownloadReported(referrer_host_id); |
| } |
| void PrecacheDatabase::RecordURLPrefetchMetrics( |
| @@ -196,11 +197,12 @@ void PrecacheDatabase::RecordURLPrefetch(const GURL& url, |
| // since it had no significant effect (besides a possible revalidation and a |
| // change in the cache LRU priority). If a row for the URL already exists, |
| // then the timestamp is updated. |
| + const PrecacheURLInfo info = precache_url_table_.GetURLInfo(url); |
| buffered_writes_.push_back(base::Bind( |
| &PrecacheDatabase::RecordURLPrefetchInternal, GetWeakPtr(), url, |
| - referrer_host, |
| - !was_cached || precache_url_table_.GetURLInfo(url).is_precached, |
| - fetch_time)); |
| + referrer_host, !was_cached || info.is_precached, fetch_time, |
| + // Reset to 0 only if is_precached && !was_cached. |
| + (!info.is_precached || was_cached) && info.is_download_reported)); |
|
twifkak
2016/12/20 22:48:09
Perhaps extract this logic to be more readable:
b
jamartin
2016/12/20 23:14:07
Done.
|
| buffered_urls_.insert(url.spec()); |
| MaybePostFlush(); |
| } |
| @@ -209,7 +211,8 @@ void PrecacheDatabase::RecordURLPrefetchInternal( |
| const GURL& url, |
| const std::string& referrer_host, |
| bool is_precached, |
| - const base::Time& fetch_time) { |
| + const base::Time& fetch_time, |
| + bool is_download_reported) { |
| int64_t referrer_host_id = |
| precache_referrer_host_table_.GetReferrerHost(referrer_host).id; |
| if (referrer_host_id == PrecacheReferrerHostEntry::kInvalidId) { |
| @@ -217,7 +220,8 @@ void PrecacheDatabase::RecordURLPrefetchInternal( |
| referrer_host, 0, fetch_time); |
| } |
| DCHECK_NE(referrer_host_id, PrecacheReferrerHostEntry::kInvalidId); |
| - precache_url_table_.AddURL(url, referrer_host_id, is_precached, fetch_time); |
| + precache_url_table_.AddURL(url, referrer_host_id, is_precached, fetch_time, |
| + is_download_reported); |
| } |
| void PrecacheDatabase::RecordURLNonPrefetch(const GURL& url, |
| @@ -337,6 +341,7 @@ void PrecacheDatabase::UpdatePrecacheReferrerHostInternal( |
| const base::Time& fetch_time) { |
| int64_t referrer_host_id = precache_referrer_host_table_.UpdateReferrerHost( |
| hostname, manifest_id, fetch_time); |
| + |
| if (referrer_host_id != PrecacheReferrerHostEntry::kInvalidId) { |
| precache_url_table_.ClearAllForReferrerHost(referrer_host_id); |
| } |