| OLD | NEW |
| 1 // Copyright (c) 2006-2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2010 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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 // how long each has taken, etc. etc. We also destroy records of suggesses | 76 // how long each has taken, etc. etc. We also destroy records of suggesses |
| 77 // (cache hits etc.). | 77 // (cache hits etc.). |
| 78 void DiscardAllResults(); | 78 void DiscardAllResults(); |
| 79 | 79 |
| 80 // Add hostname(s) to the queue for processing. | 80 // Add hostname(s) to the queue for processing. |
| 81 void ResolveList(const UrlList& urls, | 81 void ResolveList(const UrlList& urls, |
| 82 UrlInfo::ResolutionMotivation motivation); | 82 UrlInfo::ResolutionMotivation motivation); |
| 83 void Resolve(const GURL& url, | 83 void Resolve(const GURL& url, |
| 84 UrlInfo::ResolutionMotivation motivation); | 84 UrlInfo::ResolutionMotivation motivation); |
| 85 | 85 |
| 86 // Instigate pre-connection to any URLs we predict will be needed after this | 86 // Instigate pre-connection to any URLs, or pre-resolution of related host, |
| 87 // navigation (typically more-embedded resources on a page). | 87 // that we predict will be needed after this navigation (typically |
| 88 // more-embedded resources on a page). This method will actually post a task |
| 89 // to do the actual work, so as not to jump ahead of the frame navigation that |
| 90 // instigated this activity. |
| 88 void PredictFrameSubresources(const GURL& url); | 91 void PredictFrameSubresources(const GURL& url); |
| 89 | 92 |
| 90 // Record details of a navigation so that we can preresolve the host name | 93 // Record details of a navigation so that we can preresolve the host name |
| 91 // ahead of time the next time the users navigates to the indicated host. | 94 // ahead of time the next time the users navigates to the indicated host. |
| 92 void LearnFromNavigation(const GURL& referring_url, const GURL& target_url); | 95 void LearnFromNavigation(const GURL& referring_url, const GURL& target_url); |
| 93 | 96 |
| 94 // Dump HTML table containing list of referrers for about:dns. | 97 // Dump HTML table containing list of referrers for about:dns. |
| 95 void GetHtmlReferrerLists(std::string* output); | 98 void GetHtmlReferrerLists(std::string* output); |
| 96 | 99 |
| 97 // Dump the list of currently known referrer domains and related prefetchable | 100 // Dump the list of currently known referrer domains and related prefetchable |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 friend class base::RefCountedThreadSafe<Predictor>; | 134 friend class base::RefCountedThreadSafe<Predictor>; |
| 132 FRIEND_TEST_ALL_PREFIXES(PredictorTest, BenefitLookupTest); | 135 FRIEND_TEST_ALL_PREFIXES(PredictorTest, BenefitLookupTest); |
| 133 FRIEND_TEST_ALL_PREFIXES(PredictorTest, ShutdownWhenResolutionIsPendingTest); | 136 FRIEND_TEST_ALL_PREFIXES(PredictorTest, ShutdownWhenResolutionIsPendingTest); |
| 134 FRIEND_TEST_ALL_PREFIXES(PredictorTest, SingleLookupTest); | 137 FRIEND_TEST_ALL_PREFIXES(PredictorTest, SingleLookupTest); |
| 135 FRIEND_TEST_ALL_PREFIXES(PredictorTest, ConcurrentLookupTest); | 138 FRIEND_TEST_ALL_PREFIXES(PredictorTest, ConcurrentLookupTest); |
| 136 FRIEND_TEST_ALL_PREFIXES(PredictorTest, MassiveConcurrentLookupTest); | 139 FRIEND_TEST_ALL_PREFIXES(PredictorTest, MassiveConcurrentLookupTest); |
| 137 FRIEND_TEST_ALL_PREFIXES(PredictorTest, PriorityQueuePushPopTest); | 140 FRIEND_TEST_ALL_PREFIXES(PredictorTest, PriorityQueuePushPopTest); |
| 138 FRIEND_TEST_ALL_PREFIXES(PredictorTest, PriorityQueueReorderTest); | 141 FRIEND_TEST_ALL_PREFIXES(PredictorTest, PriorityQueueReorderTest); |
| 139 friend class WaitForResolutionHelper; // For testing. | 142 friend class WaitForResolutionHelper; // For testing. |
| 140 | 143 |
| 141 ~Predictor(); | |
| 142 | |
| 143 class LookupRequest; | 144 class LookupRequest; |
| 144 | 145 |
| 145 // A simple priority queue for handling host names. | 146 // A simple priority queue for handling host names. |
| 146 // Some names that are queued up have |motivation| that requires very rapid | 147 // Some names that are queued up have |motivation| that requires very rapid |
| 147 // handling. For example, a sub-resource name lookup MUST be done before the | 148 // handling. For example, a sub-resource name lookup MUST be done before the |
| 148 // actual sub-resource is fetched. In contrast, a name that was speculatively | 149 // actual sub-resource is fetched. In contrast, a name that was speculatively |
| 149 // noted in a page has to be resolved before the user "gets around to" | 150 // noted in a page has to be resolved before the user "gets around to" |
| 150 // clicking on a link. By tagging (with a motivation) each push we make into | 151 // clicking on a link. By tagging (with a motivation) each push we make into |
| 151 // this FIFO queue, the queue can re-order the more important names to service | 152 // this FIFO queue, the queue can re-order the more important names to service |
| 152 // them sooner (relative to some low priority background resolutions). | 153 // them sooner (relative to some low priority background resolutions). |
| (...skipping 14 matching lines...) Expand all Loading... |
| 167 std::queue<GURL> background_queue_; | 168 std::queue<GURL> background_queue_; |
| 168 | 169 |
| 169 DISALLOW_COPY_AND_ASSIGN(HostNameQueue); | 170 DISALLOW_COPY_AND_ASSIGN(HostNameQueue); |
| 170 }; | 171 }; |
| 171 | 172 |
| 172 // A map that is keyed with the host/port that we've learned were the cause | 173 // A map that is keyed with the host/port that we've learned were the cause |
| 173 // of loading additional URLs. The list of additional targets is held | 174 // of loading additional URLs. The list of additional targets is held |
| 174 // in a Referrer instance, which is a value in this map. | 175 // in a Referrer instance, which is a value in this map. |
| 175 typedef std::map<GURL, Referrer> Referrers; | 176 typedef std::map<GURL, Referrer> Referrers; |
| 176 | 177 |
| 178 ~Predictor(); |
| 179 |
| 180 // Perform actual resolution or preconnection to subresources now. This is |
| 181 // an internal worker method that is reached via a post task from |
| 182 // PredictFrameSubresources(). |
| 183 void PrepareFrameSubresources(const GURL& url); |
| 184 |
| 177 // Only for testing. Returns true if hostname has been successfully resolved | 185 // Only for testing. Returns true if hostname has been successfully resolved |
| 178 // (name found). | 186 // (name found). |
| 179 bool WasFound(const GURL& url) const { | 187 bool WasFound(const GURL& url) const { |
| 180 Results::const_iterator it(results_.find(url)); | 188 Results::const_iterator it(results_.find(url)); |
| 181 return (it != results_.end()) && | 189 return (it != results_.end()) && |
| 182 it->second.was_found(); | 190 it->second.was_found(); |
| 183 } | 191 } |
| 184 | 192 |
| 185 // Only for testing. Return how long was the resolution | 193 // Only for testing. Return how long was the resolution |
| 186 // or UrlInfo::kNullDuration if it hasn't been resolved yet. | 194 // or UrlInfo::kNullDuration if it hasn't been resolved yet. |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 // Are we currently using preconnection, rather than just DNS resolution, for | 263 // Are we currently using preconnection, rather than just DNS resolution, for |
| 256 // subresources and omni-box search URLs. | 264 // subresources and omni-box search URLs. |
| 257 bool preconnect_enabled_; | 265 bool preconnect_enabled_; |
| 258 | 266 |
| 259 DISALLOW_COPY_AND_ASSIGN(Predictor); | 267 DISALLOW_COPY_AND_ASSIGN(Predictor); |
| 260 }; | 268 }; |
| 261 | 269 |
| 262 } // namespace chrome_browser_net | 270 } // namespace chrome_browser_net |
| 263 | 271 |
| 264 #endif // CHROME_BROWSER_NET_PREDICTOR_H_ | 272 #endif // CHROME_BROWSER_NET_PREDICTOR_H_ |
| OLD | NEW |