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

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

Issue 360733005: Poll CanPredictNetworkActions in Predictor class. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Nits. Created 6 years, 5 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>
11 11
12 #include "base/basictypes.h" 12 #include "base/basictypes.h"
13 #include "base/bind.h" 13 #include "base/bind.h"
14 #include "base/compiler_specific.h" 14 #include "base/compiler_specific.h"
15 #include "base/containers/mru_cache.h" 15 #include "base/containers/mru_cache.h"
16 #include "base/metrics/histogram.h" 16 #include "base/metrics/histogram.h"
17 #include "base/prefs/pref_service.h" 17 #include "base/prefs/pref_service.h"
18 #include "base/prefs/scoped_user_pref_update.h" 18 #include "base/prefs/scoped_user_pref_update.h"
19 #include "base/stl_util.h" 19 #include "base/stl_util.h"
20 #include "base/strings/string_split.h" 20 #include "base/strings/string_split.h"
21 #include "base/strings/string_util.h" 21 #include "base/strings/string_util.h"
22 #include "base/strings/stringprintf.h" 22 #include "base/strings/stringprintf.h"
23 #include "base/synchronization/waitable_event.h" 23 #include "base/synchronization/waitable_event.h"
24 #include "base/threading/thread_restrictions.h" 24 #include "base/threading/thread_restrictions.h"
25 #include "base/time/time.h" 25 #include "base/time/time.h"
26 #include "base/values.h" 26 #include "base/values.h"
27 #include "chrome/browser/io_thread.h" 27 #include "chrome/browser/io_thread.h"
28 #include "chrome/browser/net/preconnect.h" 28 #include "chrome/browser/net/preconnect.h"
29 #include "chrome/browser/net/prediction_options.h"
29 #include "chrome/browser/net/spdyproxy/proxy_advisor.h" 30 #include "chrome/browser/net/spdyproxy/proxy_advisor.h"
30 #include "chrome/browser/prefs/session_startup_pref.h" 31 #include "chrome/browser/prefs/session_startup_pref.h"
32 #include "chrome/browser/profiles/profile_io_data.h"
31 #include "chrome/common/chrome_switches.h" 33 #include "chrome/common/chrome_switches.h"
32 #include "chrome/common/pref_names.h" 34 #include "chrome/common/pref_names.h"
33 #include "components/data_reduction_proxy/browser/data_reduction_proxy_settings. h" 35 #include "components/data_reduction_proxy/browser/data_reduction_proxy_settings. h"
34 #include "components/pref_registry/pref_registry_syncable.h" 36 #include "components/pref_registry/pref_registry_syncable.h"
35 #include "content/public/browser/browser_thread.h" 37 #include "content/public/browser/browser_thread.h"
36 #include "net/base/address_list.h" 38 #include "net/base/address_list.h"
37 #include "net/base/completion_callback.h" 39 #include "net/base/completion_callback.h"
38 #include "net/base/host_port_pair.h" 40 #include "net/base/host_port_pair.h"
39 #include "net/base/net_errors.h" 41 #include "net/base/net_errors.h"
40 #include "net/base/net_log.h" 42 #include "net/base/net_log.h"
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 128
127 Predictor* predictor_; // The predictor which started us. 129 Predictor* predictor_; // The predictor which started us.
128 130
129 const GURL url_; // Hostname to resolve. 131 const GURL url_; // Hostname to resolve.
130 net::SingleRequestHostResolver resolver_; 132 net::SingleRequestHostResolver resolver_;
131 net::AddressList addresses_; 133 net::AddressList addresses_;
132 134
133 DISALLOW_COPY_AND_ASSIGN(LookupRequest); 135 DISALLOW_COPY_AND_ASSIGN(LookupRequest);
134 }; 136 };
135 137
136 Predictor::Predictor(bool preconnect_enabled) 138 Predictor::Predictor(bool preconnect_enabled, bool predictor_enabled)
137 : url_request_context_getter_(NULL), 139 : url_request_context_getter_(NULL),
138 predictor_enabled_(true), 140 predictor_enabled_(predictor_enabled),
141 user_prefs_(NULL),
142 profile_io_data_(NULL),
139 peak_pending_lookups_(0), 143 peak_pending_lookups_(0),
140 shutdown_(false), 144 shutdown_(false),
141 max_concurrent_dns_lookups_(g_max_parallel_resolves), 145 max_concurrent_dns_lookups_(g_max_parallel_resolves),
142 max_dns_queue_delay_( 146 max_dns_queue_delay_(
143 TimeDelta::FromMilliseconds(g_max_queueing_delay_ms)), 147 TimeDelta::FromMilliseconds(g_max_queueing_delay_ms)),
144 host_resolver_(NULL), 148 host_resolver_(NULL),
145 transport_security_state_(NULL), 149 transport_security_state_(NULL),
146 ssl_config_service_(NULL), 150 ssl_config_service_(NULL),
147 preconnect_enabled_(preconnect_enabled), 151 preconnect_enabled_(preconnect_enabled),
148 consecutive_omnibox_preconnect_count_(0), 152 consecutive_omnibox_preconnect_count_(0),
149 next_trim_time_(base::TimeTicks::Now() + 153 next_trim_time_(base::TimeTicks::Now() +
150 TimeDelta::FromHours(kDurationBetweenTrimmingsHours)), 154 TimeDelta::FromHours(kDurationBetweenTrimmingsHours)),
151 observer_(NULL) { 155 observer_(NULL) {
152 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 156 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
153 } 157 }
154 158
155 Predictor::~Predictor() { 159 Predictor::~Predictor() {
156 // TODO(rlp): Add DCHECK for CurrentlyOn(BrowserThread::IO) when the 160 // TODO(rlp): Add DCHECK for CurrentlyOn(BrowserThread::IO) when the
157 // ProfileManagerTest has been updated with a mock profile. 161 // ProfileManagerTest has been updated with a mock profile.
158 DCHECK(shutdown_); 162 DCHECK(shutdown_);
159 } 163 }
160 164
161 // static 165 // static
162 Predictor* Predictor::CreatePredictor(bool preconnect_enabled, 166 Predictor* Predictor::CreatePredictor(bool preconnect_enabled,
167 bool predictor_enabled,
163 bool simple_shutdown) { 168 bool simple_shutdown) {
164 if (simple_shutdown) 169 if (simple_shutdown)
165 return new SimplePredictor(preconnect_enabled); 170 return new SimplePredictor(preconnect_enabled, predictor_enabled);
166 return new Predictor(preconnect_enabled); 171 return new Predictor(preconnect_enabled, predictor_enabled);
167 } 172 }
168 173
169 void Predictor::RegisterProfilePrefs( 174 void Predictor::RegisterProfilePrefs(
170 user_prefs::PrefRegistrySyncable* registry) { 175 user_prefs::PrefRegistrySyncable* registry) {
171 registry->RegisterListPref(prefs::kDnsPrefetchingStartupList, 176 registry->RegisterListPref(prefs::kDnsPrefetchingStartupList,
172 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); 177 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
173 registry->RegisterListPref(prefs::kDnsPrefetchingHostReferralList, 178 registry->RegisterListPref(prefs::kDnsPrefetchingHostReferralList,
174 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); 179 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
175 } 180 }
176 181
177 // --------------------- Start UI methods. ------------------------------------ 182 // --------------------- Start UI methods. ------------------------------------
178 183
179 void Predictor::InitNetworkPredictor(PrefService* user_prefs, 184 void Predictor::InitNetworkPredictor(PrefService* user_prefs,
180 PrefService* local_state, 185 PrefService* local_state,
181 IOThread* io_thread, 186 IOThread* io_thread,
182 net::URLRequestContextGetter* getter) { 187 net::URLRequestContextGetter* getter,
188 ProfileIOData* profile_io_data) {
183 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 189 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
184 190
185 bool predictor_enabled = 191 user_prefs_ = user_prefs;
186 user_prefs->GetBoolean(prefs::kNetworkPredictionEnabled);
187
188 url_request_context_getter_ = getter; 192 url_request_context_getter_ = getter;
189 193
190 // Gather the list of hostnames to prefetch on startup. 194 // Gather the list of hostnames to prefetch on startup.
191 UrlList urls = GetPredictedUrlListAtStartup(user_prefs, local_state); 195 UrlList urls = GetPredictedUrlListAtStartup(user_prefs, local_state);
192 196
193 base::ListValue* referral_list = 197 base::ListValue* referral_list =
194 static_cast<base::ListValue*>(user_prefs->GetList( 198 static_cast<base::ListValue*>(user_prefs->GetList(
195 prefs::kDnsPrefetchingHostReferralList)->DeepCopy()); 199 prefs::kDnsPrefetchingHostReferralList)->DeepCopy());
196 200
197 // Now that we have the statistics in memory, wipe them from the Preferences 201 // Now that we have the statistics in memory, wipe them from the Preferences
(...skipping 15 matching lines...) Expand all
213 } 217 }
214 #endif 218 #endif
215 219
216 BrowserThread::PostTask( 220 BrowserThread::PostTask(
217 BrowserThread::IO, 221 BrowserThread::IO,
218 FROM_HERE, 222 FROM_HERE,
219 base::Bind( 223 base::Bind(
220 &Predictor::FinalizeInitializationOnIOThread, 224 &Predictor::FinalizeInitializationOnIOThread,
221 base::Unretained(this), 225 base::Unretained(this),
222 urls, referral_list, 226 urls, referral_list,
223 io_thread, predictor_enabled)); 227 io_thread, profile_io_data));
224 } 228 }
225 229
226 void Predictor::AnticipateOmniboxUrl(const GURL& url, bool preconnectable) { 230 void Predictor::AnticipateOmniboxUrl(const GURL& url, bool preconnectable) {
227 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 231 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
228 if (!predictor_enabled_) 232 if (!predictor_enabled_)
229 return; 233 return;
230 if (!url.is_valid() || !url.has_host()) 234 if (!url.is_valid() || !url.has_host())
231 return; 235 return;
232 std::string host = url.HostNoBrackets(); 236 std::string host = url.HostNoBrackets();
233 bool is_new_host_request = (host != last_omnibox_host_); 237 bool is_new_host_request = (host != last_omnibox_host_);
234 last_omnibox_host_ = host; 238 last_omnibox_host_ = host;
235 239
236 UrlInfo::ResolutionMotivation motivation(UrlInfo::OMNIBOX_MOTIVATED); 240 UrlInfo::ResolutionMotivation motivation(UrlInfo::OMNIBOX_MOTIVATED);
237 base::TimeTicks now = base::TimeTicks::Now(); 241 base::TimeTicks now = base::TimeTicks::Now();
238 242
239 if (preconnect_enabled()) { 243 if (preconnect_enabled_ &&
244 chrome_browser_net::CanPredictNetworkActionsUI(user_prefs_)) {
battre 2014/07/01 08:27:48 This approach looks a little bit strange to me. Th
240 if (preconnectable && !is_new_host_request) { 245 if (preconnectable && !is_new_host_request) {
241 ++consecutive_omnibox_preconnect_count_; 246 ++consecutive_omnibox_preconnect_count_;
242 // The omnibox suggests a search URL (for which we can preconnect) after 247 // The omnibox suggests a search URL (for which we can preconnect) after
243 // one or two characters are typed, even though such typing often (1 in 248 // one or two characters are typed, even though such typing often (1 in
244 // 3?) becomes a real URL. This code waits till is has more evidence of a 249 // 3?) becomes a real URL. This code waits till is has more evidence of a
245 // preconnectable URL (search URL) before forming a preconnection, so as 250 // preconnectable URL (search URL) before forming a preconnection, so as
246 // to reduce the useless preconnect rate. 251 // to reduce the useless preconnect rate.
247 // Perchance this logic should be pushed back into the omnibox, where the 252 // Perchance this logic should be pushed back into the omnibox, where the
248 // actual characters typed, such as a space, can better forcast whether 253 // actual characters typed, such as a space, can better forcast whether
249 // we need to search/preconnect or not. By waiting for at least 4 254 // we need to search/preconnect or not. By waiting for at least 4
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 BrowserThread::IO, 297 BrowserThread::IO,
293 FROM_HERE, 298 FROM_HERE,
294 base::Bind(&Predictor::Resolve, base::Unretained(this), 299 base::Bind(&Predictor::Resolve, base::Unretained(this),
295 CanonicalizeUrl(url), motivation)); 300 CanonicalizeUrl(url), motivation));
296 } 301 }
297 302
298 void Predictor::PreconnectUrlAndSubresources(const GURL& url, 303 void Predictor::PreconnectUrlAndSubresources(const GURL& url,
299 const GURL& first_party_for_cookies) { 304 const GURL& first_party_for_cookies) {
300 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || 305 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) ||
301 BrowserThread::CurrentlyOn(BrowserThread::IO)); 306 BrowserThread::CurrentlyOn(BrowserThread::IO));
302 if (!predictor_enabled_ || !preconnect_enabled() || 307 if (!predictor_enabled_ || !preconnect_enabled_ ||
308 !chrome_browser_net::CanPredictNetworkActionsUI(user_prefs_) ||
303 !url.is_valid() || !url.has_host()) 309 !url.is_valid() || !url.has_host())
304 return; 310 return;
305 311
306 UrlInfo::ResolutionMotivation motivation(UrlInfo::EARLY_LOAD_MOTIVATED); 312 UrlInfo::ResolutionMotivation motivation(UrlInfo::EARLY_LOAD_MOTIVATED);
307 const int kConnectionsNeeded = 1; 313 const int kConnectionsNeeded = 1;
308 PreconnectUrl(CanonicalizeUrl(url), first_party_for_cookies, 314 PreconnectUrl(CanonicalizeUrl(url), first_party_for_cookies,
309 motivation, kConnectionsNeeded); 315 motivation, kConnectionsNeeded);
310 PredictFrameSubresources(url.GetWithEmptyPath(), first_party_for_cookies); 316 PredictFrameSubresources(url.GetWithEmptyPath(), first_party_for_cookies);
311 } 317 }
312 318
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 // This section supports the about:dns page. 480 // This section supports the about:dns page.
475 481
476 void Predictor::PredictorGetHtmlInfo(Predictor* predictor, 482 void Predictor::PredictorGetHtmlInfo(Predictor* predictor,
477 std::string* output) { 483 std::string* output) {
478 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 484 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
479 485
480 output->append("<html><head><title>About DNS</title>" 486 output->append("<html><head><title>About DNS</title>"
481 // We'd like the following no-cache... but it doesn't work. 487 // We'd like the following no-cache... but it doesn't work.
482 // "<META HTTP-EQUIV=\"Pragma\" CONTENT=\"no-cache\">" 488 // "<META HTTP-EQUIV=\"Pragma\" CONTENT=\"no-cache\">"
483 "</head><body>"); 489 "</head><body>");
484 if (predictor && predictor->predictor_enabled()) { 490 if (predictor && predictor->predictor_enabled() &&
491 chrome_browser_net::CanPredictNetworkActionsIO(
492 predictor->profile_io_data())) {
485 predictor->GetHtmlInfo(output); 493 predictor->GetHtmlInfo(output);
486 } else { 494 } else {
487 output->append("DNS pre-resolution and TCP pre-connection is disabled."); 495 output->append("DNS pre-resolution and TCP pre-connection is disabled.");
488 } 496 }
489 output->append("</body></html>"); 497 output->append("</body></html>");
490 } 498 }
491 499
492 // Provide sort order so all .com's are together, etc. 500 // Provide sort order so all .com's are together, etc.
493 struct RightToLeftStringSorter { 501 struct RightToLeftStringSorter {
494 bool operator()(const GURL& left, const GURL& right) const { 502 bool operator()(const GURL& left, const GURL& right) const {
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
671 void Predictor::DiscardInitialNavigationHistory() { 679 void Predictor::DiscardInitialNavigationHistory() {
672 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 680 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
673 if (initial_observer_.get()) 681 if (initial_observer_.get())
674 initial_observer_->DiscardInitialNavigationHistory(); 682 initial_observer_->DiscardInitialNavigationHistory();
675 } 683 }
676 684
677 void Predictor::FinalizeInitializationOnIOThread( 685 void Predictor::FinalizeInitializationOnIOThread(
678 const UrlList& startup_urls, 686 const UrlList& startup_urls,
679 base::ListValue* referral_list, 687 base::ListValue* referral_list,
680 IOThread* io_thread, 688 IOThread* io_thread,
681 bool predictor_enabled) { 689 ProfileIOData* profile_io_data) {
682 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 690 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
683 691
684 predictor_enabled_ = predictor_enabled; 692 profile_io_data_ = profile_io_data;
685 initial_observer_.reset(new InitialObserver()); 693 initial_observer_.reset(new InitialObserver());
686 host_resolver_ = io_thread->globals()->host_resolver.get(); 694 host_resolver_ = io_thread->globals()->host_resolver.get();
687 695
688 net::URLRequestContext* context = 696 net::URLRequestContext* context =
689 url_request_context_getter_->GetURLRequestContext(); 697 url_request_context_getter_->GetURLRequestContext();
690 transport_security_state_ = context->transport_security_state(); 698 transport_security_state_ = context->transport_security_state();
691 ssl_config_service_ = context->ssl_config_service(); 699 ssl_config_service_ = context->ssl_config_service();
692 700
693 // base::WeakPtrFactory instances need to be created and destroyed 701 // base::WeakPtrFactory instances need to be created and destroyed
694 // on the same thread. The predictor lives on the IO thread and will die 702 // on the same thread. The predictor lives on the IO thread and will die
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
765 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 773 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
766 774
767 if (NULL == predictor) { 775 if (NULL == predictor) {
768 completion->Signal(); 776 completion->Signal();
769 return; 777 return;
770 } 778 }
771 predictor->SaveDnsPrefetchStateForNextStartupAndTrim( 779 predictor->SaveDnsPrefetchStateForNextStartupAndTrim(
772 startup_list, referral_list, completion); 780 startup_list, referral_list, completion);
773 } 781 }
774 782
775 void Predictor::SaveStateForNextStartupAndTrim(PrefService* prefs) { 783 void Predictor::SaveStateForNextStartupAndTrim() {
776 if (!predictor_enabled_) 784 if (!predictor_enabled_)
777 return; 785 return;
778 786
779 base::WaitableEvent completion(true, false); 787 base::WaitableEvent completion(true, false);
780 788
781 ListPrefUpdate update_startup_list(prefs, prefs::kDnsPrefetchingStartupList); 789 ListPrefUpdate update_startup_list(user_prefs_,
782 ListPrefUpdate update_referral_list(prefs, 790 prefs::kDnsPrefetchingStartupList);
791 ListPrefUpdate update_referral_list(user_prefs_,
783 prefs::kDnsPrefetchingHostReferralList); 792 prefs::kDnsPrefetchingHostReferralList);
784 if (BrowserThread::CurrentlyOn(BrowserThread::IO)) { 793 if (BrowserThread::CurrentlyOn(BrowserThread::IO)) {
785 SaveDnsPrefetchStateForNextStartupAndTrimOnIOThread( 794 SaveDnsPrefetchStateForNextStartupAndTrimOnIOThread(
786 update_startup_list.Get(), 795 update_startup_list.Get(),
787 update_referral_list.Get(), 796 update_referral_list.Get(),
788 &completion, 797 &completion,
789 this); 798 this);
790 } else { 799 } else {
791 bool posted = BrowserThread::PostTask( 800 bool posted = BrowserThread::PostTask(
792 BrowserThread::IO, 801 BrowserThread::IO,
(...skipping 25 matching lines...) Expand all
818 initial_observer_->GetInitialDnsResolutionList(startup_list); 827 initial_observer_->GetInitialDnsResolutionList(startup_list);
819 828
820 // Do at least one trim at shutdown, in case the user wasn't running long 829 // Do at least one trim at shutdown, in case the user wasn't running long
821 // enough to do any regular trimming of referrers. 830 // enough to do any regular trimming of referrers.
822 TrimReferrersNow(); 831 TrimReferrersNow();
823 SerializeReferrers(referral_list); 832 SerializeReferrers(referral_list);
824 833
825 completion->Signal(); 834 completion->Signal();
826 } 835 }
827 836
828 void Predictor::EnablePredictor(bool enable) {
829 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) ||
830 BrowserThread::CurrentlyOn(BrowserThread::IO));
831
832 if (BrowserThread::CurrentlyOn(BrowserThread::IO)) {
833 EnablePredictorOnIOThread(enable);
834 } else {
835 BrowserThread::PostTask(
836 BrowserThread::IO,
837 FROM_HERE,
838 base::Bind(&Predictor::EnablePredictorOnIOThread,
839 base::Unretained(this), enable));
840 }
841 }
842
843 void Predictor::EnablePredictorOnIOThread(bool enable) {
844 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
845 predictor_enabled_ = enable;
846 }
847
848 void Predictor::PreconnectUrl(const GURL& url, 837 void Predictor::PreconnectUrl(const GURL& url,
849 const GURL& first_party_for_cookies, 838 const GURL& first_party_for_cookies,
850 UrlInfo::ResolutionMotivation motivation, 839 UrlInfo::ResolutionMotivation motivation,
851 int count) { 840 int count) {
852 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || 841 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) ||
853 BrowserThread::CurrentlyOn(BrowserThread::IO)); 842 BrowserThread::CurrentlyOn(BrowserThread::IO));
854 843
855 if (BrowserThread::CurrentlyOn(BrowserThread::IO)) { 844 if (BrowserThread::CurrentlyOn(BrowserThread::IO)) {
856 PreconnectUrlOnIOThread(url, first_party_for_cookies, motivation, count); 845 PreconnectUrlOnIOThread(url, first_party_for_cookies, motivation, count);
857 } else { 846 } else {
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
942 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 931 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
943 DCHECK_EQ(url.GetWithEmptyPath(), url); 932 DCHECK_EQ(url.GetWithEmptyPath(), url);
944 Referrers::iterator it = referrers_.find(url); 933 Referrers::iterator it = referrers_.find(url);
945 if (referrers_.end() == it) { 934 if (referrers_.end() == it) {
946 // Only when we don't know anything about this url, make 2 connections 935 // Only when we don't know anything about this url, make 2 connections
947 // available. We could do this completely via learning (by prepopulating 936 // available. We could do this completely via learning (by prepopulating
948 // the referrer_ list with this expected value), but it would swell the 937 // the referrer_ list with this expected value), but it would swell the
949 // size of the list with all the "Leaf" nodes in the tree (nodes that don't 938 // size of the list with all the "Leaf" nodes in the tree (nodes that don't
950 // load any subresources). If we learn about this resource, we will instead 939 // load any subresources). If we learn about this resource, we will instead
951 // provide a more carefully estimated preconnection count. 940 // provide a more carefully estimated preconnection count.
952 if (preconnect_enabled_) { 941 if (preconnect_enabled_ &&
942 chrome_browser_net::CanPredictNetworkActionsIO(profile_io_data_)) {
953 PreconnectUrlOnIOThread(url, first_party_for_cookies, 943 PreconnectUrlOnIOThread(url, first_party_for_cookies,
954 UrlInfo::SELF_REFERAL_MOTIVATED, 2); 944 UrlInfo::SELF_REFERAL_MOTIVATED, 2);
955 } 945 }
956 return; 946 return;
957 } 947 }
958 948
959 Referrer* referrer = &(it->second); 949 Referrer* referrer = &(it->second);
960 referrer->IncrementUseCount(); 950 referrer->IncrementUseCount();
961 const UrlInfo::ResolutionMotivation motivation = 951 const UrlInfo::ResolutionMotivation motivation =
962 UrlInfo::LEARNED_REFERAL_MOTIVATED; 952 UrlInfo::LEARNED_REFERAL_MOTIVATED;
963 for (Referrer::iterator future_url = referrer->begin(); 953 for (Referrer::iterator future_url = referrer->begin();
964 future_url != referrer->end(); ++future_url) { 954 future_url != referrer->end(); ++future_url) {
965 SubresourceValue evalution(TOO_NEW); 955 SubresourceValue evalution(TOO_NEW);
966 double connection_expectation = future_url->second.subresource_use_rate(); 956 double connection_expectation = future_url->second.subresource_use_rate();
967 UMA_HISTOGRAM_CUSTOM_COUNTS("Net.PreconnectSubresourceExpectation", 957 UMA_HISTOGRAM_CUSTOM_COUNTS("Net.PreconnectSubresourceExpectation",
968 static_cast<int>(connection_expectation * 100), 958 static_cast<int>(connection_expectation * 100),
969 10, 5000, 50); 959 10, 5000, 50);
970 future_url->second.ReferrerWasObserved(); 960 future_url->second.ReferrerWasObserved();
971 if (preconnect_enabled_ && 961 if (preconnect_enabled_ &&
962 chrome_browser_net::CanPredictNetworkActionsIO(profile_io_data_) &&
972 connection_expectation > kPreconnectWorthyExpectedValue) { 963 connection_expectation > kPreconnectWorthyExpectedValue) {
973 evalution = PRECONNECTION; 964 evalution = PRECONNECTION;
974 future_url->second.IncrementPreconnectionCount(); 965 future_url->second.IncrementPreconnectionCount();
975 int count = static_cast<int>(std::ceil(connection_expectation)); 966 int count = static_cast<int>(std::ceil(connection_expectation));
976 if (url.host() == future_url->first.host()) 967 if (url.host() == future_url->first.host())
977 ++count; 968 ++count;
978 PreconnectUrlOnIOThread(future_url->first, first_party_for_cookies, 969 PreconnectUrlOnIOThread(future_url->first, first_party_for_cookies,
979 motivation, count); 970 motivation, count);
980 } else if (connection_expectation > kDNSPreresolutionWorthyExpectedValue) { 971 } else if (connection_expectation > kDNSPreresolutionWorthyExpectedValue) {
981 evalution = PRERESOLUTION; 972 evalution = PRERESOLUTION;
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
1299 if (url.has_port()) 1290 if (url.has_port())
1300 colon_plus_port = ":" + url.port(); 1291 colon_plus_port = ":" + url.port();
1301 1292
1302 return GURL(scheme + "://" + url.host() + colon_plus_port); 1293 return GURL(scheme + "://" + url.host() + colon_plus_port);
1303 } 1294 }
1304 1295
1305 void SimplePredictor::InitNetworkPredictor( 1296 void SimplePredictor::InitNetworkPredictor(
1306 PrefService* user_prefs, 1297 PrefService* user_prefs,
1307 PrefService* local_state, 1298 PrefService* local_state,
1308 IOThread* io_thread, 1299 IOThread* io_thread,
1309 net::URLRequestContextGetter* getter) { 1300 net::URLRequestContextGetter* getter,
1301 ProfileIOData* profile_io_data) {
1310 // Empty function for unittests. 1302 // Empty function for unittests.
1311 } 1303 }
1312 1304
1313 void SimplePredictor::ShutdownOnUIThread() { 1305 void SimplePredictor::ShutdownOnUIThread() {
1314 SetShutdown(true); 1306 SetShutdown(true);
1315 } 1307 }
1316 1308
1317 } // namespace chrome_browser_net 1309 } // namespace chrome_browser_net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698