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

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

Issue 2440723002: predictors: Make ResourcePrefetchPredictor observable. (Closed)
Patch Set: Fix a mess with access modifiers. Created 4 years, 2 months 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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 REPORTING_EVENT_ALL_HISTORY_CLEARED = 0, 60 REPORTING_EVENT_ALL_HISTORY_CLEARED = 0,
61 REPORTING_EVENT_PARTIAL_HISTORY_CLEARED = 1, 61 REPORTING_EVENT_PARTIAL_HISTORY_CLEARED = 1,
62 REPORTING_EVENT_COUNT = 2 62 REPORTING_EVENT_COUNT = 2
63 }; 63 };
64 64
65 float ComputeRedirectConfidence(const predictors::RedirectStat& redirect) { 65 float ComputeRedirectConfidence(const predictors::RedirectStat& redirect) {
66 return (redirect.number_of_hits() + 0.0) / 66 return (redirect.number_of_hits() + 0.0) /
67 (redirect.number_of_hits() + redirect.number_of_misses()); 67 (redirect.number_of_hits() + redirect.number_of_misses());
68 } 68 }
69 69
70 // Used to fetch the visit count for a URL from the History database.
71 class GetUrlVisitCountTask : public history::HistoryDBTask {
72 public:
73 typedef predictors::ResourcePrefetchPredictor::URLRequestSummary
pasko 2016/10/21 12:12:52 our new style prefers type aliases: using URLReque
alexilin 2016/10/21 13:38:04 Done for now. Let's consider namespace changing in
74 URLRequestSummary;
75 typedef predictors::ResourcePrefetchPredictor::PageRequestSummary
76 PageRequestSummary;
77 typedef base::Callback<void(size_t, // URL visit count.
78 const PageRequestSummary&)>
79 VisitInfoCallback;
80
81 GetUrlVisitCountTask(std::unique_ptr<PageRequestSummary> summary,
82 VisitInfoCallback callback);
83
84 bool RunOnDBThread(history::HistoryBackend* backend,
85 history::HistoryDatabase* db) override;
86
87 void DoneRunOnMainThread() override;
88
89 private:
90 ~GetUrlVisitCountTask() override;
91
92 int visit_count_;
93 std::unique_ptr<PageRequestSummary> summary_;
94 VisitInfoCallback callback_;
95
96 DISALLOW_COPY_AND_ASSIGN(GetUrlVisitCountTask);
97 };
98
99 GetUrlVisitCountTask::GetUrlVisitCountTask(
100 std::unique_ptr<PageRequestSummary> summary,
101 VisitInfoCallback callback)
102 : visit_count_(0), summary_(std::move(summary)), callback_(callback) {
103 DCHECK(summary_.get());
104 }
105
106 bool GetUrlVisitCountTask::RunOnDBThread(history::HistoryBackend* backend,
107 history::HistoryDatabase* db) {
108 history::URLRow url_row;
109 if (db->GetRowForURL(summary_->main_frame_url, &url_row))
110 visit_count_ = url_row.visit_count();
111 return true;
112 }
113
114 void GetUrlVisitCountTask::DoneRunOnMainThread() {
115 callback_.Run(visit_count_, *summary_);
116 }
117
118 GetUrlVisitCountTask::~GetUrlVisitCountTask() {}
119
70 } // namespace 120 } // namespace
71 121
72 namespace predictors { 122 namespace predictors {
73 123
74 //////////////////////////////////////////////////////////////////////////////// 124 ////////////////////////////////////////////////////////////////////////////////
75 // ResourcePrefetchPredictor static functions. 125 // ResourcePrefetchPredictor static functions.
76 126
77 // static 127 // static
78 bool ResourcePrefetchPredictor::ShouldRecordRequest( 128 bool ResourcePrefetchPredictor::ShouldRecordRequest(
79 net::URLRequest* request, 129 net::URLRequest* request,
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 summary->has_validators = headers->HasValidators(); 353 summary->has_validators = headers->HasValidators();
304 // RFC 2616, section 14.9. 354 // RFC 2616, section 14.9.
305 summary->always_revalidate = 355 summary->always_revalidate =
306 headers->HasHeaderValue("cache-control", "no-cache") || 356 headers->HasHeaderValue("cache-control", "no-cache") ||
307 headers->HasHeaderValue("pragma", "no-cache") || 357 headers->HasHeaderValue("pragma", "no-cache") ||
308 headers->HasHeaderValue("vary", "*"); 358 headers->HasHeaderValue("vary", "*");
309 } 359 }
310 return true; 360 return true;
311 } 361 }
312 362
313 ResourcePrefetchPredictor::GetUrlVisitCountTask::GetUrlVisitCountTask(
314 const NavigationID& navigation_id,
315 std::unique_ptr<PageRequestSummary> summary,
316 VisitInfoCallback callback)
317 : visit_count_(0),
318 navigation_id_(navigation_id),
319 summary_(std::move(summary)),
320 callback_(callback) {
321 DCHECK(summary_.get());
322 }
323
324 bool ResourcePrefetchPredictor::GetUrlVisitCountTask::RunOnDBThread(
325 history::HistoryBackend* backend,
326 history::HistoryDatabase* db) {
327 history::URLRow url_row;
328 if (db->GetRowForURL(navigation_id_.main_frame_url, &url_row))
329 visit_count_ = url_row.visit_count();
330 return true;
331 }
332
333 void ResourcePrefetchPredictor::GetUrlVisitCountTask::DoneRunOnMainThread() {
334 callback_.Run(visit_count_, navigation_id_, *summary_);
335 }
336
337 ResourcePrefetchPredictor::GetUrlVisitCountTask::~GetUrlVisitCountTask() {}
338
339 ResourcePrefetchPredictor::PageRequestSummary::PageRequestSummary( 363 ResourcePrefetchPredictor::PageRequestSummary::PageRequestSummary(
340 const GURL& i_initial_url) 364 const GURL& i_main_frame_url)
341 : initial_url(i_initial_url) {} 365 : main_frame_url(i_main_frame_url), initial_url(i_main_frame_url) {}
342 366
343 ResourcePrefetchPredictor::PageRequestSummary::~PageRequestSummary() {} 367 ResourcePrefetchPredictor::PageRequestSummary::~PageRequestSummary() {}
344 368
345 //////////////////////////////////////////////////////////////////////////////// 369 ////////////////////////////////////////////////////////////////////////////////
346 // ResourcePrefetchPredictor. 370 // ResourcePrefetchPredictor.
347 371
348 ResourcePrefetchPredictor::ResourcePrefetchPredictor( 372 ResourcePrefetchPredictor::ResourcePrefetchPredictor(
pasko 2016/10/21 12:12:52 By default ObserverList would have NotificationTyp
alexilin 2016/10/21 13:38:04 Non-actual since we store single observer.
349 const ResourcePrefetchPredictorConfig& config, 373 const ResourcePrefetchPredictorConfig& config,
350 Profile* profile) 374 Profile* profile)
351 : profile_(profile), 375 : profile_(profile),
352 config_(config), 376 config_(config),
353 initialization_state_(NOT_INITIALIZED), 377 initialization_state_(NOT_INITIALIZED),
354 tables_(PredictorDatabaseFactory::GetForProfile(profile) 378 tables_(PredictorDatabaseFactory::GetForProfile(profile)
355 ->resource_prefetch_tables()), 379 ->resource_prefetch_tables()),
356 history_service_observer_(this) { 380 history_service_observer_(this) {
357 DCHECK_CURRENTLY_ON(BrowserThread::UI); 381 DCHECK_CURRENTLY_ON(BrowserThread::UI);
358 382
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 // corresponding to the navigation has not been created yet. 436 // corresponding to the navigation has not been created yet.
413 if (!navigation_id.main_frame_url.is_empty()) 437 if (!navigation_id.main_frame_url.is_empty())
414 OnNavigationComplete(navigation_id); 438 OnNavigationComplete(navigation_id);
415 break; 439 break;
416 default: 440 default:
417 NOTREACHED() << "Unexpected initialization_state_: " 441 NOTREACHED() << "Unexpected initialization_state_: "
418 << initialization_state_; 442 << initialization_state_;
419 } 443 }
420 } 444 }
421 445
446 void ResourcePrefetchPredictor::StartPrefetching(const GURL& url) {
447 TRACE_EVENT1("browser", "ResourcePrefetchPredictor::StartPrefetching", "url",
448 url.spec());
449 if (!prefetch_manager_.get()) // Prefetching not enabled.
450 return;
451
452 std::vector<GURL> subresource_urls;
453 if (!GetPrefetchData(url, &subresource_urls)) {
454 // No prefetching data at host or URL level.
455 return;
456 }
457
458 BrowserThread::PostTask(
459 BrowserThread::IO, FROM_HERE,
460 base::Bind(&ResourcePrefetcherManager::MaybeAddPrefetch,
461 prefetch_manager_, url, subresource_urls));
462 }
463
464 void ResourcePrefetchPredictor::StopPrefetching(const GURL& url) {
465 TRACE_EVENT1("browser", "ResourcePrefetchPredictor::StopPrefetching", "url",
466 url.spec());
467 if (!prefetch_manager_.get()) // Not enabled.
468 return;
469
470 BrowserThread::PostTask(
471 BrowserThread::IO, FROM_HERE,
472 base::Bind(&ResourcePrefetcherManager::MaybeRemovePrefetch,
473 prefetch_manager_, url));
474 }
475
476 void ResourcePrefetchPredictor::AddObserver(Observer* observer) {
477 observers_.AddObserver(observer);
478 }
479
480 void ResourcePrefetchPredictor::RemoveObserver(Observer* observer) {
481 observers_.RemoveObserver(observer);
482 }
483
422 void ResourcePrefetchPredictor::Shutdown() { 484 void ResourcePrefetchPredictor::Shutdown() {
423 if (prefetch_manager_.get()) { 485 if (prefetch_manager_.get()) {
424 prefetch_manager_->ShutdownOnUIThread(); 486 prefetch_manager_->ShutdownOnUIThread();
425 prefetch_manager_ = NULL; 487 prefetch_manager_ = NULL;
426 } 488 }
427 history_service_observer_.RemoveAll(); 489 history_service_observer_.RemoveAll();
428 } 490 }
429 491
430 void ResourcePrefetchPredictor::OnMainFrameRequest( 492 void ResourcePrefetchPredictor::OnMainFrameRequest(
431 const URLRequestSummary& request) { 493 const URLRequestSummary& request) {
432 DCHECK_CURRENTLY_ON(BrowserThread::UI); 494 DCHECK_CURRENTLY_ON(BrowserThread::UI);
433 DCHECK_EQ(INITIALIZED, initialization_state_); 495 DCHECK_EQ(INITIALIZED, initialization_state_);
434 496
435 StartPrefetching(request.navigation_id.main_frame_url); 497 const GURL& main_frame_url = request.navigation_id.main_frame_url;
498 StartPrefetching(main_frame_url);
436 499
437 // Cleanup older navigations. 500 // Cleanup older navigations.
438 CleanupAbandonedNavigations(request.navigation_id); 501 CleanupAbandonedNavigations(request.navigation_id);
439 502
440 // New empty navigation entry. 503 // New empty navigation entry.
441 const GURL& initial_url = request.navigation_id.main_frame_url;
442 inflight_navigations_.insert( 504 inflight_navigations_.insert(
443 std::make_pair(request.navigation_id, 505 std::make_pair(request.navigation_id,
444 base::MakeUnique<PageRequestSummary>(initial_url))); 506 base::MakeUnique<PageRequestSummary>(main_frame_url)));
445 } 507 }
446 508
447 void ResourcePrefetchPredictor::OnMainFrameResponse( 509 void ResourcePrefetchPredictor::OnMainFrameResponse(
448 const URLRequestSummary& response) { 510 const URLRequestSummary& response) {
449 DCHECK_CURRENTLY_ON(BrowserThread::UI); 511 DCHECK_CURRENTLY_ON(BrowserThread::UI);
450 if (initialization_state_ != INITIALIZED) 512 if (initialization_state_ != INITIALIZED)
451 return; 513 return;
452 514
453 StopPrefetching(response.navigation_id.main_frame_url); 515 StopPrefetching(response.navigation_id.main_frame_url);
454 } 516 }
455 517
456 void ResourcePrefetchPredictor::OnMainFrameRedirect( 518 void ResourcePrefetchPredictor::OnMainFrameRedirect(
457 const URLRequestSummary& response) { 519 const URLRequestSummary& response) {
458 DCHECK_CURRENTLY_ON(BrowserThread::UI); 520 DCHECK_CURRENTLY_ON(BrowserThread::UI);
459 521
522 const GURL& main_frame_url = response.navigation_id.main_frame_url;
460 std::unique_ptr<PageRequestSummary> summary; 523 std::unique_ptr<PageRequestSummary> summary;
461 NavigationMap::iterator nav_it = 524 NavigationMap::iterator nav_it =
462 inflight_navigations_.find(response.navigation_id); 525 inflight_navigations_.find(response.navigation_id);
463 if (nav_it != inflight_navigations_.end()) { 526 if (nav_it != inflight_navigations_.end()) {
464 summary.reset(nav_it->second.release()); 527 summary.reset(nav_it->second.release());
465 inflight_navigations_.erase(nav_it); 528 inflight_navigations_.erase(nav_it);
466 } 529 }
467 530
468 // The redirect url may be empty if the URL was invalid. 531 // The redirect url may be empty if the URL was invalid.
469 if (response.redirect_url.is_empty()) 532 if (response.redirect_url.is_empty())
470 return; 533 return;
471 534
472 // If we lost the information about the first hop for some reason. 535 // If we lost the information about the first hop for some reason.
473 if (!summary) { 536 if (!summary) {
474 const GURL& initial_url = response.navigation_id.main_frame_url; 537 summary = base::MakeUnique<PageRequestSummary>(main_frame_url);
475 summary = base::MakeUnique<PageRequestSummary>(initial_url);
476 } 538 }
477 539
478 // A redirect will not lead to another OnMainFrameRequest call, so record the 540 // A redirect will not lead to another OnMainFrameRequest call, so record the
479 // redirect url as a new navigation id and save the initial url. 541 // redirect url as a new navigation id and save the initial url.
480 NavigationID navigation_id(response.navigation_id); 542 NavigationID navigation_id(response.navigation_id);
481 navigation_id.main_frame_url = response.redirect_url; 543 navigation_id.main_frame_url = response.redirect_url;
544 summary->main_frame_url = response.redirect_url;
482 inflight_navigations_.insert( 545 inflight_navigations_.insert(
483 std::make_pair(navigation_id, std::move(summary))); 546 std::make_pair(navigation_id, std::move(summary)));
484 } 547 }
485 548
486 void ResourcePrefetchPredictor::OnSubresourceResponse( 549 void ResourcePrefetchPredictor::OnSubresourceResponse(
487 const URLRequestSummary& response) { 550 const URLRequestSummary& response) {
488 DCHECK_CURRENTLY_ON(BrowserThread::UI); 551 DCHECK_CURRENTLY_ON(BrowserThread::UI);
489 552
490 NavigationMap::const_iterator nav_it = 553 NavigationMap::const_iterator nav_it =
491 inflight_navigations_.find(response.navigation_id); 554 inflight_navigations_.find(response.navigation_id);
492 if (nav_it == inflight_navigations_.end()) { 555 if (nav_it == inflight_navigations_.end()) {
493 return; 556 return;
494 } 557 }
495 558
496 nav_it->second->subresource_requests.push_back(response); 559 nav_it->second->subresource_requests.push_back(response);
497 } 560 }
498 561
499 void ResourcePrefetchPredictor::OnNavigationComplete( 562 void ResourcePrefetchPredictor::OnNavigationComplete(
500 const NavigationID& nav_id_without_timing_info) { 563 const NavigationID& nav_id_without_timing_info) {
501 DCHECK_CURRENTLY_ON(BrowserThread::UI); 564 DCHECK_CURRENTLY_ON(BrowserThread::UI);
502 565
503 NavigationMap::iterator nav_it = 566 NavigationMap::iterator nav_it =
504 inflight_navigations_.find(nav_id_without_timing_info); 567 inflight_navigations_.find(nav_id_without_timing_info);
505 if (nav_it == inflight_navigations_.end()) 568 if (nav_it == inflight_navigations_.end())
506 return; 569 return;
507 570
508 const NavigationID navigation_id(nav_it->first);
509
510 // Remove the navigation from the inflight navigations. 571 // Remove the navigation from the inflight navigations.
511 std::unique_ptr<PageRequestSummary> summary = std::move(nav_it->second); 572 std::unique_ptr<PageRequestSummary> summary = std::move(nav_it->second);
512 inflight_navigations_.erase(nav_it); 573 inflight_navigations_.erase(nav_it);
513 574
514 // Kick off history lookup to determine if we should record the URL. 575 // Kick off history lookup to determine if we should record the URL.
515 history::HistoryService* history_service = 576 history::HistoryService* history_service =
516 HistoryServiceFactory::GetForProfile(profile_, 577 HistoryServiceFactory::GetForProfile(profile_,
517 ServiceAccessType::EXPLICIT_ACCESS); 578 ServiceAccessType::EXPLICIT_ACCESS);
518 DCHECK(history_service); 579 DCHECK(history_service);
519 history_service->ScheduleDBTask( 580 history_service->ScheduleDBTask(
520 std::unique_ptr<history::HistoryDBTask>(new GetUrlVisitCountTask( 581 std::unique_ptr<history::HistoryDBTask>(new GetUrlVisitCountTask(
521 navigation_id, std::move(summary), 582 std::move(summary),
522 base::Bind(&ResourcePrefetchPredictor::OnVisitCountLookup, 583 base::Bind(&ResourcePrefetchPredictor::OnVisitCountLookup,
523 AsWeakPtr()))), 584 AsWeakPtr()))),
524 &history_lookup_consumer_); 585 &history_lookup_consumer_);
525 } 586 }
526 587
527 bool ResourcePrefetchPredictor::GetPrefetchData(const GURL& main_frame_url, 588 bool ResourcePrefetchPredictor::GetPrefetchData(const GURL& main_frame_url,
528 std::vector<GURL>* urls) { 589 std::vector<GURL>* urls) {
529 DCHECK(urls); 590 DCHECK(urls);
530 DCHECK(urls->empty()); 591 DCHECK(urls->empty());
531 bool use_url_data = config_.IsPrefetchingEnabled(profile_) ? 592 bool use_url_data = config_.IsPrefetchingEnabled(profile_) ?
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
579 resource.number_of_hits() < 640 resource.number_of_hits() <
580 config_.min_resource_hits_to_trigger_prefetch) 641 config_.min_resource_hits_to_trigger_prefetch)
581 continue; 642 continue;
582 643
583 urls->push_back(GURL(resource.resource_url())); 644 urls->push_back(GURL(resource.resource_url()));
584 } 645 }
585 646
586 return urls->size() > initial_size; 647 return urls->size() > initial_size;
587 } 648 }
588 649
589 void ResourcePrefetchPredictor::StartPrefetching(const GURL& url) {
590 TRACE_EVENT1("browser", "ResourcePrefetchPredictor::StartPrefetching", "url",
591 url.spec());
592 if (!prefetch_manager_.get()) // Prefetching not enabled.
593 return;
594
595 std::vector<GURL> subresource_urls;
596 if (!GetPrefetchData(url, &subresource_urls)) {
597 // No prefetching data at host or URL level.
598 return;
599 }
600
601 BrowserThread::PostTask(
602 BrowserThread::IO, FROM_HERE,
603 base::Bind(&ResourcePrefetcherManager::MaybeAddPrefetch,
604 prefetch_manager_, url, subresource_urls));
605 }
606
607 void ResourcePrefetchPredictor::StopPrefetching(const GURL& url) {
608 TRACE_EVENT1("browser", "ResourcePrefetchPredictor::StopPrefetching", "url",
609 url.spec());
610 if (!prefetch_manager_.get()) // Not enabled.
611 return;
612
613 BrowserThread::PostTask(
614 BrowserThread::IO, FROM_HERE,
615 base::Bind(&ResourcePrefetcherManager::MaybeRemovePrefetch,
616 prefetch_manager_, url));
617 }
618
619 void ResourcePrefetchPredictor::StartInitialization() { 650 void ResourcePrefetchPredictor::StartInitialization() {
620 DCHECK_CURRENTLY_ON(BrowserThread::UI); 651 DCHECK_CURRENTLY_ON(BrowserThread::UI);
621 652
622 DCHECK_EQ(NOT_INITIALIZED, initialization_state_); 653 DCHECK_EQ(NOT_INITIALIZED, initialization_state_);
623 initialization_state_ = INITIALIZING; 654 initialization_state_ = INITIALIZING;
624 655
625 // Create local caches using the database as loaded. 656 // Create local caches using the database as loaded.
626 auto url_data_map = base::MakeUnique<PrefetchDataMap>(); 657 auto url_data_map = base::MakeUnique<PrefetchDataMap>();
627 auto host_data_map = base::MakeUnique<PrefetchDataMap>(); 658 auto host_data_map = base::MakeUnique<PrefetchDataMap>();
628 auto url_redirect_data_map = base::MakeUnique<RedirectDataMap>(); 659 auto url_redirect_data_map = base::MakeUnique<RedirectDataMap>();
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
802 833
803 data_map->erase(key_to_delete); 834 data_map->erase(key_to_delete);
804 BrowserThread::PostTask( 835 BrowserThread::PostTask(
805 BrowserThread::DB, FROM_HERE, 836 BrowserThread::DB, FROM_HERE,
806 base::Bind( 837 base::Bind(
807 &ResourcePrefetchPredictorTables::DeleteSingleRedirectDataPoint, 838 &ResourcePrefetchPredictorTables::DeleteSingleRedirectDataPoint,
808 tables_, key_to_delete, key_type)); 839 tables_, key_to_delete, key_type));
809 } 840 }
810 841
811 void ResourcePrefetchPredictor::OnVisitCountLookup( 842 void ResourcePrefetchPredictor::OnVisitCountLookup(
812 size_t visit_count, 843 size_t url_visit_count,
813 const NavigationID& navigation_id,
814 const PageRequestSummary& summary) { 844 const PageRequestSummary& summary) {
815 DCHECK_CURRENTLY_ON(BrowserThread::UI); 845 DCHECK_CURRENTLY_ON(BrowserThread::UI);
816 846
817 UMA_HISTOGRAM_COUNTS("ResourcePrefetchPredictor.HistoryVisitCountForUrl", 847 UMA_HISTOGRAM_COUNTS("ResourcePrefetchPredictor.HistoryVisitCountForUrl",
818 visit_count); 848 url_visit_count);
819 849
820 // TODO(alexilin): make only one request to DB thread. 850 // TODO(alexilin): make only one request to DB thread.
821 851
822 // URL level data - merge only if we already saved the data, or it 852 // URL level data - merge only if we already saved the data, or it
823 // meets the cutoff requirement. 853 // meets the cutoff requirement.
824 const std::string url_spec = navigation_id.main_frame_url.spec(); 854 const std::string url_spec = summary.main_frame_url.spec();
825 bool already_tracking = url_table_cache_->find(url_spec) != 855 bool already_tracking = url_table_cache_->find(url_spec) !=
826 url_table_cache_->end(); 856 url_table_cache_->end();
827 bool should_track_url = already_tracking || 857 bool should_track_url =
828 (visit_count >= config_.min_url_visit_count); 858 already_tracking || (url_visit_count >= config_.min_url_visit_count);
829 859
830 if (should_track_url && config_.IsURLLearningEnabled()) { 860 if (should_track_url && config_.IsURLLearningEnabled()) {
831 LearnNavigation(url_spec, PREFETCH_KEY_TYPE_URL, 861 LearnNavigation(url_spec, PREFETCH_KEY_TYPE_URL,
832 summary.subresource_requests, config_.max_urls_to_track, 862 summary.subresource_requests, config_.max_urls_to_track,
833 url_table_cache_.get(), summary.initial_url.spec(), 863 url_table_cache_.get(), summary.initial_url.spec(),
834 url_redirect_table_cache_.get()); 864 url_redirect_table_cache_.get());
835 } 865 }
836 866
837 // Host level data - no cutoff, always learn the navigation if enabled. 867 // Host level data - no cutoff, always learn the navigation if enabled.
838 if (config_.IsHostLearningEnabled()) { 868 if (config_.IsHostLearningEnabled()) {
839 const std::string host = navigation_id.main_frame_url.host(); 869 const std::string host = summary.main_frame_url.host();
840 LearnNavigation(host, PREFETCH_KEY_TYPE_HOST, summary.subresource_requests, 870 LearnNavigation(host, PREFETCH_KEY_TYPE_HOST, summary.subresource_requests,
841 config_.max_hosts_to_track, host_table_cache_.get(), 871 config_.max_hosts_to_track, host_table_cache_.get(),
842 summary.initial_url.host(), 872 summary.initial_url.host(),
843 host_redirect_table_cache_.get()); 873 host_redirect_table_cache_.get());
844 } 874 }
875
876 for (auto& observer : observers_)
877 observer.OnNavigationLearned(url_visit_count, summary);
845 } 878 }
846 879
847 void ResourcePrefetchPredictor::LearnNavigation( 880 void ResourcePrefetchPredictor::LearnNavigation(
848 const std::string& key, 881 const std::string& key,
849 PrefetchKeyType key_type, 882 PrefetchKeyType key_type,
850 const std::vector<URLRequestSummary>& new_resources, 883 const std::vector<URLRequestSummary>& new_resources,
851 size_t max_data_map_size, 884 size_t max_data_map_size,
852 PrefetchDataMap* data_map, 885 PrefetchDataMap* data_map,
853 const std::string& key_before_redirects, 886 const std::string& key_before_redirects,
854 RedirectDataMap* redirect_map) { 887 RedirectDataMap* redirect_map) {
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
1124 // HistoryService is already loaded. Continue with Initialization. 1157 // HistoryService is already loaded. Continue with Initialization.
1125 OnHistoryAndCacheLoaded(); 1158 OnHistoryAndCacheLoaded();
1126 return; 1159 return;
1127 } 1160 }
1128 DCHECK(!history_service_observer_.IsObserving(history_service)); 1161 DCHECK(!history_service_observer_.IsObserving(history_service));
1129 history_service_observer_.Add(history_service); 1162 history_service_observer_.Add(history_service);
1130 return; 1163 return;
1131 } 1164 }
1132 1165
1133 } // namespace predictors 1166 } // namespace predictors
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698