Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(325)

Side by Side Diff: chrome/browser/predictors/resource_prefetch_predictor.cc

Issue 573553004: Eliminate NOTIFICATION_HISTORY_LOADED notification (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Clean up of code in ResourcePrefetchPredictor Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 298
299 //////////////////////////////////////////////////////////////////////////////// 299 ////////////////////////////////////////////////////////////////////////////////
300 // ResourcePrefetchPredictor. 300 // ResourcePrefetchPredictor.
301 301
302 ResourcePrefetchPredictor::ResourcePrefetchPredictor( 302 ResourcePrefetchPredictor::ResourcePrefetchPredictor(
303 const ResourcePrefetchPredictorConfig& config, 303 const ResourcePrefetchPredictorConfig& config,
304 Profile* profile) 304 Profile* profile)
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(profile)
309 profile)->resource_prefetch_tables()), 309 ->resource_prefetch_tables()),
310 results_map_deleter_(&results_map_) { 310 results_map_deleter_(&results_map_),
311 history_service_observer_(this) {
311 DCHECK_CURRENTLY_ON(BrowserThread::UI); 312 DCHECK_CURRENTLY_ON(BrowserThread::UI);
312 313
313 // Some form of learning has to be enabled. 314 // Some form of learning has to be enabled.
314 DCHECK(config_.IsLearningEnabled()); 315 DCHECK(config_.IsLearningEnabled());
315 if (config_.IsURLPrefetchingEnabled(profile_)) 316 if (config_.IsURLPrefetchingEnabled(profile_))
316 DCHECK(config_.IsURLLearningEnabled()); 317 DCHECK(config_.IsURLLearningEnabled());
317 if (config_.IsHostPrefetchingEnabled(profile_)) 318 if (config_.IsHostPrefetchingEnabled(profile_))
318 DCHECK(config_.IsHostLearningEnabled()); 319 DCHECK(config_.IsHostLearningEnabled());
319 } 320 }
320 321
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 } 392 }
392 } 393 }
393 394
394 void ResourcePrefetchPredictor::Observe( 395 void ResourcePrefetchPredictor::Observe(
395 int type, 396 int type,
396 const content::NotificationSource& source, 397 const content::NotificationSource& source,
397 const content::NotificationDetails& details) { 398 const content::NotificationDetails& details) {
398 DCHECK_CURRENTLY_ON(BrowserThread::UI); 399 DCHECK_CURRENTLY_ON(BrowserThread::UI);
399 400
400 switch (type) { 401 switch (type) {
401 case chrome::NOTIFICATION_HISTORY_LOADED: {
402 DCHECK_EQ(initialization_state_, INITIALIZING);
403 notification_registrar_.Remove(this,
404 chrome::NOTIFICATION_HISTORY_LOADED,
405 content::Source<Profile>(profile_));
406 OnHistoryAndCacheLoaded();
407 break;
408 }
409
410 case chrome::NOTIFICATION_HISTORY_URLS_DELETED: { 402 case chrome::NOTIFICATION_HISTORY_URLS_DELETED: {
411 DCHECK_EQ(initialization_state_, INITIALIZED); 403 DCHECK_EQ(initialization_state_, INITIALIZED);
412 const content::Details<const history::URLsDeletedDetails> 404 const content::Details<const history::URLsDeletedDetails>
413 urls_deleted_details = 405 urls_deleted_details =
414 content::Details<const history::URLsDeletedDetails>(details); 406 content::Details<const history::URLsDeletedDetails>(details);
415 if (urls_deleted_details->all_history) { 407 if (urls_deleted_details->all_history) {
416 DeleteAllUrls(); 408 DeleteAllUrls();
417 UMA_HISTOGRAM_ENUMERATION("ResourcePrefetchPredictor.ReportingEvent", 409 UMA_HISTOGRAM_ENUMERATION("ResourcePrefetchPredictor.ReportingEvent",
418 REPORTING_EVENT_ALL_HISTORY_CLEARED, 410 REPORTING_EVENT_ALL_HISTORY_CLEARED,
419 REPORTING_EVENT_COUNT); 411 REPORTING_EVENT_COUNT);
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
687 DCHECK(inflight_navigations_.empty()); 679 DCHECK(inflight_navigations_.empty());
688 680
689 url_table_cache_.reset(url_data_map.release()); 681 url_table_cache_.reset(url_data_map.release());
690 host_table_cache_.reset(host_data_map.release()); 682 host_table_cache_.reset(host_data_map.release());
691 683
692 UMA_HISTOGRAM_COUNTS("ResourcePrefetchPredictor.UrlTableMainFrameUrlCount", 684 UMA_HISTOGRAM_COUNTS("ResourcePrefetchPredictor.UrlTableMainFrameUrlCount",
693 url_table_cache_->size()); 685 url_table_cache_->size());
694 UMA_HISTOGRAM_COUNTS("ResourcePrefetchPredictor.HostTableHostCount", 686 UMA_HISTOGRAM_COUNTS("ResourcePrefetchPredictor.HostTableHostCount",
695 host_table_cache_->size()); 687 host_table_cache_->size());
696 688
697 // Add notifications for history loading if it is not ready. 689 CheckForHistoryService();
698 HistoryService* history_service = HistoryServiceFactory::GetForProfile(
699 profile_, Profile::EXPLICIT_ACCESS);
700 if (!history_service) {
701 notification_registrar_.Add(this, chrome::NOTIFICATION_HISTORY_LOADED,
702 content::Source<Profile>(profile_));
703 } else {
704 OnHistoryAndCacheLoaded();
705 }
706 } 690 }
707 691
708 void ResourcePrefetchPredictor::OnHistoryAndCacheLoaded() { 692 void ResourcePrefetchPredictor::OnHistoryAndCacheLoaded() {
709 DCHECK_CURRENTLY_ON(BrowserThread::UI); 693 DCHECK_CURRENTLY_ON(BrowserThread::UI);
710 DCHECK_EQ(initialization_state_, INITIALIZING); 694 DCHECK_EQ(initialization_state_, INITIALIZING);
711 695
712 notification_registrar_.Add(this, 696 notification_registrar_.Add(this,
713 chrome::NOTIFICATION_HISTORY_URLS_DELETED, 697 chrome::NOTIFICATION_HISTORY_URLS_DELETED,
714 content::Source<Profile>(profile_)); 698 content::Source<Profile>(profile_));
715 699
716 // Initialize the prefetch manager only if prefetching is enabled. 700 // Initialize the prefetch manager only if prefetching is enabled.
717 if (config_.IsPrefetchingEnabled(profile_)) { 701 if (config_.IsPrefetchingEnabled(profile_)) {
718 prefetch_manager_ = new ResourcePrefetcherManager( 702 prefetch_manager_ = new ResourcePrefetcherManager(
719 this, config_, profile_->GetRequestContext()); 703 this, config_, profile_->GetRequestContext());
720 } 704 }
721 705
706 history_service_observer_.RemoveAll();
722 initialization_state_ = INITIALIZED; 707 initialization_state_ = INITIALIZED;
723 } 708 }
724 709
725 void ResourcePrefetchPredictor::CleanupAbandonedNavigations( 710 void ResourcePrefetchPredictor::CleanupAbandonedNavigations(
726 const NavigationID& navigation_id) { 711 const NavigationID& navigation_id) {
727 static const base::TimeDelta max_navigation_age = 712 static const base::TimeDelta max_navigation_age =
728 base::TimeDelta::FromSeconds(config_.max_navigation_lifetime_seconds); 713 base::TimeDelta::FromSeconds(config_.max_navigation_lifetime_seconds);
729 714
730 base::TimeTicks time_now = base::TimeTicks::Now(); 715 base::TimeTicks time_now = base::TimeTicks::Now();
731 for (NavigationMap::iterator it = inflight_navigations_.begin(); 716 for (NavigationMap::iterator it = inflight_navigations_.begin();
(...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after
1214 if (total_resources_fetched_from_network > 0) { 1199 if (total_resources_fetched_from_network > 0) {
1215 RPP_PREDICTED_HISTOGRAM_PERCENTAGE( 1200 RPP_PREDICTED_HISTOGRAM_PERCENTAGE(
1216 "PrefetchFromNetworkPercentOfTotalFromNetwork", 1201 "PrefetchFromNetworkPercentOfTotalFromNetwork",
1217 prefetch_network * 100.0 / total_resources_fetched_from_network); 1202 prefetch_network * 100.0 / total_resources_fetched_from_network);
1218 } 1203 }
1219 1204
1220 #undef RPP_PREDICTED_HISTOGRAM_PERCENTAGE 1205 #undef RPP_PREDICTED_HISTOGRAM_PERCENTAGE
1221 #undef RPP_PREDICTED_HISTOGRAM_COUNTS 1206 #undef RPP_PREDICTED_HISTOGRAM_COUNTS
1222 } 1207 }
1223 1208
1209 bool ResourcePrefetchPredictor::CheckForHistoryService() {
sdefresne 2014/11/04 14:12:29 nit: you never use the return value, so you can ch
nshaik 2014/11/04 21:20:27 Done.
1210 // Register for HistoryServiceLoading if it is not ready.
1211 HistoryService* history_service =
1212 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS);
1213 if (!history_service)
1214 return false;
1215 if (history_service->BackendLoaded()) {
1216 // HistoryService is already loaded. Continue with Initialization.
1217 OnHistoryAndCacheLoaded();
1218 return true;
1219 }
1220 DCHECK(!history_service_observer_.IsObserving(history_service));
1221 history_service_observer_.Add(history_service);
1222 return false;
1223 }
1224
1225 void ResourcePrefetchPredictor::OnHistoryServiceLoaded(
1226 HistoryService* history_service) {
1227 OnHistoryAndCacheLoaded();
1228 history_service_observer_.Remove(history_service);
1229 }
1230
1224 } // namespace predictors 1231 } // namespace predictors
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698