OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/browser/predictors/resource_prefetch_predictor.h" | 5 #include "chrome/browser/predictors/resource_prefetch_predictor.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <set> | 8 #include <set> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 : profile_(profile), | 305 : profile_(profile), |
306 config_(config), | 306 config_(config), |
307 initialization_state_(NOT_INITIALIZED), | 307 initialization_state_(NOT_INITIALIZED), |
308 tables_(PredictorDatabaseFactory::GetForProfile( | 308 tables_(PredictorDatabaseFactory::GetForProfile( |
309 profile)->resource_prefetch_tables()), | 309 profile)->resource_prefetch_tables()), |
310 results_map_deleter_(&results_map_) { | 310 results_map_deleter_(&results_map_) { |
311 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 311 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
312 | 312 |
313 // Some form of learning has to be enabled. | 313 // Some form of learning has to be enabled. |
314 DCHECK(config_.IsLearningEnabled()); | 314 DCHECK(config_.IsLearningEnabled()); |
315 if (config_.IsURLPrefetchingEnabled()) | 315 if (config_.IsURLPrefetchingEnabled(profile_)) |
316 DCHECK(config_.IsURLLearningEnabled()); | 316 DCHECK(config_.IsURLLearningEnabled()); |
317 if (config_.IsHostPrefetchingEnabled()) | 317 if (config_.IsHostPrefetchingEnabled(profile_)) |
318 DCHECK(config_.IsHostLearningEnabled()); | 318 DCHECK(config_.IsHostLearningEnabled()); |
319 } | 319 } |
320 | 320 |
321 ResourcePrefetchPredictor::~ResourcePrefetchPredictor() { | 321 ResourcePrefetchPredictor::~ResourcePrefetchPredictor() { |
322 } | 322 } |
323 | 323 |
324 void ResourcePrefetchPredictor::RecordURLRequest( | 324 void ResourcePrefetchPredictor::RecordURLRequest( |
325 const URLRequestSummary& request) { | 325 const URLRequestSummary& request) { |
326 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 326 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
327 if (initialization_state_ != INITIALIZED) | 327 if (initialization_state_ != INITIALIZED) |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
570 bool ResourcePrefetchPredictor::GetPrefetchData( | 570 bool ResourcePrefetchPredictor::GetPrefetchData( |
571 const NavigationID& navigation_id, | 571 const NavigationID& navigation_id, |
572 ResourcePrefetcher::RequestVector* prefetch_requests, | 572 ResourcePrefetcher::RequestVector* prefetch_requests, |
573 PrefetchKeyType* key_type) { | 573 PrefetchKeyType* key_type) { |
574 DCHECK(prefetch_requests); | 574 DCHECK(prefetch_requests); |
575 DCHECK(key_type); | 575 DCHECK(key_type); |
576 | 576 |
577 *key_type = PREFETCH_KEY_TYPE_URL; | 577 *key_type = PREFETCH_KEY_TYPE_URL; |
578 const GURL& main_frame_url = navigation_id.main_frame_url; | 578 const GURL& main_frame_url = navigation_id.main_frame_url; |
579 | 579 |
580 bool use_url_data = config_.IsPrefetchingEnabled() ? | 580 bool use_url_data = config_.IsPrefetchingEnabled(profile_) ? |
581 config_.IsURLPrefetchingEnabled() : config_.IsURLLearningEnabled(); | 581 config_.IsURLPrefetchingEnabled(profile_) : |
| 582 config_.IsURLLearningEnabled(); |
582 if (use_url_data) { | 583 if (use_url_data) { |
583 PrefetchDataMap::const_iterator iterator = | 584 PrefetchDataMap::const_iterator iterator = |
584 url_table_cache_->find(main_frame_url.spec()); | 585 url_table_cache_->find(main_frame_url.spec()); |
585 if (iterator != url_table_cache_->end()) | 586 if (iterator != url_table_cache_->end()) |
586 PopulatePrefetcherRequest(iterator->second, prefetch_requests); | 587 PopulatePrefetcherRequest(iterator->second, prefetch_requests); |
587 } | 588 } |
588 if (!prefetch_requests->empty()) | 589 if (!prefetch_requests->empty()) |
589 return true; | 590 return true; |
590 | 591 |
591 bool use_host_data = config_.IsPrefetchingEnabled() ? | 592 bool use_host_data = config_.IsPrefetchingEnabled(profile_) ? |
592 config_.IsHostPrefetchingEnabled() : config_.IsHostLearningEnabled(); | 593 config_.IsHostPrefetchingEnabled(profile_) : |
| 594 config_.IsHostLearningEnabled(); |
593 if (use_host_data) { | 595 if (use_host_data) { |
594 PrefetchDataMap::const_iterator iterator = | 596 PrefetchDataMap::const_iterator iterator = |
595 host_table_cache_->find(main_frame_url.host()); | 597 host_table_cache_->find(main_frame_url.host()); |
596 if (iterator != host_table_cache_->end()) { | 598 if (iterator != host_table_cache_->end()) { |
597 *key_type = PREFETCH_KEY_TYPE_HOST; | 599 *key_type = PREFETCH_KEY_TYPE_HOST; |
598 PopulatePrefetcherRequest(iterator->second, prefetch_requests); | 600 PopulatePrefetcherRequest(iterator->second, prefetch_requests); |
599 } | 601 } |
600 } | 602 } |
601 | 603 |
602 return !prefetch_requests->empty(); | 604 return !prefetch_requests->empty(); |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
705 | 707 |
706 void ResourcePrefetchPredictor::OnHistoryAndCacheLoaded() { | 708 void ResourcePrefetchPredictor::OnHistoryAndCacheLoaded() { |
707 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 709 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
708 DCHECK_EQ(initialization_state_, INITIALIZING); | 710 DCHECK_EQ(initialization_state_, INITIALIZING); |
709 | 711 |
710 notification_registrar_.Add(this, | 712 notification_registrar_.Add(this, |
711 chrome::NOTIFICATION_HISTORY_URLS_DELETED, | 713 chrome::NOTIFICATION_HISTORY_URLS_DELETED, |
712 content::Source<Profile>(profile_)); | 714 content::Source<Profile>(profile_)); |
713 | 715 |
714 // Initialize the prefetch manager only if prefetching is enabled. | 716 // Initialize the prefetch manager only if prefetching is enabled. |
715 if (config_.IsPrefetchingEnabled()) { | 717 if (config_.IsPrefetchingEnabled(profile_)) { |
716 prefetch_manager_ = new ResourcePrefetcherManager( | 718 prefetch_manager_ = new ResourcePrefetcherManager( |
717 this, config_, profile_->GetRequestContext()); | 719 this, config_, profile_->GetRequestContext()); |
718 } | 720 } |
719 | 721 |
720 initialization_state_ = INITIALIZED; | 722 initialization_state_ = INITIALIZED; |
721 } | 723 } |
722 | 724 |
723 void ResourcePrefetchPredictor::CleanupAbandonedNavigations( | 725 void ResourcePrefetchPredictor::CleanupAbandonedNavigations( |
724 const NavigationID& navigation_id) { | 726 const NavigationID& navigation_id) { |
725 static const base::TimeDelta max_navigation_age = | 727 static const base::TimeDelta max_navigation_age = |
(...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1213 RPP_PREDICTED_HISTOGRAM_PERCENTAGE( | 1215 RPP_PREDICTED_HISTOGRAM_PERCENTAGE( |
1214 "PrefetchFromNetworkPercentOfTotalFromNetwork", | 1216 "PrefetchFromNetworkPercentOfTotalFromNetwork", |
1215 prefetch_network * 100.0 / total_resources_fetched_from_network); | 1217 prefetch_network * 100.0 / total_resources_fetched_from_network); |
1216 } | 1218 } |
1217 | 1219 |
1218 #undef RPP_PREDICTED_HISTOGRAM_PERCENTAGE | 1220 #undef RPP_PREDICTED_HISTOGRAM_PERCENTAGE |
1219 #undef RPP_PREDICTED_HISTOGRAM_COUNTS | 1221 #undef RPP_PREDICTED_HISTOGRAM_COUNTS |
1220 } | 1222 } |
1221 | 1223 |
1222 } // namespace predictors | 1224 } // namespace predictors |
OLD | NEW |