Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 61 RESOURCE_STATUS_URL_TOO_LONG = 16, | 61 RESOURCE_STATUS_URL_TOO_LONG = 16, |
| 62 RESOURCE_STATUS_NOT_CACHEABLE = 32, | 62 RESOURCE_STATUS_NOT_CACHEABLE = 32, |
| 63 RESOURCE_STATUS_HEADERS_MISSING = 64, | 63 RESOURCE_STATUS_HEADERS_MISSING = 64, |
| 64 RESOURCE_STATUS_MAX = 128, | 64 RESOURCE_STATUS_MAX = 128, |
| 65 }; | 65 }; |
| 66 | 66 |
| 67 } // namespace | 67 } // namespace |
| 68 | 68 |
| 69 namespace predictors { | 69 namespace predictors { |
| 70 | 70 |
| 71 ResourcePrefetchPredictor::Config::Config() | |
| 72 : max_navigation_lifetime_seconds(60), | |
| 73 max_urls_to_track(500), | |
| 74 min_url_visit_count(3), | |
| 75 max_resources_per_entry(50), | |
| 76 max_consecutive_misses(3), | |
| 77 num_resources_assumed_prefetched(25) { | |
| 78 } | |
| 79 | |
| 80 ResourcePrefetchPredictor::URLRequestSummary::URLRequestSummary() | 71 ResourcePrefetchPredictor::URLRequestSummary::URLRequestSummary() |
| 81 : resource_type(ResourceType::LAST_TYPE), | 72 : resource_type(ResourceType::LAST_TYPE), |
| 82 was_cached(false) { | 73 was_cached(false) { |
| 83 } | 74 } |
| 84 | 75 |
| 85 ResourcePrefetchPredictor::URLRequestSummary::URLRequestSummary( | 76 ResourcePrefetchPredictor::URLRequestSummary::URLRequestSummary( |
| 86 const URLRequestSummary& other) | 77 const URLRequestSummary& other) |
| 87 : navigation_id(other.navigation_id), | 78 : navigation_id(other.navigation_id), |
| 88 resource_url(other.resource_url), | 79 resource_url(other.resource_url), |
| 89 resource_type(other.resource_type), | 80 resource_type(other.resource_type), |
| 90 mime_type(other.mime_type), | 81 mime_type(other.mime_type), |
| 91 was_cached(other.was_cached) { | 82 was_cached(other.was_cached) { |
| 92 } | 83 } |
| 93 | 84 |
| 94 ResourcePrefetchPredictor::URLRequestSummary::~URLRequestSummary() { | 85 ResourcePrefetchPredictor::URLRequestSummary::~URLRequestSummary() { |
| 95 } | 86 } |
| 96 | 87 |
| 97 ResourcePrefetchPredictor::UrlTableCacheValue::UrlTableCacheValue() { | 88 ResourcePrefetchPredictor::UrlTableCacheValue::UrlTableCacheValue() { |
| 98 } | 89 } |
| 99 | 90 |
| 100 ResourcePrefetchPredictor::UrlTableCacheValue::~UrlTableCacheValue() { | 91 ResourcePrefetchPredictor::UrlTableCacheValue::~UrlTableCacheValue() { |
| 101 } | 92 } |
| 102 | 93 |
| 103 ResourcePrefetchPredictor::ResourcePrefetchPredictor( | 94 ResourcePrefetchPredictor::ResourcePrefetchPredictor( |
| 104 const Config& config, | 95 const ResourcePrefetchPredictorConfig& config, |
| 105 Profile* profile) | 96 Profile* profile) |
| 106 : profile_(profile), | 97 : profile_(profile), |
| 107 config_(config), | 98 config_(config), |
| 108 initialization_state_(NOT_INITIALIZED), | 99 initialization_state_(NOT_INITIALIZED), |
| 109 tables_(PredictorDatabaseFactory::GetForProfile( | 100 tables_(PredictorDatabaseFactory::GetForProfile( |
| 110 profile)->resource_prefetch_tables()) { | 101 profile)->resource_prefetch_tables()) { |
| 111 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 102 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 112 } | 103 } |
| 113 | 104 |
| 114 ResourcePrefetchPredictor::~ResourcePrefetchPredictor() { | 105 ResourcePrefetchPredictor::~ResourcePrefetchPredictor() { |
| 115 } | 106 prefetch_manager_->ShutdownOnUIThread(); |
| 116 | 107 prefetch_manager_ = NULL; |
| 117 // static | |
| 118 bool ResourcePrefetchPredictor::IsEnabled(Profile* profile) { | |
| 119 return prerender::IsSpeculativeResourcePrefetchingLearningEnabled(profile); | |
| 120 } | 108 } |
| 121 | 109 |
| 122 void ResourcePrefetchPredictor::LazilyInitialize() { | 110 void ResourcePrefetchPredictor::LazilyInitialize() { |
| 123 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 111 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 124 | 112 |
| 125 DCHECK_EQ(initialization_state_, NOT_INITIALIZED); | 113 DCHECK_EQ(initialization_state_, NOT_INITIALIZED); |
| 126 initialization_state_ = INITIALIZING; | 114 initialization_state_ = INITIALIZING; |
| 127 | 115 |
| 128 // Request the in-memory database from the history to force it to load so it's | 116 // Request the in-memory database from the history to force it to load so it's |
| 129 // available as soon as possible. | 117 // available as soon as possible. |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 286 void ResourcePrefetchPredictor::RecordURLRequest( | 274 void ResourcePrefetchPredictor::RecordURLRequest( |
| 287 const URLRequestSummary& request) { | 275 const URLRequestSummary& request) { |
| 288 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 276 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 289 | 277 |
| 290 if (initialization_state_ == NOT_INITIALIZED) { | 278 if (initialization_state_ == NOT_INITIALIZED) { |
| 291 LazilyInitialize(); | 279 LazilyInitialize(); |
| 292 return; | 280 return; |
| 293 } else if (initialization_state_ != INITIALIZED) { | 281 } else if (initialization_state_ != INITIALIZED) { |
| 294 return; | 282 return; |
| 295 } | 283 } |
| 296 DCHECK_EQ(INITIALIZED, initialization_state_); | |
| 297 | 284 |
| 298 CHECK_EQ(request.resource_type, ResourceType::MAIN_FRAME); | 285 CHECK_EQ(request.resource_type, ResourceType::MAIN_FRAME); |
| 299 OnMainFrameRequest(request); | 286 OnMainFrameRequest(request); |
| 300 } | 287 } |
| 301 | 288 |
| 302 void ResourcePrefetchPredictor::RecordUrlResponse( | 289 void ResourcePrefetchPredictor::RecordUrlResponse( |
| 303 const URLRequestSummary& response) { | 290 const URLRequestSummary& response) { |
| 304 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 291 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 305 if (initialization_state_ != INITIALIZED) | 292 if (initialization_state_ != INITIALIZED) |
| 306 return; | 293 return; |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 333 if (it != inflight_navigations_.end()) { | 320 if (it != inflight_navigations_.end()) { |
| 334 DCHECK(it->first.creation_time != request.navigation_id.creation_time); | 321 DCHECK(it->first.creation_time != request.navigation_id.creation_time); |
| 335 } | 322 } |
| 336 | 323 |
| 337 // Cleanup older navigations. | 324 // Cleanup older navigations. |
| 338 CleanupAbandonedNavigations(request.navigation_id); | 325 CleanupAbandonedNavigations(request.navigation_id); |
| 339 | 326 |
| 340 // New empty navigation entry. | 327 // New empty navigation entry. |
| 341 inflight_navigations_.insert(std::make_pair( | 328 inflight_navigations_.insert(std::make_pair( |
| 342 request.navigation_id, std::vector<URLRequestSummary>())); | 329 request.navigation_id, std::vector<URLRequestSummary>())); |
| 330 | |
| 331 const GURL& main_frame_url = request.navigation_id.main_frame_url; | |
| 332 | |
| 333 // If prefetching is enabled, and we can prefetch something, start | |
| 334 // prefetching. | |
| 335 if (prefetch_manager_.get() && | |
|
dominich
2012/07/23 16:04:41
simpler:
if (!prefetch_manager_.get())
return;
Shishir
2012/08/01 22:35:24
Done.
| |
| 336 url_table_cache_.find(main_frame_url) != url_table_cache_.end()) { | |
| 337 const UrlTableCacheValue& value = url_table_cache_[main_frame_url]; | |
| 338 | |
| 339 scoped_ptr<ResourcePrefetcher::RequestVector> requests( | |
| 340 new ResourcePrefetcher::RequestVector); | |
| 341 for (UrlTableRowVector::const_iterator it = value.rows.begin(); | |
| 342 it != value.rows.end(); ++it) { | |
| 343 double confidence = static_cast<double>(it->number_of_hits) / | |
| 344 (it->number_of_hits + it->number_of_misses); | |
| 345 if (confidence < config_.min_resource_confidence_to_trigger_prefetch || | |
|
dominich
2012/07/23 16:04:41
warning: comparing double to float. Use double thr
Shishir
2012/08/01 22:35:24
Everything is float now.
| |
| 346 it->number_of_hits < config_.min_resource_hits_to_trigger_prefetch) { | |
|
dominich
2012/07/23 16:04:41
maybe histogram this failure case
Shishir
2012/08/01 22:35:24
We indirectly measure this.
| |
| 347 continue; | |
| 348 } | |
| 349 | |
| 350 ResourcePrefetcher::Request* req = new ResourcePrefetcher::Request( | |
| 351 it->resource_url); | |
| 352 requests->push_back(make_linked_ptr(req)); | |
|
dominich
2012/07/23 16:04:41
why is this a linked_ptr?
Shishir
2012/08/01 22:35:24
Changed to scoped vector.
| |
| 353 } | |
| 354 | |
| 355 if (requests->empty()) | |
| 356 return; | |
| 357 | |
| 358 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | |
| 359 base::Bind(&ResourcePrefetcherManager::MaybeAddPrefetch, | |
| 360 prefetch_manager_, | |
| 361 request.navigation_id, | |
| 362 base::Passed(requests.Pass()))); | |
| 363 } | |
| 343 } | 364 } |
| 344 | 365 |
| 345 void ResourcePrefetchPredictor::OnMainFrameResponse( | 366 void ResourcePrefetchPredictor::OnMainFrameResponse( |
| 346 const URLRequestSummary& response) { | 367 const URLRequestSummary& response) { |
| 347 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 368 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 369 if (initialization_state_ != INITIALIZED) | |
| 370 return; | |
| 348 | 371 |
| 349 // TODO(shishir): The prefreshing will be stopped here. | 372 if (prefetch_manager_.get()) |
| 373 BrowserThread::PostTask( | |
| 374 BrowserThread::IO, FROM_HERE, | |
| 375 base::Bind(&ResourcePrefetcherManager::MaybeRemovePrefetch, | |
| 376 prefetch_manager_, | |
| 377 response.navigation_id)); | |
| 350 } | 378 } |
| 351 | 379 |
| 352 void ResourcePrefetchPredictor::OnMainFrameRedirect( | 380 void ResourcePrefetchPredictor::OnMainFrameRedirect( |
| 353 const URLRequestSummary& response) { | 381 const URLRequestSummary& response) { |
| 354 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 382 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 355 | 383 |
| 356 inflight_navigations_.erase(response.navigation_id); | 384 inflight_navigations_.erase(response.navigation_id); |
| 357 } | 385 } |
| 358 | 386 |
| 359 void ResourcePrefetchPredictor::OnSubresourceResponse( | 387 void ResourcePrefetchPredictor::OnSubresourceResponse( |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 396 if (it->first.IsSameRenderer(navigation_id) || | 424 if (it->first.IsSameRenderer(navigation_id) || |
| 397 (time_now - it->first.creation_time > max_navigation_age)) { | 425 (time_now - it->first.creation_time > max_navigation_age)) { |
| 398 inflight_navigations_.erase(it++); | 426 inflight_navigations_.erase(it++); |
| 399 UMA_HISTOGRAM_ENUMERATION("ResourcePrefetchPredictor.NavigationStatus", | 427 UMA_HISTOGRAM_ENUMERATION("ResourcePrefetchPredictor.NavigationStatus", |
| 400 NAVIGATION_STATUS_ABANDONED, | 428 NAVIGATION_STATUS_ABANDONED, |
| 401 NAVIGATION_STATUS_COUNT); | 429 NAVIGATION_STATUS_COUNT); |
| 402 } else { | 430 } else { |
| 403 ++it; | 431 ++it; |
| 404 } | 432 } |
| 405 } | 433 } |
| 434 for (ResultsMap::iterator it = results_map_.begin(); | |
| 435 it != results_map_.end();) { | |
| 436 if (it->first.IsSameRenderer(navigation_id) || | |
| 437 (time_now - it->first.creation_time > max_navigation_age)) { | |
| 438 results_map_.erase(it++); | |
| 439 } else { | |
| 440 ++it; | |
| 441 } | |
| 442 } | |
| 406 } | 443 } |
| 407 | 444 |
| 408 void ResourcePrefetchPredictor::Observe( | 445 void ResourcePrefetchPredictor::Observe( |
| 409 int type, | 446 int type, |
| 410 const content::NotificationSource& source, | 447 const content::NotificationSource& source, |
| 411 const content::NotificationDetails& details) { | 448 const content::NotificationDetails& details) { |
| 412 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 449 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 413 | 450 |
| 414 switch (type) { | 451 switch (type) { |
| 415 case content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME: { | 452 case content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME: { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 455 DeleteUrls(urls_deleted_details->rows); | 492 DeleteUrls(urls_deleted_details->rows); |
| 456 break; | 493 break; |
| 457 } | 494 } |
| 458 | 495 |
| 459 default: | 496 default: |
| 460 NOTREACHED() << "Unexpected notification observed."; | 497 NOTREACHED() << "Unexpected notification observed."; |
| 461 break; | 498 break; |
| 462 } | 499 } |
| 463 } | 500 } |
| 464 | 501 |
| 502 void ResourcePrefetchPredictor::FinishedPrefetchForNavigation( | |
| 503 const NavigationID& navigation_id, | |
| 504 scoped_ptr<ResourcePrefetcher::RequestVector> requests) { | |
| 505 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 506 | |
| 507 DCHECK(results_map_.find(navigation_id) == results_map_.end()); | |
|
dominich
2012/07/23 16:04:41
again here you're doing a double lookup (in DEBUG)
Shishir
2012/08/01 22:35:24
Done.
| |
| 508 | |
| 509 // Add the results to the results map. | |
| 510 results_map_[navigation_id].reset(requests.release()); | |
|
dominich
2012/07/23 16:04:41
ah, so you're using linked_ptr to have the vector
Shishir
2012/08/01 22:35:24
Done.
| |
| 511 } | |
| 512 | |
| 465 void ResourcePrefetchPredictor::OnHistoryAndCacheLoaded() { | 513 void ResourcePrefetchPredictor::OnHistoryAndCacheLoaded() { |
| 466 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 514 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 467 DCHECK_EQ(initialization_state_, INITIALIZING); | 515 DCHECK_EQ(initialization_state_, INITIALIZING); |
| 468 | 516 |
| 469 // Update the data with last visit info from in memory history db. | 517 // Update the data with last visit info from in memory history db. |
| 470 HistoryService* history_service = | 518 HistoryService* history_service = |
| 471 profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); | 519 profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); |
| 472 DCHECK(history_service); | 520 DCHECK(history_service); |
| 473 history::URLDatabase* url_db = history_service->InMemoryDatabase(); | 521 history::URLDatabase* url_db = history_service->InMemoryDatabase(); |
| 474 if (url_db) { | 522 if (url_db) { |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 497 notification_registrar_.Add(this, | 545 notification_registrar_.Add(this, |
| 498 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, | 546 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, |
| 499 content::NotificationService::AllSources()); | 547 content::NotificationService::AllSources()); |
| 500 notification_registrar_.Add(this, | 548 notification_registrar_.Add(this, |
| 501 chrome::NOTIFICATION_HISTORY_URLS_DELETED, | 549 chrome::NOTIFICATION_HISTORY_URLS_DELETED, |
| 502 content::Source<Profile>(profile_)); | 550 content::Source<Profile>(profile_)); |
| 503 | 551 |
| 504 // TODO(shishir): Maybe listen for notifications for navigation being | 552 // TODO(shishir): Maybe listen for notifications for navigation being |
| 505 // abandoned and cleanup the inflight_navigations_. | 553 // abandoned and cleanup the inflight_navigations_. |
| 506 | 554 |
| 555 // Initialize the prefetch manager only if prefetching is enabled. | |
| 556 if (prerender::IsSpeculativeResourcePrefetchingEnabled(profile_)) { | |
| 557 prefetch_manager_ = new ResourcePrefetcherManager( | |
| 558 this, config_, profile_->GetRequestContext()); | |
| 559 } | |
| 560 | |
| 507 initialization_state_ = INITIALIZED; | 561 initialization_state_ = INITIALIZED; |
| 508 } | 562 } |
| 509 | 563 |
| 510 bool ResourcePrefetchPredictor::ShouldTrackUrl(const GURL& url) { | 564 bool ResourcePrefetchPredictor::ShouldTrackUrl(const GURL& url) { |
| 511 if (url_table_cache_.find(url) != url_table_cache_.end()) | 565 if (url_table_cache_.find(url) != url_table_cache_.end()) |
| 512 return true; | 566 return true; |
| 513 | 567 |
| 514 HistoryService* history_service = | 568 HistoryService* history_service = |
| 515 profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); | 569 profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); |
| 516 DCHECK(history_service); | 570 DCHECK(history_service); |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 533 NAVIGATION_STATUS_COMPLETE_ABANDONED, | 587 NAVIGATION_STATUS_COMPLETE_ABANDONED, |
| 534 NAVIGATION_STATUS_COUNT); | 588 NAVIGATION_STATUS_COUNT); |
| 535 return; | 589 return; |
| 536 } | 590 } |
| 537 | 591 |
| 538 UMA_HISTOGRAM_ENUMERATION("ResourcePrefetchPredictor.NavigationStatus", | 592 UMA_HISTOGRAM_ENUMERATION("ResourcePrefetchPredictor.NavigationStatus", |
| 539 NAVIGATION_STATUS_COMPLETE, | 593 NAVIGATION_STATUS_COMPLETE, |
| 540 NAVIGATION_STATUS_COUNT); | 594 NAVIGATION_STATUS_COUNT); |
| 541 | 595 |
| 542 // Report any stats. | 596 // Report any stats. |
| 543 MaybeReportAccuracyStats(navigation_id); | 597 if (prefetch_manager_.get()) { |
| 598 MaybeReportAccuracyStats(navigation_id); | |
| 599 } else { | |
| 600 MaybeReportSimulatedAccuracyStats(navigation_id); | |
| 601 } | |
| 544 | 602 |
| 545 // Update the URL table. | 603 // Update the URL table. |
| 546 const GURL& main_frame_url = navigation_id.main_frame_url; | 604 const GURL& main_frame_url = navigation_id.main_frame_url; |
| 547 if (ShouldTrackUrl(main_frame_url)) | 605 if (ShouldTrackUrl(main_frame_url)) |
| 548 LearnUrlNavigation(main_frame_url, inflight_navigations_[navigation_id]); | 606 LearnUrlNavigation(main_frame_url, inflight_navigations_[navigation_id]); |
| 549 | 607 |
| 550 // Remove the navigation. | 608 // Remove the navigation. |
| 551 inflight_navigations_.erase(navigation_id); | 609 inflight_navigations_.erase(navigation_id); |
| 610 results_map_.erase(navigation_id); | |
| 552 } | 611 } |
| 553 | 612 |
| 554 void ResourcePrefetchPredictor::LearnUrlNavigation( | 613 void ResourcePrefetchPredictor::LearnUrlNavigation( |
| 555 const GURL& main_frame_url, | 614 const GURL& main_frame_url, |
| 556 const std::vector<URLRequestSummary>& new_resources) { | 615 const std::vector<URLRequestSummary>& new_resources) { |
| 557 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 616 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 558 | 617 |
| 559 if (url_table_cache_.find(main_frame_url) == url_table_cache_.end()) { | 618 if (url_table_cache_.find(main_frame_url) == url_table_cache_.end()) { |
| 560 if (url_table_cache_.size() >= config_.max_urls_to_track) | 619 if (url_table_cache_.size() >= config_.max_urls_to_track) |
| 561 RemoveAnEntryFromUrlDB(); | 620 RemoveAnEntryFromUrlDB(); |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 678 } | 737 } |
| 679 url_table_cache_.erase(url_to_erase); | 738 url_table_cache_.erase(url_to_erase); |
| 680 | 739 |
| 681 std::vector<GURL> urls_to_delete(1, url_to_erase); | 740 std::vector<GURL> urls_to_delete(1, url_to_erase); |
| 682 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, | 741 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, |
| 683 base::Bind(&ResourcePrefetchPredictorTables::DeleteRowsForUrls, | 742 base::Bind(&ResourcePrefetchPredictorTables::DeleteRowsForUrls, |
| 684 tables_, | 743 tables_, |
| 685 urls_to_delete)); | 744 urls_to_delete)); |
| 686 } | 745 } |
| 687 | 746 |
| 688 void ResourcePrefetchPredictor::MaybeReportAccuracyStats( | 747 void ResourcePrefetchPredictor::MaybeReportSimulatedAccuracyStats( |
| 689 const NavigationID& navigation_id) const { | 748 const NavigationID& navigation_id) const { |
| 690 const GURL& main_frame_url = navigation_id.main_frame_url; | 749 const GURL& main_frame_url = navigation_id.main_frame_url; |
| 691 DCHECK(inflight_navigations_.find(navigation_id) != | 750 DCHECK(inflight_navigations_.find(navigation_id) != |
| 692 inflight_navigations_.end()); | 751 inflight_navigations_.end()); |
| 693 | 752 |
| 694 bool have_predictions_for_url = | 753 bool have_predictions_for_url = |
| 695 url_table_cache_.find(main_frame_url) != url_table_cache_.end(); | 754 url_table_cache_.find(main_frame_url) != url_table_cache_.end(); |
| 696 UMA_HISTOGRAM_BOOLEAN("ResourcePrefetchPredictor.HavePredictionsForUrl", | 755 UMA_HISTOGRAM_BOOLEAN("ResourcePrefetchPredictor.HavePredictionsForUrl", |
| 697 have_predictions_for_url); | 756 have_predictions_for_url); |
| 698 if (!have_predictions_for_url) | 757 if (!have_predictions_for_url) |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 728 "ResourcePrefetchPredictor.PredictedPrefetchMisses", | 787 "ResourcePrefetchPredictor.PredictedPrefetchMisses", |
| 729 prefetch_missed * 100.0 / num_assumed_prefetched); | 788 prefetch_missed * 100.0 / num_assumed_prefetched); |
| 730 UMA_HISTOGRAM_PERCENTAGE( | 789 UMA_HISTOGRAM_PERCENTAGE( |
| 731 "ResourcePrefetchPredictor.PredictedPrefetchFromCache", | 790 "ResourcePrefetchPredictor.PredictedPrefetchFromCache", |
| 732 prefetch_cached * 100.0 / num_assumed_prefetched); | 791 prefetch_cached * 100.0 / num_assumed_prefetched); |
| 733 UMA_HISTOGRAM_PERCENTAGE( | 792 UMA_HISTOGRAM_PERCENTAGE( |
| 734 "ResourcePrefetchPredictor.PredictedPrefetchFromNetwork", | 793 "ResourcePrefetchPredictor.PredictedPrefetchFromNetwork", |
| 735 prefetch_network * 100.0 / num_assumed_prefetched); | 794 prefetch_network * 100.0 / num_assumed_prefetched); |
| 736 } | 795 } |
| 737 | 796 |
| 797 void ResourcePrefetchPredictor::MaybeReportAccuracyStats( | |
| 798 const NavigationID& navigation_id) { | |
| 799 DCHECK(inflight_navigations_.find(navigation_id) != | |
| 800 inflight_navigations_.end()); | |
| 801 | |
| 802 bool have_prefetch_results = results_map_.find(navigation_id) != | |
| 803 results_map_.end(); | |
| 804 UMA_HISTOGRAM_BOOLEAN("ResourcePrefetchPredictor.HavePrefetchResults", | |
| 805 have_prefetch_results); | |
| 806 if (!have_prefetch_results) | |
| 807 return; | |
| 808 | |
| 809 // Annotate the results. | |
| 810 const std::vector<URLRequestSummary>& actual = | |
| 811 inflight_navigations_.find(navigation_id)->second; | |
|
dominich
2012/07/23 16:04:41
you're doing this find twice - do it once and use
Shishir
2012/08/01 22:35:24
Done.
| |
| 812 ResourcePrefetcher::RequestVector* prefetched = | |
| 813 results_map_.find(navigation_id)->second.get(); | |
|
dominich
2012/07/23 16:04:41
you're doing this find twice. do it once and cache
Shishir
2012/08/01 22:35:24
Done.
| |
| 814 | |
| 815 std::map<GURL, bool> actual_resources; | |
| 816 for (std::vector<URLRequestSummary>::const_iterator it = actual.begin(); | |
| 817 it != actual.end(); ++it) { | |
| 818 actual_resources[it->resource_url] = it->was_cached; | |
| 819 } | |
| 820 for (ResourcePrefetcher::RequestVector::iterator it = prefetched->begin(); | |
| 821 it != prefetched->end(); ++it) { | |
| 822 ResourcePrefetcher::Request* req = it->get(); | |
| 823 if (actual_resources.find(req->resource_url) != actual_resources.end()) { | |
| 824 if (actual_resources[req->resource_url]) { | |
|
dominich
2012/07/23 16:04:41
You just did the find to get the iterator - you sh
Shishir
2012/08/01 22:35:24
Done.
| |
| 825 req->usage_status = | |
| 826 ResourcePrefetcher::Request::USAGE_STATUS_FROM_CACHE; | |
| 827 } else { | |
| 828 req->usage_status = | |
| 829 ResourcePrefetcher::Request::USAGE_STATUS_FROM_NETWORK; | |
| 830 } | |
| 831 } | |
| 832 } | |
| 833 | |
| 834 int prefetch_cancelled = 0, prefetch_failed = 0, prefetch_not_started = 0; | |
| 835 int p_cache_a_cache = 0, p_cache_a_network = 0, p_cache_a_notused = 0, | |
|
dominich
2012/07/23 16:04:41
what is p_? don't use abbreviations.
Shishir
2012/08/01 22:35:24
p_ is for predicted and a_ is actual. Added commen
| |
| 836 p_network_a_cache = 0, p_network_a_network = 0, p_network_a_notused = 0; | |
| 837 | |
| 838 for (ResourcePrefetcher::RequestVector::iterator it = prefetched->begin(); | |
| 839 it != prefetched->end(); ++it) { | |
| 840 ResourcePrefetcher::Request* req = it->get(); | |
|
dominich
2012/07/23 16:04:41
You can combine this loop with the one above that
Shishir
2012/08/01 22:35:24
Done.
| |
| 841 switch (req->prefetch_status) { | |
| 842 case ResourcePrefetcher::Request::PREFETCH_STATUS_CANCELLED: | |
| 843 ++prefetch_cancelled; | |
| 844 break; | |
| 845 | |
| 846 case ResourcePrefetcher::Request::PREFETCH_STATUS_FAILED: | |
| 847 ++prefetch_failed; | |
| 848 break; | |
| 849 | |
| 850 case ResourcePrefetcher::Request::PREFETCH_STATUS_FROM_CACHE: | |
| 851 if (req->usage_status == | |
| 852 ResourcePrefetcher::Request::USAGE_STATUS_FROM_CACHE) | |
| 853 ++p_cache_a_cache; | |
| 854 else if (req->usage_status == | |
| 855 ResourcePrefetcher::Request::USAGE_STATUS_FROM_NETWORK) | |
| 856 ++p_cache_a_network; | |
| 857 else | |
| 858 ++p_cache_a_notused; | |
| 859 break; | |
| 860 | |
| 861 case ResourcePrefetcher::Request::PREFETCH_STATUS_FROM_NETWORK: | |
| 862 if (req->usage_status == | |
| 863 ResourcePrefetcher::Request::USAGE_STATUS_FROM_CACHE) | |
| 864 ++p_network_a_cache; | |
| 865 else if (req->usage_status == | |
| 866 ResourcePrefetcher::Request::USAGE_STATUS_FROM_NETWORK) | |
| 867 ++p_network_a_network; | |
| 868 else | |
| 869 ++p_network_a_notused; | |
| 870 break; | |
| 871 | |
| 872 case ResourcePrefetcher::Request::PREFETCH_STATUS_NOT_STARTED: | |
| 873 ++prefetch_not_started; | |
| 874 break; | |
| 875 | |
| 876 case ResourcePrefetcher::Request::PREFETCH_STATUS_STARTED: | |
| 877 DLOG(FATAL) << "Invalid prefetch status"; | |
| 878 | |
| 879 } | |
| 880 } | |
| 881 | |
| 882 int total_prefetched = p_cache_a_cache + p_cache_a_network + p_cache_a_notused | |
| 883 + p_network_a_cache + p_network_a_network + p_network_a_notused; | |
| 884 | |
| 885 UMA_HISTOGRAM_PERCENTAGE( | |
| 886 "ResourcePrefetchPredictor.PrefetchCancelled", | |
| 887 prefetch_cancelled * 100.0 / total_prefetched); | |
| 888 UMA_HISTOGRAM_PERCENTAGE( | |
| 889 "ResourcePrefetchPredictor.PrefetchFailed", | |
| 890 prefetch_failed * 100.0 / total_prefetched); | |
| 891 UMA_HISTOGRAM_PERCENTAGE( | |
| 892 "ResourcePrefetchPredictor.PrefetchFromCacheUsedFromCache", | |
| 893 p_cache_a_cache * 100.0 / total_prefetched); | |
| 894 UMA_HISTOGRAM_PERCENTAGE( | |
| 895 "ResourcePrefetchPredictor.PrefetchFromCacheUsedFromNetwork", | |
| 896 p_cache_a_network * 100.0 / total_prefetched); | |
| 897 UMA_HISTOGRAM_PERCENTAGE( | |
| 898 "ResourcePrefetchPredictor.PrefetchFromCacheNotUsed", | |
| 899 p_cache_a_notused * 100.0 / total_prefetched); | |
| 900 UMA_HISTOGRAM_PERCENTAGE( | |
| 901 "ResourcePrefetchPredictor.PrefetchFromNetworkUsedFromCache", | |
| 902 p_network_a_cache * 100.0 / total_prefetched); | |
| 903 UMA_HISTOGRAM_PERCENTAGE( | |
| 904 "ResourcePrefetchPredictor.PrefetchFromNetworkUsedFromNetwork", | |
| 905 p_network_a_network * 100.0 / total_prefetched); | |
| 906 UMA_HISTOGRAM_PERCENTAGE( | |
| 907 "ResourcePrefetchPredictor.PrefetchFromNetworkNotUsed", | |
| 908 p_network_a_notused * 100.0 / total_prefetched); | |
| 909 | |
| 910 UMA_HISTOGRAM_PERCENTAGE( | |
| 911 "ResourcePrefetchPredictor.PrefetchNotStarted", | |
| 912 prefetch_not_started * 100.0 / (prefetch_not_started + total_prefetched)); | |
| 913 } | |
| 914 | |
| 738 void ResourcePrefetchPredictor::DeleteAllUrls() { | 915 void ResourcePrefetchPredictor::DeleteAllUrls() { |
| 739 inflight_navigations_.clear(); | 916 inflight_navigations_.clear(); |
| 740 url_table_cache_.clear(); | 917 url_table_cache_.clear(); |
| 741 | 918 |
| 742 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, | 919 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, |
| 743 base::Bind(&ResourcePrefetchPredictorTables::DeleteAllRows, tables_)); | 920 base::Bind(&ResourcePrefetchPredictorTables::DeleteAllRows, tables_)); |
| 744 } | 921 } |
| 745 | 922 |
| 746 void ResourcePrefetchPredictor::DeleteUrls(const history::URLRows& urls) { | 923 void ResourcePrefetchPredictor::DeleteUrls(const history::URLRows& urls) { |
| 747 std::vector<GURL> urls_to_delete; | 924 std::vector<GURL> urls_to_delete; |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 762 tables_, | 939 tables_, |
| 763 urls_to_delete)); | 940 urls_to_delete)); |
| 764 } | 941 } |
| 765 | 942 |
| 766 void ResourcePrefetchPredictor::SetTablesForTesting( | 943 void ResourcePrefetchPredictor::SetTablesForTesting( |
| 767 scoped_refptr<ResourcePrefetchPredictorTables> tables) { | 944 scoped_refptr<ResourcePrefetchPredictorTables> tables) { |
| 768 tables_ = tables; | 945 tables_ = tables; |
| 769 } | 946 } |
| 770 | 947 |
| 771 } // namespace predictors | 948 } // namespace predictors |
| OLD | NEW |