| OLD | NEW |
| 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 Loading... |
| 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 } | 145 } |
| 146 | 146 |
| 147 void PrecacheDatabase::RecordURLPrefetchMetrics( | 147 void PrecacheDatabase::RecordURLPrefetchMetrics( |
| 148 const net::HttpResponseInfo& info, | 148 const net::HttpResponseInfo& info, |
| 149 const base::TimeDelta& latency) { | 149 const base::TimeDelta& latency) { |
| 150 DCHECK(thread_checker_.CalledOnValidThread()); | 150 DCHECK(thread_checker_.CalledOnValidThread()); |
| 151 | 151 |
| 152 UMA_HISTOGRAM_TIMES("Precache.Latency.Prefetch", latency); | 152 UMA_HISTOGRAM_TIMES("Precache.Latency.Prefetch", latency); |
| 153 | 153 |
| 154 DCHECK(info.headers) << "The headers are required to get the freshness."; | 154 DCHECK(info.headers) << "The headers are required to get the freshness."; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 // precache-motivated. URLs that came from the cache and not recorded as | 193 // precache-motivated. URLs that came from the cache and not recorded as |
| 194 // precached previously, were already in the cache because of user browsing. | 194 // precached previously, were already in the cache because of user browsing. |
| 195 // Therefore, this precache will not be considered as precache-motivated, | 195 // Therefore, this precache will not be considered as precache-motivated, |
| 196 // since it had no significant effect (besides a possible revalidation and a | 196 // 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, | 197 // change in the cache LRU priority). If a row for the URL already exists, |
| 198 // then the timestamp is updated. | 198 // then the timestamp is updated. |
| 199 buffered_writes_.push_back(base::Bind( | 199 buffered_writes_.push_back(base::Bind( |
| 200 &PrecacheDatabase::RecordURLPrefetchInternal, GetWeakPtr(), url, | 200 &PrecacheDatabase::RecordURLPrefetchInternal, GetWeakPtr(), url, |
| 201 referrer_host, | 201 referrer_host, |
| 202 !was_cached || precache_url_table_.GetURLInfo(url).is_precached, | 202 !was_cached || precache_url_table_.GetURLInfo(url).is_precached, |
| 203 fetch_time)); | 203 was_cached, fetch_time)); |
| 204 buffered_urls_.insert(url.spec()); | 204 buffered_urls_.insert(url.spec()); |
| 205 MaybePostFlush(); | 205 MaybePostFlush(); |
| 206 } | 206 } |
| 207 | 207 |
| 208 void PrecacheDatabase::RecordURLPrefetchInternal( | 208 void PrecacheDatabase::RecordURLPrefetchInternal( |
| 209 const GURL& url, | 209 const GURL& url, |
| 210 const std::string& referrer_host, | 210 const std::string& referrer_host, |
| 211 bool is_precached, | 211 bool is_precached, |
| 212 bool was_cached, |
| 212 const base::Time& fetch_time) { | 213 const base::Time& fetch_time) { |
| 213 int64_t referrer_host_id = | 214 int64_t referrer_host_id = |
| 214 precache_referrer_host_table_.GetReferrerHost(referrer_host).id; | 215 precache_referrer_host_table_.GetReferrerHost(referrer_host).id; |
| 215 if (referrer_host_id == PrecacheReferrerHostEntry::kInvalidId) { | 216 if (referrer_host_id == PrecacheReferrerHostEntry::kInvalidId) { |
| 216 referrer_host_id = precache_referrer_host_table_.UpdateReferrerHost( | 217 referrer_host_id = precache_referrer_host_table_.UpdateReferrerHost( |
| 217 referrer_host, 0, fetch_time); | 218 referrer_host, 0, fetch_time); |
| 218 } | 219 } |
| 219 DCHECK_NE(referrer_host_id, PrecacheReferrerHostEntry::kInvalidId); | 220 DCHECK_NE(referrer_host_id, PrecacheReferrerHostEntry::kInvalidId); |
| 220 precache_url_table_.AddURL(url, referrer_host_id, is_precached, fetch_time); | 221 precache_url_table_.AddURL(url, referrer_host_id, is_precached, was_cached, |
| 222 fetch_time); |
| 221 } | 223 } |
| 222 | 224 |
| 223 void PrecacheDatabase::RecordURLNonPrefetch(const GURL& url, | 225 void PrecacheDatabase::RecordURLNonPrefetch(const GURL& url, |
| 224 const base::TimeDelta& latency, | 226 const base::TimeDelta& latency, |
| 225 const base::Time& fetch_time, | 227 const base::Time& fetch_time, |
| 226 const net::HttpResponseInfo& info, | 228 const net::HttpResponseInfo& info, |
| 227 int64_t size, | 229 int64_t size, |
| 228 int host_rank, | 230 int host_rank, |
| 229 bool is_connection_cellular) { | 231 bool is_connection_cellular) { |
| 230 UMA_HISTOGRAM_TIMES("Precache.Latency.NonPrefetch", latency); | 232 UMA_HISTOGRAM_TIMES("Precache.Latency.NonPrefetch", latency); |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 330 GetWeakPtr(), hostname, manifest_id, fetch_time)); | 332 GetWeakPtr(), hostname, manifest_id, fetch_time)); |
| 331 MaybePostFlush(); | 333 MaybePostFlush(); |
| 332 } | 334 } |
| 333 | 335 |
| 334 void PrecacheDatabase::UpdatePrecacheReferrerHostInternal( | 336 void PrecacheDatabase::UpdatePrecacheReferrerHostInternal( |
| 335 const std::string& hostname, | 337 const std::string& hostname, |
| 336 int64_t manifest_id, | 338 int64_t manifest_id, |
| 337 const base::Time& fetch_time) { | 339 const base::Time& fetch_time) { |
| 338 int64_t referrer_host_id = precache_referrer_host_table_.UpdateReferrerHost( | 340 int64_t referrer_host_id = precache_referrer_host_table_.UpdateReferrerHost( |
| 339 hostname, manifest_id, fetch_time); | 341 hostname, manifest_id, fetch_time); |
| 342 |
| 340 if (referrer_host_id != PrecacheReferrerHostEntry::kInvalidId) { | 343 if (referrer_host_id != PrecacheReferrerHostEntry::kInvalidId) { |
| 341 precache_url_table_.ClearAllForReferrerHost(referrer_host_id); | 344 precache_url_table_.ClearAllForReferrerHost(referrer_host_id); |
| 342 } | 345 } |
| 343 } | 346 } |
| 344 | 347 |
| 345 void PrecacheDatabase::RecordTimeSinceLastPrecache( | 348 void PrecacheDatabase::RecordTimeSinceLastPrecache( |
| 346 const base::Time& fetch_time) { | 349 const base::Time& fetch_time) { |
| 347 const base::Time& last_precache_timestamp = GetLastPrecacheTimestamp(); | 350 const base::Time& last_precache_timestamp = GetLastPrecacheTimestamp(); |
| 348 // It could still be null if the DB was not accessible. | 351 // It could still be null if the DB was not accessible. |
| 349 if (!last_precache_timestamp.is_null()) { | 352 if (!last_precache_timestamp.is_null()) { |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 445 | 448 |
| 446 PrecacheQuota PrecacheDatabase::GetQuota() { | 449 PrecacheQuota PrecacheDatabase::GetQuota() { |
| 447 return precache_session_table_.GetQuota(); | 450 return precache_session_table_.GetQuota(); |
| 448 } | 451 } |
| 449 | 452 |
| 450 base::WeakPtr<PrecacheDatabase> PrecacheDatabase::GetWeakPtr() { | 453 base::WeakPtr<PrecacheDatabase> PrecacheDatabase::GetWeakPtr() { |
| 451 return weak_factory_.GetWeakPtr(); | 454 return weak_factory_.GetWeakPtr(); |
| 452 } | 455 } |
| 453 | 456 |
| 454 } // namespace precache | 457 } // namespace precache |
| OLD | NEW |