blob: 8db8a3856bd81f9ed24f27bd09309da4123933c3 [file] [log] [blame]
[email protected]7c46a7082012-01-14 01:24:361// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]74be069e82010-06-25 00:12:495// 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]f4ef861ba2010-07-28 22:37:2316// 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.commit09911bf2008-07-26 23:55:2918
[email protected]3530cd92010-06-27 06:22:0119#ifndef CHROME_BROWSER_NET_PREDICTOR_H_
20#define CHROME_BROWSER_NET_PREDICTOR_H_
initial.commit09911bf2008-07-26 23:55:2921
22#include <map>
23#include <queue>
[email protected]1933eb202009-02-19 18:23:2524#include <set>
initial.commit09911bf2008-07-26 23:55:2925#include <string>
[email protected]579f2a12011-04-06 16:27:3126#include <vector>
initial.commit09911bf2008-07-26 23:55:2927
[email protected]a918f872010-06-01 14:30:5128#include "base/gtest_prod_util.h"
[email protected]67372ecf2011-09-10 01:30:4629#include "base/memory/scoped_ptr.h"
[email protected]c6944272012-01-06 22:12:2830#include "base/memory/weak_ptr.h"
[email protected]21dae9b2008-11-06 23:32:5331#include "chrome/browser/net/referrer.h"
[email protected]c753f142013-02-10 13:14:0432#include "chrome/browser/net/url_info.h"
[email protected]3530cd92010-06-27 06:22:0133#include "chrome/common/net/predictor_common.h"
[email protected]760d970a2010-05-18 00:39:1834#include "net/base/host_port_pair.h"
initial.commit09911bf2008-07-26 23:55:2935
[email protected]f3a1c642011-07-12 19:15:0336namespace base {
[email protected]c02c853d72010-08-07 06:23:2437class ListValue;
[email protected]f3a1c642011-07-12 19:15:0338}
[email protected]c02c853d72010-08-07 06:23:2439
[email protected]67372ecf2011-09-10 01:30:4640namespace base {
41class WaitableEvent;
42}
43
[email protected]fd2f8afe2009-06-11 21:53:5544namespace net {
45class HostResolver;
[email protected]7c46a7082012-01-14 01:24:3646class URLRequestContextGetter;
[email protected]0ac83682010-01-22 17:46:2747} // namespace net
[email protected]fd2f8afe2009-06-11 21:53:5548
[email protected]67372ecf2011-09-10 01:30:4649class IOThread;
50class PrefService;
[email protected]c753f142013-02-10 13:14:0451class PrefRegistrySyncable;
[email protected]67372ecf2011-09-10 01:30:4652class Profile;
53
initial.commit09911bf2008-07-26 23:55:2954namespace chrome_browser_net {
55
[email protected]c5629c32010-06-23 01:22:4356typedef chrome_common_net::UrlList UrlList;
initial.commit09911bf2008-07-26 23:55:2957typedef chrome_common_net::NameList NameList;
[email protected]74be069e82010-06-25 00:12:4958typedef std::map<GURL, UrlInfo> Results;
initial.commit09911bf2008-07-26 23:55:2959
[email protected]67372ecf2011-09-10 01:30:4660// Predictor is constructed during Profile construction (on the UI thread),
61// but it is destroyed on the IO thread when ProfileIOData goes away. All of
62// its core state and functionality happens on the IO thread. The only UI
63// methods are initialization / shutdown related (including preconnect
64// initialization), or convenience methods that internally forward calls to
65// the IO thread.
66class Predictor {
initial.commit09911bf2008-07-26 23:55:2967 public:
[email protected]760d970a2010-05-18 00:39:1868 // A version number for prefs that are saved. This should be incremented when
69 // we change the format so that we discard old data.
[email protected]d6431722011-09-01 00:46:3370 static const int kPredictorReferrerVersion;
[email protected]760d970a2010-05-18 00:39:1871
[email protected]67372ecf2011-09-10 01:30:4672 // Given that the underlying Chromium resolver defaults to a total maximum of
73 // 8 paralell resolutions, we will avoid any chance of starving navigational
74 // resolutions by limiting the number of paralell speculative resolutions.
75 // This is used in the field trials and testing.
76 // TODO(jar): Move this limitation into the resolver.
77 static const size_t kMaxSpeculativeParallelResolves;
78
79 // To control the congestion avoidance system, we need an estimate of how
80 // many speculative requests may arrive at once. Since we currently only
81 // keep 8 subresource names for each frame, we'll use that as our basis.
82 // Note that when scanning search results lists, we might actually get 10 at
83 // a time, and wikipedia can often supply (during a page scan) upwards of 50.
84 // In those odd cases, we may discard some of the later speculative requests
85 // mistakenly assuming that the resolutions took too long.
86 static const int kTypicalSpeculativeGroupSize;
87
88 // The next constant specifies an amount of queueing delay that is
89 // "too large," and indicative of problems with resolutions (perhaps due to
90 // an overloaded router, or such). When we exceed this delay, congestion
91 // avoidance will kick in and all speculations in the queue will be discarded.
92 static const int kMaxSpeculativeResolveQueueDelayMs;
93
[email protected]f4ef861ba2010-07-28 22:37:2394 // |max_concurrent| specifies how many concurrent (parallel) prefetches will
[email protected]ec86bea2009-12-08 18:35:1495 // be performed. Host lookups will be issued through |host_resolver|.
[email protected]67372ecf2011-09-10 01:30:4696 explicit Predictor(bool preconnect_enabled);
97
98 virtual ~Predictor();
99
100 // This function is used to create a predictor. For testing, we can create
101 // a version which does a simpler shutdown.
102 static Predictor* CreatePredictor(bool preconnect_enabled,
103 bool simple_shutdown);
104
[email protected]c753f142013-02-10 13:14:04105 static void RegisterUserPrefs(PrefRegistrySyncable* registry);
[email protected]67372ecf2011-09-10 01:30:46106
107 // ------------- Start UI thread methods.
108
109 virtual void InitNetworkPredictor(PrefService* user_prefs,
110 PrefService* local_state,
[email protected]7c46a7082012-01-14 01:24:36111 IOThread* io_thread,
112 net::URLRequestContextGetter* getter);
[email protected]67372ecf2011-09-10 01:30:46113
114 // The Omnibox has proposed a given url to the user, and if it is a search
115 // URL, then it also indicates that this is preconnectable (i.e., we could
116 // preconnect to the search server).
117 void AnticipateOmniboxUrl(const GURL& url, bool preconnectable);
118
119 // Preconnect a URL and all of its subresource domains.
120 void PreconnectUrlAndSubresources(const GURL& url);
121
122 static UrlList GetPredictedUrlListAtStartup(PrefService* user_prefs,
123 PrefService* local_state);
124
125 static void set_max_queueing_delay(int max_queueing_delay_ms);
126
127 static void set_max_parallel_resolves(size_t max_parallel_resolves);
128
129 virtual void ShutdownOnUIThread(PrefService* user_prefs);
130
131 // ------------- End UI thread methods.
132
133 // ------------- Start IO thread methods.
[email protected]b2b8b832009-02-06 19:03:29134
[email protected]1933eb202009-02-19 18:23:25135 // Cancel pending requests and prevent new ones from being made.
136 void Shutdown();
initial.commit09911bf2008-07-26 23:55:29137
138 // In some circumstances, for privacy reasons, all results should be
139 // discarded. This method gracefully handles that activity.
140 // Destroy all our internal state, which shows what names we've looked up, and
141 // how long each has taken, etc. etc. We also destroy records of suggesses
142 // (cache hits etc.).
143 void DiscardAllResults();
144
[email protected]1933eb202009-02-19 18:23:25145 // Add hostname(s) to the queue for processing.
[email protected]c5629c32010-06-23 01:22:43146 void ResolveList(const UrlList& urls,
[email protected]74be069e82010-06-25 00:12:49147 UrlInfo::ResolutionMotivation motivation);
initial.commit09911bf2008-07-26 23:55:29148
[email protected]67372ecf2011-09-10 01:30:46149 void Resolve(const GURL& url, UrlInfo::ResolutionMotivation motivation);
[email protected]e326922d2010-09-03 09:08:10150
[email protected]21dae9b2008-11-06 23:32:53151 // Record details of a navigation so that we can preresolve the host name
152 // ahead of time the next time the users navigates to the indicated host.
[email protected]d6bb2562010-08-25 23:31:30153 // Should only be called when urls are distinct, and they should already be
154 // canonicalized to not have a path.
[email protected]74be069e82010-06-25 00:12:49155 void LearnFromNavigation(const GURL& referring_url, const GURL& target_url);
[email protected]21dae9b2008-11-06 23:32:53156
[email protected]67372ecf2011-09-10 01:30:46157 // When displaying info in about:dns, the following API is called.
158 static void PredictorGetHtmlInfo(Predictor* predictor, std::string* output);
159
[email protected]21dae9b2008-11-06 23:32:53160 // Dump HTML table containing list of referrers for about:dns.
161 void GetHtmlReferrerLists(std::string* output);
162
[email protected]74be069e82010-06-25 00:12:49163 // Dump the list of currently known referrer domains and related prefetchable
[email protected]67372ecf2011-09-10 01:30:46164 // domains for about:dns.
initial.commit09911bf2008-07-26 23:55:29165 void GetHtmlInfo(std::string* output);
166
[email protected]579f2a12011-04-06 16:27:31167 // Discards any referrer for which all the suggested host names are currently
168 // annotated with negligible expected-use. Scales down (diminishes) the
169 // expected-use of those that remain, so that their use will go down by a
170 // factor each time we trim (moving the referrer closer to being discarded in
171 // a future call).
172 // The task is performed synchronously and completes before returing.
173 void TrimReferrersNow();
[email protected]03c5e862009-02-17 22:50:14174
175 // Construct a ListValue object that contains all the data in the referrers_
176 // so that it can be persisted in a pref.
[email protected]f3a1c642011-07-12 19:15:03177 void SerializeReferrers(base::ListValue* referral_list);
[email protected]03c5e862009-02-17 22:50:14178
179 // Process a ListValue that contains all the data from a previous reference
180 // list, as constructed by SerializeReferrers(), and add all the identified
181 // values into the current referrer list.
[email protected]f3a1c642011-07-12 19:15:03182 void DeserializeReferrers(const base::ListValue& referral_list);
[email protected]03c5e862009-02-17 22:50:14183
[email protected]f3a1c642011-07-12 19:15:03184 void DeserializeReferrersThenDelete(base::ListValue* referral_list);
[email protected]ec86bea2009-12-08 18:35:14185
[email protected]67372ecf2011-09-10 01:30:46186 void DiscardInitialNavigationHistory();
[email protected]e695fbd62009-06-30 16:31:54187
[email protected]67372ecf2011-09-10 01:30:46188 void FinalizeInitializationOnIOThread(
189 const std::vector<GURL>& urls_to_prefetch,
190 base::ListValue* referral_list,
191 IOThread* io_thread,
192 bool predictor_enabled);
193
194 // During startup, we learn what the first N urls visited are, and then
195 // resolve the associated hosts ASAP during our next startup.
196 void LearnAboutInitialNavigation(const GURL& url);
197
198 // Renderer bundles up list and sends to this browser API via IPC.
199 // TODO(jar): Use UrlList instead to include port and scheme.
200 void DnsPrefetchList(const NameList& hostnames);
201
202 // May be called from either the IO or UI thread and will PostTask
203 // to the IO thread if necessary.
204 void DnsPrefetchMotivatedList(const UrlList& urls,
205 UrlInfo::ResolutionMotivation motivation);
206
207 // May be called from either the IO or UI thread and will PostTask
208 // to the IO thread if necessary.
209 void SaveStateForNextStartupAndTrim(PrefService* prefs);
210
211 void SaveDnsPrefetchStateForNextStartupAndTrim(
212 base::ListValue* startup_list,
213 base::ListValue* referral_list,
214 base::WaitableEvent* completion);
215
216 // May be called from either the IO or UI thread and will PostTask
217 // to the IO thread if necessary.
218 void EnablePredictor(bool enable);
219
220 void EnablePredictorOnIOThread(bool enable);
221
222 // ------------- End IO thread methods.
223
224 // The following methods may be called on either the IO or UI threads.
225
226 // Instigate pre-connection to any URLs, or pre-resolution of related host,
227 // that we predict will be needed after this navigation (typically
228 // more-embedded resources on a page). This method will actually post a task
229 // to do the actual work, so as not to jump ahead of the frame navigation that
230 // instigated this activity.
231 void PredictFrameSubresources(const GURL& url);
[email protected]760d970a2010-05-18 00:39:18232
[email protected]1455ccf12010-08-18 16:32:14233 // Put URL in canonical form, including a scheme, host, and port.
234 // Returns GURL::EmptyGURL() if the scheme is not http/https or if the url
235 // cannot be otherwise canonicalized.
236 static GURL CanonicalizeUrl(const GURL& url);
237
[email protected]67372ecf2011-09-10 01:30:46238 // Used for testing.
239 void SetHostResolver(net::HostResolver* host_resolver) {
240 host_resolver_ = host_resolver;
241 }
242 // Used for testing.
243 size_t max_concurrent_dns_lookups() const {
244 return max_concurrent_dns_lookups_;
245 }
246 // Used for testing.
247 void SetShutdown(bool shutdown) {
248 shutdown_ = shutdown;
249 }
250
251 // Flag setting to use preconnection instead of just DNS pre-fetching.
252 bool preconnect_enabled() const {
253 return preconnect_enabled_;
254 }
255
256 // Flag setting for whether we are prefetching dns lookups.
257 bool predictor_enabled() const {
258 return predictor_enabled_;
259 }
260
261
[email protected]b2b8b832009-02-06 19:03:29262 private:
[email protected]74be069e82010-06-25 00:12:49263 FRIEND_TEST_ALL_PREFIXES(PredictorTest, BenefitLookupTest);
264 FRIEND_TEST_ALL_PREFIXES(PredictorTest, ShutdownWhenResolutionIsPendingTest);
265 FRIEND_TEST_ALL_PREFIXES(PredictorTest, SingleLookupTest);
266 FRIEND_TEST_ALL_PREFIXES(PredictorTest, ConcurrentLookupTest);
267 FRIEND_TEST_ALL_PREFIXES(PredictorTest, MassiveConcurrentLookupTest);
268 FRIEND_TEST_ALL_PREFIXES(PredictorTest, PriorityQueuePushPopTest);
269 FRIEND_TEST_ALL_PREFIXES(PredictorTest, PriorityQueueReorderTest);
[email protected]579f2a12011-04-06 16:27:31270 FRIEND_TEST_ALL_PREFIXES(PredictorTest, ReferrerSerializationTrimTest);
[email protected]1933eb202009-02-19 18:23:25271 friend class WaitForResolutionHelper; // For testing.
272
273 class LookupRequest;
274
[email protected]a20bc092009-06-05 01:34:20275 // A simple priority queue for handling host names.
276 // Some names that are queued up have |motivation| that requires very rapid
277 // handling. For example, a sub-resource name lookup MUST be done before the
278 // actual sub-resource is fetched. In contrast, a name that was speculatively
279 // noted in a page has to be resolved before the user "gets around to"
280 // clicking on a link. By tagging (with a motivation) each push we make into
281 // this FIFO queue, the queue can re-order the more important names to service
282 // them sooner (relative to some low priority background resolutions).
283 class HostNameQueue {
284 public:
285 HostNameQueue();
286 ~HostNameQueue();
[email protected]c5629c32010-06-23 01:22:43287 void Push(const GURL& url,
[email protected]74be069e82010-06-25 00:12:49288 UrlInfo::ResolutionMotivation motivation);
[email protected]a20bc092009-06-05 01:34:20289 bool IsEmpty() const;
[email protected]c5629c32010-06-23 01:22:43290 GURL Pop();
[email protected]a20bc092009-06-05 01:34:20291
[email protected]579f2a12011-04-06 16:27:31292 private:
[email protected]a20bc092009-06-05 01:34:20293 // The names in the queue that should be serviced (popped) ASAP.
[email protected]c5629c32010-06-23 01:22:43294 std::queue<GURL> rush_queue_;
[email protected]a20bc092009-06-05 01:34:20295 // The names in the queue that should only be serviced when rush_queue is
296 // empty.
[email protected]c5629c32010-06-23 01:22:43297 std::queue<GURL> background_queue_;
[email protected]a20bc092009-06-05 01:34:20298
299 DISALLOW_COPY_AND_ASSIGN(HostNameQueue);
300 };
301
[email protected]67372ecf2011-09-10 01:30:46302 // The InitialObserver monitors navigations made by the network stack. This
303 // is only used to identify startup time resolutions (for re-resolution
304 // during our next process startup).
305 // TODO(jar): Consider preconnecting at startup, which may be faster than
306 // waiting for render process to start and request a connection.
307 class InitialObserver {
308 public:
309 InitialObserver();
310 ~InitialObserver();
311 // Recording of when we observed each navigation.
312 typedef std::map<GURL, base::TimeTicks> FirstNavigations;
313
314 // Potentially add a new URL to our startup list.
315 void Append(const GURL& url, Predictor* predictor);
316
317 // Get an HTML version of our current planned first_navigations_.
318 void GetFirstResolutionsHtml(std::string* output);
319
320 // Persist the current first_navigations_ for storage in a list.
321 void GetInitialDnsResolutionList(base::ListValue* startup_list);
322
323 // Discards all initial loading history.
324 void DiscardInitialNavigationHistory() { first_navigations_.clear(); }
325
326 private:
327 // List of the first N URL resolutions observed in this run.
328 FirstNavigations first_navigations_;
329
330 // The number of URLs we'll save for pre-resolving at next startup.
331 static const size_t kStartupResolutionCount = 10;
332 };
333
[email protected]760d970a2010-05-18 00:39:18334 // A map that is keyed with the host/port that we've learned were the cause
335 // of loading additional URLs. The list of additional targets is held
336 // in a Referrer instance, which is a value in this map.
[email protected]c5629c32010-06-23 01:22:43337 typedef std::map<GURL, Referrer> Referrers;
[email protected]7c19b87b02009-01-26 16:19:44338
[email protected]579f2a12011-04-06 16:27:31339 // Depending on the expected_subresource_use_, we may either make a TCP/IP
340 // preconnection, or merely pre-resolve the hostname via DNS (or even do
341 // nothing). The following are the threasholds for taking those actions.
342 static const double kPreconnectWorthyExpectedValue;
343 static const double kDNSPreresolutionWorthyExpectedValue;
344 // Referred hosts with a subresource_use_rate_ that are less than the
345 // following threshold will be discarded when we Trim() the list.
346 static const double kDiscardableExpectedValue;
347 // During trimming operation to discard hosts for which we don't have likely
348 // subresources, we multiply the expected_subresource_use_ value by the
349 // following ratio until that value is less than kDiscardableExpectedValue.
350 // This number should always be less than 1, an more than 0.
351 static const double kReferrerTrimRatio;
352
353 // Interval between periodic trimming of our whole referrer list.
354 // We only do a major trimming about once an hour, and then only when the user
355 // is actively browsing.
[email protected]4890fe592012-01-27 09:19:03356 static const int64 kDurationBetweenTrimmingsHours;
[email protected]579f2a12011-04-06 16:27:31357 // Interval between incremental trimmings (to avoid inducing Jank).
[email protected]4890fe592012-01-27 09:19:03358 static const int64 kDurationBetweenTrimmingIncrementsSeconds;
[email protected]579f2a12011-04-06 16:27:31359 // Number of referring URLs processed in an incremental trimming.
360 static const size_t kUrlsTrimmedPerIncrement;
361
[email protected]1933eb202009-02-19 18:23:25362 // Only for testing. Returns true if hostname has been successfully resolved
363 // (name found).
[email protected]c5629c32010-06-23 01:22:43364 bool WasFound(const GURL& url) const {
365 Results::const_iterator it(results_.find(url));
[email protected]760d970a2010-05-18 00:39:18366 return (it != results_.end()) &&
367 it->second.was_found();
[email protected]1933eb202009-02-19 18:23:25368 }
369
370 // Only for testing. Return how long was the resolution
[email protected]368797e2012-03-09 14:39:48371 // or UrlInfo::NullDuration() if it hasn't been resolved yet.
[email protected]c5629c32010-06-23 01:22:43372 base::TimeDelta GetResolutionDuration(const GURL& url) {
[email protected]c5629c32010-06-23 01:22:43373 if (results_.find(url) == results_.end())
[email protected]368797e2012-03-09 14:39:48374 return UrlInfo::NullDuration();
[email protected]c5629c32010-06-23 01:22:43375 return results_[url].resolve_duration();
[email protected]1933eb202009-02-19 18:23:25376 }
377
378 // Only for testing;
379 size_t peak_pending_lookups() const { return peak_pending_lookups_; }
380
[email protected]67372ecf2011-09-10 01:30:46381 // ------------- Start IO thread methods.
382
383 // Perform actual resolution or preconnection to subresources now. This is
384 // an internal worker method that is reached via a post task from
385 // PredictFrameSubresources().
386 void PrepareFrameSubresources(const GURL& url);
387
[email protected]85398532009-06-16 21:32:18388 // Access method for use by async lookup request to pass resolution result.
[email protected]c5629c32010-06-23 01:22:43389 void OnLookupFinished(LookupRequest* request, const GURL& url, bool found);
[email protected]1933eb202009-02-19 18:23:25390
[email protected]85398532009-06-16 21:32:18391 // Underlying method for both async and synchronous lookup to update state.
[email protected]ec86bea2009-12-08 18:35:14392 void LookupFinished(LookupRequest* request,
[email protected]c5629c32010-06-23 01:22:43393 const GURL& url, bool found);
[email protected]85398532009-06-16 21:32:18394
[email protected]21dae9b2008-11-06 23:32:53395 // Queue hostname for resolution. If queueing was done, return the pointer
396 // to the queued instance, otherwise return NULL.
[email protected]74be069e82010-06-25 00:12:49397 UrlInfo* AppendToResolutionQueue(const GURL& url,
398 UrlInfo::ResolutionMotivation motivation);
initial.commit09911bf2008-07-26 23:55:29399
[email protected]a20bc092009-06-05 01:34:20400 // Check to see if too much queuing delay has been noted for the given info,
401 // which indicates that there is "congestion" or growing delay in handling the
402 // resolution of names. Rather than letting this congestion potentially grow
403 // without bounds, we abandon our queued efforts at pre-resolutions in such a
404 // case.
405 // To do this, we will recycle |info|, as well as all queued items, back to
406 // the state they had before they were queued up. We can't do anything about
407 // the resolutions we've already sent off for processing on another thread, so
408 // we just let them complete. On a slow system, subject to congestion, this
409 // will greatly reduce the number of resolutions done, but it will assure that
410 // any resolutions that are done, are in a timely and hence potentially
411 // helpful manner.
[email protected]74be069e82010-06-25 00:12:49412 bool CongestionControlPerformed(UrlInfo* info);
[email protected]a20bc092009-06-05 01:34:20413
414 // Take lookup requests from work_queue_ and tell HostResolver to look them up
415 // asynchronously, provided we don't exceed concurrent resolution limit.
[email protected]ec86bea2009-12-08 18:35:14416 void StartSomeQueuedResolutions();
initial.commit09911bf2008-07-26 23:55:29417
[email protected]579f2a12011-04-06 16:27:31418 // Performs trimming similar to TrimReferrersNow(), except it does it as a
419 // series of short tasks by posting continuations again an again until done.
420 void TrimReferrers();
421
422 // Loads urls_being_trimmed_ from keys of current referrers_.
423 void LoadUrlsForTrimming();
424
425 // Posts a task to do additional incremental trimming of referrers_.
426 void PostIncrementalTrimTask();
427
428 // Calls Trim() on some or all of urls_being_trimmed_.
429 // If it does not process all the URLs in that vector, it posts a task to
430 // continue with them shortly (i.e., it yeilds and continues).
431 void IncrementalTrimReferrers(bool trim_all_now);
432
[email protected]67372ecf2011-09-10 01:30:46433 // ------------- End IO thread methods.
434
435 scoped_ptr<InitialObserver> initial_observer_;
436
[email protected]7c46a7082012-01-14 01:24:36437 // Reference to URLRequestContextGetter from the Profile which owns the
438 // predictor. Used by Preconnect.
439 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_;
440
[email protected]67372ecf2011-09-10 01:30:46441 // Status of speculative DNS resolution and speculative TCP/IP connection
442 // feature.
443 bool predictor_enabled_;
444
[email protected]a20bc092009-06-05 01:34:20445 // work_queue_ holds a list of names we need to look up.
446 HostNameQueue work_queue_;
initial.commit09911bf2008-07-26 23:55:29447
[email protected]21dae9b2008-11-06 23:32:53448 // results_ contains information for existing/prior prefetches.
initial.commit09911bf2008-07-26 23:55:29449 Results results_;
450
[email protected]1933eb202009-02-19 18:23:25451 std::set<LookupRequest*> pending_lookups_;
initial.commit09911bf2008-07-26 23:55:29452
[email protected]1933eb202009-02-19 18:23:25453 // For testing, to verify that we don't exceed the limit.
454 size_t peak_pending_lookups_;
[email protected]b2b8b832009-02-06 19:03:29455
[email protected]1933eb202009-02-19 18:23:25456 // When true, we don't make new lookup requests.
[email protected]b2b8b832009-02-06 19:03:29457 bool shutdown_;
458
[email protected]755a93352010-10-29 06:33:59459 // The number of concurrent speculative lookups currently allowed to be sent
460 // to the resolver. Any additional lookups will be queued to avoid exceeding
461 // this value. The queue is a priority queue that will accelerate
462 // sub-resource speculation, and retard resolutions suggested by page scans.
[email protected]74be069e82010-06-25 00:12:49463 const size_t max_concurrent_dns_lookups_;
[email protected]e085c302009-06-01 18:31:36464
[email protected]602faf3c2009-06-27 14:35:44465 // The maximum queueing delay that is acceptable before we enter congestion
466 // reduction mode, and discard all queued (but not yet assigned) resolutions.
[email protected]74be069e82010-06-25 00:12:49467 const base::TimeDelta max_dns_queue_delay_;
[email protected]602faf3c2009-06-27 14:35:44468
[email protected]73c45322010-10-01 23:57:54469 // The host resolver we warm DNS entries for.
[email protected]67372ecf2011-09-10 01:30:46470 net::HostResolver* host_resolver_;
[email protected]fd2f8afe2009-06-11 21:53:55471
[email protected]760d970a2010-05-18 00:39:18472 // Are we currently using preconnection, rather than just DNS resolution, for
473 // subresources and omni-box search URLs.
474 bool preconnect_enabled_;
475
[email protected]1455ccf12010-08-18 16:32:14476 // Most recent suggestion from Omnibox provided via AnticipateOmniboxUrl().
477 std::string last_omnibox_host_;
478
479 // The time when the last preresolve was done for last_omnibox_host_.
480 base::TimeTicks last_omnibox_preresolve_;
481
482 // The number of consecutive requests to AnticipateOmniboxUrl() that suggested
483 // preconnecting (because it was to a search service).
484 int consecutive_omnibox_preconnect_count_;
485
486 // The time when the last preconnection was requested to a search service.
487 base::TimeTicks last_omnibox_preconnect_;
488
[email protected]579f2a12011-04-06 16:27:31489 // For each URL that we might navigate to (that we've "learned about")
490 // we have a Referrer list. Each Referrer list has all hostnames we might
491 // need to pre-resolve or pre-connect to when there is a navigation to the
492 // orginial hostname.
493 Referrers referrers_;
494
495 // List of URLs in referrers_ currently being trimmed (scaled down to
496 // eventually be aged out of use).
497 std::vector<GURL> urls_being_trimmed_;
498
499 // A time after which we need to do more trimming of referrers.
500 base::TimeTicks next_trim_time_;
501
[email protected]12465ec2011-11-17 21:18:23502 scoped_ptr<base::WeakPtrFactory<Predictor> > weak_factory_;
[email protected]579f2a12011-04-06 16:27:31503
[email protected]74be069e82010-06-25 00:12:49504 DISALLOW_COPY_AND_ASSIGN(Predictor);
initial.commit09911bf2008-07-26 23:55:29505};
506
[email protected]67372ecf2011-09-10 01:30:46507// This version of the predictor is used for testing.
508class SimplePredictor : public Predictor {
509 public:
510 explicit SimplePredictor(bool preconnect_enabled)
511 : Predictor(preconnect_enabled) {}
512 virtual ~SimplePredictor() {}
[email protected]7c46a7082012-01-14 01:24:36513 virtual void InitNetworkPredictor(
514 PrefService* user_prefs,
515 PrefService* local_state,
516 IOThread* io_thread,
517 net::URLRequestContextGetter* getter) OVERRIDE;
[email protected]0d5c08e2011-11-21 16:51:06518 virtual void ShutdownOnUIThread(PrefService* user_prefs) OVERRIDE;
[email protected]67372ecf2011-09-10 01:30:46519};
520
initial.commit09911bf2008-07-26 23:55:29521} // namespace chrome_browser_net
522
[email protected]3530cd92010-06-27 06:22:01523#endif // CHROME_BROWSER_NET_PREDICTOR_H_