| 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 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 bool PreconnectEnabled() const; | 309 bool PreconnectEnabled() const; |
| 310 | 310 |
| 311 // Used only for testing. Overrides command line flag to disable preconnect, | 311 // Used only for testing. Overrides command line flag to disable preconnect, |
| 312 // which is added in the browser test fixture. | 312 // which is added in the browser test fixture. |
| 313 void SetPreconnectEnabledForTest(bool preconnect_enabled); | 313 void SetPreconnectEnabledForTest(bool preconnect_enabled); |
| 314 | 314 |
| 315 net::URLRequestContextGetter* url_request_context_getter_for_test() { | 315 net::URLRequestContextGetter* url_request_context_getter_for_test() { |
| 316 return url_request_context_getter_.get(); | 316 return url_request_context_getter_.get(); |
| 317 } | 317 } |
| 318 | 318 |
| 319 TimedCache* timed_cache() { return timed_cache_.get(); } |
| 320 |
| 319 private: | 321 private: |
| 320 FRIEND_TEST_ALL_PREFIXES(PredictorTest, BenefitLookupTest); | 322 FRIEND_TEST_ALL_PREFIXES(PredictorTest, BenefitLookupTest); |
| 321 FRIEND_TEST_ALL_PREFIXES(PredictorTest, ShutdownWhenResolutionIsPendingTest); | 323 FRIEND_TEST_ALL_PREFIXES(PredictorTest, ShutdownWhenResolutionIsPendingTest); |
| 322 FRIEND_TEST_ALL_PREFIXES(PredictorTest, SingleLookupTest); | 324 FRIEND_TEST_ALL_PREFIXES(PredictorTest, SingleLookupTest); |
| 323 FRIEND_TEST_ALL_PREFIXES(PredictorTest, ConcurrentLookupTest); | 325 FRIEND_TEST_ALL_PREFIXES(PredictorTest, ConcurrentLookupTest); |
| 324 FRIEND_TEST_ALL_PREFIXES(PredictorTest, MassiveConcurrentLookupTest); | 326 FRIEND_TEST_ALL_PREFIXES(PredictorTest, MassiveConcurrentLookupTest); |
| 325 FRIEND_TEST_ALL_PREFIXES(PredictorTest, PriorityQueuePushPopTest); | 327 FRIEND_TEST_ALL_PREFIXES(PredictorTest, PriorityQueuePushPopTest); |
| 326 FRIEND_TEST_ALL_PREFIXES(PredictorTest, PriorityQueueReorderTest); | 328 FRIEND_TEST_ALL_PREFIXES(PredictorTest, PriorityQueueReorderTest); |
| 327 FRIEND_TEST_ALL_PREFIXES(PredictorTest, ReferrerSerializationTrimTest); | 329 FRIEND_TEST_ALL_PREFIXES(PredictorTest, ReferrerSerializationTrimTest); |
| 328 FRIEND_TEST_ALL_PREFIXES(PredictorTest, SingleLookupTestWithDisabledAdvisor); | 330 FRIEND_TEST_ALL_PREFIXES(PredictorTest, SingleLookupTestWithDisabledAdvisor); |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 597 // List of URLs in referrers_ currently being trimmed (scaled down to | 599 // List of URLs in referrers_ currently being trimmed (scaled down to |
| 598 // eventually be aged out of use). | 600 // eventually be aged out of use). |
| 599 std::vector<GURL> urls_being_trimmed_; | 601 std::vector<GURL> urls_being_trimmed_; |
| 600 | 602 |
| 601 // A time after which we need to do more trimming of referrers. | 603 // A time after which we need to do more trimming of referrers. |
| 602 base::TimeTicks next_trim_time_; | 604 base::TimeTicks next_trim_time_; |
| 603 | 605 |
| 604 // An observer for testing. | 606 // An observer for testing. |
| 605 PredictorObserver* observer_; | 607 PredictorObserver* observer_; |
| 606 | 608 |
| 609 std::unique_ptr<TimedCache> timed_cache_; |
| 610 |
| 607 std::unique_ptr<base::WeakPtrFactory<Predictor>> weak_factory_; | 611 std::unique_ptr<base::WeakPtrFactory<Predictor>> weak_factory_; |
| 608 | 612 |
| 609 // Protects |preconnect_enabled_|. | 613 // Protects |preconnect_enabled_|. |
| 610 mutable base::Lock preconnect_enabled_lock_; | 614 mutable base::Lock preconnect_enabled_lock_; |
| 611 | 615 |
| 612 DISALLOW_COPY_AND_ASSIGN(Predictor); | 616 DISALLOW_COPY_AND_ASSIGN(Predictor); |
| 613 }; | 617 }; |
| 614 | 618 |
| 615 // This version of the predictor is used for testing. | 619 // This version of the predictor is used for testing. |
| 616 class SimplePredictor : public Predictor { | 620 class SimplePredictor : public Predictor { |
| 617 public: | 621 public: |
| 618 explicit SimplePredictor(bool preconnect_enabled, bool predictor_enabled) | 622 explicit SimplePredictor(bool preconnect_enabled, bool predictor_enabled) |
| 619 : Predictor(preconnect_enabled, predictor_enabled) {} | 623 : Predictor(preconnect_enabled, predictor_enabled) {} |
| 620 ~SimplePredictor() override {} | 624 ~SimplePredictor() override {} |
| 621 void InitNetworkPredictor(PrefService* user_prefs, | 625 void InitNetworkPredictor(PrefService* user_prefs, |
| 622 IOThread* io_thread, | 626 IOThread* io_thread, |
| 623 net::URLRequestContextGetter* getter, | 627 net::URLRequestContextGetter* getter, |
| 624 ProfileIOData* profile_io_data) override; | 628 ProfileIOData* profile_io_data) override; |
| 625 void ShutdownOnUIThread() override; | 629 void ShutdownOnUIThread() override; |
| 626 | 630 |
| 627 private: | 631 private: |
| 628 // These member functions return True for unittests. | 632 // These member functions return True for unittests. |
| 629 bool CanPrefetchAndPrerender() const override; | 633 bool CanPrefetchAndPrerender() const override; |
| 630 bool CanPreresolveAndPreconnect() const override; | 634 bool CanPreresolveAndPreconnect() const override; |
| 631 }; | 635 }; |
| 632 | 636 |
| 633 } // namespace chrome_browser_net | 637 } // namespace chrome_browser_net |
| 634 | 638 |
| 635 #endif // CHROME_BROWSER_NET_PREDICTOR_H_ | 639 #endif // CHROME_BROWSER_NET_PREDICTOR_H_ |
| OLD | NEW |