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