OLD | NEW |
---|---|
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/ref_counted.h" | 30 #include "base/memory/scoped_ptr.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 | |
40 namespace net { | 44 namespace net { |
41 class HostResolver; | 45 class HostResolver; |
42 } // namespace net | 46 } // namespace net |
43 | 47 |
48 class IOThread; | |
49 class PrefService; | |
50 class Profile; | |
51 | |
44 namespace chrome_browser_net { | 52 namespace chrome_browser_net { |
45 | 53 |
46 typedef chrome_common_net::UrlList UrlList; | 54 typedef chrome_common_net::UrlList UrlList; |
47 typedef chrome_common_net::NameList NameList; | 55 typedef chrome_common_net::NameList NameList; |
48 typedef std::map<GURL, UrlInfo> Results; | 56 typedef std::map<GURL, UrlInfo> Results; |
49 | 57 |
50 // Note that Predictor is not thread safe, and must only be called from | 58 // Predictor is constructed during Profile construction (on the UI thread), |
51 // the IO thread. Failure to do so will result in a DCHECK at runtime. | 59 // but it is destroyed on the IO thread when ProfileIOData goes away. All of |
52 class Predictor : public base::RefCountedThreadSafe<Predictor> { | 60 // its core state and functionality happens on the IO thread. The only UI |
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 { | |
53 public: | 65 public: |
54 // A version number for prefs that are saved. This should be incremented when | 66 // A version number for prefs that are saved. This should be incremented when |
55 // we change the format so that we discard old data. | 67 // we change the format so that we discard old data. |
56 enum { PREDICTOR_REFERRER_VERSION = 2 }; | 68 enum { PREDICTOR_REFERRER_VERSION = 2 }; |
57 | 69 |
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 | |
58 // |max_concurrent| specifies how many concurrent (parallel) prefetches will | 92 // |max_concurrent| specifies how many concurrent (parallel) prefetches will |
59 // be performed. Host lookups will be issued through |host_resolver|. | 93 // be performed. Host lookups will be issued through |host_resolver|. |
60 Predictor(net::HostResolver* host_resolver, | 94 explicit Predictor(bool preconnect_enabled); |
61 base::TimeDelta max_queue_delay_ms, size_t max_concurrent, | 95 |
62 bool preconnect_enabled); | 96 virtual ~Predictor(); |
97 | |
98 static void RegisterUserPrefs(PrefService* user_prefs); | |
99 | |
100 // ------------- Start UI thread methods. | |
101 | |
102 virtual void InitNetworkPredictor(PrefService* user_prefs, | |
103 PrefService* local_state, | |
104 IOThread* io_thread); | |
105 | |
106 // The Omnibox has proposed a given url to the user, and if it is a search | |
107 // URL, then it also indicates that this is preconnectable (i.e., we could | |
108 // preconnect to the search server). | |
109 virtual void AnticipateOmniboxUrl(const GURL& url, bool preconnectable); | |
110 | |
111 // Preconnect a URL and all of its subresource domains. | |
112 virtual void PreconnectUrlAndSubresources(const GURL& url); | |
113 | |
114 static UrlList GetPredictedUrlListAtStartup(PrefService* user_prefs, | |
115 PrefService* local_state); | |
116 | |
117 static void set_max_queueing_delay(int max_queueing_delay_ms); | |
118 | |
119 static void set_max_parallel_resolves(size_t max_parallel_resolves); | |
120 | |
121 virtual void ShutdownOnUIThread(PrefService* user_prefs); | |
122 | |
123 // ------------- End UI thread methods. | |
124 | |
125 // ------------- Start IO thread methods. | |
63 | 126 |
64 // Cancel pending requests and prevent new ones from being made. | 127 // Cancel pending requests and prevent new ones from being made. |
65 void Shutdown(); | 128 virtual void Shutdown(); |
willchan no longer on Chromium
2011/08/16 00:16:51
Are all these virtuals necessary still? They're us
rpetterson
2011/08/16 03:52:12
Waiting on mirandac for the final work on the Prof
| |
66 | 129 |
67 // In some circumstances, for privacy reasons, all results should be | 130 // In some circumstances, for privacy reasons, all results should be |
68 // discarded. This method gracefully handles that activity. | 131 // discarded. This method gracefully handles that activity. |
69 // Destroy all our internal state, which shows what names we've looked up, and | 132 // Destroy all our internal state, which shows what names we've looked up, and |
70 // how long each has taken, etc. etc. We also destroy records of suggesses | 133 // how long each has taken, etc. etc. We also destroy records of suggesses |
71 // (cache hits etc.). | 134 // (cache hits etc.). |
72 void DiscardAllResults(); | 135 virtual void DiscardAllResults(); |
73 | 136 |
74 // Add hostname(s) to the queue for processing. | 137 // Add hostname(s) to the queue for processing. |
75 void ResolveList(const UrlList& urls, | 138 virtual void ResolveList(const UrlList& urls, |
76 UrlInfo::ResolutionMotivation motivation); | 139 UrlInfo::ResolutionMotivation motivation); |
77 void Resolve(const GURL& url, | |
78 UrlInfo::ResolutionMotivation motivation); | |
79 | 140 |
80 // Instigate pre-connection to any URLs, or pre-resolution of related host, | 141 virtual void Resolve(const GURL& url, |
81 // that we predict will be needed after this navigation (typically | 142 UrlInfo::ResolutionMotivation motivation); |
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); | |
94 | 143 |
95 // Record details of a navigation so that we can preresolve the host name | 144 // Record details of a navigation so that we can preresolve the host name |
96 // ahead of time the next time the users navigates to the indicated host. | 145 // ahead of time the next time the users navigates to the indicated host. |
97 // Should only be called when urls are distinct, and they should already be | 146 // Should only be called when urls are distinct, and they should already be |
98 // canonicalized to not have a path. | 147 // canonicalized to not have a path. |
99 void LearnFromNavigation(const GURL& referring_url, const GURL& target_url); | 148 virtual void LearnFromNavigation(const GURL& referring_url, |
149 const GURL& target_url); | |
100 | 150 |
101 // Dump HTML table containing list of referrers for about:dns. | 151 // Dump HTML table containing list of referrers for about:dns. |
102 void GetHtmlReferrerLists(std::string* output); | 152 virtual void GetHtmlReferrerLists(std::string* output); |
103 | 153 |
104 // Dump the list of currently known referrer domains and related prefetchable | 154 // Dump the list of currently known referrer domains and related prefetchable |
105 // domains. | 155 // domains. |
106 void GetHtmlInfo(std::string* output); | 156 virtual void GetHtmlInfo(std::string* output); |
107 | 157 |
108 // Discards any referrer for which all the suggested host names are currently | 158 // Discards any referrer for which all the suggested host names are currently |
109 // annotated with negligible expected-use. Scales down (diminishes) the | 159 // annotated with negligible expected-use. Scales down (diminishes) the |
110 // expected-use of those that remain, so that their use will go down by a | 160 // expected-use of those that remain, so that their use will go down by a |
111 // factor each time we trim (moving the referrer closer to being discarded in | 161 // factor each time we trim (moving the referrer closer to being discarded in |
112 // a future call). | 162 // a future call). |
113 // The task is performed synchronously and completes before returing. | 163 // The task is performed synchronously and completes before returing. |
114 void TrimReferrersNow(); | 164 virtual void TrimReferrersNow(); |
115 | 165 |
116 // Construct a ListValue object that contains all the data in the referrers_ | 166 // Construct a ListValue object that contains all the data in the referrers_ |
117 // so that it can be persisted in a pref. | 167 // so that it can be persisted in a pref. |
118 void SerializeReferrers(base::ListValue* referral_list); | 168 virtual void SerializeReferrers(base::ListValue* referral_list); |
119 | 169 |
120 // Process a ListValue that contains all the data from a previous reference | 170 // Process a ListValue that contains all the data from a previous reference |
121 // list, as constructed by SerializeReferrers(), and add all the identified | 171 // list, as constructed by SerializeReferrers(), and add all the identified |
122 // values into the current referrer list. | 172 // values into the current referrer list. |
123 void DeserializeReferrers(const base::ListValue& referral_list); | 173 virtual void DeserializeReferrers(const base::ListValue& referral_list); |
124 | 174 |
125 void DeserializeReferrersThenDelete(base::ListValue* referral_list); | 175 virtual void DeserializeReferrersThenDelete(base::ListValue* referral_list); |
126 | 176 |
127 // For unit test code only. | 177 virtual void DiscardInitialNavigationHistory(); |
128 size_t max_concurrent_dns_lookups() const { | |
129 return max_concurrent_dns_lookups_; | |
130 } | |
131 | 178 |
132 // Flag setting to use preconnection instead of just DNS pre-fetching. | 179 virtual void FinalizeInitializationOnIOThread( |
133 bool preconnect_enabled() const { return preconnect_enabled_; } | 180 const std::vector<GURL>& urls_to_prefetch, |
181 base::ListValue* referral_list, | |
182 IOThread* io_thread); | |
183 | |
184 // During startup, we learn what the first N urls visited are, and then | |
185 // resolve the associated hosts ASAP during our next startup. | |
186 virtual void LearnAboutInitialNavigation(const GURL& url); | |
187 | |
188 // Renderer bundles up list and sends to this browser API via IPC. | |
189 // TODO(jar): Use UrlList instead to include port and scheme. | |
190 virtual void DnsPrefetchList(const NameList& hostnames); | |
191 | |
192 // May be called from either the IO or UI thread and will PostTask | |
193 // to the IO thread if necessary. | |
194 virtual void Predictor::DnsPrefetchMotivatedList( | |
195 const UrlList& urls, | |
196 UrlInfo::ResolutionMotivation motivation); | |
197 | |
198 // May be called from either the IO or UI thread and will PostTask | |
199 // to the IO thread if necessary. | |
200 virtual void SaveStateForNextStartupAndTrim(PrefService* prefs); | |
201 | |
202 virtual void SaveDnsPrefetchStateForNextStartupAndTrim( | |
203 base::ListValue* startup_list, | |
204 base::ListValue* referral_list, | |
205 base::WaitableEvent* completion); | |
206 | |
207 // May be called from either the IO or UI thread and will PostTask | |
208 // to the IO thread if necessary. | |
209 virtual void EnablePredictor(bool enable); | |
210 | |
211 virtual void EnablePredictorOnIOThread(bool enable); | |
212 | |
213 // ------------- End IO thread methods. | |
214 | |
215 // The following methods may be called on either the IO or UI threads. | |
216 | |
217 // Instigate pre-connection to any URLs, or pre-resolution of related host, | |
218 // that we predict will be needed after this navigation (typically | |
219 // more-embedded resources on a page). This method will actually post a task | |
220 // to do the actual work, so as not to jump ahead of the frame navigation that | |
221 // instigated this activity. | |
222 virtual void PredictFrameSubresources(const GURL& url); | |
134 | 223 |
135 // Put URL in canonical form, including a scheme, host, and port. | 224 // Put URL in canonical form, including a scheme, host, and port. |
136 // Returns GURL::EmptyGURL() if the scheme is not http/https or if the url | 225 // Returns GURL::EmptyGURL() if the scheme is not http/https or if the url |
137 // cannot be otherwise canonicalized. | 226 // cannot be otherwise canonicalized. |
138 static GURL CanonicalizeUrl(const GURL& url); | 227 static GURL CanonicalizeUrl(const GURL& url); |
139 | 228 |
229 // Used for testing. | |
230 void SetHostResolver(net::HostResolver* host_resolver) { | |
231 host_resolver_ = host_resolver; | |
232 } | |
233 // Used for testing. | |
234 size_t max_concurrent_dns_lookups() const { | |
235 return max_concurrent_dns_lookups_; | |
236 } | |
237 | |
238 // Flag setting to use preconnection instead of just DNS pre-fetching. | |
239 bool preconnect_enabled() const { | |
240 return preconnect_enabled_; | |
241 } | |
242 | |
243 // Flag setting for whether we are prefetching dns lookups. | |
244 bool predictor_enabled() const { | |
245 return predictor_enabled_; | |
246 } | |
247 | |
248 | |
140 private: | 249 private: |
141 friend class base::RefCountedThreadSafe<Predictor>; | |
142 FRIEND_TEST_ALL_PREFIXES(PredictorTest, BenefitLookupTest); | 250 FRIEND_TEST_ALL_PREFIXES(PredictorTest, BenefitLookupTest); |
143 FRIEND_TEST_ALL_PREFIXES(PredictorTest, ShutdownWhenResolutionIsPendingTest); | 251 FRIEND_TEST_ALL_PREFIXES(PredictorTest, ShutdownWhenResolutionIsPendingTest); |
144 FRIEND_TEST_ALL_PREFIXES(PredictorTest, SingleLookupTest); | 252 FRIEND_TEST_ALL_PREFIXES(PredictorTest, SingleLookupTest); |
145 FRIEND_TEST_ALL_PREFIXES(PredictorTest, ConcurrentLookupTest); | 253 FRIEND_TEST_ALL_PREFIXES(PredictorTest, ConcurrentLookupTest); |
146 FRIEND_TEST_ALL_PREFIXES(PredictorTest, MassiveConcurrentLookupTest); | 254 FRIEND_TEST_ALL_PREFIXES(PredictorTest, MassiveConcurrentLookupTest); |
147 FRIEND_TEST_ALL_PREFIXES(PredictorTest, PriorityQueuePushPopTest); | 255 FRIEND_TEST_ALL_PREFIXES(PredictorTest, PriorityQueuePushPopTest); |
148 FRIEND_TEST_ALL_PREFIXES(PredictorTest, PriorityQueueReorderTest); | 256 FRIEND_TEST_ALL_PREFIXES(PredictorTest, PriorityQueueReorderTest); |
149 FRIEND_TEST_ALL_PREFIXES(PredictorTest, ReferrerSerializationTrimTest); | 257 FRIEND_TEST_ALL_PREFIXES(PredictorTest, ReferrerSerializationTrimTest); |
150 friend class WaitForResolutionHelper; // For testing. | 258 friend class WaitForResolutionHelper; // For testing. |
151 | 259 |
(...skipping 19 matching lines...) Expand all Loading... | |
171 private: | 279 private: |
172 // The names in the queue that should be serviced (popped) ASAP. | 280 // The names in the queue that should be serviced (popped) ASAP. |
173 std::queue<GURL> rush_queue_; | 281 std::queue<GURL> rush_queue_; |
174 // The names in the queue that should only be serviced when rush_queue is | 282 // The names in the queue that should only be serviced when rush_queue is |
175 // empty. | 283 // empty. |
176 std::queue<GURL> background_queue_; | 284 std::queue<GURL> background_queue_; |
177 | 285 |
178 DISALLOW_COPY_AND_ASSIGN(HostNameQueue); | 286 DISALLOW_COPY_AND_ASSIGN(HostNameQueue); |
179 }; | 287 }; |
180 | 288 |
289 // The InitialObserver monitors navigations made by the network stack. This | |
290 // is only used to identify startup time resolutions (for re-resolution | |
291 // during our next process startup). | |
292 // TODO(jar): Consider preconnecting at startup, which may be faster than | |
293 // waiting for render process to start and request a connection. | |
294 class InitialObserver { | |
295 public: | |
296 // Recording of when we observed each navigation. | |
297 typedef std::map<GURL, base::TimeTicks> FirstNavigations; | |
298 | |
299 // Potentially add a new URL to our startup list. | |
300 void Append(const GURL& url, Predictor* predictor); | |
301 | |
302 // Get an HTML version of our current planned first_navigations_. | |
303 void GetFirstResolutionsHtml(std::string* output); | |
304 | |
305 // Persist the current first_navigations_ for storage in a list. | |
306 void GetInitialDnsResolutionList(base::ListValue* startup_list); | |
307 | |
308 // Discards all initial loading history. | |
309 void DiscardInitialNavigationHistory() { first_navigations_.clear(); } | |
310 | |
311 private: | |
312 // List of the first N URL resolutions observed in this run. | |
313 FirstNavigations first_navigations_; | |
314 | |
315 // The number of URLs we'll save for pre-resolving at next startup. | |
316 static const size_t kStartupResolutionCount = 10; | |
317 }; | |
318 | |
181 // A map that is keyed with the host/port that we've learned were the cause | 319 // A map that is keyed with the host/port that we've learned were the cause |
182 // of loading additional URLs. The list of additional targets is held | 320 // of loading additional URLs. The list of additional targets is held |
183 // in a Referrer instance, which is a value in this map. | 321 // in a Referrer instance, which is a value in this map. |
184 typedef std::map<GURL, Referrer> Referrers; | 322 typedef std::map<GURL, Referrer> Referrers; |
185 | 323 |
186 // Depending on the expected_subresource_use_, we may either make a TCP/IP | 324 // Depending on the expected_subresource_use_, we may either make a TCP/IP |
187 // preconnection, or merely pre-resolve the hostname via DNS (or even do | 325 // preconnection, or merely pre-resolve the hostname via DNS (or even do |
188 // nothing). The following are the threasholds for taking those actions. | 326 // nothing). The following are the threasholds for taking those actions. |
189 static const double kPreconnectWorthyExpectedValue; | 327 static const double kPreconnectWorthyExpectedValue; |
190 static const double kDNSPreresolutionWorthyExpectedValue; | 328 static const double kDNSPreresolutionWorthyExpectedValue; |
191 // Referred hosts with a subresource_use_rate_ that are less than the | 329 // Referred hosts with a subresource_use_rate_ that are less than the |
192 // following threshold will be discarded when we Trim() the list. | 330 // following threshold will be discarded when we Trim() the list. |
193 static const double kDiscardableExpectedValue; | 331 static const double kDiscardableExpectedValue; |
194 // During trimming operation to discard hosts for which we don't have likely | 332 // During trimming operation to discard hosts for which we don't have likely |
195 // subresources, we multiply the expected_subresource_use_ value by the | 333 // subresources, we multiply the expected_subresource_use_ value by the |
196 // following ratio until that value is less than kDiscardableExpectedValue. | 334 // following ratio until that value is less than kDiscardableExpectedValue. |
197 // This number should always be less than 1, an more than 0. | 335 // This number should always be less than 1, an more than 0. |
198 static const double kReferrerTrimRatio; | 336 static const double kReferrerTrimRatio; |
199 | 337 |
200 // Interval between periodic trimming of our whole referrer list. | 338 // Interval between periodic trimming of our whole referrer list. |
201 // We only do a major trimming about once an hour, and then only when the user | 339 // We only do a major trimming about once an hour, and then only when the user |
202 // is actively browsing. | 340 // is actively browsing. |
203 static const base::TimeDelta kDurationBetweenTrimmings; | 341 static const base::TimeDelta kDurationBetweenTrimmings; |
204 // Interval between incremental trimmings (to avoid inducing Jank). | 342 // Interval between incremental trimmings (to avoid inducing Jank). |
205 static const base::TimeDelta kDurationBetweenTrimmingIncrements; | 343 static const base::TimeDelta kDurationBetweenTrimmingIncrements; |
206 // Number of referring URLs processed in an incremental trimming. | 344 // Number of referring URLs processed in an incremental trimming. |
207 static const size_t kUrlsTrimmedPerIncrement; | 345 static const size_t kUrlsTrimmedPerIncrement; |
208 | 346 |
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 | |
216 // Only for testing. Returns true if hostname has been successfully resolved | 347 // Only for testing. Returns true if hostname has been successfully resolved |
217 // (name found). | 348 // (name found). |
218 bool WasFound(const GURL& url) const { | 349 bool WasFound(const GURL& url) const { |
219 Results::const_iterator it(results_.find(url)); | 350 Results::const_iterator it(results_.find(url)); |
220 return (it != results_.end()) && | 351 return (it != results_.end()) && |
221 it->second.was_found(); | 352 it->second.was_found(); |
222 } | 353 } |
223 | 354 |
224 // Only for testing. Return how long was the resolution | 355 // Only for testing. Return how long was the resolution |
225 // or UrlInfo::kNullDuration if it hasn't been resolved yet. | 356 // or UrlInfo::kNullDuration if it hasn't been resolved yet. |
226 base::TimeDelta GetResolutionDuration(const GURL& url) { | 357 base::TimeDelta GetResolutionDuration(const GURL& url) { |
227 if (results_.find(url) == results_.end()) | 358 if (results_.find(url) == results_.end()) |
228 return UrlInfo::kNullDuration; | 359 return UrlInfo::kNullDuration; |
229 return results_[url].resolve_duration(); | 360 return results_[url].resolve_duration(); |
230 } | 361 } |
231 | 362 |
232 // Only for testing; | 363 // Only for testing; |
233 size_t peak_pending_lookups() const { return peak_pending_lookups_; } | 364 size_t peak_pending_lookups() const { return peak_pending_lookups_; } |
234 | 365 |
366 // ------------- Start IO thread methods. | |
367 | |
368 // Perform actual resolution or preconnection to subresources now. This is | |
369 // an internal worker method that is reached via a post task from | |
370 // PredictFrameSubresources(). | |
371 void PrepareFrameSubresources(const GURL& url); | |
372 | |
235 // Access method for use by async lookup request to pass resolution result. | 373 // Access method for use by async lookup request to pass resolution result. |
236 void OnLookupFinished(LookupRequest* request, const GURL& url, bool found); | 374 void OnLookupFinished(LookupRequest* request, const GURL& url, bool found); |
237 | 375 |
238 // Underlying method for both async and synchronous lookup to update state. | 376 // Underlying method for both async and synchronous lookup to update state. |
239 void LookupFinished(LookupRequest* request, | 377 void LookupFinished(LookupRequest* request, |
240 const GURL& url, bool found); | 378 const GURL& url, bool found); |
241 | 379 |
242 // Queue hostname for resolution. If queueing was done, return the pointer | 380 // Queue hostname for resolution. If queueing was done, return the pointer |
243 // to the queued instance, otherwise return NULL. | 381 // to the queued instance, otherwise return NULL. |
244 UrlInfo* AppendToResolutionQueue(const GURL& url, | 382 UrlInfo* AppendToResolutionQueue(const GURL& url, |
(...skipping 25 matching lines...) Expand all Loading... | |
270 void LoadUrlsForTrimming(); | 408 void LoadUrlsForTrimming(); |
271 | 409 |
272 // Posts a task to do additional incremental trimming of referrers_. | 410 // Posts a task to do additional incremental trimming of referrers_. |
273 void PostIncrementalTrimTask(); | 411 void PostIncrementalTrimTask(); |
274 | 412 |
275 // Calls Trim() on some or all of urls_being_trimmed_. | 413 // Calls Trim() on some or all of urls_being_trimmed_. |
276 // If it does not process all the URLs in that vector, it posts a task to | 414 // If it does not process all the URLs in that vector, it posts a task to |
277 // continue with them shortly (i.e., it yeilds and continues). | 415 // continue with them shortly (i.e., it yeilds and continues). |
278 void IncrementalTrimReferrers(bool trim_all_now); | 416 void IncrementalTrimReferrers(bool trim_all_now); |
279 | 417 |
418 // ------------- End IO thread methods. | |
419 | |
420 scoped_ptr<InitialObserver> initial_observer_; | |
421 | |
422 // Status of speculative DNS resolution and speculative TCP/IP connection | |
423 // feature. | |
424 bool predictor_enabled_; | |
425 | |
280 // work_queue_ holds a list of names we need to look up. | 426 // work_queue_ holds a list of names we need to look up. |
281 HostNameQueue work_queue_; | 427 HostNameQueue work_queue_; |
282 | 428 |
283 // results_ contains information for existing/prior prefetches. | 429 // results_ contains information for existing/prior prefetches. |
284 Results results_; | 430 Results results_; |
285 | 431 |
286 std::set<LookupRequest*> pending_lookups_; | 432 std::set<LookupRequest*> pending_lookups_; |
287 | 433 |
288 // For testing, to verify that we don't exceed the limit. | 434 // For testing, to verify that we don't exceed the limit. |
289 size_t peak_pending_lookups_; | 435 size_t peak_pending_lookups_; |
290 | 436 |
291 // When true, we don't make new lookup requests. | 437 // When true, we don't make new lookup requests. |
292 bool shutdown_; | 438 bool shutdown_; |
293 | 439 |
294 // The number of concurrent speculative lookups currently allowed to be sent | 440 // The number of concurrent speculative lookups currently allowed to be sent |
295 // to the resolver. Any additional lookups will be queued to avoid exceeding | 441 // to the resolver. Any additional lookups will be queued to avoid exceeding |
296 // this value. The queue is a priority queue that will accelerate | 442 // this value. The queue is a priority queue that will accelerate |
297 // sub-resource speculation, and retard resolutions suggested by page scans. | 443 // sub-resource speculation, and retard resolutions suggested by page scans. |
298 const size_t max_concurrent_dns_lookups_; | 444 const size_t max_concurrent_dns_lookups_; |
299 | 445 |
300 // The maximum queueing delay that is acceptable before we enter congestion | 446 // The maximum queueing delay that is acceptable before we enter congestion |
301 // reduction mode, and discard all queued (but not yet assigned) resolutions. | 447 // reduction mode, and discard all queued (but not yet assigned) resolutions. |
302 const base::TimeDelta max_dns_queue_delay_; | 448 const base::TimeDelta max_dns_queue_delay_; |
303 | 449 |
304 // The host resolver we warm DNS entries for. | 450 // The host resolver we warm DNS entries for. |
305 net::HostResolver* const host_resolver_; | 451 net::HostResolver* host_resolver_; |
306 | 452 |
307 // Are we currently using preconnection, rather than just DNS resolution, for | 453 // Are we currently using preconnection, rather than just DNS resolution, for |
308 // subresources and omni-box search URLs. | 454 // subresources and omni-box search URLs. |
309 bool preconnect_enabled_; | 455 bool preconnect_enabled_; |
310 | 456 |
311 // Most recent suggestion from Omnibox provided via AnticipateOmniboxUrl(). | 457 // Most recent suggestion from Omnibox provided via AnticipateOmniboxUrl(). |
312 std::string last_omnibox_host_; | 458 std::string last_omnibox_host_; |
313 | 459 |
314 // The time when the last preresolve was done for last_omnibox_host_. | 460 // The time when the last preresolve was done for last_omnibox_host_. |
315 base::TimeTicks last_omnibox_preresolve_; | 461 base::TimeTicks last_omnibox_preresolve_; |
(...skipping 11 matching lines...) Expand all Loading... | |
327 // orginial hostname. | 473 // orginial hostname. |
328 Referrers referrers_; | 474 Referrers referrers_; |
329 | 475 |
330 // List of URLs in referrers_ currently being trimmed (scaled down to | 476 // List of URLs in referrers_ currently being trimmed (scaled down to |
331 // eventually be aged out of use). | 477 // eventually be aged out of use). |
332 std::vector<GURL> urls_being_trimmed_; | 478 std::vector<GURL> urls_being_trimmed_; |
333 | 479 |
334 // A time after which we need to do more trimming of referrers. | 480 // A time after which we need to do more trimming of referrers. |
335 base::TimeTicks next_trim_time_; | 481 base::TimeTicks next_trim_time_; |
336 | 482 |
337 ScopedRunnableMethodFactory<Predictor> trim_task_factory_; | 483 scoped_ptr<ScopedRunnableMethodFactory<Predictor> > trim_task_factory_; |
338 | 484 |
339 DISALLOW_COPY_AND_ASSIGN(Predictor); | 485 DISALLOW_COPY_AND_ASSIGN(Predictor); |
340 }; | 486 }; |
341 | 487 |
342 } // namespace chrome_browser_net | 488 } // namespace chrome_browser_net |
343 | 489 |
344 #endif // CHROME_BROWSER_NET_PREDICTOR_H_ | 490 #endif // CHROME_BROWSER_NET_PREDICTOR_H_ |
OLD | NEW |