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

Side by Side Diff: chrome/browser/net/predictor.cc

Issue 2004453002: Add a Dns preresolve interface in //content (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@predictor_dns_browsertest
Patch Set: Move AddressList to unique_ptr Created 4 years, 6 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 (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/net/predictor.h" 5 #include "chrome/browser/net/predictor.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 #include <set> 9 #include <set>
10 #include <sstream> 10 #include <sstream>
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 97
98 static int g_max_queueing_delay_ms = 98 static int g_max_queueing_delay_ms =
99 Predictor::kMaxSpeculativeResolveQueueDelayMs; 99 Predictor::kMaxSpeculativeResolveQueueDelayMs;
100 static size_t g_max_parallel_resolves = 100 static size_t g_max_parallel_resolves =
101 Predictor::kMaxSpeculativeParallelResolves; 101 Predictor::kMaxSpeculativeParallelResolves;
102 102
103 // A version number for prefs that are saved. This should be incremented when 103 // A version number for prefs that are saved. This should be incremented when
104 // we change the format so that we discard old data. 104 // we change the format so that we discard old data.
105 static const int kPredictorStartupFormatVersion = 1; 105 static const int kPredictorStartupFormatVersion = 1;
106 106
107 class Predictor::LookupRequest {
108 public:
109 LookupRequest(Predictor* predictor,
110 net::HostResolver* host_resolver,
111 const GURL& url)
112 : predictor_(predictor),
113 url_(url),
114 resolver_(host_resolver) {
115 }
116
117 // Return underlying network resolver status.
118 // net::OK ==> Host was found synchronously.
119 // net:ERR_IO_PENDING ==> Network will callback later with result.
120 // anything else ==> Host was not found synchronously.
121 int Start() {
122 net::HostResolver::RequestInfo resolve_info(
123 net::HostPortPair::FromURL(url_));
124
125 // Make a note that this is a speculative resolve request. This allows us
126 // to separate it from real navigations in the observer's callback, and
127 // lets the HostResolver know it can de-prioritize it.
128 resolve_info.set_is_speculative(true);
129 return resolver_.Resolve(
130 resolve_info,
131 net::DEFAULT_PRIORITY,
132 &addresses_,
133 base::Bind(&LookupRequest::OnLookupFinished, base::Unretained(this)),
134 net::BoundNetLog());
135 }
136
137 private:
138 void OnLookupFinished(int result) {
139 predictor_->OnLookupFinished(this, url_, result == net::OK);
140 }
141
142 Predictor* predictor_; // The predictor which started us.
143
144 const GURL url_; // Hostname to resolve.
145 net::SingleRequestHostResolver resolver_;
146 net::AddressList addresses_;
147
148 DISALLOW_COPY_AND_ASSIGN(LookupRequest);
149 };
150
151 Predictor::Predictor(bool preconnect_enabled, bool predictor_enabled) 107 Predictor::Predictor(bool preconnect_enabled, bool predictor_enabled)
152 : url_request_context_getter_(NULL), 108 : url_request_context_getter_(nullptr),
153 predictor_enabled_(predictor_enabled), 109 predictor_enabled_(predictor_enabled),
154 user_prefs_(NULL), 110 user_prefs_(nullptr),
155 profile_io_data_(NULL), 111 profile_io_data_(nullptr),
112 num_pending_lookups_(0),
156 peak_pending_lookups_(0), 113 peak_pending_lookups_(0),
157 shutdown_(false), 114 shutdown_(false),
158 max_concurrent_dns_lookups_(g_max_parallel_resolves), 115 max_concurrent_dns_lookups_(g_max_parallel_resolves),
159 max_dns_queue_delay_( 116 max_dns_queue_delay_(
160 TimeDelta::FromMilliseconds(g_max_queueing_delay_ms)), 117 TimeDelta::FromMilliseconds(g_max_queueing_delay_ms)),
161 host_resolver_(NULL), 118 transport_security_state_(nullptr),
162 transport_security_state_(NULL), 119 ssl_config_service_(nullptr),
163 ssl_config_service_(NULL), 120 proxy_service_(nullptr),
164 proxy_service_(NULL),
165 preconnect_enabled_(preconnect_enabled), 121 preconnect_enabled_(preconnect_enabled),
166 consecutive_omnibox_preconnect_count_(0), 122 consecutive_omnibox_preconnect_count_(0),
167 next_trim_time_(base::TimeTicks::Now() + 123 next_trim_time_(base::TimeTicks::Now() +
168 TimeDelta::FromHours(kDurationBetweenTrimmingsHours)), 124 TimeDelta::FromHours(kDurationBetweenTrimmingsHours)),
169 observer_(NULL) { 125 observer_(nullptr) {
170 DCHECK_CURRENTLY_ON(BrowserThread::UI); 126 DCHECK_CURRENTLY_ON(BrowserThread::UI);
171 } 127 }
172 128
173 Predictor::~Predictor() { 129 Predictor::~Predictor() {
174 DCHECK_CURRENTLY_ON(BrowserThread::IO); 130 DCHECK_CURRENTLY_ON(BrowserThread::IO);
175 DCHECK(shutdown_); 131 DCHECK(shutdown_);
176 } 132 }
177 133
178 // static 134 // static
179 Predictor* Predictor::CreatePredictor(bool preconnect_enabled, 135 Predictor* Predictor::CreatePredictor(bool preconnect_enabled,
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 } 347 }
392 348
393 // ---------------------- End UI methods. ------------------------------------- 349 // ---------------------- End UI methods. -------------------------------------
394 350
395 // --------------------- Start IO methods. ------------------------------------ 351 // --------------------- Start IO methods. ------------------------------------
396 352
397 void Predictor::Shutdown() { 353 void Predictor::Shutdown() {
398 DCHECK_CURRENTLY_ON(BrowserThread::IO); 354 DCHECK_CURRENTLY_ON(BrowserThread::IO);
399 DCHECK(!shutdown_); 355 DCHECK(!shutdown_);
400 shutdown_ = true; 356 shutdown_ = true;
401
402 STLDeleteElements(&pending_lookups_);
403 } 357 }
404 358
405 void Predictor::DiscardAllResults() { 359 void Predictor::DiscardAllResults() {
406 DCHECK_CURRENTLY_ON(BrowserThread::IO); 360 DCHECK_CURRENTLY_ON(BrowserThread::IO);
407 // Delete anything listed so far in this session that shows in about:dns. 361 // Delete anything listed so far in this session that shows in about:dns.
408 referrers_.clear(); 362 referrers_.clear();
409 363
410 364
411 // Try to delete anything in our work queue. 365 // Try to delete anything in our work queue.
412 while (!work_queue_.IsEmpty()) { 366 while (!work_queue_.IsEmpty()) {
413 // Emulate processing cycle as though host was not found. 367 // Emulate processing cycle as though host was not found.
414 GURL url = work_queue_.Pop(); 368 GURL url = work_queue_.Pop();
415 UrlInfo* info = &results_[url]; 369 UrlInfo* info = &results_[url];
416 DCHECK(info->HasUrl(url)); 370 DCHECK(info->HasUrl(url));
417 info->SetAssignedState(); 371 info->SetAssignedState();
418 info->SetNoSuchNameState(); 372 info->SetNoSuchNameState();
419 } 373 }
420 // Now every result_ is either resolved, or is being resolved 374 // Now every result_ is either resolved, or is being resolved.
421 // (see LookupRequest).
422 375
423 // Step through result_, recording names of all hosts that can't be erased. 376 // Step through result_, recording names of all hosts that can't be erased.
424 // We can't erase anything being worked on. 377 // We can't erase anything being worked on.
425 Results assignees; 378 Results assignees;
426 for (Results::iterator it = results_.begin(); results_.end() != it; ++it) { 379 for (Results::iterator it = results_.begin(); results_.end() != it; ++it) {
427 GURL url(it->first); 380 GURL url(it->first);
428 UrlInfo* info = &it->second; 381 UrlInfo* info = &it->second;
429 DCHECK(info->HasUrl(url)); 382 DCHECK(info->HasUrl(url));
430 if (info->is_assigned()) { 383 if (info->is_assigned()) {
431 info->SetPendingDeleteState(); 384 info->SetPendingDeleteState();
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
686 639
687 void Predictor::FinalizeInitializationOnIOThread( 640 void Predictor::FinalizeInitializationOnIOThread(
688 const UrlList& startup_urls, 641 const UrlList& startup_urls,
689 base::ListValue* referral_list, 642 base::ListValue* referral_list,
690 IOThread* io_thread, 643 IOThread* io_thread,
691 ProfileIOData* profile_io_data) { 644 ProfileIOData* profile_io_data) {
692 DCHECK_CURRENTLY_ON(BrowserThread::IO); 645 DCHECK_CURRENTLY_ON(BrowserThread::IO);
693 646
694 profile_io_data_ = profile_io_data; 647 profile_io_data_ = profile_io_data;
695 initial_observer_.reset(new InitialObserver()); 648 initial_observer_.reset(new InitialObserver());
696 host_resolver_ = io_thread->globals()->host_resolver.get();
697 649
698 net::URLRequestContext* context = 650 net::URLRequestContext* context =
699 url_request_context_getter_->GetURLRequestContext(); 651 url_request_context_getter_->GetURLRequestContext();
700 transport_security_state_ = context->transport_security_state(); 652 transport_security_state_ = context->transport_security_state();
701 ssl_config_service_ = context->ssl_config_service(); 653 ssl_config_service_ = context->ssl_config_service();
702 proxy_service_ = context->proxy_service(); 654 proxy_service_ = context->proxy_service();
703 655
704 // base::WeakPtrFactory instances need to be created and destroyed 656 // base::WeakPtrFactory instances need to be created and destroyed
705 // on the same thread. The predictor lives on the IO thread and will die 657 // on the same thread. The predictor lives on the IO thread and will die
706 // from there so now that we're on the IO thread we need to properly 658 // from there so now that we're on the IO thread we need to properly
707 // initialize the base::WeakPtrFactory. 659 // initialize the base::WeakPtrFactory.
708 // TODO(groby): Check if WeakPtrFactory has the same constraint. 660 // TODO(groby): Check if WeakPtrFactory has the same constraint.
709 weak_factory_.reset(new base::WeakPtrFactory<Predictor>(this)); 661 weak_factory_.reset(new base::WeakPtrFactory<Predictor>(this));
710 662
711 // Prefetch these hostnames on startup. 663 // Prefetch these hostnames on startup.
712 DnsPrefetchMotivatedList(startup_urls, UrlInfo::STARTUP_LIST_MOTIVATED); 664 DnsPrefetchMotivatedList(startup_urls, UrlInfo::STARTUP_LIST_MOTIVATED);
713 665
714 DeserializeReferrersThenDelete(referral_list); 666 DeserializeReferrersThenDelete(referral_list);
715 } 667 }
716 668
717 //----------------------------------------------------------------------------- 669 //-----------------------------------------------------------------------------
718 // This section intermingles prefetch results with actual browser HTTP 670 // This section intermingles prefetch results with actual browser HTTP
719 // network activity. It supports calculating of the benefit of a prefetch, as 671 // network activity. It supports calculating of the benefit of a prefetch, as
720 // well as recording what prefetched hostname resolutions might be potentially 672 // well as recording what prefetched hostname resolutions might be potentially
721 // helpful during the next chrome-startup. 673 // helpful during the next chrome-startup.
722 //----------------------------------------------------------------------------- 674 //-----------------------------------------------------------------------------
723 675
724 void Predictor::LearnAboutInitialNavigation(const GURL& url) { 676 void Predictor::LearnAboutInitialNavigation(const GURL& url) {
725 DCHECK_CURRENTLY_ON(BrowserThread::IO); 677 DCHECK_CURRENTLY_ON(BrowserThread::IO);
726 if (!predictor_enabled_ || NULL == initial_observer_.get() || 678 if (!predictor_enabled_ || nullptr == initial_observer_.get() ||
727 !CanPreresolveAndPreconnect()) { 679 !CanPreresolveAndPreconnect()) {
728 return; 680 return;
729 } 681 }
730 initial_observer_->Append(url, this); 682 initial_observer_->Append(url, this);
731 } 683 }
732 684
733 // This API is only used in the browser process. 685 // This API is only used in the browser process.
734 // It is called from an IPC message originating in the renderer. It currently 686 // It is called from an IPC message originating in the renderer. It currently
735 // includes both Page-Scan, and Link-Hover prefetching. 687 // includes both Page-Scan, and Link-Hover prefetching.
736 // TODO(jar): Separate out link-hover prefetching, and page-scan results. 688 // TODO(jar): Separate out link-hover prefetching, and page-scan results.
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
773 // Functions to handle saving of hostnames from one session to the next, to 725 // Functions to handle saving of hostnames from one session to the next, to
774 // expedite startup times. 726 // expedite startup times.
775 727
776 static void SaveDnsPrefetchStateForNextStartupAndTrimOnIOThread( 728 static void SaveDnsPrefetchStateForNextStartupAndTrimOnIOThread(
777 base::ListValue* startup_list, 729 base::ListValue* startup_list,
778 base::ListValue* referral_list, 730 base::ListValue* referral_list,
779 base::WaitableEvent* completion, 731 base::WaitableEvent* completion,
780 Predictor* predictor) { 732 Predictor* predictor) {
781 DCHECK_CURRENTLY_ON(BrowserThread::IO); 733 DCHECK_CURRENTLY_ON(BrowserThread::IO);
782 734
783 if (NULL == predictor) { 735 if (nullptr == predictor) {
784 completion->Signal(); 736 completion->Signal();
785 return; 737 return;
786 } 738 }
787 predictor->SaveDnsPrefetchStateForNextStartupAndTrim( 739 predictor->SaveDnsPrefetchStateForNextStartupAndTrim(
788 startup_list, referral_list, completion); 740 startup_list, referral_list, completion);
789 } 741 }
790 742
791 void Predictor::SaveStateForNextStartupAndTrim() { 743 void Predictor::SaveStateForNextStartupAndTrim() {
792 if (!predictor_enabled_) 744 if (!predictor_enabled_)
793 return; 745 return;
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
869 void Predictor::PreconnectUrlOnIOThread( 821 void Predictor::PreconnectUrlOnIOThread(
870 const GURL& original_url, 822 const GURL& original_url,
871 const GURL& first_party_for_cookies, 823 const GURL& first_party_for_cookies,
872 UrlInfo::ResolutionMotivation motivation, 824 UrlInfo::ResolutionMotivation motivation,
873 bool allow_credentials, 825 bool allow_credentials,
874 int count) { 826 int count) {
875 // Skip the HSTS redirect. 827 // Skip the HSTS redirect.
876 GURL url = GetHSTSRedirectOnIOThread(original_url); 828 GURL url = GetHSTSRedirectOnIOThread(original_url);
877 829
878 // TODO(csharrison): The observer should only be notified after the null check 830 // TODO(csharrison): The observer should only be notified after the null check
879 // for the URLRequestContextGetter. The predictor tests should be fixed to 831 // for the ProfileIOData. The predictor tests should be fixed to allow for
880 // allow for this, as they currently expect a callback with no getter. 832 // this, as they currently expect a callback with no getter.
881 // URLRequestContextGetter is null. Tests rely on this behavior.
882 if (observer_) { 833 if (observer_) {
883 observer_->OnPreconnectUrl( 834 observer_->OnPreconnectUrl(
884 url, first_party_for_cookies, motivation, count); 835 url, first_party_for_cookies, motivation, count);
885 } 836 }
886 837
887 net::URLRequestContextGetter* getter = url_request_context_getter_.get(); 838 if (!profile_io_data_)
888 if (!getter)
889 return; 839 return;
890 840
891 // Translate the motivation from UrlRequest motivations to HttpRequest 841 // Translate the motivation from UrlRequest motivations to HttpRequest
892 // motivations. 842 // motivations.
893 net::HttpRequestInfo::RequestMotivation request_motivation = 843 net::HttpRequestInfo::RequestMotivation request_motivation =
894 net::HttpRequestInfo::NORMAL_MOTIVATION; 844 net::HttpRequestInfo::NORMAL_MOTIVATION;
895 switch (motivation) { 845 switch (motivation) {
896 case UrlInfo::OMNIBOX_MOTIVATED: 846 case UrlInfo::OMNIBOX_MOTIVATED:
897 request_motivation = net::HttpRequestInfo::OMNIBOX_MOTIVATED; 847 request_motivation = net::HttpRequestInfo::OMNIBOX_MOTIVATED;
898 break; 848 break;
899 case UrlInfo::LEARNED_REFERAL_MOTIVATED: 849 case UrlInfo::LEARNED_REFERAL_MOTIVATED:
900 request_motivation = net::HttpRequestInfo::PRECONNECT_MOTIVATED; 850 request_motivation = net::HttpRequestInfo::PRECONNECT_MOTIVATED;
901 break; 851 break;
902 case UrlInfo::MOUSE_OVER_MOTIVATED: 852 case UrlInfo::MOUSE_OVER_MOTIVATED:
903 case UrlInfo::SELF_REFERAL_MOTIVATED: 853 case UrlInfo::SELF_REFERAL_MOTIVATED:
904 case UrlInfo::EARLY_LOAD_MOTIVATED: 854 case UrlInfo::EARLY_LOAD_MOTIVATED:
905 request_motivation = net::HttpRequestInfo::EARLY_LOAD_MOTIVATED; 855 request_motivation = net::HttpRequestInfo::EARLY_LOAD_MOTIVATED;
906 break; 856 break;
907 default: 857 default:
908 // Other motivations should never happen here. 858 // Other motivations should never happen here.
909 NOTREACHED(); 859 NOTREACHED();
910 break; 860 break;
911 } 861 }
912 UMA_HISTOGRAM_ENUMERATION("Net.PreconnectMotivation", motivation, 862 UMA_HISTOGRAM_ENUMERATION("Net.PreconnectMotivation", motivation,
913 UrlInfo::MAX_MOTIVATED); 863 UrlInfo::MAX_MOTIVATED);
914 content::PreconnectUrl(getter, url, first_party_for_cookies, count, 864 content::PreconnectUrl(profile_io_data_->GetResourceContext(), url,
915 allow_credentials, request_motivation); 865 first_party_for_cookies, count, allow_credentials,
866 request_motivation);
916 } 867 }
917 868
918 void Predictor::PredictFrameSubresources(const GURL& url, 869 void Predictor::PredictFrameSubresources(const GURL& url,
919 const GURL& first_party_for_cookies) { 870 const GURL& first_party_for_cookies) {
920 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || 871 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) ||
921 BrowserThread::CurrentlyOn(BrowserThread::IO)); 872 BrowserThread::CurrentlyOn(BrowserThread::IO));
922 if (!predictor_enabled_) 873 if (!predictor_enabled_)
923 return; 874 return;
924 if (!CanPreresolveAndPreconnect()) 875 if (!CanPreresolveAndPreconnect())
925 return; 876 return;
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
1016 UrlInfo* queued_info = AppendToResolutionQueue(future_url->first, 967 UrlInfo* queued_info = AppendToResolutionQueue(future_url->first,
1017 motivation); 968 motivation);
1018 if (queued_info) 969 if (queued_info)
1019 queued_info->SetReferringHostname(url); 970 queued_info->SetReferringHostname(url);
1020 } 971 }
1021 UMA_HISTOGRAM_ENUMERATION("Net.PreconnectSubresourceEval", evalution, 972 UMA_HISTOGRAM_ENUMERATION("Net.PreconnectSubresourceEval", evalution,
1022 SUBRESOURCE_VALUE_MAX); 973 SUBRESOURCE_VALUE_MAX);
1023 } 974 }
1024 } 975 }
1025 976
1026 void Predictor::OnLookupFinished(LookupRequest* request, const GURL& url, 977 void Predictor::OnLookupFinished(const GURL& url, int result) {
1027 bool found) {
1028 DCHECK_CURRENTLY_ON(BrowserThread::IO); 978 DCHECK_CURRENTLY_ON(BrowserThread::IO);
1029 979 LookupFinished(url, result == net::OK);
1030 LookupFinished(request, url, found);
1031 if (observer_) 980 if (observer_)
1032 observer_->OnDnsLookupFinished(url, found); 981 observer_->OnDnsLookupFinished(url, result == net::OK);
1033 pending_lookups_.erase(request); 982 DCHECK_GT(num_pending_lookups_, 0u);
1034 delete request; 983 num_pending_lookups_--;
1035
1036 StartSomeQueuedResolutions(); 984 StartSomeQueuedResolutions();
1037 } 985 }
1038 986
1039 void Predictor::LookupFinished(LookupRequest* request, const GURL& url, 987 void Predictor::LookupFinished(const GURL& url, bool found) {
1040 bool found) {
1041 DCHECK_CURRENTLY_ON(BrowserThread::IO); 988 DCHECK_CURRENTLY_ON(BrowserThread::IO);
1042 UrlInfo* info = &results_[url]; 989 UrlInfo* info = &results_[url];
1043 DCHECK(info->HasUrl(url)); 990 DCHECK(info->HasUrl(url));
1044 if (info->is_marked_to_delete()) { 991 if (info->is_marked_to_delete()) {
1045 results_.erase(url); 992 results_.erase(url);
1046 } else { 993 } else {
1047 if (found) 994 if (found)
1048 info->SetFoundState(); 995 info->SetFoundState();
1049 else 996 else
1050 info->SetNoSuchNameState(); 997 info->SetNoSuchNameState();
1051 } 998 }
1052 } 999 }
1053 1000
1054 bool Predictor::WouldLikelyProxyURL(const GURL& url) { 1001 bool Predictor::WouldLikelyProxyURL(const GURL& url) {
1055 if (!proxy_service_) 1002 if (!proxy_service_)
1056 return false; 1003 return false;
1057 1004
1058 net::ProxyInfo info; 1005 net::ProxyInfo info;
1059 bool synchronous_success = proxy_service_->TryResolveProxySynchronously( 1006 bool synchronous_success = proxy_service_->TryResolveProxySynchronously(
1060 url, std::string(), net::LOAD_NORMAL, &info, NULL, net::BoundNetLog()); 1007 url, std::string(), net::LOAD_NORMAL, &info, nullptr, net::BoundNetLog());
1061 1008
1062 return synchronous_success && !info.is_direct(); 1009 return synchronous_success && !info.is_direct();
1063 } 1010 }
1064 1011
1065 UrlInfo* Predictor::AppendToResolutionQueue( 1012 UrlInfo* Predictor::AppendToResolutionQueue(
1066 const GURL& url, 1013 const GURL& url,
1067 UrlInfo::ResolutionMotivation motivation) { 1014 UrlInfo::ResolutionMotivation motivation) {
1068 DCHECK_CURRENTLY_ON(BrowserThread::IO); 1015 DCHECK_CURRENTLY_ON(BrowserThread::IO);
1069 DCHECK(url.has_host()); 1016 DCHECK(url.has_host());
1070 1017
1071 if (shutdown_) 1018 if (shutdown_)
1072 return NULL; 1019 return nullptr;
1073 1020
1074 UrlInfo* info = &results_[url]; 1021 UrlInfo* info = &results_[url];
1075 info->SetUrl(url); // Initialize or DCHECK. 1022 info->SetUrl(url); // Initialize or DCHECK.
1076 // TODO(jar): I need to discard names that have long since expired. 1023 // TODO(jar): I need to discard names that have long since expired.
1077 // Currently we only add to the domain map :-/ 1024 // Currently we only add to the domain map :-/
1078 1025
1079 DCHECK(info->HasUrl(url)); 1026 DCHECK(info->HasUrl(url));
1080 1027
1081 if (!info->NeedsDnsUpdate()) { 1028 if (!info->NeedsDnsUpdate()) {
1082 info->DLogResultsStats("DNS PrefetchNotUpdated"); 1029 info->DLogResultsStats("DNS PrefetchNotUpdated");
1083 return NULL; 1030 return nullptr;
1084 } 1031 }
1085 1032
1086 if (WouldLikelyProxyURL(url)) { 1033 if (WouldLikelyProxyURL(url)) {
1087 info->DLogResultsStats("DNS PrefetchForProxiedRequest"); 1034 info->DLogResultsStats("DNS PrefetchForProxiedRequest");
1088 return NULL; 1035 return nullptr;
1089 } 1036 }
1090 1037
1091 info->SetQueuedState(motivation); 1038 info->SetQueuedState(motivation);
1092 work_queue_.Push(url, motivation); 1039 work_queue_.Push(url, motivation);
1093 1040
1094 StartSomeQueuedResolutions(); 1041 StartSomeQueuedResolutions();
1095 return info; 1042 return info;
1096 } 1043 }
1097 1044
1098 bool Predictor::CongestionControlPerformed(UrlInfo* info) { 1045 bool Predictor::CongestionControlPerformed(UrlInfo* info) {
(...skipping 11 matching lines...) Expand all
1110 break; 1057 break;
1111 info = &results_[work_queue_.Pop()]; 1058 info = &results_[work_queue_.Pop()];
1112 info->SetAssignedState(); 1059 info->SetAssignedState();
1113 } 1060 }
1114 return true; 1061 return true;
1115 } 1062 }
1116 1063
1117 void Predictor::StartSomeQueuedResolutions() { 1064 void Predictor::StartSomeQueuedResolutions() {
1118 DCHECK_CURRENTLY_ON(BrowserThread::IO); 1065 DCHECK_CURRENTLY_ON(BrowserThread::IO);
1119 1066
1120 // If the queue is disabled, just make LookupRequests for all entries. 1067 // If the queue is disabled, just make requests for all entries.
1121 bool enable_queue = base::FeatureList::IsEnabled(kUsePredictorDNSQueue); 1068 bool enable_queue = base::FeatureList::IsEnabled(kUsePredictorDNSQueue);
1122 while (!work_queue_.IsEmpty() && 1069 while (
1123 (!enable_queue || 1070 !work_queue_.IsEmpty() &&
1124 pending_lookups_.size() < max_concurrent_dns_lookups_)) { 1071 (!enable_queue || num_pending_lookups_ < max_concurrent_dns_lookups_)) {
1125 const GURL url(work_queue_.Pop()); 1072 const GURL url(work_queue_.Pop());
1126 UrlInfo* info = &results_[url]; 1073 UrlInfo* info = &results_[url];
1127 DCHECK(info->HasUrl(url)); 1074 DCHECK(info->HasUrl(url));
1128 info->SetAssignedState(); 1075 info->SetAssignedState();
1129 1076
1130 // Only perform congestion control if the queue is enabled. 1077 // Only perform congestion control if the queue is enabled.
1131 if (enable_queue && CongestionControlPerformed(info)) { 1078 if (enable_queue && CongestionControlPerformed(info)) {
1132 DCHECK(work_queue_.IsEmpty()); 1079 DCHECK(work_queue_.IsEmpty());
1133 return; 1080 return;
1134 } 1081 }
1135 1082
1136 LookupRequest* request = new LookupRequest(this, host_resolver_, url); 1083 int status =
1137 1084 content::PreresolveUrl(profile_io_data_->GetResourceContext(), url,
1138 int status = request->Start(); 1085 base::Bind(&Predictor::OnLookupFinished,
1086 weak_factory_->GetWeakPtr(), url));
1139 if (status == net::ERR_IO_PENDING) { 1087 if (status == net::ERR_IO_PENDING) {
1140 // Will complete asynchronously. 1088 // Will complete asynchronously.
1141 pending_lookups_.insert(request); 1089 num_pending_lookups_++;
1142 peak_pending_lookups_ = std::max(peak_pending_lookups_, 1090 peak_pending_lookups_ =
1143 pending_lookups_.size()); 1091 std::max(peak_pending_lookups_, num_pending_lookups_);
1144 } else { 1092 } else {
1145 // Completed synchronously (was already cached by HostResolver), or else 1093 // Completed synchronously (was already cached by HostResolver), or else
1146 // there was (equivalently) some network error that prevents us from 1094 // there was (equivalently) some network error that prevents us from
1147 // finding the name. Status net::OK means it was "found." 1095 // finding the name. Status net::OK means it was "found."
1148 LookupFinished(request, url, status == net::OK); 1096 LookupFinished(url, status == net::OK);
1149 delete request;
1150 } 1097 }
1151 } 1098 }
1152 } 1099 }
1153 1100
1154 void Predictor::TrimReferrers() { 1101 void Predictor::TrimReferrers() {
1155 DCHECK_CURRENTLY_ON(BrowserThread::IO); 1102 DCHECK_CURRENTLY_ON(BrowserThread::IO);
1156 if (!urls_being_trimmed_.empty()) 1103 if (!urls_being_trimmed_.empty())
1157 return; // There is incremental trimming in progress already. 1104 return; // There is incremental trimming in progress already.
1158 1105
1159 // Check to see if it is time to trim yet. 1106 // Check to see if it is time to trim yet.
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
1271 } 1218 }
1272 1219
1273 Predictor::InitialObserver::~InitialObserver() { 1220 Predictor::InitialObserver::~InitialObserver() {
1274 } 1221 }
1275 1222
1276 void Predictor::InitialObserver::Append(const GURL& url, 1223 void Predictor::InitialObserver::Append(const GURL& url,
1277 Predictor* predictor) { 1224 Predictor* predictor) {
1278 DCHECK_CURRENTLY_ON(BrowserThread::IO); 1225 DCHECK_CURRENTLY_ON(BrowserThread::IO);
1279 1226
1280 // TODO(rlp): Do we really need the predictor check here? 1227 // TODO(rlp): Do we really need the predictor check here?
1281 if (NULL == predictor) 1228 if (nullptr == predictor)
1282 return; 1229 return;
1283 if (kStartupResolutionCount <= first_navigations_.size()) 1230 if (kStartupResolutionCount <= first_navigations_.size())
1284 return; 1231 return;
1285 1232
1286 DCHECK(url.SchemeIsHTTPOrHTTPS()); 1233 DCHECK(url.SchemeIsHTTPOrHTTPS());
1287 DCHECK_EQ(url, Predictor::CanonicalizeUrl(url)); 1234 DCHECK_EQ(url, Predictor::CanonicalizeUrl(url));
1288 if (first_navigations_.find(url) == first_navigations_.end()) 1235 if (first_navigations_.find(url) == first_navigations_.end())
1289 first_navigations_[url] = base::TimeTicks::Now(); 1236 first_navigations_[url] = base::TimeTicks::Now();
1290 } 1237 }
1291 1238
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
1361 } 1308 }
1362 1309
1363 void SimplePredictor::ShutdownOnUIThread() { 1310 void SimplePredictor::ShutdownOnUIThread() {
1364 SetShutdown(true); 1311 SetShutdown(true);
1365 } 1312 }
1366 1313
1367 bool SimplePredictor::CanPrefetchAndPrerender() const { return true; } 1314 bool SimplePredictor::CanPrefetchAndPrerender() const { return true; }
1368 bool SimplePredictor::CanPreresolveAndPreconnect() const { return true; } 1315 bool SimplePredictor::CanPreresolveAndPreconnect() const { return true; }
1369 1316
1370 } // namespace chrome_browser_net 1317 } // namespace chrome_browser_net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698