[email protected] | 7c46a708 | 2012-01-14 01:24:36 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4 | |
[email protected] | 74be069e8 | 2010-06-25 00:12:49 | [diff] [blame] | 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 |
| 7 | // subresources. |
| 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 |
| 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 |
| 12 | // paths. |
| 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 |
| 15 | // navigations may, if the likelihood of needing the subresource is high enough, |
[email protected] | f4ef861ba | 2010-07-28 22:37:23 | [diff] [blame] | 16 | // cause this module to speculatively create a TCP/IP connection. If there is |
| 17 | // only a low likelihood, then a DNS pre-resolution operation may be performed. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 18 | |
[email protected] | 3530cd9 | 2010-06-27 06:22:01 | [diff] [blame] | 19 | #ifndef CHROME_BROWSER_NET_PREDICTOR_H_ |
| 20 | #define CHROME_BROWSER_NET_PREDICTOR_H_ |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 21 | |
| 22 | #include <map> |
| 23 | #include <queue> |
[email protected] | 1933eb20 | 2009-02-19 18:23:25 | [diff] [blame] | 24 | #include <set> |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 25 | #include <string> |
[email protected] | 579f2a1 | 2011-04-06 16:27:31 | [diff] [blame] | 26 | #include <vector> |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 27 | |
[email protected] | a918f87 | 2010-06-01 14:30:51 | [diff] [blame] | 28 | #include "base/gtest_prod_util.h" |
[email protected] | 67372ecf | 2011-09-10 01:30:46 | [diff] [blame] | 29 | #include "base/memory/scoped_ptr.h" |
[email protected] | c694427 | 2012-01-06 22:12:28 | [diff] [blame] | 30 | #include "base/memory/weak_ptr.h" |
[email protected] | 8a9712c2 | 2014-07-21 22:47:28 | [diff] [blame] | 31 | #include "chrome/browser/net/prediction_options.h" |
[email protected] | 21dae9b | 2008-11-06 23:32:53 | [diff] [blame] | 32 | #include "chrome/browser/net/referrer.h" |
[email protected] | c9043a88 | 2013-11-16 00:06:00 | [diff] [blame] | 33 | #include "chrome/browser/net/spdyproxy/proxy_advisor.h" |
[email protected] | 685e284 | 2013-05-27 09:43:56 | [diff] [blame] | 34 | #include "chrome/browser/net/timed_cache.h" |
[email protected] | c753f14 | 2013-02-10 13:14:04 | [diff] [blame] | 35 | #include "chrome/browser/net/url_info.h" |
[email protected] | 3530cd9 | 2010-06-27 06:22:01 | [diff] [blame] | 36 | #include "chrome/common/net/predictor_common.h" |
[email protected] | 760d970a | 2010-05-18 00:39:18 | [diff] [blame] | 37 | #include "net/base/host_port_pair.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 38 | |
[email protected] | 443e931 | 2013-05-06 06:17:34 | [diff] [blame] | 39 | class IOThread; |
| 40 | class PrefService; |
| 41 | class Profile; |
[email protected] | 8a9712c2 | 2014-07-21 22:47:28 | [diff] [blame] | 42 | class ProfileIOData; |
[email protected] | c02c853d7 | 2010-08-07 06:23:24 | [diff] [blame] | 43 | |
[email protected] | 67372ecf | 2011-09-10 01:30:46 | [diff] [blame] | 44 | namespace base { |
[email protected] | 443e931 | 2013-05-06 06:17:34 | [diff] [blame] | 45 | class ListValue; |
[email protected] | 67372ecf | 2011-09-10 01:30:46 | [diff] [blame] | 46 | class WaitableEvent; |
| 47 | } |
| 48 | |
[email protected] | fd2f8afe | 2009-06-11 21:53:55 | [diff] [blame] | 49 | namespace net { |
| 50 | class HostResolver; |
[email protected] | bb5ec785 | 2014-04-02 00:45:49 | [diff] [blame] | 51 | class SSLConfigService; |
bemasc | 1515a12c | 2014-10-20 22:30:16 | [diff] [blame] | 52 | class ProxyService; |
[email protected] | bb5ec785 | 2014-04-02 00:45:49 | [diff] [blame] | 53 | class TransportSecurityState; |
[email protected] | 7c46a708 | 2012-01-14 01:24:36 | [diff] [blame] | 54 | class URLRequestContextGetter; |
[email protected] | 443e931 | 2013-05-06 06:17:34 | [diff] [blame] | 55 | } |
[email protected] | fd2f8afe | 2009-06-11 21:53:55 | [diff] [blame] | 56 | |
[email protected] | 443e931 | 2013-05-06 06:17:34 | [diff] [blame] | 57 | namespace user_prefs { |
[email protected] | c753f14 | 2013-02-10 13:14:04 | [diff] [blame] | 58 | class PrefRegistrySyncable; |
[email protected] | 443e931 | 2013-05-06 06:17:34 | [diff] [blame] | 59 | } |
[email protected] | 67372ecf | 2011-09-10 01:30:46 | [diff] [blame] | 60 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 61 | namespace chrome_browser_net { |
| 62 | |
[email protected] | c5629c3 | 2010-06-23 01:22:43 | [diff] [blame] | 63 | typedef chrome_common_net::UrlList UrlList; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 64 | typedef chrome_common_net::NameList NameList; |
[email protected] | 74be069e8 | 2010-06-25 00:12:49 | [diff] [blame] | 65 | typedef std::map<GURL, UrlInfo> Results; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 66 | |
[email protected] | bb5ec785 | 2014-04-02 00:45:49 | [diff] [blame] | 67 | // An observer for testing. |
| 68 | class PredictorObserver { |
| 69 | public: |
| 70 | virtual ~PredictorObserver() {} |
| 71 | |
| 72 | virtual void OnPreconnectUrl(const GURL& original_url, |
| 73 | const GURL& first_party_for_cookies, |
| 74 | UrlInfo::ResolutionMotivation motivation, |
| 75 | int count) = 0; |
| 76 | }; |
| 77 | |
[email protected] | 67372ecf | 2011-09-10 01:30:46 | [diff] [blame] | 78 | // Predictor is constructed during Profile construction (on the UI thread), |
| 79 | // but it is destroyed on the IO thread when ProfileIOData goes away. All of |
| 80 | // its core state and functionality happens on the IO thread. The only UI |
| 81 | // methods are initialization / shutdown related (including preconnect |
| 82 | // initialization), or convenience methods that internally forward calls to |
| 83 | // the IO thread. |
| 84 | class Predictor { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 85 | public: |
[email protected] | 760d970a | 2010-05-18 00:39:18 | [diff] [blame] | 86 | // A version number for prefs that are saved. This should be incremented when |
| 87 | // we change the format so that we discard old data. |
[email protected] | d643172 | 2011-09-01 00:46:33 | [diff] [blame] | 88 | static const int kPredictorReferrerVersion; |
[email protected] | 760d970a | 2010-05-18 00:39:18 | [diff] [blame] | 89 | |
[email protected] | 67372ecf | 2011-09-10 01:30:46 | [diff] [blame] | 90 | // Given that the underlying Chromium resolver defaults to a total maximum of |
| 91 | // 8 paralell resolutions, we will avoid any chance of starving navigational |
| 92 | // resolutions by limiting the number of paralell speculative resolutions. |
| 93 | // This is used in the field trials and testing. |
| 94 | // TODO(jar): Move this limitation into the resolver. |
| 95 | static const size_t kMaxSpeculativeParallelResolves; |
| 96 | |
| 97 | // To control the congestion avoidance system, we need an estimate of how |
| 98 | // many speculative requests may arrive at once. Since we currently only |
| 99 | // keep 8 subresource names for each frame, we'll use that as our basis. |
| 100 | // Note that when scanning search results lists, we might actually get 10 at |
| 101 | // a time, and wikipedia can often supply (during a page scan) upwards of 50. |
| 102 | // In those odd cases, we may discard some of the later speculative requests |
| 103 | // mistakenly assuming that the resolutions took too long. |
| 104 | static const int kTypicalSpeculativeGroupSize; |
| 105 | |
| 106 | // The next constant specifies an amount of queueing delay that is |
| 107 | // "too large," and indicative of problems with resolutions (perhaps due to |
| 108 | // an overloaded router, or such). When we exceed this delay, congestion |
| 109 | // avoidance will kick in and all speculations in the queue will be discarded. |
| 110 | static const int kMaxSpeculativeResolveQueueDelayMs; |
| 111 | |
[email protected] | 685e284 | 2013-05-27 09:43:56 | [diff] [blame] | 112 | // We don't bother learning to preconnect via a GET if the original URL |
| 113 | // navigation was so long ago, that a preconnection would have been dropped |
| 114 | // anyway. We believe most servers will drop the connection in 10 seconds, so |
| 115 | // we currently estimate this time-till-drop at 10 seconds. |
| 116 | // TODO(jar): We should do a persistent field trial to validate/optimize this. |
| 117 | static const int kMaxUnusedSocketLifetimeSecondsWithoutAGet; |
| 118 | |
[email protected] | f4ef861ba | 2010-07-28 22:37:23 | [diff] [blame] | 119 | // |max_concurrent| specifies how many concurrent (parallel) prefetches will |
[email protected] | ec86bea | 2009-12-08 18:35:14 | [diff] [blame] | 120 | // be performed. Host lookups will be issued through |host_resolver|. |
[email protected] | 8a9712c2 | 2014-07-21 22:47:28 | [diff] [blame] | 121 | explicit Predictor(bool preconnect_enabled, bool predictor_enabled); |
[email protected] | 67372ecf | 2011-09-10 01:30:46 | [diff] [blame] | 122 | |
| 123 | virtual ~Predictor(); |
| 124 | |
| 125 | // This function is used to create a predictor. For testing, we can create |
| 126 | // a version which does a simpler shutdown. |
| 127 | static Predictor* CreatePredictor(bool preconnect_enabled, |
[email protected] | 8a9712c2 | 2014-07-21 22:47:28 | [diff] [blame] | 128 | bool predictor_enabled, |
[email protected] | 67372ecf | 2011-09-10 01:30:46 | [diff] [blame] | 129 | bool simple_shutdown); |
| 130 | |
[email protected] | 37ca3fe0 | 2013-07-05 15:32:44 | [diff] [blame] | 131 | static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); |
[email protected] | 67372ecf | 2011-09-10 01:30:46 | [diff] [blame] | 132 | |
| 133 | // ------------- Start UI thread methods. |
| 134 | |
| 135 | virtual void InitNetworkPredictor(PrefService* user_prefs, |
| 136 | PrefService* local_state, |
[email protected] | 7c46a708 | 2012-01-14 01:24:36 | [diff] [blame] | 137 | IOThread* io_thread, |
[email protected] | 8a9712c2 | 2014-07-21 22:47:28 | [diff] [blame] | 138 | net::URLRequestContextGetter* getter, |
| 139 | ProfileIOData* profile_io_data); |
[email protected] | 67372ecf | 2011-09-10 01:30:46 | [diff] [blame] | 140 | |
| 141 | // The Omnibox has proposed a given url to the user, and if it is a search |
| 142 | // URL, then it also indicates that this is preconnectable (i.e., we could |
| 143 | // preconnect to the search server). |
| 144 | void AnticipateOmniboxUrl(const GURL& url, bool preconnectable); |
| 145 | |
| 146 | // Preconnect a URL and all of its subresource domains. |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 147 | void PreconnectUrlAndSubresources(const GURL& url, |
| 148 | const GURL& first_party_for_cookies); |
[email protected] | 67372ecf | 2011-09-10 01:30:46 | [diff] [blame] | 149 | |
| 150 | static UrlList GetPredictedUrlListAtStartup(PrefService* user_prefs, |
| 151 | PrefService* local_state); |
| 152 | |
| 153 | static void set_max_queueing_delay(int max_queueing_delay_ms); |
| 154 | |
| 155 | static void set_max_parallel_resolves(size_t max_parallel_resolves); |
| 156 | |
[email protected] | 1101dbc5 | 2013-10-05 00:19:12 | [diff] [blame] | 157 | virtual void ShutdownOnUIThread(); |
[email protected] | 67372ecf | 2011-09-10 01:30:46 | [diff] [blame] | 158 | |
| 159 | // ------------- End UI thread methods. |
| 160 | |
| 161 | // ------------- Start IO thread methods. |
[email protected] | b2b8b83 | 2009-02-06 19:03:29 | [diff] [blame] | 162 | |
[email protected] | 1933eb20 | 2009-02-19 18:23:25 | [diff] [blame] | 163 | // Cancel pending requests and prevent new ones from being made. |
| 164 | void Shutdown(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 165 | |
| 166 | // In some circumstances, for privacy reasons, all results should be |
| 167 | // discarded. This method gracefully handles that activity. |
| 168 | // Destroy all our internal state, which shows what names we've looked up, and |
| 169 | // how long each has taken, etc. etc. We also destroy records of suggesses |
| 170 | // (cache hits etc.). |
| 171 | void DiscardAllResults(); |
| 172 | |
[email protected] | 1933eb20 | 2009-02-19 18:23:25 | [diff] [blame] | 173 | // Add hostname(s) to the queue for processing. |
[email protected] | c5629c3 | 2010-06-23 01:22:43 | [diff] [blame] | 174 | void ResolveList(const UrlList& urls, |
[email protected] | 74be069e8 | 2010-06-25 00:12:49 | [diff] [blame] | 175 | UrlInfo::ResolutionMotivation motivation); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 176 | |
[email protected] | 67372ecf | 2011-09-10 01:30:46 | [diff] [blame] | 177 | void Resolve(const GURL& url, UrlInfo::ResolutionMotivation motivation); |
[email protected] | e326922d | 2010-09-03 09:08:10 | [diff] [blame] | 178 | |
[email protected] | 21dae9b | 2008-11-06 23:32:53 | [diff] [blame] | 179 | // Record details of a navigation so that we can preresolve the host name |
| 180 | // ahead of time the next time the users navigates to the indicated host. |
[email protected] | d6bb256 | 2010-08-25 23:31:30 | [diff] [blame] | 181 | // Should only be called when urls are distinct, and they should already be |
| 182 | // canonicalized to not have a path. |
[email protected] | 74be069e8 | 2010-06-25 00:12:49 | [diff] [blame] | 183 | void LearnFromNavigation(const GURL& referring_url, const GURL& target_url); |
[email protected] | 21dae9b | 2008-11-06 23:32:53 | [diff] [blame] | 184 | |
[email protected] | 67372ecf | 2011-09-10 01:30:46 | [diff] [blame] | 185 | // When displaying info in about:dns, the following API is called. |
| 186 | static void PredictorGetHtmlInfo(Predictor* predictor, std::string* output); |
| 187 | |
[email protected] | 21dae9b | 2008-11-06 23:32:53 | [diff] [blame] | 188 | // Dump HTML table containing list of referrers for about:dns. |
| 189 | void GetHtmlReferrerLists(std::string* output); |
| 190 | |
[email protected] | 74be069e8 | 2010-06-25 00:12:49 | [diff] [blame] | 191 | // Dump the list of currently known referrer domains and related prefetchable |
[email protected] | 67372ecf | 2011-09-10 01:30:46 | [diff] [blame] | 192 | // domains for about:dns. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 193 | void GetHtmlInfo(std::string* output); |
| 194 | |
[email protected] | 579f2a1 | 2011-04-06 16:27:31 | [diff] [blame] | 195 | // Discards any referrer for which all the suggested host names are currently |
| 196 | // annotated with negligible expected-use. Scales down (diminishes) the |
| 197 | // expected-use of those that remain, so that their use will go down by a |
| 198 | // factor each time we trim (moving the referrer closer to being discarded in |
| 199 | // a future call). |
| 200 | // The task is performed synchronously and completes before returing. |
| 201 | void TrimReferrersNow(); |
[email protected] | 03c5e86 | 2009-02-17 22:50:14 | [diff] [blame] | 202 | |
| 203 | // Construct a ListValue object that contains all the data in the referrers_ |
| 204 | // so that it can be persisted in a pref. |
[email protected] | f3a1c64 | 2011-07-12 19:15:03 | [diff] [blame] | 205 | void SerializeReferrers(base::ListValue* referral_list); |
[email protected] | 03c5e86 | 2009-02-17 22:50:14 | [diff] [blame] | 206 | |
| 207 | // Process a ListValue that contains all the data from a previous reference |
| 208 | // list, as constructed by SerializeReferrers(), and add all the identified |
| 209 | // values into the current referrer list. |
[email protected] | f3a1c64 | 2011-07-12 19:15:03 | [diff] [blame] | 210 | void DeserializeReferrers(const base::ListValue& referral_list); |
[email protected] | 03c5e86 | 2009-02-17 22:50:14 | [diff] [blame] | 211 | |
[email protected] | f3a1c64 | 2011-07-12 19:15:03 | [diff] [blame] | 212 | void DeserializeReferrersThenDelete(base::ListValue* referral_list); |
[email protected] | ec86bea | 2009-12-08 18:35:14 | [diff] [blame] | 213 | |
[email protected] | 67372ecf | 2011-09-10 01:30:46 | [diff] [blame] | 214 | void DiscardInitialNavigationHistory(); |
[email protected] | e695fbd6 | 2009-06-30 16:31:54 | [diff] [blame] | 215 | |
[email protected] | 67372ecf | 2011-09-10 01:30:46 | [diff] [blame] | 216 | void FinalizeInitializationOnIOThread( |
| 217 | const std::vector<GURL>& urls_to_prefetch, |
| 218 | base::ListValue* referral_list, |
| 219 | IOThread* io_thread, |
[email protected] | 8a9712c2 | 2014-07-21 22:47:28 | [diff] [blame] | 220 | ProfileIOData* profile_io_data); |
[email protected] | 67372ecf | 2011-09-10 01:30:46 | [diff] [blame] | 221 | |
| 222 | // During startup, we learn what the first N urls visited are, and then |
| 223 | // resolve the associated hosts ASAP during our next startup. |
| 224 | void LearnAboutInitialNavigation(const GURL& url); |
| 225 | |
| 226 | // Renderer bundles up list and sends to this browser API via IPC. |
| 227 | // TODO(jar): Use UrlList instead to include port and scheme. |
| 228 | void DnsPrefetchList(const NameList& hostnames); |
| 229 | |
| 230 | // May be called from either the IO or UI thread and will PostTask |
| 231 | // to the IO thread if necessary. |
| 232 | void DnsPrefetchMotivatedList(const UrlList& urls, |
| 233 | UrlInfo::ResolutionMotivation motivation); |
| 234 | |
| 235 | // May be called from either the IO or UI thread and will PostTask |
| 236 | // to the IO thread if necessary. |
[email protected] | 8a9712c2 | 2014-07-21 22:47:28 | [diff] [blame] | 237 | void SaveStateForNextStartupAndTrim(); |
[email protected] | 67372ecf | 2011-09-10 01:30:46 | [diff] [blame] | 238 | |
| 239 | void SaveDnsPrefetchStateForNextStartupAndTrim( |
| 240 | base::ListValue* startup_list, |
| 241 | base::ListValue* referral_list, |
| 242 | base::WaitableEvent* completion); |
| 243 | |
| 244 | // May be called from either the IO or UI thread and will PostTask |
| 245 | // to the IO thread if necessary. |
[email protected] | 685e284 | 2013-05-27 09:43:56 | [diff] [blame] | 246 | void PreconnectUrl(const GURL& url, const GURL& first_party_for_cookies, |
| 247 | UrlInfo::ResolutionMotivation motivation, int count); |
| 248 | |
| 249 | void PreconnectUrlOnIOThread(const GURL& url, |
| 250 | const GURL& first_party_for_cookies, |
| 251 | UrlInfo::ResolutionMotivation motivation, |
| 252 | int count); |
| 253 | |
[email protected] | 67372ecf | 2011-09-10 01:30:46 | [diff] [blame] | 254 | // ------------- End IO thread methods. |
| 255 | |
| 256 | // The following methods may be called on either the IO or UI threads. |
| 257 | |
| 258 | // Instigate pre-connection to any URLs, or pre-resolution of related host, |
| 259 | // that we predict will be needed after this navigation (typically |
| 260 | // more-embedded resources on a page). This method will actually post a task |
| 261 | // to do the actual work, so as not to jump ahead of the frame navigation that |
| 262 | // instigated this activity. |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 263 | void PredictFrameSubresources(const GURL& url, |
| 264 | const GURL& first_party_for_cookies); |
[email protected] | 760d970a | 2010-05-18 00:39:18 | [diff] [blame] | 265 | |
[email protected] | 1455ccf1 | 2010-08-18 16:32:14 | [diff] [blame] | 266 | // Put URL in canonical form, including a scheme, host, and port. |
| 267 | // Returns GURL::EmptyGURL() if the scheme is not http/https or if the url |
| 268 | // cannot be otherwise canonicalized. |
| 269 | static GURL CanonicalizeUrl(const GURL& url); |
| 270 | |
[email protected] | 67372ecf | 2011-09-10 01:30:46 | [diff] [blame] | 271 | // Used for testing. |
| 272 | void SetHostResolver(net::HostResolver* host_resolver) { |
| 273 | host_resolver_ = host_resolver; |
| 274 | } |
| 275 | // Used for testing. |
[email protected] | bb5ec785 | 2014-04-02 00:45:49 | [diff] [blame] | 276 | void SetTransportSecurityState( |
| 277 | net::TransportSecurityState* transport_security_state) { |
| 278 | transport_security_state_ = transport_security_state; |
| 279 | } |
| 280 | // Used for testing. |
[email protected] | c9043a88 | 2013-11-16 00:06:00 | [diff] [blame] | 281 | void SetProxyAdvisor(ProxyAdvisor* proxy_advisor) { |
| 282 | proxy_advisor_.reset(proxy_advisor); |
| 283 | } |
| 284 | // Used for testing. |
[email protected] | 67372ecf | 2011-09-10 01:30:46 | [diff] [blame] | 285 | size_t max_concurrent_dns_lookups() const { |
| 286 | return max_concurrent_dns_lookups_; |
| 287 | } |
| 288 | // Used for testing. |
| 289 | void SetShutdown(bool shutdown) { |
| 290 | shutdown_ = shutdown; |
| 291 | } |
[email protected] | bb5ec785 | 2014-04-02 00:45:49 | [diff] [blame] | 292 | // Used for testing. |
| 293 | void SetObserver(PredictorObserver* observer) { |
| 294 | observer_ = observer; |
| 295 | } |
[email protected] | 67372ecf | 2011-09-10 01:30:46 | [diff] [blame] | 296 | |
[email protected] | 8a9712c2 | 2014-07-21 22:47:28 | [diff] [blame] | 297 | ProfileIOData* profile_io_data() const { |
| 298 | return profile_io_data_; |
| 299 | } |
| 300 | |
[email protected] | 67372ecf | 2011-09-10 01:30:46 | [diff] [blame] | 301 | bool preconnect_enabled() const { |
| 302 | return preconnect_enabled_; |
| 303 | } |
| 304 | |
[email protected] | 67372ecf | 2011-09-10 01:30:46 | [diff] [blame] | 305 | bool predictor_enabled() const { |
| 306 | return predictor_enabled_; |
| 307 | } |
| 308 | |
| 309 | |
[email protected] | b2b8b83 | 2009-02-06 19:03:29 | [diff] [blame] | 310 | private: |
[email protected] | 74be069e8 | 2010-06-25 00:12:49 | [diff] [blame] | 311 | FRIEND_TEST_ALL_PREFIXES(PredictorTest, BenefitLookupTest); |
| 312 | FRIEND_TEST_ALL_PREFIXES(PredictorTest, ShutdownWhenResolutionIsPendingTest); |
| 313 | FRIEND_TEST_ALL_PREFIXES(PredictorTest, SingleLookupTest); |
| 314 | FRIEND_TEST_ALL_PREFIXES(PredictorTest, ConcurrentLookupTest); |
| 315 | FRIEND_TEST_ALL_PREFIXES(PredictorTest, MassiveConcurrentLookupTest); |
| 316 | FRIEND_TEST_ALL_PREFIXES(PredictorTest, PriorityQueuePushPopTest); |
| 317 | FRIEND_TEST_ALL_PREFIXES(PredictorTest, PriorityQueueReorderTest); |
[email protected] | 579f2a1 | 2011-04-06 16:27:31 | [diff] [blame] | 318 | FRIEND_TEST_ALL_PREFIXES(PredictorTest, ReferrerSerializationTrimTest); |
[email protected] | c9043a88 | 2013-11-16 00:06:00 | [diff] [blame] | 319 | FRIEND_TEST_ALL_PREFIXES(PredictorTest, SingleLookupTestWithDisabledAdvisor); |
| 320 | FRIEND_TEST_ALL_PREFIXES(PredictorTest, SingleLookupTestWithEnabledAdvisor); |
| 321 | FRIEND_TEST_ALL_PREFIXES(PredictorTest, TestSimplePreconnectAdvisor); |
bemasc | 1515a12c | 2014-10-20 22:30:16 | [diff] [blame] | 322 | FRIEND_TEST_ALL_PREFIXES(PredictorTest, NoProxyService); |
| 323 | FRIEND_TEST_ALL_PREFIXES(PredictorTest, ProxyDefinitelyEnabled); |
| 324 | FRIEND_TEST_ALL_PREFIXES(PredictorTest, ProxyDefinitelyNotEnabled); |
| 325 | FRIEND_TEST_ALL_PREFIXES(PredictorTest, ProxyMaybeEnabled); |
[email protected] | 1933eb20 | 2009-02-19 18:23:25 | [diff] [blame] | 326 | friend class WaitForResolutionHelper; // For testing. |
| 327 | |
| 328 | class LookupRequest; |
| 329 | |
[email protected] | a20bc09 | 2009-06-05 01:34:20 | [diff] [blame] | 330 | // A simple priority queue for handling host names. |
| 331 | // Some names that are queued up have |motivation| that requires very rapid |
| 332 | // handling. For example, a sub-resource name lookup MUST be done before the |
| 333 | // actual sub-resource is fetched. In contrast, a name that was speculatively |
| 334 | // noted in a page has to be resolved before the user "gets around to" |
| 335 | // clicking on a link. By tagging (with a motivation) each push we make into |
| 336 | // this FIFO queue, the queue can re-order the more important names to service |
| 337 | // them sooner (relative to some low priority background resolutions). |
| 338 | class HostNameQueue { |
| 339 | public: |
| 340 | HostNameQueue(); |
| 341 | ~HostNameQueue(); |
[email protected] | c5629c3 | 2010-06-23 01:22:43 | [diff] [blame] | 342 | void Push(const GURL& url, |
[email protected] | 74be069e8 | 2010-06-25 00:12:49 | [diff] [blame] | 343 | UrlInfo::ResolutionMotivation motivation); |
[email protected] | a20bc09 | 2009-06-05 01:34:20 | [diff] [blame] | 344 | bool IsEmpty() const; |
[email protected] | c5629c3 | 2010-06-23 01:22:43 | [diff] [blame] | 345 | GURL Pop(); |
[email protected] | a20bc09 | 2009-06-05 01:34:20 | [diff] [blame] | 346 | |
[email protected] | 579f2a1 | 2011-04-06 16:27:31 | [diff] [blame] | 347 | private: |
[email protected] | a20bc09 | 2009-06-05 01:34:20 | [diff] [blame] | 348 | // The names in the queue that should be serviced (popped) ASAP. |
[email protected] | c5629c3 | 2010-06-23 01:22:43 | [diff] [blame] | 349 | std::queue<GURL> rush_queue_; |
[email protected] | a20bc09 | 2009-06-05 01:34:20 | [diff] [blame] | 350 | // The names in the queue that should only be serviced when rush_queue is |
| 351 | // empty. |
[email protected] | c5629c3 | 2010-06-23 01:22:43 | [diff] [blame] | 352 | std::queue<GURL> background_queue_; |
[email protected] | a20bc09 | 2009-06-05 01:34:20 | [diff] [blame] | 353 | |
| 354 | DISALLOW_COPY_AND_ASSIGN(HostNameQueue); |
| 355 | }; |
| 356 | |
[email protected] | 67372ecf | 2011-09-10 01:30:46 | [diff] [blame] | 357 | // The InitialObserver monitors navigations made by the network stack. This |
| 358 | // is only used to identify startup time resolutions (for re-resolution |
| 359 | // during our next process startup). |
| 360 | // TODO(jar): Consider preconnecting at startup, which may be faster than |
| 361 | // waiting for render process to start and request a connection. |
| 362 | class InitialObserver { |
| 363 | public: |
| 364 | InitialObserver(); |
| 365 | ~InitialObserver(); |
| 366 | // Recording of when we observed each navigation. |
| 367 | typedef std::map<GURL, base::TimeTicks> FirstNavigations; |
| 368 | |
| 369 | // Potentially add a new URL to our startup list. |
| 370 | void Append(const GURL& url, Predictor* predictor); |
| 371 | |
| 372 | // Get an HTML version of our current planned first_navigations_. |
| 373 | void GetFirstResolutionsHtml(std::string* output); |
| 374 | |
| 375 | // Persist the current first_navigations_ for storage in a list. |
| 376 | void GetInitialDnsResolutionList(base::ListValue* startup_list); |
| 377 | |
| 378 | // Discards all initial loading history. |
| 379 | void DiscardInitialNavigationHistory() { first_navigations_.clear(); } |
| 380 | |
| 381 | private: |
| 382 | // List of the first N URL resolutions observed in this run. |
| 383 | FirstNavigations first_navigations_; |
| 384 | |
| 385 | // The number of URLs we'll save for pre-resolving at next startup. |
| 386 | static const size_t kStartupResolutionCount = 10; |
| 387 | }; |
| 388 | |
[email protected] | 760d970a | 2010-05-18 00:39:18 | [diff] [blame] | 389 | // A map that is keyed with the host/port that we've learned were the cause |
| 390 | // of loading additional URLs. The list of additional targets is held |
| 391 | // in a Referrer instance, which is a value in this map. |
[email protected] | c5629c3 | 2010-06-23 01:22:43 | [diff] [blame] | 392 | typedef std::map<GURL, Referrer> Referrers; |
[email protected] | 7c19b87b0 | 2009-01-26 16:19:44 | [diff] [blame] | 393 | |
[email protected] | 579f2a1 | 2011-04-06 16:27:31 | [diff] [blame] | 394 | // Depending on the expected_subresource_use_, we may either make a TCP/IP |
| 395 | // preconnection, or merely pre-resolve the hostname via DNS (or even do |
| 396 | // nothing). The following are the threasholds for taking those actions. |
| 397 | static const double kPreconnectWorthyExpectedValue; |
| 398 | static const double kDNSPreresolutionWorthyExpectedValue; |
| 399 | // Referred hosts with a subresource_use_rate_ that are less than the |
| 400 | // following threshold will be discarded when we Trim() the list. |
| 401 | static const double kDiscardableExpectedValue; |
| 402 | // During trimming operation to discard hosts for which we don't have likely |
| 403 | // subresources, we multiply the expected_subresource_use_ value by the |
| 404 | // following ratio until that value is less than kDiscardableExpectedValue. |
| 405 | // This number should always be less than 1, an more than 0. |
| 406 | static const double kReferrerTrimRatio; |
| 407 | |
| 408 | // Interval between periodic trimming of our whole referrer list. |
| 409 | // We only do a major trimming about once an hour, and then only when the user |
| 410 | // is actively browsing. |
[email protected] | 4890fe59 | 2012-01-27 09:19:03 | [diff] [blame] | 411 | static const int64 kDurationBetweenTrimmingsHours; |
[email protected] | 579f2a1 | 2011-04-06 16:27:31 | [diff] [blame] | 412 | // Interval between incremental trimmings (to avoid inducing Jank). |
[email protected] | 4890fe59 | 2012-01-27 09:19:03 | [diff] [blame] | 413 | static const int64 kDurationBetweenTrimmingIncrementsSeconds; |
[email protected] | 579f2a1 | 2011-04-06 16:27:31 | [diff] [blame] | 414 | // Number of referring URLs processed in an incremental trimming. |
| 415 | static const size_t kUrlsTrimmedPerIncrement; |
| 416 | |
[email protected] | 1933eb20 | 2009-02-19 18:23:25 | [diff] [blame] | 417 | // Only for testing. Returns true if hostname has been successfully resolved |
| 418 | // (name found). |
[email protected] | c5629c3 | 2010-06-23 01:22:43 | [diff] [blame] | 419 | bool WasFound(const GURL& url) const { |
| 420 | Results::const_iterator it(results_.find(url)); |
[email protected] | 760d970a | 2010-05-18 00:39:18 | [diff] [blame] | 421 | return (it != results_.end()) && |
| 422 | it->second.was_found(); |
[email protected] | 1933eb20 | 2009-02-19 18:23:25 | [diff] [blame] | 423 | } |
| 424 | |
| 425 | // Only for testing. Return how long was the resolution |
[email protected] | 368797e | 2012-03-09 14:39:48 | [diff] [blame] | 426 | // or UrlInfo::NullDuration() if it hasn't been resolved yet. |
[email protected] | c5629c3 | 2010-06-23 01:22:43 | [diff] [blame] | 427 | base::TimeDelta GetResolutionDuration(const GURL& url) { |
[email protected] | c5629c3 | 2010-06-23 01:22:43 | [diff] [blame] | 428 | if (results_.find(url) == results_.end()) |
[email protected] | 368797e | 2012-03-09 14:39:48 | [diff] [blame] | 429 | return UrlInfo::NullDuration(); |
[email protected] | c5629c3 | 2010-06-23 01:22:43 | [diff] [blame] | 430 | return results_[url].resolve_duration(); |
[email protected] | 1933eb20 | 2009-02-19 18:23:25 | [diff] [blame] | 431 | } |
| 432 | |
| 433 | // Only for testing; |
| 434 | size_t peak_pending_lookups() const { return peak_pending_lookups_; } |
| 435 | |
[email protected] | c9043a88 | 2013-11-16 00:06:00 | [diff] [blame] | 436 | // If a proxy advisor is defined, let it know that |url| will be prefetched or |
| 437 | // preconnected to. Can be called on either UI or IO threads and will post to |
| 438 | // the IO thread if necessary, invoking AdviseProxyOnIOThread(). |
| 439 | void AdviseProxy(const GURL& url, |
| 440 | UrlInfo::ResolutionMotivation motivation, |
| 441 | bool is_preconnect); |
| 442 | |
[email protected] | 16b061fe | 2014-08-13 15:54:05 | [diff] [blame] | 443 | // These two members call the appropriate global functions in |
| 444 | // prediction_options.cc depending on which thread they are called on. |
| 445 | virtual bool CanPrefetchAndPrerender() const; |
| 446 | virtual bool CanPreresolveAndPreconnect() const; |
[email protected] | 8a9712c2 | 2014-07-21 22:47:28 | [diff] [blame] | 447 | |
[email protected] | 67372ecf | 2011-09-10 01:30:46 | [diff] [blame] | 448 | // ------------- Start IO thread methods. |
| 449 | |
| 450 | // Perform actual resolution or preconnection to subresources now. This is |
| 451 | // an internal worker method that is reached via a post task from |
| 452 | // PredictFrameSubresources(). |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 453 | void PrepareFrameSubresources(const GURL& url, |
| 454 | const GURL& first_party_for_cookies); |
[email protected] | 67372ecf | 2011-09-10 01:30:46 | [diff] [blame] | 455 | |
[email protected] | 8539853 | 2009-06-16 21:32:18 | [diff] [blame] | 456 | // Access method for use by async lookup request to pass resolution result. |
[email protected] | c5629c3 | 2010-06-23 01:22:43 | [diff] [blame] | 457 | void OnLookupFinished(LookupRequest* request, const GURL& url, bool found); |
[email protected] | 1933eb20 | 2009-02-19 18:23:25 | [diff] [blame] | 458 | |
[email protected] | 8539853 | 2009-06-16 21:32:18 | [diff] [blame] | 459 | // Underlying method for both async and synchronous lookup to update state. |
[email protected] | ec86bea | 2009-12-08 18:35:14 | [diff] [blame] | 460 | void LookupFinished(LookupRequest* request, |
[email protected] | c5629c3 | 2010-06-23 01:22:43 | [diff] [blame] | 461 | const GURL& url, bool found); |
[email protected] | 8539853 | 2009-06-16 21:32:18 | [diff] [blame] | 462 | |
[email protected] | 21dae9b | 2008-11-06 23:32:53 | [diff] [blame] | 463 | // Queue hostname for resolution. If queueing was done, return the pointer |
[email protected] | c9043a88 | 2013-11-16 00:06:00 | [diff] [blame] | 464 | // to the queued instance, otherwise return NULL. If the proxy advisor is |
| 465 | // enabled, and |url| is likely to be proxied, the hostname will not be |
| 466 | // queued as the browser is not expected to fetch it directly. |
[email protected] | 74be069e8 | 2010-06-25 00:12:49 | [diff] [blame] | 467 | UrlInfo* AppendToResolutionQueue(const GURL& url, |
[email protected] | c9043a88 | 2013-11-16 00:06:00 | [diff] [blame] | 468 | UrlInfo::ResolutionMotivation motivation); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 469 | |
[email protected] | a20bc09 | 2009-06-05 01:34:20 | [diff] [blame] | 470 | // Check to see if too much queuing delay has been noted for the given info, |
| 471 | // which indicates that there is "congestion" or growing delay in handling the |
| 472 | // resolution of names. Rather than letting this congestion potentially grow |
| 473 | // without bounds, we abandon our queued efforts at pre-resolutions in such a |
| 474 | // case. |
| 475 | // To do this, we will recycle |info|, as well as all queued items, back to |
| 476 | // the state they had before they were queued up. We can't do anything about |
| 477 | // the resolutions we've already sent off for processing on another thread, so |
| 478 | // we just let them complete. On a slow system, subject to congestion, this |
| 479 | // will greatly reduce the number of resolutions done, but it will assure that |
| 480 | // any resolutions that are done, are in a timely and hence potentially |
| 481 | // helpful manner. |
[email protected] | 74be069e8 | 2010-06-25 00:12:49 | [diff] [blame] | 482 | bool CongestionControlPerformed(UrlInfo* info); |
[email protected] | a20bc09 | 2009-06-05 01:34:20 | [diff] [blame] | 483 | |
| 484 | // Take lookup requests from work_queue_ and tell HostResolver to look them up |
| 485 | // asynchronously, provided we don't exceed concurrent resolution limit. |
[email protected] | ec86bea | 2009-12-08 18:35:14 | [diff] [blame] | 486 | void StartSomeQueuedResolutions(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 487 | |
[email protected] | 579f2a1 | 2011-04-06 16:27:31 | [diff] [blame] | 488 | // Performs trimming similar to TrimReferrersNow(), except it does it as a |
| 489 | // series of short tasks by posting continuations again an again until done. |
| 490 | void TrimReferrers(); |
| 491 | |
| 492 | // Loads urls_being_trimmed_ from keys of current referrers_. |
| 493 | void LoadUrlsForTrimming(); |
| 494 | |
| 495 | // Posts a task to do additional incremental trimming of referrers_. |
| 496 | void PostIncrementalTrimTask(); |
| 497 | |
| 498 | // Calls Trim() on some or all of urls_being_trimmed_. |
| 499 | // If it does not process all the URLs in that vector, it posts a task to |
| 500 | // continue with them shortly (i.e., it yeilds and continues). |
| 501 | void IncrementalTrimReferrers(bool trim_all_now); |
| 502 | |
[email protected] | c9043a88 | 2013-11-16 00:06:00 | [diff] [blame] | 503 | // If a proxy advisor is defined, let it know that |url| will be prefetched or |
| 504 | // preconnected to. |
| 505 | void AdviseProxyOnIOThread(const GURL& url, |
| 506 | UrlInfo::ResolutionMotivation motivation, |
| 507 | bool is_preconnect); |
| 508 | |
bemasc | 1515a12c | 2014-10-20 22:30:16 | [diff] [blame] | 509 | // If we can determine immediately (i.e. synchronously) that requests to this |
| 510 | // URL would likely go through a proxy, then return true. Otherwise, return |
| 511 | // false. This is used to avoid issuing DNS requests when a fixed proxy |
| 512 | // configuration is in place, which improves efficiency, and is also important |
| 513 | // if the unproxied DNS may contain incorrect entries. |
| 514 | bool WouldLikelyProxyURL(const GURL& url); |
| 515 | |
[email protected] | bb5ec785 | 2014-04-02 00:45:49 | [diff] [blame] | 516 | // Applies the HSTS redirect for |url|, if any. |
| 517 | GURL GetHSTSRedirectOnIOThread(const GURL& url); |
| 518 | |
[email protected] | 67372ecf | 2011-09-10 01:30:46 | [diff] [blame] | 519 | // ------------- End IO thread methods. |
| 520 | |
| 521 | scoped_ptr<InitialObserver> initial_observer_; |
| 522 | |
[email protected] | 7c46a708 | 2012-01-14 01:24:36 | [diff] [blame] | 523 | // Reference to URLRequestContextGetter from the Profile which owns the |
| 524 | // predictor. Used by Preconnect. |
| 525 | scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_; |
| 526 | |
[email protected] | 67372ecf | 2011-09-10 01:30:46 | [diff] [blame] | 527 | // Status of speculative DNS resolution and speculative TCP/IP connection |
[email protected] | 8a9712c2 | 2014-07-21 22:47:28 | [diff] [blame] | 528 | // feature. This is false if and only if disabled by a command line switch. |
| 529 | const bool predictor_enabled_; |
| 530 | |
| 531 | // This is set by InitNetworkPredictor and used for calling |
bnc | 85ee710 | 2014-09-02 16:15:57 | [diff] [blame] | 532 | // CanPrefetchAndPrerenderUI and CanPreresolveAndPreconnectUI. |
[email protected] | 8a9712c2 | 2014-07-21 22:47:28 | [diff] [blame] | 533 | PrefService* user_prefs_; |
| 534 | |
| 535 | // This is set by InitNetworkPredictor and used for calling |
bnc | 85ee710 | 2014-09-02 16:15:57 | [diff] [blame] | 536 | // CanPrefetchAndPrerenderIO and CanPreresolveAndPreconnectIO. |
[email protected] | 8a9712c2 | 2014-07-21 22:47:28 | [diff] [blame] | 537 | ProfileIOData* profile_io_data_; |
[email protected] | 67372ecf | 2011-09-10 01:30:46 | [diff] [blame] | 538 | |
[email protected] | a20bc09 | 2009-06-05 01:34:20 | [diff] [blame] | 539 | // work_queue_ holds a list of names we need to look up. |
| 540 | HostNameQueue work_queue_; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 541 | |
[email protected] | 21dae9b | 2008-11-06 23:32:53 | [diff] [blame] | 542 | // results_ contains information for existing/prior prefetches. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 543 | Results results_; |
| 544 | |
[email protected] | 1933eb20 | 2009-02-19 18:23:25 | [diff] [blame] | 545 | std::set<LookupRequest*> pending_lookups_; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 546 | |
[email protected] | 1933eb20 | 2009-02-19 18:23:25 | [diff] [blame] | 547 | // For testing, to verify that we don't exceed the limit. |
| 548 | size_t peak_pending_lookups_; |
[email protected] | b2b8b83 | 2009-02-06 19:03:29 | [diff] [blame] | 549 | |
[email protected] | 1933eb20 | 2009-02-19 18:23:25 | [diff] [blame] | 550 | // When true, we don't make new lookup requests. |
[email protected] | b2b8b83 | 2009-02-06 19:03:29 | [diff] [blame] | 551 | bool shutdown_; |
| 552 | |
[email protected] | 755a9335 | 2010-10-29 06:33:59 | [diff] [blame] | 553 | // The number of concurrent speculative lookups currently allowed to be sent |
| 554 | // to the resolver. Any additional lookups will be queued to avoid exceeding |
| 555 | // this value. The queue is a priority queue that will accelerate |
| 556 | // sub-resource speculation, and retard resolutions suggested by page scans. |
[email protected] | 74be069e8 | 2010-06-25 00:12:49 | [diff] [blame] | 557 | const size_t max_concurrent_dns_lookups_; |
[email protected] | e085c30 | 2009-06-01 18:31:36 | [diff] [blame] | 558 | |
[email protected] | 602faf3c | 2009-06-27 14:35:44 | [diff] [blame] | 559 | // The maximum queueing delay that is acceptable before we enter congestion |
| 560 | // reduction mode, and discard all queued (but not yet assigned) resolutions. |
[email protected] | 74be069e8 | 2010-06-25 00:12:49 | [diff] [blame] | 561 | const base::TimeDelta max_dns_queue_delay_; |
[email protected] | 602faf3c | 2009-06-27 14:35:44 | [diff] [blame] | 562 | |
[email protected] | 73c4532 | 2010-10-01 23:57:54 | [diff] [blame] | 563 | // The host resolver we warm DNS entries for. |
[email protected] | 67372ecf | 2011-09-10 01:30:46 | [diff] [blame] | 564 | net::HostResolver* host_resolver_; |
[email protected] | fd2f8afe | 2009-06-11 21:53:55 | [diff] [blame] | 565 | |
[email protected] | bb5ec785 | 2014-04-02 00:45:49 | [diff] [blame] | 566 | // The TransportSecurityState instance we query HSTS redirects from. |
| 567 | net::TransportSecurityState* transport_security_state_; |
| 568 | |
| 569 | // The SSLConfigService we query SNI support from (used in querying HSTS |
| 570 | // redirects). |
| 571 | net::SSLConfigService* ssl_config_service_; |
| 572 | |
bemasc | 1515a12c | 2014-10-20 22:30:16 | [diff] [blame] | 573 | // The ProxyService, used to determine whether preresolve is useful. |
| 574 | net::ProxyService* proxy_service_; |
| 575 | |
[email protected] | 760d970a | 2010-05-18 00:39:18 | [diff] [blame] | 576 | // Are we currently using preconnection, rather than just DNS resolution, for |
| 577 | // subresources and omni-box search URLs. |
[email protected] | 8a9712c2 | 2014-07-21 22:47:28 | [diff] [blame] | 578 | // This is false if and only if disabled by a command line switch. |
| 579 | const bool preconnect_enabled_; |
[email protected] | 760d970a | 2010-05-18 00:39:18 | [diff] [blame] | 580 | |
[email protected] | 1455ccf1 | 2010-08-18 16:32:14 | [diff] [blame] | 581 | // Most recent suggestion from Omnibox provided via AnticipateOmniboxUrl(). |
| 582 | std::string last_omnibox_host_; |
| 583 | |
| 584 | // The time when the last preresolve was done for last_omnibox_host_. |
| 585 | base::TimeTicks last_omnibox_preresolve_; |
| 586 | |
| 587 | // The number of consecutive requests to AnticipateOmniboxUrl() that suggested |
| 588 | // preconnecting (because it was to a search service). |
| 589 | int consecutive_omnibox_preconnect_count_; |
| 590 | |
| 591 | // The time when the last preconnection was requested to a search service. |
| 592 | base::TimeTicks last_omnibox_preconnect_; |
| 593 | |
[email protected] | 579f2a1 | 2011-04-06 16:27:31 | [diff] [blame] | 594 | // For each URL that we might navigate to (that we've "learned about") |
| 595 | // we have a Referrer list. Each Referrer list has all hostnames we might |
| 596 | // need to pre-resolve or pre-connect to when there is a navigation to the |
| 597 | // orginial hostname. |
| 598 | Referrers referrers_; |
| 599 | |
| 600 | // List of URLs in referrers_ currently being trimmed (scaled down to |
| 601 | // eventually be aged out of use). |
| 602 | std::vector<GURL> urls_being_trimmed_; |
| 603 | |
| 604 | // A time after which we need to do more trimming of referrers. |
| 605 | base::TimeTicks next_trim_time_; |
| 606 | |
[email protected] | c9043a88 | 2013-11-16 00:06:00 | [diff] [blame] | 607 | scoped_ptr<ProxyAdvisor> proxy_advisor_; |
| 608 | |
[email protected] | bb5ec785 | 2014-04-02 00:45:49 | [diff] [blame] | 609 | // An observer for testing. |
| 610 | PredictorObserver* observer_; |
| 611 | |
mohan.reddy | 14cb4ad4 | 2014-09-17 18:15:14 | [diff] [blame] | 612 | scoped_ptr<base::WeakPtrFactory<Predictor> > weak_factory_; |
| 613 | |
[email protected] | 74be069e8 | 2010-06-25 00:12:49 | [diff] [blame] | 614 | DISALLOW_COPY_AND_ASSIGN(Predictor); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 615 | }; |
| 616 | |
[email protected] | 67372ecf | 2011-09-10 01:30:46 | [diff] [blame] | 617 | // This version of the predictor is used for testing. |
| 618 | class SimplePredictor : public Predictor { |
| 619 | public: |
[email protected] | 8a9712c2 | 2014-07-21 22:47:28 | [diff] [blame] | 620 | explicit SimplePredictor(bool preconnect_enabled, bool predictor_enabled) |
| 621 | : Predictor(preconnect_enabled, predictor_enabled) {} |
dcheng | fce29ad | 2014-10-23 03:47:47 | [diff] [blame^] | 622 | ~SimplePredictor() override {} |
| 623 | void InitNetworkPredictor(PrefService* user_prefs, |
| 624 | PrefService* local_state, |
| 625 | IOThread* io_thread, |
| 626 | net::URLRequestContextGetter* getter, |
| 627 | ProfileIOData* profile_io_data) override; |
| 628 | void ShutdownOnUIThread() override; |
| 629 | |
[email protected] | 8a9712c2 | 2014-07-21 22:47:28 | [diff] [blame] | 630 | private: |
[email protected] | 16b061fe | 2014-08-13 15:54:05 | [diff] [blame] | 631 | // These member functions return True for unittests. |
dcheng | fce29ad | 2014-10-23 03:47:47 | [diff] [blame^] | 632 | bool CanPrefetchAndPrerender() const override; |
| 633 | bool CanPreresolveAndPreconnect() const override; |
[email protected] | 67372ecf | 2011-09-10 01:30:46 | [diff] [blame] | 634 | }; |
| 635 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 636 | } // namespace chrome_browser_net |
| 637 | |
[email protected] | 3530cd9 | 2010-06-27 06:22:01 | [diff] [blame] | 638 | #endif // CHROME_BROWSER_NET_PREDICTOR_H_ |