| 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/content/precache_manager.h" | 5 #include "components/precache/content/precache_manager.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 bool PrecacheManager::IsPrecaching() const { | 217 bool PrecacheManager::IsPrecaching() const { |
| 218 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 218 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 219 return is_precaching_; | 219 return is_precaching_; |
| 220 } | 220 } |
| 221 | 221 |
| 222 void PrecacheManager::UpdatePrecacheMetricsAndState( | 222 void PrecacheManager::UpdatePrecacheMetricsAndState( |
| 223 const GURL& url, | 223 const GURL& url, |
| 224 const GURL& referrer, | 224 const GURL& referrer, |
| 225 const base::TimeDelta& latency, | 225 const base::TimeDelta& latency, |
| 226 const base::Time& fetch_time, | 226 const base::Time& fetch_time, |
| 227 const net::HttpResponseInfo& info, |
| 227 int64_t size, | 228 int64_t size, |
| 228 bool was_cached, | |
| 229 bool is_user_traffic) { | 229 bool is_user_traffic) { |
| 230 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 230 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 231 | 231 |
| 232 RecordStatsForFetch(url, referrer, latency, fetch_time, size, was_cached); | 232 RecordStatsForFetch(url, referrer, latency, fetch_time, info, size); |
| 233 if (is_user_traffic && IsPrecaching()) | 233 if (is_user_traffic && IsPrecaching()) |
| 234 CancelPrecaching(); | 234 CancelPrecaching(); |
| 235 } | 235 } |
| 236 | 236 |
| 237 void PrecacheManager::RecordStatsForFetch(const GURL& url, | 237 void PrecacheManager::RecordStatsForFetch(const GURL& url, |
| 238 const GURL& referrer, | 238 const GURL& referrer, |
| 239 const base::TimeDelta& latency, | 239 const base::TimeDelta& latency, |
| 240 const base::Time& fetch_time, | 240 const base::Time& fetch_time, |
| 241 int64_t size, | 241 const net::HttpResponseInfo& info, |
| 242 bool was_cached) { | 242 int64_t size) { |
| 243 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 243 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 244 | 244 |
| 245 if (size == 0 || url.is_empty() || !url.SchemeIsHTTPOrHTTPS()) { | 245 if (size == 0 || url.is_empty() || !url.SchemeIsHTTPOrHTTPS()) { |
| 246 // Ignore empty responses, empty URLs, or URLs that aren't HTTP or HTTPS. | 246 // Ignore empty responses, empty URLs, or URLs that aren't HTTP or HTTPS. |
| 247 return; | 247 return; |
| 248 } | 248 } |
| 249 | 249 |
| 250 if (!history_service_) | 250 if (!history_service_) |
| 251 return; | 251 return; |
| 252 | 252 |
| 253 history_service_->HostRankIfAvailable( | 253 history_service_->HostRankIfAvailable( |
| 254 referrer, | 254 referrer, base::Bind(&PrecacheManager::RecordStatsForFetchInternal, |
| 255 base::Bind(&PrecacheManager::RecordStatsForFetchInternal, AsWeakPtr(), | 255 AsWeakPtr(), url, latency, fetch_time, info, size)); |
| 256 url, latency, fetch_time, size, was_cached)); | |
| 257 } | 256 } |
| 258 | 257 |
| 259 void PrecacheManager::RecordStatsForFetchInternal( | 258 void PrecacheManager::RecordStatsForFetchInternal( |
| 260 const GURL& url, | 259 const GURL& url, |
| 261 const base::TimeDelta& latency, | 260 const base::TimeDelta& latency, |
| 262 const base::Time& fetch_time, | 261 const base::Time& fetch_time, |
| 262 const net::HttpResponseInfo& info, |
| 263 int64_t size, | 263 int64_t size, |
| 264 bool was_cached, | |
| 265 int host_rank) { | 264 int host_rank) { |
| 266 if (is_precaching_) { | 265 if (is_precaching_) { |
| 267 // Assume that precache is responsible for all requests made while | 266 // Assume that precache is responsible for all requests made while |
| 268 // precaching is currently in progress. | 267 // precaching is currently in progress. |
| 269 // TODO(sclittle): Make PrecacheFetcher explicitly mark precache-motivated | 268 // TODO(sclittle): Make PrecacheFetcher explicitly mark precache-motivated |
| 270 // fetches, and use that to determine whether or not a fetch was motivated | 269 // fetches, and use that to determine whether or not a fetch was motivated |
| 271 // by precaching. | 270 // by precaching. |
| 272 BrowserThread::PostTask( | 271 BrowserThread::PostTask( |
| 273 BrowserThread::DB, FROM_HERE, | 272 BrowserThread::DB, FROM_HERE, |
| 274 base::Bind(&PrecacheDatabase::RecordURLPrefetch, | 273 base::Bind(&PrecacheDatabase::RecordURLPrefetch, |
| 275 base::Unretained(precache_database_.get()), url, latency, | 274 base::Unretained(precache_database_.get()), url, latency, |
| 276 fetch_time, size, was_cached)); | 275 fetch_time, info, size)); |
| 277 } else { | 276 } else { |
| 278 bool is_connection_cellular = | 277 bool is_connection_cellular = |
| 279 net::NetworkChangeNotifier::IsConnectionCellular( | 278 net::NetworkChangeNotifier::IsConnectionCellular( |
| 280 net::NetworkChangeNotifier::GetConnectionType()); | 279 net::NetworkChangeNotifier::GetConnectionType()); |
| 281 | 280 |
| 282 BrowserThread::PostTask( | 281 BrowserThread::PostTask( |
| 283 BrowserThread::DB, FROM_HERE, | 282 BrowserThread::DB, FROM_HERE, |
| 284 base::Bind(&PrecacheDatabase::RecordURLNonPrefetch, | 283 base::Bind(&PrecacheDatabase::RecordURLNonPrefetch, |
| 285 base::Unretained(precache_database_.get()), url, latency, | 284 base::Unretained(precache_database_.get()), url, latency, |
| 286 fetch_time, size, was_cached, host_rank, | 285 fetch_time, info, size, host_rank, is_connection_cellular)); |
| 287 is_connection_cellular)); | |
| 288 } | 286 } |
| 289 } | 287 } |
| 290 | 288 |
| 291 void PrecacheManager::ClearHistory() { | 289 void PrecacheManager::ClearHistory() { |
| 292 // PrecacheDatabase::ClearHistory must run after PrecacheDatabase::Init has | 290 // PrecacheDatabase::ClearHistory must run after PrecacheDatabase::Init has |
| 293 // finished. Using PostNonNestableTask guarantees this, by definition. See | 291 // finished. Using PostNonNestableTask guarantees this, by definition. See |
| 294 // base::SequencedTaskRunner for details. | 292 // base::SequencedTaskRunner for details. |
| 295 BrowserThread::PostNonNestableTask( | 293 BrowserThread::PostNonNestableTask( |
| 296 BrowserThread::DB, FROM_HERE, | 294 BrowserThread::DB, FROM_HERE, |
| 297 base::Bind(&PrecacheDatabase::ClearHistory, | 295 base::Bind(&PrecacheDatabase::ClearHistory, |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 this)); | 346 this)); |
| 349 precache_fetcher_->Start(); | 347 precache_fetcher_->Start(); |
| 350 } | 348 } |
| 351 | 349 |
| 352 void PrecacheManager::OnHostsReceivedThenDone( | 350 void PrecacheManager::OnHostsReceivedThenDone( |
| 353 const history::TopHostsList& host_counts) { | 351 const history::TopHostsList& host_counts) { |
| 354 OnDone(); | 352 OnDone(); |
| 355 } | 353 } |
| 356 | 354 |
| 357 } // namespace precache | 355 } // namespace precache |
| OLD | NEW |