Chromium Code Reviews| 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 29 matching lines...) Expand all Loading... | |
| 40 #include "net/base/host_port_pair.h" | 40 #include "net/base/host_port_pair.h" |
| 41 #include "url/gurl.h" | 41 #include "url/gurl.h" |
| 42 | 42 |
| 43 class IOThread; | 43 class IOThread; |
| 44 class PrefService; | 44 class PrefService; |
| 45 class Profile; | 45 class Profile; |
| 46 class ProfileIOData; | 46 class ProfileIOData; |
| 47 | 47 |
| 48 namespace base { | 48 namespace base { |
| 49 class ListValue; | 49 class ListValue; |
| 50 class WaitableEvent; | 50 class WaitableEvent; |
|
mmenke
2016/08/01 17:41:25
WaitableEvent not needed.
Charlie Harrison
2016/08/01 17:48:09
Done.
| |
| 51 } | 51 } |
| 52 | 52 |
| 53 namespace net { | 53 namespace net { |
| 54 class HostResolver; | 54 class HostResolver; |
| 55 class SSLConfigService; | 55 class SSLConfigService; |
| 56 class ProxyService; | 56 class ProxyService; |
| 57 class TransportSecurityState; | 57 class TransportSecurityState; |
| 58 class URLRequestContextGetter; | 58 class URLRequestContextGetter; |
| 59 } | 59 } |
| 60 | 60 |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 165 // Clears the preferences used by the predictor. Must be called on the UI | 165 // Clears the preferences used by the predictor. Must be called on the UI |
| 166 // thread. | 166 // thread. |
| 167 void ClearPrefsOnUIThread(); | 167 void ClearPrefsOnUIThread(); |
| 168 | 168 |
| 169 static void set_max_queueing_delay(int max_queueing_delay_ms); | 169 static void set_max_queueing_delay(int max_queueing_delay_ms); |
| 170 | 170 |
| 171 static void set_max_parallel_resolves(size_t max_parallel_resolves); | 171 static void set_max_parallel_resolves(size_t max_parallel_resolves); |
| 172 | 172 |
| 173 virtual void ShutdownOnUIThread(); | 173 virtual void ShutdownOnUIThread(); |
| 174 | 174 |
| 175 void UpdatePrefsOnUIThread(std::unique_ptr<base::ListValue> startup_list, | |
| 176 std::unique_ptr<base::ListValue> referral_list); | |
| 177 | |
| 175 // ------------- End UI thread methods. | 178 // ------------- End UI thread methods. |
| 176 | 179 |
| 177 // ------------- Start IO thread methods. | 180 // ------------- Start IO thread methods. |
| 178 | 181 |
| 182 void WriteDnsPrefetchState(base::ListValue* startup_list, | |
| 183 base::ListValue* referral_list); | |
| 184 | |
| 179 // Cancel pending requests and prevent new ones from being made. | 185 // Cancel pending requests and prevent new ones from being made. |
| 180 void Shutdown(); | 186 void Shutdown(); |
| 181 | 187 |
| 182 // In some circumstances, for privacy reasons, all results should be | 188 // In some circumstances, for privacy reasons, all results should be |
| 183 // discarded. This method gracefully handles that activity. | 189 // discarded. This method gracefully handles that activity. |
| 184 // Destroy all our internal state, which shows what names we've looked up, and | 190 // Destroy all our internal state, which shows what names we've looked up, and |
| 185 // how long each has taken, etc. etc. We also destroy records of suggesses | 191 // how long each has taken, etc. etc. We also destroy records of suggesses |
| 186 // (cache hits etc.). | 192 // (cache hits etc.). |
| 187 void DiscardAllResults(); | 193 void DiscardAllResults(); |
| 188 | 194 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 231 | 237 |
| 232 // Renderer bundles up list and sends to this browser API via IPC. | 238 // Renderer bundles up list and sends to this browser API via IPC. |
| 233 // TODO(csharrison): Use a GURL vector instead to include port and scheme. | 239 // TODO(csharrison): Use a GURL vector instead to include port and scheme. |
| 234 void DnsPrefetchList(const std::vector<std::string>& hostnames); | 240 void DnsPrefetchList(const std::vector<std::string>& hostnames); |
| 235 | 241 |
| 236 // May be called from either the IO or UI thread and will PostTask | 242 // May be called from either the IO or UI thread and will PostTask |
| 237 // to the IO thread if necessary. | 243 // to the IO thread if necessary. |
| 238 void DnsPrefetchMotivatedList(const std::vector<GURL>& urls, | 244 void DnsPrefetchMotivatedList(const std::vector<GURL>& urls, |
| 239 UrlInfo::ResolutionMotivation motivation); | 245 UrlInfo::ResolutionMotivation motivation); |
| 240 | 246 |
| 241 // May be called from either the IO or UI thread and will PostTask | 247 // Called from the UI thread in response to the load event. |
| 242 // to the IO thread if necessary. | |
| 243 void SaveStateForNextStartup(); | 248 void SaveStateForNextStartup(); |
| 244 | 249 |
| 245 void SaveDnsPrefetchStateForNextStartup(base::ListValue* startup_list, | |
| 246 base::ListValue* referral_list, | |
| 247 base::WaitableEvent* completion); | |
| 248 | |
| 249 // May be called from either the IO or UI thread and will PostTask | 250 // May be called from either the IO or UI thread and will PostTask |
| 250 // to the IO thread if necessary. | 251 // to the IO thread if necessary. |
| 251 void PreconnectUrl(const GURL& url, | 252 void PreconnectUrl(const GURL& url, |
| 252 const GURL& first_party_for_cookies, | 253 const GURL& first_party_for_cookies, |
| 253 UrlInfo::ResolutionMotivation motivation, | 254 UrlInfo::ResolutionMotivation motivation, |
| 254 bool allow_credentials, | 255 bool allow_credentials, |
| 255 int count); | 256 int count); |
| 256 | 257 |
| 257 void PreconnectUrlOnIOThread(const GURL& url, | 258 void PreconnectUrlOnIOThread(const GURL& url, |
| 258 const GURL& first_party_for_cookies, | 259 const GURL& first_party_for_cookies, |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 533 // we have a Referrer list. Each Referrer list has all hostnames we might | 534 // we have a Referrer list. Each Referrer list has all hostnames we might |
| 534 // need to pre-resolve or pre-connect to when there is a navigation to the | 535 // need to pre-resolve or pre-connect to when there is a navigation to the |
| 535 // orginial hostname. | 536 // orginial hostname. |
| 536 Referrers referrers_; | 537 Referrers referrers_; |
| 537 | 538 |
| 538 // An observer for testing. | 539 // An observer for testing. |
| 539 PredictorObserver* observer_; | 540 PredictorObserver* observer_; |
| 540 | 541 |
| 541 std::unique_ptr<TimedCache> timed_cache_; | 542 std::unique_ptr<TimedCache> timed_cache_; |
| 542 | 543 |
| 543 std::unique_ptr<base::WeakPtrFactory<Predictor>> weak_factory_; | 544 // TODO(csharrison): It is not great that two weak pointer factories are |
| 545 // needed in this class. Let's split it into two classes that live on each | |
| 546 // thread. | |
| 547 // | |
| 548 // Weak factory for weak pointers that should be dereferenced on the IO | |
| 549 // thread. | |
| 550 std::unique_ptr<base::WeakPtrFactory<Predictor>> io_weak_factory_; | |
| 551 | |
| 552 // Weak factory for weak pointers that should be dereferenced on the UI | |
| 553 // thread. | |
| 554 std::unique_ptr<base::WeakPtrFactory<Predictor>> ui_weak_factory_; | |
| 544 | 555 |
| 545 // Protects |preconnect_enabled_|. | 556 // Protects |preconnect_enabled_|. |
| 546 mutable base::Lock preconnect_enabled_lock_; | 557 mutable base::Lock preconnect_enabled_lock_; |
| 547 | 558 |
| 548 DISALLOW_COPY_AND_ASSIGN(Predictor); | 559 DISALLOW_COPY_AND_ASSIGN(Predictor); |
| 549 }; | 560 }; |
| 550 | 561 |
| 551 // This version of the predictor is used for testing. | 562 // This version of the predictor is used for testing. |
| 552 class SimplePredictor : public Predictor { | 563 class SimplePredictor : public Predictor { |
| 553 public: | 564 public: |
| 554 explicit SimplePredictor(bool preconnect_enabled, bool predictor_enabled) | 565 explicit SimplePredictor(bool preconnect_enabled, bool predictor_enabled) |
| 555 : Predictor(preconnect_enabled, predictor_enabled) {} | 566 : Predictor(preconnect_enabled, predictor_enabled) {} |
| 556 ~SimplePredictor() override {} | 567 ~SimplePredictor() override {} |
| 557 void InitNetworkPredictor(PrefService* user_prefs, | 568 void InitNetworkPredictor(PrefService* user_prefs, |
| 558 IOThread* io_thread, | 569 IOThread* io_thread, |
| 559 net::URLRequestContextGetter* getter, | 570 net::URLRequestContextGetter* getter, |
| 560 ProfileIOData* profile_io_data) override; | 571 ProfileIOData* profile_io_data) override; |
| 561 void ShutdownOnUIThread() override; | 572 void ShutdownOnUIThread() override; |
| 562 | 573 |
| 563 private: | 574 private: |
| 564 // These member functions return True for unittests. | 575 // These member functions return True for unittests. |
| 565 bool CanPrefetchAndPrerender() const override; | 576 bool CanPrefetchAndPrerender() const override; |
| 566 bool CanPreresolveAndPreconnect() const override; | 577 bool CanPreresolveAndPreconnect() const override; |
| 567 }; | 578 }; |
| 568 | 579 |
| 569 } // namespace chrome_browser_net | 580 } // namespace chrome_browser_net |
| 570 | 581 |
| 571 #endif // CHROME_BROWSER_NET_PREDICTOR_H_ | 582 #endif // CHROME_BROWSER_NET_PREDICTOR_H_ |
| OLD | NEW |