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/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 20 matching lines...) Expand all Loading... | |
31 #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" | 32 #include "chrome/browser/profiles/profile_io_data.h" |
33 #include "chrome/common/chrome_switches.h" | 33 #include "chrome/common/chrome_switches.h" |
34 #include "chrome/common/pref_names.h" | 34 #include "chrome/common/pref_names.h" |
35 #include "components/data_reduction_proxy/browser/data_reduction_proxy_settings. h" | 35 #include "components/data_reduction_proxy/browser/data_reduction_proxy_settings. h" |
36 #include "components/pref_registry/pref_registry_syncable.h" | 36 #include "components/pref_registry/pref_registry_syncable.h" |
37 #include "content/public/browser/browser_thread.h" | 37 #include "content/public/browser/browser_thread.h" |
38 #include "net/base/address_list.h" | 38 #include "net/base/address_list.h" |
39 #include "net/base/completion_callback.h" | 39 #include "net/base/completion_callback.h" |
40 #include "net/base/host_port_pair.h" | 40 #include "net/base/host_port_pair.h" |
41 #include "net/base/load_flags.h" | |
41 #include "net/base/net_errors.h" | 42 #include "net/base/net_errors.h" |
42 #include "net/base/net_log.h" | 43 #include "net/base/net_log.h" |
43 #include "net/dns/host_resolver.h" | 44 #include "net/dns/host_resolver.h" |
44 #include "net/dns/single_request_host_resolver.h" | 45 #include "net/dns/single_request_host_resolver.h" |
45 #include "net/http/transport_security_state.h" | 46 #include "net/http/transport_security_state.h" |
46 #include "net/ssl/ssl_config_service.h" | 47 #include "net/ssl/ssl_config_service.h" |
47 #include "net/url_request/url_request_context.h" | 48 #include "net/url_request/url_request_context.h" |
48 #include "net/url_request/url_request_context_getter.h" | 49 #include "net/url_request/url_request_context_getter.h" |
49 | 50 |
50 using base::TimeDelta; | 51 using base::TimeDelta; |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
141 user_prefs_(NULL), | 142 user_prefs_(NULL), |
142 profile_io_data_(NULL), | 143 profile_io_data_(NULL), |
143 peak_pending_lookups_(0), | 144 peak_pending_lookups_(0), |
144 shutdown_(false), | 145 shutdown_(false), |
145 max_concurrent_dns_lookups_(g_max_parallel_resolves), | 146 max_concurrent_dns_lookups_(g_max_parallel_resolves), |
146 max_dns_queue_delay_( | 147 max_dns_queue_delay_( |
147 TimeDelta::FromMilliseconds(g_max_queueing_delay_ms)), | 148 TimeDelta::FromMilliseconds(g_max_queueing_delay_ms)), |
148 host_resolver_(NULL), | 149 host_resolver_(NULL), |
149 transport_security_state_(NULL), | 150 transport_security_state_(NULL), |
150 ssl_config_service_(NULL), | 151 ssl_config_service_(NULL), |
152 proxy_service_(NULL), | |
151 preconnect_enabled_(preconnect_enabled), | 153 preconnect_enabled_(preconnect_enabled), |
152 consecutive_omnibox_preconnect_count_(0), | 154 consecutive_omnibox_preconnect_count_(0), |
153 next_trim_time_(base::TimeTicks::Now() + | 155 next_trim_time_(base::TimeTicks::Now() + |
154 TimeDelta::FromHours(kDurationBetweenTrimmingsHours)), | 156 TimeDelta::FromHours(kDurationBetweenTrimmingsHours)), |
155 observer_(NULL) { | 157 observer_(NULL) { |
156 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 158 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
157 } | 159 } |
158 | 160 |
159 Predictor::~Predictor() { | 161 Predictor::~Predictor() { |
160 // TODO(rlp): Add DCHECK for CurrentlyOn(BrowserThread::IO) when the | 162 // TODO(rlp): Add DCHECK for CurrentlyOn(BrowserThread::IO) when the |
(...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
692 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 694 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
693 | 695 |
694 profile_io_data_ = profile_io_data; | 696 profile_io_data_ = profile_io_data; |
695 initial_observer_.reset(new InitialObserver()); | 697 initial_observer_.reset(new InitialObserver()); |
696 host_resolver_ = io_thread->globals()->host_resolver.get(); | 698 host_resolver_ = io_thread->globals()->host_resolver.get(); |
697 | 699 |
698 net::URLRequestContext* context = | 700 net::URLRequestContext* context = |
699 url_request_context_getter_->GetURLRequestContext(); | 701 url_request_context_getter_->GetURLRequestContext(); |
700 transport_security_state_ = context->transport_security_state(); | 702 transport_security_state_ = context->transport_security_state(); |
701 ssl_config_service_ = context->ssl_config_service(); | 703 ssl_config_service_ = context->ssl_config_service(); |
704 proxy_service_ = context->proxy_service(); | |
702 | 705 |
703 // base::WeakPtrFactory instances need to be created and destroyed | 706 // base::WeakPtrFactory instances need to be created and destroyed |
704 // on the same thread. The predictor lives on the IO thread and will die | 707 // on the same thread. The predictor lives on the IO thread and will die |
705 // from there so now that we're on the IO thread we need to properly | 708 // from there so now that we're on the IO thread we need to properly |
706 // initialize the base::WeakPtrFactory. | 709 // initialize the base::WeakPtrFactory. |
707 // TODO(groby): Check if WeakPtrFactory has the same constraint. | 710 // TODO(groby): Check if WeakPtrFactory has the same constraint. |
708 weak_factory_.reset(new base::WeakPtrFactory<Predictor>(this)); | 711 weak_factory_.reset(new base::WeakPtrFactory<Predictor>(this)); |
709 | 712 |
710 // Prefetch these hostnames on startup. | 713 // Prefetch these hostnames on startup. |
711 DnsPrefetchMotivatedList(startup_urls, UrlInfo::STARTUP_LIST_MOTIVATED); | 714 DnsPrefetchMotivatedList(startup_urls, UrlInfo::STARTUP_LIST_MOTIVATED); |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1026 if (info->is_marked_to_delete()) { | 1029 if (info->is_marked_to_delete()) { |
1027 results_.erase(url); | 1030 results_.erase(url); |
1028 } else { | 1031 } else { |
1029 if (found) | 1032 if (found) |
1030 info->SetFoundState(); | 1033 info->SetFoundState(); |
1031 else | 1034 else |
1032 info->SetNoSuchNameState(); | 1035 info->SetNoSuchNameState(); |
1033 } | 1036 } |
1034 } | 1037 } |
1035 | 1038 |
1039 bool Predictor::WouldLikelyProxyURL(const GURL& url) { | |
1040 if (!proxy_service_) | |
1041 return false; | |
1042 | |
1043 net::ProxyInfo info; | |
1044 net::CompletionCallback null_callback; | |
1045 int response_code = proxy_service_->ResolveProxy(url, net::LOAD_NORMAL, &info, | |
1046 null_callback, NULL, NULL, net::BoundNetLog()); | |
1047 | |
1048 return response_code == net::OK && !info.is_direct(); | |
1049 } | |
1050 | |
1036 UrlInfo* Predictor::AppendToResolutionQueue( | 1051 UrlInfo* Predictor::AppendToResolutionQueue( |
1037 const GURL& url, | 1052 const GURL& url, |
1038 UrlInfo::ResolutionMotivation motivation) { | 1053 UrlInfo::ResolutionMotivation motivation) { |
1039 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 1054 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
1040 DCHECK(url.has_host()); | 1055 DCHECK(url.has_host()); |
1041 | 1056 |
1042 if (shutdown_) | 1057 if (shutdown_) |
1043 return NULL; | 1058 return NULL; |
1044 | 1059 |
1045 UrlInfo* info = &results_[url]; | 1060 UrlInfo* info = &results_[url]; |
1046 info->SetUrl(url); // Initialize or DCHECK. | 1061 info->SetUrl(url); // Initialize or DCHECK. |
1047 // TODO(jar): I need to discard names that have long since expired. | 1062 // TODO(jar): I need to discard names that have long since expired. |
1048 // Currently we only add to the domain map :-/ | 1063 // Currently we only add to the domain map :-/ |
1049 | 1064 |
1050 DCHECK(info->HasUrl(url)); | 1065 DCHECK(info->HasUrl(url)); |
1051 | 1066 |
1052 if (!info->NeedsDnsUpdate()) { | 1067 if (!info->NeedsDnsUpdate()) { |
1053 info->DLogResultsStats("DNS PrefetchNotUpdated"); | 1068 info->DLogResultsStats("DNS PrefetchNotUpdated"); |
1054 return NULL; | 1069 return NULL; |
1055 } | 1070 } |
1056 | 1071 |
1057 AdviseProxy(url, motivation, false /* is_preconnect */); | 1072 AdviseProxy(url, motivation, false /* is_preconnect */); |
1058 if (proxy_advisor_ && proxy_advisor_->WouldProxyURL(url)) { | 1073 if ((proxy_advisor_ && proxy_advisor_->WouldProxyURL(url)) || |
eroman
2014/09/23 20:50:41
What is the role of proxy_advisor? How does this d
bemasc
2014/09/24 18:34:36
proxy_advisor is poorly named, IMHO. It is only n
| |
1074 WouldLikelyProxyURL(url)) { | |
1059 info->DLogResultsStats("DNS PrefetchForProxiedRequest"); | 1075 info->DLogResultsStats("DNS PrefetchForProxiedRequest"); |
1060 return NULL; | 1076 return NULL; |
1061 } | 1077 } |
1062 | 1078 |
1063 info->SetQueuedState(motivation); | 1079 info->SetQueuedState(motivation); |
1064 work_queue_.Push(url, motivation); | 1080 work_queue_.Push(url, motivation); |
1065 StartSomeQueuedResolutions(); | 1081 StartSomeQueuedResolutions(); |
1066 return info; | 1082 return info; |
1067 } | 1083 } |
1068 | 1084 |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1329 } | 1345 } |
1330 | 1346 |
1331 void SimplePredictor::ShutdownOnUIThread() { | 1347 void SimplePredictor::ShutdownOnUIThread() { |
1332 SetShutdown(true); | 1348 SetShutdown(true); |
1333 } | 1349 } |
1334 | 1350 |
1335 bool SimplePredictor::CanPrefetchAndPrerender() const { return true; } | 1351 bool SimplePredictor::CanPrefetchAndPrerender() const { return true; } |
1336 bool SimplePredictor::CanPreresolveAndPreconnect() const { return true; } | 1352 bool SimplePredictor::CanPreresolveAndPreconnect() const { return true; } |
1337 | 1353 |
1338 } // namespace chrome_browser_net | 1354 } // namespace chrome_browser_net |
OLD | NEW |