| OLD | NEW |
| 1 // Copyright (c) 2006-2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2010 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 // A Predictor object is instantiated once in the browser process, and manages | 5 // A Predictor object is instantiated once in the browser process, and manages |
| 6 // both preresolution of hostnames, as well as TCP/IP preconnection to expected | 6 // both preresolution of hostnames, as well as TCP/IP preconnection to expected |
| 7 // subresources. | 7 // subresources. |
| 8 // Most hostname lists are provided by the renderer processes, and include URLs | 8 // Most hostname lists are provided by the renderer processes, and include URLs |
| 9 // that *might* be used in the near future by the browsing user. One goal of | 9 // that *might* be used in the near future by the browsing user. One goal of |
| 10 // this class is to cause the underlying DNS structure to lookup a hostname | 10 // this class is to cause the underlying DNS structure to lookup a hostname |
| 11 // before it is really needed, and hence reduce latency in the standard lookup | 11 // before it is really needed, and hence reduce latency in the standard lookup |
| 12 // paths. | 12 // paths. |
| 13 // Subresource relationships are usually acquired from the referrer field in a | 13 // Subresource relationships are usually acquired from the referrer field in a |
| 14 // navigation. A subresource URL may be associated with a referrer URL. Later | 14 // navigation. A subresource URL may be associated with a referrer URL. Later |
| 15 // navigations may, if the likelihood of needing the subresource is high enough, | 15 // navigations may, if the likelihood of needing the subresource is high enough, |
| 16 // cause this module to speculatively create a TCP/IP connection that will | 16 // cause this module to speculatively create a TCP/IP connection. If there is |
| 17 // probably be needed to fetch the subresource. | 17 // only a low likelihood, then a DNS pre-resolution operation may be performed. |
| 18 | 18 |
| 19 #ifndef CHROME_BROWSER_NET_PREDICTOR_H_ | 19 #ifndef CHROME_BROWSER_NET_PREDICTOR_H_ |
| 20 #define CHROME_BROWSER_NET_PREDICTOR_H_ | 20 #define CHROME_BROWSER_NET_PREDICTOR_H_ |
| 21 #pragma once | 21 #pragma once |
| 22 | 22 |
| 23 #include <map> | 23 #include <map> |
| 24 #include <queue> | 24 #include <queue> |
| 25 #include <set> | 25 #include <set> |
| 26 #include <string> | 26 #include <string> |
| 27 #include <vector> | 27 #include <vector> |
| (...skipping 14 matching lines...) Expand all Loading... |
| 42 typedef chrome_common_net::UrlList UrlList; | 42 typedef chrome_common_net::UrlList UrlList; |
| 43 typedef chrome_common_net::NameList NameList; | 43 typedef chrome_common_net::NameList NameList; |
| 44 typedef std::map<GURL, UrlInfo> Results; | 44 typedef std::map<GURL, UrlInfo> Results; |
| 45 | 45 |
| 46 // Note that Predictor is not thread safe, and must only be called from | 46 // Note that Predictor is not thread safe, and must only be called from |
| 47 // the IO thread. Failure to do so will result in a DCHECK at runtime. | 47 // the IO thread. Failure to do so will result in a DCHECK at runtime. |
| 48 class Predictor : public base::RefCountedThreadSafe<Predictor> { | 48 class Predictor : public base::RefCountedThreadSafe<Predictor> { |
| 49 public: | 49 public: |
| 50 // A version number for prefs that are saved. This should be incremented when | 50 // A version number for prefs that are saved. This should be incremented when |
| 51 // we change the format so that we discard old data. | 51 // we change the format so that we discard old data. |
| 52 enum { DNS_REFERRER_VERSION = 1 }; | 52 enum { PREDICTOR_REFERRER_VERSION = 2 }; |
| 53 | 53 |
| 54 // |max_concurrent| specifies how many concurrent (parallel) prefetches will | 54 // Depending on the expected_subresource_use_, we may either make a TCP/IP |
| 55 // preconnection, or merely pre-resolve the hostname via DNS (or even do |
| 56 // nothing). The following are the threasholds for taking those actions. |
| 57 static const double kPreconnectWorthyExpectedValue; |
| 58 static const double kDNSPreresolutionWorthyExpectedValue; |
| 59 // Values of expected_subresource_use_ that are less than the following |
| 60 // threshold will be discarded when we Trim() the values, such as is done when |
| 61 // the process ends, and some values are persisted. |
| 62 static const double kPersistWorthyExpectedValue; |
| 63 |
| 64 // |max_concurrent| specifies how many concurrent (parallel) prefetches will |
| 55 // be performed. Host lookups will be issued through |host_resolver|. | 65 // be performed. Host lookups will be issued through |host_resolver|. |
| 56 Predictor(net::HostResolver* host_resolver, | 66 Predictor(net::HostResolver* host_resolver, |
| 57 base::TimeDelta max_queue_delay_ms, size_t max_concurrent, | 67 base::TimeDelta max_queue_delay_ms, size_t max_concurrent, |
| 58 bool preconnect_enabled); | 68 bool preconnect_enabled); |
| 59 | 69 |
| 60 // Cancel pending requests and prevent new ones from being made. | 70 // Cancel pending requests and prevent new ones from being made. |
| 61 void Shutdown(); | 71 void Shutdown(); |
| 62 | 72 |
| 63 // In some circumstances, for privacy reasons, all results should be | 73 // In some circumstances, for privacy reasons, all results should be |
| 64 // discarded. This method gracefully handles that activity. | 74 // discarded. This method gracefully handles that activity. |
| 65 // Destroy all our internal state, which shows what names we've looked up, and | 75 // Destroy all our internal state, which shows what names we've looked up, and |
| 66 // how long each has taken, etc. etc. We also destroy records of suggesses | 76 // how long each has taken, etc. etc. We also destroy records of suggesses |
| 67 // (cache hits etc.). | 77 // (cache hits etc.). |
| 68 void DiscardAllResults(); | 78 void DiscardAllResults(); |
| 69 | 79 |
| 70 // Add hostname(s) to the queue for processing. | 80 // Add hostname(s) to the queue for processing. |
| 71 void ResolveList(const UrlList& urls, | 81 void ResolveList(const UrlList& urls, |
| 72 UrlInfo::ResolutionMotivation motivation); | 82 UrlInfo::ResolutionMotivation motivation); |
| 73 void Resolve(const GURL& url, | 83 void Resolve(const GURL& url, |
| 74 UrlInfo::ResolutionMotivation motivation); | 84 UrlInfo::ResolutionMotivation motivation); |
| 75 | 85 |
| 76 // Get latency benefit of the prefetch that we are navigating to. | |
| 77 bool AccruePrefetchBenefits(const GURL& referrer, | |
| 78 UrlInfo* navigation_info); | |
| 79 | |
| 80 // Instigate preresolution of any domains we predict will be needed after this | |
| 81 // navigation. | |
| 82 void PredictSubresources(const GURL& url); | |
| 83 | |
| 84 // Instigate pre-connection to any URLs we predict will be needed after this | 86 // Instigate pre-connection to any URLs we predict will be needed after this |
| 85 // navigation (typically more-embedded resources on a page). | 87 // navigation (typically more-embedded resources on a page). |
| 86 void PredictFrameSubresources(const GURL& url); | 88 void PredictFrameSubresources(const GURL& url); |
| 87 | 89 |
| 88 // Record details of a navigation so that we can preresolve the host name | 90 // Record details of a navigation so that we can preresolve the host name |
| 89 // ahead of time the next time the users navigates to the indicated host. | 91 // ahead of time the next time the users navigates to the indicated host. |
| 90 void LearnFromNavigation(const GURL& referring_url, const GURL& target_url); | 92 void LearnFromNavigation(const GURL& referring_url, const GURL& target_url); |
| 91 | 93 |
| 92 // Dump HTML table containing list of referrers for about:dns. | 94 // Dump HTML table containing list of referrers for about:dns. |
| 93 void GetHtmlReferrerLists(std::string* output); | 95 void GetHtmlReferrerLists(std::string* output); |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 Referrers referrers_; | 235 Referrers referrers_; |
| 234 | 236 |
| 235 std::set<LookupRequest*> pending_lookups_; | 237 std::set<LookupRequest*> pending_lookups_; |
| 236 | 238 |
| 237 // For testing, to verify that we don't exceed the limit. | 239 // For testing, to verify that we don't exceed the limit. |
| 238 size_t peak_pending_lookups_; | 240 size_t peak_pending_lookups_; |
| 239 | 241 |
| 240 // When true, we don't make new lookup requests. | 242 // When true, we don't make new lookup requests. |
| 241 bool shutdown_; | 243 bool shutdown_; |
| 242 | 244 |
| 243 // A list of successful events resulting from pre-fetching. | |
| 244 UrlInfo::DnsInfoTable dns_cache_hits_; | |
| 245 // A map of hosts that were evicted from our cache (after we prefetched them) | |
| 246 // and before the HTTP stack tried to look them up. | |
| 247 Results cache_eviction_map_; | |
| 248 | |
| 249 // The number of concurrent lookups currently allowed. | 245 // The number of concurrent lookups currently allowed. |
| 250 const size_t max_concurrent_dns_lookups_; | 246 const size_t max_concurrent_dns_lookups_; |
| 251 | 247 |
| 252 // The maximum queueing delay that is acceptable before we enter congestion | 248 // The maximum queueing delay that is acceptable before we enter congestion |
| 253 // reduction mode, and discard all queued (but not yet assigned) resolutions. | 249 // reduction mode, and discard all queued (but not yet assigned) resolutions. |
| 254 const base::TimeDelta max_dns_queue_delay_; | 250 const base::TimeDelta max_dns_queue_delay_; |
| 255 | 251 |
| 256 // The host resovler we warm DNS entries for. | 252 // The host resovler we warm DNS entries for. |
| 257 scoped_refptr<net::HostResolver> host_resolver_; | 253 scoped_refptr<net::HostResolver> host_resolver_; |
| 258 | 254 |
| 259 // Are we currently using preconnection, rather than just DNS resolution, for | 255 // Are we currently using preconnection, rather than just DNS resolution, for |
| 260 // subresources and omni-box search URLs. | 256 // subresources and omni-box search URLs. |
| 261 bool preconnect_enabled_; | 257 bool preconnect_enabled_; |
| 262 | 258 |
| 263 DISALLOW_COPY_AND_ASSIGN(Predictor); | 259 DISALLOW_COPY_AND_ASSIGN(Predictor); |
| 264 }; | 260 }; |
| 265 | 261 |
| 266 } // namespace chrome_browser_net | 262 } // namespace chrome_browser_net |
| 267 | 263 |
| 268 #endif // CHROME_BROWSER_NET_PREDICTOR_H_ | 264 #endif // CHROME_BROWSER_NET_PREDICTOR_H_ |
| OLD | NEW |