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

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

Issue 545633002: Don't preresolve DNS if a fixed proxy configuration is in place. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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
« no previous file with comments | « chrome/browser/net/predictor.h ('k') | chrome/browser/net/predictor_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 20 matching lines...) Expand all
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
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
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
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 // Dummy function, used to discard asynchronous results from ResolveProxy.
1040 void DiscardInput(int x) {}
1041
1042 bool Predictor::WouldDefinitelyProxyURL(const GURL& url) {
eroman 2014/09/10 01:26:04 This title is misleading. It is still possible for
bemasc 2014/09/10 15:19:02 OK. Do you think I should change the name ("Would
eroman 2014/09/18 17:51:28 How about: "WouldLikelyProxyURL()" That name is
bemasc 2014/09/19 19:41:37 Done.
1043 if (!proxy_service_)
1044 return false;
1045
1046 net::ProxyInfo info;
1047 net::CompletionCallback callback = base::Bind(&DiscardInput);
1048 net::ProxyService::PacRequest* pac_request = NULL;
1049 int response_code = proxy_service_->ResolveProxy(url, net::LOAD_NORMAL, &info,
1050 callback, &pac_request, NULL, net::BoundNetLog());
1051 if (response_code != net::LOAD_NORMAL) {
eroman 2014/09/10 01:26:04 This code is incorrect: (1) Use net::OK not net:
bemasc 2014/09/19 19:41:37 Done.
1052 // Avoid performing the asynchronous proxy resolution work for no reason.
1053 DCHECK(pac_request != NULL);
1054 proxy_service_->CancelPacRequest(pac_request);
eroman 2014/09/10 01:26:04 In the case where a PAC script _is_ configured, it
bemasc 2014/09/10 15:19:02 OK. There are 10 calls to ResolveProxy in the cod
eroman 2014/09/18 17:51:28 My thinking was that ResolveProxy() keep the same
bemasc 2014/09/19 19:41:37 Done.
1055
1056 // The request did not synchronously return "success", so we do not know
1057 // whether a proxy would be used for requests to this URL.
1058 return false;
1059 }
1060
1061 return !info.is_direct();
1062 }
1063
1036 UrlInfo* Predictor::AppendToResolutionQueue( 1064 UrlInfo* Predictor::AppendToResolutionQueue(
1037 const GURL& url, 1065 const GURL& url,
1038 UrlInfo::ResolutionMotivation motivation) { 1066 UrlInfo::ResolutionMotivation motivation) {
1039 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 1067 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1040 DCHECK(url.has_host()); 1068 DCHECK(url.has_host());
1041 1069
1042 if (shutdown_) 1070 if (shutdown_)
1043 return NULL; 1071 return NULL;
1044 1072
1045 UrlInfo* info = &results_[url]; 1073 UrlInfo* info = &results_[url];
1046 info->SetUrl(url); // Initialize or DCHECK. 1074 info->SetUrl(url); // Initialize or DCHECK.
1047 // TODO(jar): I need to discard names that have long since expired. 1075 // TODO(jar): I need to discard names that have long since expired.
1048 // Currently we only add to the domain map :-/ 1076 // Currently we only add to the domain map :-/
1049 1077
1050 DCHECK(info->HasUrl(url)); 1078 DCHECK(info->HasUrl(url));
1051 1079
1052 if (!info->NeedsDnsUpdate()) { 1080 if (!info->NeedsDnsUpdate()) {
1053 info->DLogResultsStats("DNS PrefetchNotUpdated"); 1081 info->DLogResultsStats("DNS PrefetchNotUpdated");
1054 return NULL; 1082 return NULL;
1055 } 1083 }
1056 1084
1057 AdviseProxy(url, motivation, false /* is_preconnect */); 1085 AdviseProxy(url, motivation, false /* is_preconnect */);
1058 if (proxy_advisor_ && proxy_advisor_->WouldProxyURL(url)) { 1086 if ((proxy_advisor_ && proxy_advisor_->WouldProxyURL(url)) ||
1087 WouldDefinitelyProxyURL(url)) {
1059 info->DLogResultsStats("DNS PrefetchForProxiedRequest"); 1088 info->DLogResultsStats("DNS PrefetchForProxiedRequest");
1060 return NULL; 1089 return NULL;
1061 } 1090 }
1062 1091
1063 info->SetQueuedState(motivation); 1092 info->SetQueuedState(motivation);
1064 work_queue_.Push(url, motivation); 1093 work_queue_.Push(url, motivation);
1065 StartSomeQueuedResolutions(); 1094 StartSomeQueuedResolutions();
1066 return info; 1095 return info;
1067 } 1096 }
1068 1097
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
1329 } 1358 }
1330 1359
1331 void SimplePredictor::ShutdownOnUIThread() { 1360 void SimplePredictor::ShutdownOnUIThread() {
1332 SetShutdown(true); 1361 SetShutdown(true);
1333 } 1362 }
1334 1363
1335 bool SimplePredictor::CanPrefetchAndPrerender() const { return true; } 1364 bool SimplePredictor::CanPrefetchAndPrerender() const { return true; }
1336 bool SimplePredictor::CanPreresolveAndPreconnect() const { return true; } 1365 bool SimplePredictor::CanPreresolveAndPreconnect() const { return true; }
1337 1366
1338 } // namespace chrome_browser_net 1367 } // namespace chrome_browser_net
OLDNEW
« no previous file with comments | « chrome/browser/net/predictor.h ('k') | chrome/browser/net/predictor_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698