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

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

Issue 7690006: Revert 97446 - Modifying prefetch to account for multi-profile. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/net/net_pref_observer.cc ('k') | chrome/browser/net/predictor.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // A Predictor object is instantiated once in the browser process, and manages 5 // A Predictor object is instantiated once in the browser process, and manages
6 // both preresolution of hostnames, as well as TCP/IP preconnection to expected 6 // both preresolution of hostnames, as well as TCP/IP preconnection to expected
7 // subresources. 7 // subresources.
8 // Most hostname lists are provided by the renderer processes, and include URLs 8 // Most hostname lists are provided by the renderer processes, and include URLs
9 // that *might* be used in the near future by the browsing user. One goal of 9 // that *might* be used in the near future by the browsing user. One goal of
10 // this class is to cause the underlying DNS structure to lookup a hostname 10 // this class is to cause the underlying DNS structure to lookup a hostname
11 // before it is really needed, and hence reduce latency in the standard lookup 11 // before it is really needed, and hence reduce latency in the standard lookup
12 // paths. 12 // paths.
13 // Subresource relationships are usually acquired from the referrer field in a 13 // Subresource relationships are usually acquired from the referrer field in a
14 // navigation. A subresource URL may be associated with a referrer URL. Later 14 // navigation. A subresource URL may be associated with a referrer URL. Later
15 // navigations may, if the likelihood of needing the subresource is high enough, 15 // navigations may, if the likelihood of needing the subresource is high enough,
16 // cause this module to speculatively create a TCP/IP connection. If there is 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. 17 // only a low likelihood, then a DNS pre-resolution operation may be performed.
18 18
19 #ifndef CHROME_BROWSER_NET_PREDICTOR_H_ 19 #ifndef CHROME_BROWSER_NET_PREDICTOR_H_
20 #define CHROME_BROWSER_NET_PREDICTOR_H_ 20 #define CHROME_BROWSER_NET_PREDICTOR_H_
21 #pragma once 21 #pragma once
22 22
23 #include <map> 23 #include <map>
24 #include <queue> 24 #include <queue>
25 #include <set> 25 #include <set>
26 #include <string> 26 #include <string>
27 #include <vector> 27 #include <vector>
28 28
29 #include "base/gtest_prod_util.h" 29 #include "base/gtest_prod_util.h"
30 #include "base/memory/scoped_ptr.h" 30 #include "base/memory/ref_counted.h"
31 #include "chrome/browser/net/url_info.h" 31 #include "chrome/browser/net/url_info.h"
32 #include "chrome/browser/net/referrer.h" 32 #include "chrome/browser/net/referrer.h"
33 #include "chrome/common/net/predictor_common.h" 33 #include "chrome/common/net/predictor_common.h"
34 #include "net/base/host_port_pair.h" 34 #include "net/base/host_port_pair.h"
35 35
36 namespace base { 36 namespace base {
37 class ListValue; 37 class ListValue;
38 } 38 }
39 39
40 namespace base {
41 class WaitableEvent;
42 }
43
44 namespace net { 40 namespace net {
45 class HostResolver; 41 class HostResolver;
46 } // namespace net 42 } // namespace net
47 43
48 class IOThread;
49 class PrefService;
50 class Profile;
51
52 namespace chrome_browser_net { 44 namespace chrome_browser_net {
53 45
54 typedef chrome_common_net::UrlList UrlList; 46 typedef chrome_common_net::UrlList UrlList;
55 typedef chrome_common_net::NameList NameList; 47 typedef chrome_common_net::NameList NameList;
56 typedef std::map<GURL, UrlInfo> Results; 48 typedef std::map<GURL, UrlInfo> Results;
57 49
58 // Predictor is constructed during Profile construction (on the UI thread), 50 // Note that Predictor is not thread safe, and must only be called from
59 // but it is destroyed on the IO thread when ProfileIOData goes away. All of 51 // the IO thread. Failure to do so will result in a DCHECK at runtime.
60 // its core state and functionality happens on the IO thread. The only UI 52 class Predictor : public base::RefCountedThreadSafe<Predictor> {
61 // methods are initialization / shutdown related (including preconnect
62 // initialization), or convenience methods that internally forward calls to
63 // the IO thread.
64 class Predictor {
65 public: 53 public:
66 // A version number for prefs that are saved. This should be incremented when 54 // A version number for prefs that are saved. This should be incremented when
67 // we change the format so that we discard old data. 55 // we change the format so that we discard old data.
68 enum { PREDICTOR_REFERRER_VERSION = 2 }; 56 enum { PREDICTOR_REFERRER_VERSION = 2 };
69 57
70 // Given that the underlying Chromium resolver defaults to a total maximum of
71 // 8 paralell resolutions, we will avoid any chance of starving navigational
72 // resolutions by limiting the number of paralell speculative resolutions.
73 // This is used in the field trials and testing.
74 // TODO(jar): Move this limitation into the resolver.
75 static const size_t kMaxSpeculativeParallelResolves;
76
77 // To control the congestion avoidance system, we need an estimate of how
78 // many speculative requests may arrive at once. Since we currently only
79 // keep 8 subresource names for each frame, we'll use that as our basis.
80 // Note that when scanning search results lists, we might actually get 10 at
81 // a time, and wikipedia can often supply (during a page scan) upwards of 50.
82 // In those odd cases, we may discard some of the later speculative requests
83 // mistakenly assuming that the resolutions took too long.
84 static const int kTypicalSpeculativeGroupSize;
85
86 // The next constant specifies an amount of queueing delay that is
87 // "too large," and indicative of problems with resolutions (perhaps due to
88 // an overloaded router, or such). When we exceed this delay, congestion
89 // avoidance will kick in and all speculations in the queue will be discarded.
90 static const int kMaxSpeculativeResolveQueueDelayMs;
91
92 // |max_concurrent| specifies how many concurrent (parallel) prefetches will 58 // |max_concurrent| specifies how many concurrent (parallel) prefetches will
93 // be performed. Host lookups will be issued through |host_resolver|. 59 // be performed. Host lookups will be issued through |host_resolver|.
94 explicit Predictor(bool preconnect_enabled); 60 Predictor(net::HostResolver* host_resolver,
95 61 base::TimeDelta max_queue_delay_ms, size_t max_concurrent,
96 virtual ~Predictor(); 62 bool preconnect_enabled);
97
98 // This function is used to create a predictor. For testing, we can create
99 // a version which does a simpler shutdown.
100 static Predictor* CreatePredictor(bool preconnect_enabled,
101 bool simple_shutdown);
102
103 static void RegisterUserPrefs(PrefService* user_prefs);
104
105 // ------------- Start UI thread methods.
106
107 void InitNetworkPredictor(PrefService* user_prefs,
108 PrefService* local_state,
109 IOThread* io_thread);
110
111 // The Omnibox has proposed a given url to the user, and if it is a search
112 // URL, then it also indicates that this is preconnectable (i.e., we could
113 // preconnect to the search server).
114 void AnticipateOmniboxUrl(const GURL& url, bool preconnectable);
115
116 // Preconnect a URL and all of its subresource domains.
117 void PreconnectUrlAndSubresources(const GURL& url);
118
119 static UrlList GetPredictedUrlListAtStartup(PrefService* user_prefs,
120 PrefService* local_state);
121
122 static void set_max_queueing_delay(int max_queueing_delay_ms);
123
124 static void set_max_parallel_resolves(size_t max_parallel_resolves);
125
126 virtual void ShutdownOnUIThread(PrefService* user_prefs);
127
128 // ------------- End UI thread methods.
129
130 // ------------- Start IO thread methods.
131 63
132 // Cancel pending requests and prevent new ones from being made. 64 // Cancel pending requests and prevent new ones from being made.
133 void Shutdown(); 65 void Shutdown();
134 66
135 // In some circumstances, for privacy reasons, all results should be 67 // In some circumstances, for privacy reasons, all results should be
136 // discarded. This method gracefully handles that activity. 68 // discarded. This method gracefully handles that activity.
137 // Destroy all our internal state, which shows what names we've looked up, and 69 // Destroy all our internal state, which shows what names we've looked up, and
138 // how long each has taken, etc. etc. We also destroy records of suggesses 70 // how long each has taken, etc. etc. We also destroy records of suggesses
139 // (cache hits etc.). 71 // (cache hits etc.).
140 void DiscardAllResults(); 72 void DiscardAllResults();
141 73
142 // Add hostname(s) to the queue for processing. 74 // Add hostname(s) to the queue for processing.
143 void ResolveList(const UrlList& urls, 75 void ResolveList(const UrlList& urls,
144 UrlInfo::ResolutionMotivation motivation); 76 UrlInfo::ResolutionMotivation motivation);
77 void Resolve(const GURL& url,
78 UrlInfo::ResolutionMotivation motivation);
145 79
146 void Resolve(const GURL& url, UrlInfo::ResolutionMotivation motivation); 80 // Instigate pre-connection to any URLs, or pre-resolution of related host,
81 // that we predict will be needed after this navigation (typically
82 // more-embedded resources on a page). This method will actually post a task
83 // to do the actual work, so as not to jump ahead of the frame navigation that
84 // instigated this activity.
85 void PredictFrameSubresources(const GURL& url);
86
87 // The Omnibox has proposed a given url to the user, and if it is a search
88 // URL, then it also indicates that this is preconnectable (i.e., we could
89 // preconnect to the search server).
90 void AnticipateOmniboxUrl(const GURL& url, bool preconnectable);
91
92 // Preconnect a URL and all of its subresource domains.
93 void PreconnectUrlAndSubresources(const GURL& url);
147 94
148 // Record details of a navigation so that we can preresolve the host name 95 // Record details of a navigation so that we can preresolve the host name
149 // ahead of time the next time the users navigates to the indicated host. 96 // ahead of time the next time the users navigates to the indicated host.
150 // Should only be called when urls are distinct, and they should already be 97 // Should only be called when urls are distinct, and they should already be
151 // canonicalized to not have a path. 98 // canonicalized to not have a path.
152 void LearnFromNavigation(const GURL& referring_url, const GURL& target_url); 99 void LearnFromNavigation(const GURL& referring_url, const GURL& target_url);
153 100
154 // When displaying info in about:dns, the following API is called.
155 static void PredictorGetHtmlInfo(Predictor* predictor, std::string* output);
156
157 // Dump HTML table containing list of referrers for about:dns. 101 // Dump HTML table containing list of referrers for about:dns.
158 void GetHtmlReferrerLists(std::string* output); 102 void GetHtmlReferrerLists(std::string* output);
159 103
160 // Dump the list of currently known referrer domains and related prefetchable 104 // Dump the list of currently known referrer domains and related prefetchable
161 // domains for about:dns. 105 // domains.
162 void GetHtmlInfo(std::string* output); 106 void GetHtmlInfo(std::string* output);
163 107
164 // Discards any referrer for which all the suggested host names are currently 108 // Discards any referrer for which all the suggested host names are currently
165 // annotated with negligible expected-use. Scales down (diminishes) the 109 // annotated with negligible expected-use. Scales down (diminishes) the
166 // expected-use of those that remain, so that their use will go down by a 110 // expected-use of those that remain, so that their use will go down by a
167 // factor each time we trim (moving the referrer closer to being discarded in 111 // factor each time we trim (moving the referrer closer to being discarded in
168 // a future call). 112 // a future call).
169 // The task is performed synchronously and completes before returing. 113 // The task is performed synchronously and completes before returing.
170 void TrimReferrersNow(); 114 void TrimReferrersNow();
171 115
172 // Construct a ListValue object that contains all the data in the referrers_ 116 // Construct a ListValue object that contains all the data in the referrers_
173 // so that it can be persisted in a pref. 117 // so that it can be persisted in a pref.
174 void SerializeReferrers(base::ListValue* referral_list); 118 void SerializeReferrers(base::ListValue* referral_list);
175 119
176 // Process a ListValue that contains all the data from a previous reference 120 // Process a ListValue that contains all the data from a previous reference
177 // list, as constructed by SerializeReferrers(), and add all the identified 121 // list, as constructed by SerializeReferrers(), and add all the identified
178 // values into the current referrer list. 122 // values into the current referrer list.
179 void DeserializeReferrers(const base::ListValue& referral_list); 123 void DeserializeReferrers(const base::ListValue& referral_list);
180 124
181 void DeserializeReferrersThenDelete(base::ListValue* referral_list); 125 void DeserializeReferrersThenDelete(base::ListValue* referral_list);
182 126
183 void DiscardInitialNavigationHistory(); 127 // For unit test code only.
128 size_t max_concurrent_dns_lookups() const {
129 return max_concurrent_dns_lookups_;
130 }
184 131
185 void FinalizeInitializationOnIOThread( 132 // Flag setting to use preconnection instead of just DNS pre-fetching.
186 const std::vector<GURL>& urls_to_prefetch, 133 bool preconnect_enabled() const { return preconnect_enabled_; }
187 base::ListValue* referral_list,
188 IOThread* io_thread);
189
190 // During startup, we learn what the first N urls visited are, and then
191 // resolve the associated hosts ASAP during our next startup.
192 void LearnAboutInitialNavigation(const GURL& url);
193
194 // Renderer bundles up list and sends to this browser API via IPC.
195 // TODO(jar): Use UrlList instead to include port and scheme.
196 void DnsPrefetchList(const NameList& hostnames);
197
198 // May be called from either the IO or UI thread and will PostTask
199 // to the IO thread if necessary.
200 void DnsPrefetchMotivatedList(const UrlList& urls,
201 UrlInfo::ResolutionMotivation motivation);
202
203 // May be called from either the IO or UI thread and will PostTask
204 // to the IO thread if necessary.
205 void SaveStateForNextStartupAndTrim(PrefService* prefs);
206
207 void SaveDnsPrefetchStateForNextStartupAndTrim(
208 base::ListValue* startup_list,
209 base::ListValue* referral_list,
210 base::WaitableEvent* completion);
211
212 // May be called from either the IO or UI thread and will PostTask
213 // to the IO thread if necessary.
214 void EnablePredictor(bool enable);
215
216 void EnablePredictorOnIOThread(bool enable);
217
218 // ------------- End IO thread methods.
219
220 // The following methods may be called on either the IO or UI threads.
221
222 // Instigate pre-connection to any URLs, or pre-resolution of related host,
223 // that we predict will be needed after this navigation (typically
224 // more-embedded resources on a page). This method will actually post a task
225 // to do the actual work, so as not to jump ahead of the frame navigation that
226 // instigated this activity.
227 void PredictFrameSubresources(const GURL& url);
228 134
229 // Put URL in canonical form, including a scheme, host, and port. 135 // Put URL in canonical form, including a scheme, host, and port.
230 // Returns GURL::EmptyGURL() if the scheme is not http/https or if the url 136 // Returns GURL::EmptyGURL() if the scheme is not http/https or if the url
231 // cannot be otherwise canonicalized. 137 // cannot be otherwise canonicalized.
232 static GURL CanonicalizeUrl(const GURL& url); 138 static GURL CanonicalizeUrl(const GURL& url);
233 139
234 // Used for testing.
235 void SetHostResolver(net::HostResolver* host_resolver) {
236 host_resolver_ = host_resolver;
237 }
238 // Used for testing.
239 size_t max_concurrent_dns_lookups() const {
240 return max_concurrent_dns_lookups_;
241 }
242 // Used for testing.
243 void SetShutdown(bool shutdown) {
244 shutdown_ = shutdown;
245 }
246
247 // Flag setting to use preconnection instead of just DNS pre-fetching.
248 bool preconnect_enabled() const {
249 return preconnect_enabled_;
250 }
251
252 // Flag setting for whether we are prefetching dns lookups.
253 bool predictor_enabled() const {
254 return predictor_enabled_;
255 }
256
257
258 private: 140 private:
141 friend class base::RefCountedThreadSafe<Predictor>;
259 FRIEND_TEST_ALL_PREFIXES(PredictorTest, BenefitLookupTest); 142 FRIEND_TEST_ALL_PREFIXES(PredictorTest, BenefitLookupTest);
260 FRIEND_TEST_ALL_PREFIXES(PredictorTest, ShutdownWhenResolutionIsPendingTest); 143 FRIEND_TEST_ALL_PREFIXES(PredictorTest, ShutdownWhenResolutionIsPendingTest);
261 FRIEND_TEST_ALL_PREFIXES(PredictorTest, SingleLookupTest); 144 FRIEND_TEST_ALL_PREFIXES(PredictorTest, SingleLookupTest);
262 FRIEND_TEST_ALL_PREFIXES(PredictorTest, ConcurrentLookupTest); 145 FRIEND_TEST_ALL_PREFIXES(PredictorTest, ConcurrentLookupTest);
263 FRIEND_TEST_ALL_PREFIXES(PredictorTest, MassiveConcurrentLookupTest); 146 FRIEND_TEST_ALL_PREFIXES(PredictorTest, MassiveConcurrentLookupTest);
264 FRIEND_TEST_ALL_PREFIXES(PredictorTest, PriorityQueuePushPopTest); 147 FRIEND_TEST_ALL_PREFIXES(PredictorTest, PriorityQueuePushPopTest);
265 FRIEND_TEST_ALL_PREFIXES(PredictorTest, PriorityQueueReorderTest); 148 FRIEND_TEST_ALL_PREFIXES(PredictorTest, PriorityQueueReorderTest);
266 FRIEND_TEST_ALL_PREFIXES(PredictorTest, ReferrerSerializationTrimTest); 149 FRIEND_TEST_ALL_PREFIXES(PredictorTest, ReferrerSerializationTrimTest);
267 friend class WaitForResolutionHelper; // For testing. 150 friend class WaitForResolutionHelper; // For testing.
268 151
(...skipping 19 matching lines...) Expand all
288 private: 171 private:
289 // The names in the queue that should be serviced (popped) ASAP. 172 // The names in the queue that should be serviced (popped) ASAP.
290 std::queue<GURL> rush_queue_; 173 std::queue<GURL> rush_queue_;
291 // The names in the queue that should only be serviced when rush_queue is 174 // The names in the queue that should only be serviced when rush_queue is
292 // empty. 175 // empty.
293 std::queue<GURL> background_queue_; 176 std::queue<GURL> background_queue_;
294 177
295 DISALLOW_COPY_AND_ASSIGN(HostNameQueue); 178 DISALLOW_COPY_AND_ASSIGN(HostNameQueue);
296 }; 179 };
297 180
298 // The InitialObserver monitors navigations made by the network stack. This
299 // is only used to identify startup time resolutions (for re-resolution
300 // during our next process startup).
301 // TODO(jar): Consider preconnecting at startup, which may be faster than
302 // waiting for render process to start and request a connection.
303 class InitialObserver {
304 public:
305 InitialObserver();
306 ~InitialObserver();
307 // Recording of when we observed each navigation.
308 typedef std::map<GURL, base::TimeTicks> FirstNavigations;
309
310 // Potentially add a new URL to our startup list.
311 void Append(const GURL& url, Predictor* predictor);
312
313 // Get an HTML version of our current planned first_navigations_.
314 void GetFirstResolutionsHtml(std::string* output);
315
316 // Persist the current first_navigations_ for storage in a list.
317 void GetInitialDnsResolutionList(base::ListValue* startup_list);
318
319 // Discards all initial loading history.
320 void DiscardInitialNavigationHistory() { first_navigations_.clear(); }
321
322 private:
323 // List of the first N URL resolutions observed in this run.
324 FirstNavigations first_navigations_;
325
326 // The number of URLs we'll save for pre-resolving at next startup.
327 static const size_t kStartupResolutionCount = 10;
328 };
329
330 // A map that is keyed with the host/port that we've learned were the cause 181 // A map that is keyed with the host/port that we've learned were the cause
331 // of loading additional URLs. The list of additional targets is held 182 // of loading additional URLs. The list of additional targets is held
332 // in a Referrer instance, which is a value in this map. 183 // in a Referrer instance, which is a value in this map.
333 typedef std::map<GURL, Referrer> Referrers; 184 typedef std::map<GURL, Referrer> Referrers;
334 185
335 // Depending on the expected_subresource_use_, we may either make a TCP/IP 186 // Depending on the expected_subresource_use_, we may either make a TCP/IP
336 // preconnection, or merely pre-resolve the hostname via DNS (or even do 187 // preconnection, or merely pre-resolve the hostname via DNS (or even do
337 // nothing). The following are the threasholds for taking those actions. 188 // nothing). The following are the threasholds for taking those actions.
338 static const double kPreconnectWorthyExpectedValue; 189 static const double kPreconnectWorthyExpectedValue;
339 static const double kDNSPreresolutionWorthyExpectedValue; 190 static const double kDNSPreresolutionWorthyExpectedValue;
340 // Referred hosts with a subresource_use_rate_ that are less than the 191 // Referred hosts with a subresource_use_rate_ that are less than the
341 // following threshold will be discarded when we Trim() the list. 192 // following threshold will be discarded when we Trim() the list.
342 static const double kDiscardableExpectedValue; 193 static const double kDiscardableExpectedValue;
343 // During trimming operation to discard hosts for which we don't have likely 194 // During trimming operation to discard hosts for which we don't have likely
344 // subresources, we multiply the expected_subresource_use_ value by the 195 // subresources, we multiply the expected_subresource_use_ value by the
345 // following ratio until that value is less than kDiscardableExpectedValue. 196 // following ratio until that value is less than kDiscardableExpectedValue.
346 // This number should always be less than 1, an more than 0. 197 // This number should always be less than 1, an more than 0.
347 static const double kReferrerTrimRatio; 198 static const double kReferrerTrimRatio;
348 199
349 // Interval between periodic trimming of our whole referrer list. 200 // Interval between periodic trimming of our whole referrer list.
350 // We only do a major trimming about once an hour, and then only when the user 201 // We only do a major trimming about once an hour, and then only when the user
351 // is actively browsing. 202 // is actively browsing.
352 static const base::TimeDelta kDurationBetweenTrimmings; 203 static const base::TimeDelta kDurationBetweenTrimmings;
353 // Interval between incremental trimmings (to avoid inducing Jank). 204 // Interval between incremental trimmings (to avoid inducing Jank).
354 static const base::TimeDelta kDurationBetweenTrimmingIncrements; 205 static const base::TimeDelta kDurationBetweenTrimmingIncrements;
355 // Number of referring URLs processed in an incremental trimming. 206 // Number of referring URLs processed in an incremental trimming.
356 static const size_t kUrlsTrimmedPerIncrement; 207 static const size_t kUrlsTrimmedPerIncrement;
357 208
209 ~Predictor();
210
211 // Perform actual resolution or preconnection to subresources now. This is
212 // an internal worker method that is reached via a post task from
213 // PredictFrameSubresources().
214 void PrepareFrameSubresources(const GURL& url);
215
358 // Only for testing. Returns true if hostname has been successfully resolved 216 // Only for testing. Returns true if hostname has been successfully resolved
359 // (name found). 217 // (name found).
360 bool WasFound(const GURL& url) const { 218 bool WasFound(const GURL& url) const {
361 Results::const_iterator it(results_.find(url)); 219 Results::const_iterator it(results_.find(url));
362 return (it != results_.end()) && 220 return (it != results_.end()) &&
363 it->second.was_found(); 221 it->second.was_found();
364 } 222 }
365 223
366 // Only for testing. Return how long was the resolution 224 // Only for testing. Return how long was the resolution
367 // or UrlInfo::kNullDuration if it hasn't been resolved yet. 225 // or UrlInfo::kNullDuration if it hasn't been resolved yet.
368 base::TimeDelta GetResolutionDuration(const GURL& url) { 226 base::TimeDelta GetResolutionDuration(const GURL& url) {
369 if (results_.find(url) == results_.end()) 227 if (results_.find(url) == results_.end())
370 return UrlInfo::kNullDuration; 228 return UrlInfo::kNullDuration;
371 return results_[url].resolve_duration(); 229 return results_[url].resolve_duration();
372 } 230 }
373 231
374 // Only for testing; 232 // Only for testing;
375 size_t peak_pending_lookups() const { return peak_pending_lookups_; } 233 size_t peak_pending_lookups() const { return peak_pending_lookups_; }
376 234
377 // ------------- Start IO thread methods.
378
379 // Perform actual resolution or preconnection to subresources now. This is
380 // an internal worker method that is reached via a post task from
381 // PredictFrameSubresources().
382 void PrepareFrameSubresources(const GURL& url);
383
384 // Access method for use by async lookup request to pass resolution result. 235 // Access method for use by async lookup request to pass resolution result.
385 void OnLookupFinished(LookupRequest* request, const GURL& url, bool found); 236 void OnLookupFinished(LookupRequest* request, const GURL& url, bool found);
386 237
387 // Underlying method for both async and synchronous lookup to update state. 238 // Underlying method for both async and synchronous lookup to update state.
388 void LookupFinished(LookupRequest* request, 239 void LookupFinished(LookupRequest* request,
389 const GURL& url, bool found); 240 const GURL& url, bool found);
390 241
391 // Queue hostname for resolution. If queueing was done, return the pointer 242 // Queue hostname for resolution. If queueing was done, return the pointer
392 // to the queued instance, otherwise return NULL. 243 // to the queued instance, otherwise return NULL.
393 UrlInfo* AppendToResolutionQueue(const GURL& url, 244 UrlInfo* AppendToResolutionQueue(const GURL& url,
(...skipping 25 matching lines...) Expand all
419 void LoadUrlsForTrimming(); 270 void LoadUrlsForTrimming();
420 271
421 // Posts a task to do additional incremental trimming of referrers_. 272 // Posts a task to do additional incremental trimming of referrers_.
422 void PostIncrementalTrimTask(); 273 void PostIncrementalTrimTask();
423 274
424 // Calls Trim() on some or all of urls_being_trimmed_. 275 // Calls Trim() on some or all of urls_being_trimmed_.
425 // If it does not process all the URLs in that vector, it posts a task to 276 // If it does not process all the URLs in that vector, it posts a task to
426 // continue with them shortly (i.e., it yeilds and continues). 277 // continue with them shortly (i.e., it yeilds and continues).
427 void IncrementalTrimReferrers(bool trim_all_now); 278 void IncrementalTrimReferrers(bool trim_all_now);
428 279
429 // ------------- End IO thread methods.
430
431 scoped_ptr<InitialObserver> initial_observer_;
432
433 // Status of speculative DNS resolution and speculative TCP/IP connection
434 // feature.
435 bool predictor_enabled_;
436
437 // work_queue_ holds a list of names we need to look up. 280 // work_queue_ holds a list of names we need to look up.
438 HostNameQueue work_queue_; 281 HostNameQueue work_queue_;
439 282
440 // results_ contains information for existing/prior prefetches. 283 // results_ contains information for existing/prior prefetches.
441 Results results_; 284 Results results_;
442 285
443 std::set<LookupRequest*> pending_lookups_; 286 std::set<LookupRequest*> pending_lookups_;
444 287
445 // For testing, to verify that we don't exceed the limit. 288 // For testing, to verify that we don't exceed the limit.
446 size_t peak_pending_lookups_; 289 size_t peak_pending_lookups_;
447 290
448 // When true, we don't make new lookup requests. 291 // When true, we don't make new lookup requests.
449 bool shutdown_; 292 bool shutdown_;
450 293
451 // The number of concurrent speculative lookups currently allowed to be sent 294 // The number of concurrent speculative lookups currently allowed to be sent
452 // to the resolver. Any additional lookups will be queued to avoid exceeding 295 // to the resolver. Any additional lookups will be queued to avoid exceeding
453 // this value. The queue is a priority queue that will accelerate 296 // this value. The queue is a priority queue that will accelerate
454 // sub-resource speculation, and retard resolutions suggested by page scans. 297 // sub-resource speculation, and retard resolutions suggested by page scans.
455 const size_t max_concurrent_dns_lookups_; 298 const size_t max_concurrent_dns_lookups_;
456 299
457 // The maximum queueing delay that is acceptable before we enter congestion 300 // The maximum queueing delay that is acceptable before we enter congestion
458 // reduction mode, and discard all queued (but not yet assigned) resolutions. 301 // reduction mode, and discard all queued (but not yet assigned) resolutions.
459 const base::TimeDelta max_dns_queue_delay_; 302 const base::TimeDelta max_dns_queue_delay_;
460 303
461 // The host resolver we warm DNS entries for. 304 // The host resolver we warm DNS entries for.
462 net::HostResolver* host_resolver_; 305 net::HostResolver* const host_resolver_;
463 306
464 // Are we currently using preconnection, rather than just DNS resolution, for 307 // Are we currently using preconnection, rather than just DNS resolution, for
465 // subresources and omni-box search URLs. 308 // subresources and omni-box search URLs.
466 bool preconnect_enabled_; 309 bool preconnect_enabled_;
467 310
468 // Most recent suggestion from Omnibox provided via AnticipateOmniboxUrl(). 311 // Most recent suggestion from Omnibox provided via AnticipateOmniboxUrl().
469 std::string last_omnibox_host_; 312 std::string last_omnibox_host_;
470 313
471 // The time when the last preresolve was done for last_omnibox_host_. 314 // The time when the last preresolve was done for last_omnibox_host_.
472 base::TimeTicks last_omnibox_preresolve_; 315 base::TimeTicks last_omnibox_preresolve_;
(...skipping 11 matching lines...) Expand all
484 // orginial hostname. 327 // orginial hostname.
485 Referrers referrers_; 328 Referrers referrers_;
486 329
487 // List of URLs in referrers_ currently being trimmed (scaled down to 330 // List of URLs in referrers_ currently being trimmed (scaled down to
488 // eventually be aged out of use). 331 // eventually be aged out of use).
489 std::vector<GURL> urls_being_trimmed_; 332 std::vector<GURL> urls_being_trimmed_;
490 333
491 // A time after which we need to do more trimming of referrers. 334 // A time after which we need to do more trimming of referrers.
492 base::TimeTicks next_trim_time_; 335 base::TimeTicks next_trim_time_;
493 336
494 scoped_ptr<ScopedRunnableMethodFactory<Predictor> > trim_task_factory_; 337 ScopedRunnableMethodFactory<Predictor> trim_task_factory_;
495 338
496 DISALLOW_COPY_AND_ASSIGN(Predictor); 339 DISALLOW_COPY_AND_ASSIGN(Predictor);
497 }; 340 };
498 341
499 // This version of hte predictor is used for testing
500 class SimpleShutdownPredictor : public Predictor {
501 public:
502 explicit SimpleShutdownPredictor(bool preconnect_enabled)
503 : Predictor(preconnect_enabled) {}
504 virtual ~SimpleShutdownPredictor() {}
505 virtual void ShutdownOnUIThread(PrefService* user_prefs);
506 };
507
508 } // namespace chrome_browser_net 342 } // namespace chrome_browser_net
509 343
510 #endif // CHROME_BROWSER_NET_PREDICTOR_H_ 344 #endif // CHROME_BROWSER_NET_PREDICTOR_H_
OLDNEW
« no previous file with comments | « chrome/browser/net/net_pref_observer.cc ('k') | chrome/browser/net/predictor.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698