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