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 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 // Use the URL table to keep track of URLs. URLs that are fetched via network | 191 // 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 | 192 // 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 | 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, !was_cached || precache_url_table_.IsURLPrecached(url), | 201 referrer_host, |
| 202 !was_cached || precache_url_table_.GetURLInfo(url).is_precached, |
202 fetch_time)); | 203 fetch_time)); |
203 buffered_urls_.insert(url.spec()); | 204 buffered_urls_.insert(url.spec()); |
204 MaybePostFlush(); | 205 MaybePostFlush(); |
205 } | 206 } |
206 | 207 |
207 void PrecacheDatabase::RecordURLPrefetchInternal( | 208 void PrecacheDatabase::RecordURLPrefetchInternal( |
208 const GURL& url, | 209 const GURL& url, |
209 const std::string& referrer_host, | 210 const std::string& referrer_host, |
210 bool is_precached, | 211 bool is_precached, |
211 const base::Time& fetch_time) { | 212 const base::Time& fetch_time) { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 } | 244 } |
244 | 245 |
245 RecordTimeSinceLastPrecache(fetch_time); | 246 RecordTimeSinceLastPrecache(fetch_time); |
246 | 247 |
247 if (buffered_urls_.find(url.spec()) != buffered_urls_.end()) { | 248 if (buffered_urls_.find(url.spec()) != buffered_urls_.end()) { |
248 // If the URL for this fetch is in the write buffer, then flush the write | 249 // If the URL for this fetch is in the write buffer, then flush the write |
249 // buffer. | 250 // buffer. |
250 Flush(); | 251 Flush(); |
251 } | 252 } |
252 | 253 |
253 bool is_precached = precache_url_table_.IsURLPrecachedAndUnused(url); | 254 const PrecacheURLInfo url_info = precache_url_table_.GetURLInfo(url); |
254 if (info.was_cached && !is_precached) { | 255 |
255 // Ignore cache hits that precache can't take credit for. | 256 if (url_info.was_precached) { |
256 return; | 257 UMA_HISTOGRAM_ENUMERATION( |
| 258 "Precache.CacheStatus.NonPrefetch.FromPrecache", |
| 259 info.cache_entry_status, |
| 260 net::HttpResponseInfo::CacheEntryStatus::ENTRY_MAX); |
257 } | 261 } |
258 | 262 |
259 base::HistogramBase::Sample size_sample = | 263 base::HistogramBase::Sample size_sample = |
260 static_cast<base::HistogramBase::Sample>(size); | 264 static_cast<base::HistogramBase::Sample>(size); |
261 if (!info.was_cached) { | 265 if (!info.was_cached) { |
262 // The fetch was served over the network during user browsing, so count it | 266 // The fetch was served over the network during user browsing, so count it |
263 // as downloaded non-precache bytes. | 267 // as downloaded non-precache bytes. |
264 UMA_HISTOGRAM_COUNTS("Precache.DownloadedNonPrecache", size_sample); | 268 UMA_HISTOGRAM_COUNTS("Precache.DownloadedNonPrecache", size_sample); |
265 if (is_connection_cellular) { | 269 if (is_connection_cellular) { |
266 UMA_HISTOGRAM_COUNTS("Precache.DownloadedNonPrecache.Cellular", | 270 UMA_HISTOGRAM_COUNTS("Precache.DownloadedNonPrecache.Cellular", |
267 size_sample); | 271 size_sample); |
268 } | 272 } |
269 // Since the resource has been fetched during user browsing, mark the URL as | 273 // Since the resource has been fetched during user browsing, mark the URL as |
270 // used in the precache URL table, if any exists. The current fetch would | 274 // used in the precache URL table, if any exists. The current fetch would |
271 // have put this resource in the cache regardless of whether or not it was | 275 // have put this resource in the cache regardless of whether or not it was |
272 // previously precached, so mark the URL as used. | 276 // previously precached, so mark the URL as used. |
273 buffered_writes_.push_back( | 277 buffered_writes_.push_back( |
274 base::Bind(&PrecacheURLTable::SetURLAsNotPrecached, | 278 base::Bind(&PrecacheURLTable::SetURLAsNotPrecached, |
275 base::Unretained(&precache_url_table_), url)); | 279 base::Unretained(&precache_url_table_), url)); |
276 buffered_urls_.insert(url.spec()); | 280 buffered_urls_.insert(url.spec()); |
277 MaybePostFlush(); | 281 MaybePostFlush(); |
278 } else { // info.was_cached. | 282 } else if (/* info.was_cached && */ url_info.is_precached && |
| 283 !url_info.was_used) { |
279 // The fetch was served from the cache, and since there's an entry for this | 284 // The fetch was served from the cache, and since there's an entry for this |
280 // URL in the URL table, this means that the resource was served from the | 285 // URL in the URL table, this means that the resource was served from the |
281 // cache only because precaching put it there. Thus, precaching was helpful, | 286 // cache only because precaching put it there. Thus, precaching was helpful, |
282 // so count the fetch as saved bytes. | 287 // so count the fetch as saved bytes. |
283 UMA_HISTOGRAM_COUNTS("Precache.Saved", size_sample); | 288 UMA_HISTOGRAM_COUNTS("Precache.Saved", size_sample); |
284 if (is_connection_cellular) { | 289 if (is_connection_cellular) { |
285 UMA_HISTOGRAM_COUNTS("Precache.Saved.Cellular", size_sample); | 290 UMA_HISTOGRAM_COUNTS("Precache.Saved.Cellular", size_sample); |
286 } | 291 } |
287 | 292 |
288 DCHECK(info.headers) << "The headers are required to get the freshness."; | 293 DCHECK(info.headers) << "The headers are required to get the freshness."; |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
436 | 441 |
437 PrecacheQuota PrecacheDatabase::GetQuota() { | 442 PrecacheQuota PrecacheDatabase::GetQuota() { |
438 return precache_session_table_.GetQuota(); | 443 return precache_session_table_.GetQuota(); |
439 } | 444 } |
440 | 445 |
441 base::WeakPtr<PrecacheDatabase> PrecacheDatabase::GetWeakPtr() { | 446 base::WeakPtr<PrecacheDatabase> PrecacheDatabase::GetWeakPtr() { |
442 return weak_factory_.GetWeakPtr(); | 447 return weak_factory_.GetWeakPtr(); |
443 } | 448 } |
444 | 449 |
445 } // namespace precache | 450 } // namespace precache |
OLD | NEW |