OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 class PredictorObserver { | 72 class PredictorObserver { |
73 public: | 73 public: |
74 virtual ~PredictorObserver() {} | 74 virtual ~PredictorObserver() {} |
75 | 75 |
76 virtual void OnPreconnectUrl(const GURL& original_url, | 76 virtual void OnPreconnectUrl(const GURL& original_url, |
77 const GURL& first_party_for_cookies, | 77 const GURL& first_party_for_cookies, |
78 UrlInfo::ResolutionMotivation motivation, | 78 UrlInfo::ResolutionMotivation motivation, |
79 int count) {} | 79 int count) {} |
80 virtual void OnLearnFromNavigation(const GURL& referring_url, | 80 virtual void OnLearnFromNavigation(const GURL& referring_url, |
81 const GURL& target_url) {} | 81 const GURL& target_url) {} |
| 82 |
| 83 virtual void OnDnsLookupFinished(const GURL& url, bool found) {} |
82 }; | 84 }; |
83 | 85 |
84 // Predictor is constructed during Profile construction (on the UI thread), | 86 // Predictor is constructed during Profile construction (on the UI thread), |
85 // but it is destroyed on the IO thread when ProfileIOData goes away. All of | 87 // but it is destroyed on the IO thread when ProfileIOData goes away. All of |
86 // its core state and functionality happens on the IO thread. The only UI | 88 // its core state and functionality happens on the IO thread. The only UI |
87 // methods are initialization / shutdown related (including preconnect | 89 // methods are initialization / shutdown related (including preconnect |
88 // initialization), or convenience methods that internally forward calls to | 90 // initialization), or convenience methods that internally forward calls to |
89 // the IO thread. | 91 // the IO thread. |
90 class Predictor { | 92 class Predictor { |
91 public: | 93 public: |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 | 312 |
311 // Used only for testing. Overrides command line flag to disable preconnect, | 313 // Used only for testing. Overrides command line flag to disable preconnect, |
312 // which is added in the browser test fixture. | 314 // which is added in the browser test fixture. |
313 void SetPreconnectEnabledForTest(bool preconnect_enabled); | 315 void SetPreconnectEnabledForTest(bool preconnect_enabled); |
314 | 316 |
315 net::URLRequestContextGetter* url_request_context_getter_for_test() { | 317 net::URLRequestContextGetter* url_request_context_getter_for_test() { |
316 return url_request_context_getter_.get(); | 318 return url_request_context_getter_.get(); |
317 } | 319 } |
318 | 320 |
319 private: | 321 private: |
320 FRIEND_TEST_ALL_PREFIXES(PredictorTest, BenefitLookupTest); | |
321 FRIEND_TEST_ALL_PREFIXES(PredictorTest, ShutdownWhenResolutionIsPendingTest); | |
322 FRIEND_TEST_ALL_PREFIXES(PredictorTest, SingleLookupTest); | |
323 FRIEND_TEST_ALL_PREFIXES(PredictorTest, ConcurrentLookupTest); | |
324 FRIEND_TEST_ALL_PREFIXES(PredictorTest, MassiveConcurrentLookupTest); | |
325 FRIEND_TEST_ALL_PREFIXES(PredictorTest, PriorityQueuePushPopTest); | 322 FRIEND_TEST_ALL_PREFIXES(PredictorTest, PriorityQueuePushPopTest); |
326 FRIEND_TEST_ALL_PREFIXES(PredictorTest, PriorityQueueReorderTest); | 323 FRIEND_TEST_ALL_PREFIXES(PredictorTest, PriorityQueueReorderTest); |
327 FRIEND_TEST_ALL_PREFIXES(PredictorTest, ReferrerSerializationTrimTest); | 324 FRIEND_TEST_ALL_PREFIXES(PredictorTest, ReferrerSerializationTrimTest); |
328 FRIEND_TEST_ALL_PREFIXES(PredictorTest, SingleLookupTestWithDisabledAdvisor); | 325 FRIEND_TEST_ALL_PREFIXES(PredictorTest, SingleLookupTestWithDisabledAdvisor); |
329 FRIEND_TEST_ALL_PREFIXES(PredictorTest, SingleLookupTestWithEnabledAdvisor); | 326 FRIEND_TEST_ALL_PREFIXES(PredictorTest, SingleLookupTestWithEnabledAdvisor); |
330 FRIEND_TEST_ALL_PREFIXES(PredictorTest, TestSimplePreconnectAdvisor); | 327 FRIEND_TEST_ALL_PREFIXES(PredictorTest, TestSimplePreconnectAdvisor); |
331 FRIEND_TEST_ALL_PREFIXES(PredictorTest, NoProxyService); | 328 FRIEND_TEST_ALL_PREFIXES(PredictorTest, NoProxyService); |
332 FRIEND_TEST_ALL_PREFIXES(PredictorTest, ProxyDefinitelyEnabled); | 329 FRIEND_TEST_ALL_PREFIXES(PredictorTest, ProxyDefinitelyEnabled); |
333 FRIEND_TEST_ALL_PREFIXES(PredictorTest, ProxyDefinitelyNotEnabled); | 330 FRIEND_TEST_ALL_PREFIXES(PredictorTest, ProxyDefinitelyNotEnabled); |
334 FRIEND_TEST_ALL_PREFIXES(PredictorTest, ProxyMaybeEnabled); | 331 FRIEND_TEST_ALL_PREFIXES(PredictorTest, ProxyMaybeEnabled); |
335 friend class WaitForResolutionHelper; // For testing. | 332 friend class WaitForResolutionHelper; // For testing. |
| 333 friend class PredictorBrowserTest; |
336 | 334 |
337 class LookupRequest; | 335 class LookupRequest; |
338 | 336 |
339 // A simple priority queue for handling host names. | 337 // A simple priority queue for handling host names. |
340 // Some names that are queued up have |motivation| that requires very rapid | 338 // Some names that are queued up have |motivation| that requires very rapid |
341 // handling. For example, a sub-resource name lookup MUST be done before the | 339 // handling. For example, a sub-resource name lookup MUST be done before the |
342 // actual sub-resource is fetched. In contrast, a name that was speculatively | 340 // actual sub-resource is fetched. In contrast, a name that was speculatively |
343 // noted in a page has to be resolved before the user "gets around to" | 341 // noted in a page has to be resolved before the user "gets around to" |
344 // clicking on a link. By tagging (with a motivation) each push we make into | 342 // clicking on a link. By tagging (with a motivation) each push we make into |
345 // this FIFO queue, the queue can re-order the more important names to service | 343 // this FIFO queue, the queue can re-order the more important names to service |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
416 | 414 |
417 // Interval between periodic trimming of our whole referrer list. | 415 // Interval between periodic trimming of our whole referrer list. |
418 // We only do a major trimming about once an hour, and then only when the user | 416 // We only do a major trimming about once an hour, and then only when the user |
419 // is actively browsing. | 417 // is actively browsing. |
420 static const int64_t kDurationBetweenTrimmingsHours; | 418 static const int64_t kDurationBetweenTrimmingsHours; |
421 // Interval between incremental trimmings (to avoid inducing Jank). | 419 // Interval between incremental trimmings (to avoid inducing Jank). |
422 static const int64_t kDurationBetweenTrimmingIncrementsSeconds; | 420 static const int64_t kDurationBetweenTrimmingIncrementsSeconds; |
423 // Number of referring URLs processed in an incremental trimming. | 421 // Number of referring URLs processed in an incremental trimming. |
424 static const size_t kUrlsTrimmedPerIncrement; | 422 static const size_t kUrlsTrimmedPerIncrement; |
425 | 423 |
426 // Only for testing. Returns true if hostname has been successfully resolved | |
427 // (name found). | |
428 bool WasFound(const GURL& url) const { | |
429 Results::const_iterator it(results_.find(url)); | |
430 return (it != results_.end()) && | |
431 it->second.was_found(); | |
432 } | |
433 | |
434 // Only for testing. Return how long was the resolution | |
435 // or UrlInfo::NullDuration() if it hasn't been resolved yet. | |
436 base::TimeDelta GetResolutionDuration(const GURL& url) { | |
437 if (results_.find(url) == results_.end()) | |
438 return UrlInfo::NullDuration(); | |
439 return results_[url].resolve_duration(); | |
440 } | |
441 | |
442 // Only for testing; | |
443 size_t peak_pending_lookups() const { return peak_pending_lookups_; } | |
444 | |
445 // These two members call the appropriate global functions in | 424 // These two members call the appropriate global functions in |
446 // prediction_options.cc depending on which thread they are called on. | 425 // prediction_options.cc depending on which thread they are called on. |
447 virtual bool CanPrefetchAndPrerender() const; | 426 virtual bool CanPrefetchAndPrerender() const; |
448 virtual bool CanPreresolveAndPreconnect() const; | 427 virtual bool CanPreresolveAndPreconnect() const; |
449 | 428 |
450 // ------------- Start IO thread methods. | 429 // ------------- Start IO thread methods. |
451 | 430 |
452 // Perform actual resolution or preconnection to subresources now. This is | 431 // Perform actual resolution or preconnection to subresources now. This is |
453 // an internal worker method that is reached via a post task from | 432 // an internal worker method that is reached via a post task from |
454 // PredictFrameSubresources(). | 433 // PredictFrameSubresources(). |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
626 | 605 |
627 private: | 606 private: |
628 // These member functions return True for unittests. | 607 // These member functions return True for unittests. |
629 bool CanPrefetchAndPrerender() const override; | 608 bool CanPrefetchAndPrerender() const override; |
630 bool CanPreresolveAndPreconnect() const override; | 609 bool CanPreresolveAndPreconnect() const override; |
631 }; | 610 }; |
632 | 611 |
633 } // namespace chrome_browser_net | 612 } // namespace chrome_browser_net |
634 | 613 |
635 #endif // CHROME_BROWSER_NET_PREDICTOR_H_ | 614 #endif // CHROME_BROWSER_NET_PREDICTOR_H_ |
OLD | NEW |