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 20 matching lines...) Expand all Loading... | |
31 #include "chrome/browser/net/referrer.h" | 31 #include "chrome/browser/net/referrer.h" |
32 #include "chrome/browser/net/spdyproxy/proxy_advisor.h" | 32 #include "chrome/browser/net/spdyproxy/proxy_advisor.h" |
33 #include "chrome/browser/net/timed_cache.h" | 33 #include "chrome/browser/net/timed_cache.h" |
34 #include "chrome/browser/net/url_info.h" | 34 #include "chrome/browser/net/url_info.h" |
35 #include "chrome/common/net/predictor_common.h" | 35 #include "chrome/common/net/predictor_common.h" |
36 #include "net/base/host_port_pair.h" | 36 #include "net/base/host_port_pair.h" |
37 | 37 |
38 class IOThread; | 38 class IOThread; |
39 class PrefService; | 39 class PrefService; |
40 class Profile; | 40 class Profile; |
41 class ProfileIOData; | |
41 | 42 |
42 namespace base { | 43 namespace base { |
43 class ListValue; | 44 class ListValue; |
44 class WaitableEvent; | 45 class WaitableEvent; |
45 } | 46 } |
46 | 47 |
47 namespace net { | 48 namespace net { |
48 class HostResolver; | 49 class HostResolver; |
49 class SSLConfigService; | 50 class SSLConfigService; |
50 class TransportSecurityState; | 51 class TransportSecurityState; |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
108 | 109 |
109 // We don't bother learning to preconnect via a GET if the original URL | 110 // We don't bother learning to preconnect via a GET if the original URL |
110 // navigation was so long ago, that a preconnection would have been dropped | 111 // navigation was so long ago, that a preconnection would have been dropped |
111 // anyway. We believe most servers will drop the connection in 10 seconds, so | 112 // anyway. We believe most servers will drop the connection in 10 seconds, so |
112 // we currently estimate this time-till-drop at 10 seconds. | 113 // we currently estimate this time-till-drop at 10 seconds. |
113 // TODO(jar): We should do a persistent field trial to validate/optimize this. | 114 // TODO(jar): We should do a persistent field trial to validate/optimize this. |
114 static const int kMaxUnusedSocketLifetimeSecondsWithoutAGet; | 115 static const int kMaxUnusedSocketLifetimeSecondsWithoutAGet; |
115 | 116 |
116 // |max_concurrent| specifies how many concurrent (parallel) prefetches will | 117 // |max_concurrent| specifies how many concurrent (parallel) prefetches will |
117 // be performed. Host lookups will be issued through |host_resolver|. | 118 // be performed. Host lookups will be issued through |host_resolver|. |
118 explicit Predictor(bool preconnect_enabled); | 119 explicit Predictor(bool preconnect_enabled, bool predictor_enabled); |
119 | 120 |
120 virtual ~Predictor(); | 121 virtual ~Predictor(); |
121 | 122 |
122 // This function is used to create a predictor. For testing, we can create | 123 // This function is used to create a predictor. For testing, we can create |
123 // a version which does a simpler shutdown. | 124 // a version which does a simpler shutdown. |
124 static Predictor* CreatePredictor(bool preconnect_enabled, | 125 static Predictor* CreatePredictor(bool preconnect_enabled, |
126 bool predictor_enabled, | |
125 bool simple_shutdown); | 127 bool simple_shutdown); |
126 | 128 |
127 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); | 129 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); |
128 | 130 |
129 // ------------- Start UI thread methods. | 131 // ------------- Start UI thread methods. |
130 | 132 |
131 virtual void InitNetworkPredictor(PrefService* user_prefs, | 133 virtual void InitNetworkPredictor(PrefService* user_prefs, |
132 PrefService* local_state, | 134 PrefService* local_state, |
133 IOThread* io_thread, | 135 IOThread* io_thread, |
134 net::URLRequestContextGetter* getter); | 136 net::URLRequestContextGetter* getter, |
137 ProfileIOData* profile_io_data); | |
135 | 138 |
136 // The Omnibox has proposed a given url to the user, and if it is a search | 139 // The Omnibox has proposed a given url to the user, and if it is a search |
137 // URL, then it also indicates that this is preconnectable (i.e., we could | 140 // URL, then it also indicates that this is preconnectable (i.e., we could |
138 // preconnect to the search server). | 141 // preconnect to the search server). |
139 void AnticipateOmniboxUrl(const GURL& url, bool preconnectable); | 142 void AnticipateOmniboxUrl(const GURL& url, bool preconnectable); |
140 | 143 |
141 // Preconnect a URL and all of its subresource domains. | 144 // Preconnect a URL and all of its subresource domains. |
142 void PreconnectUrlAndSubresources(const GURL& url, | 145 void PreconnectUrlAndSubresources(const GURL& url, |
143 const GURL& first_party_for_cookies); | 146 const GURL& first_party_for_cookies); |
144 | 147 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
205 void DeserializeReferrers(const base::ListValue& referral_list); | 208 void DeserializeReferrers(const base::ListValue& referral_list); |
206 | 209 |
207 void DeserializeReferrersThenDelete(base::ListValue* referral_list); | 210 void DeserializeReferrersThenDelete(base::ListValue* referral_list); |
208 | 211 |
209 void DiscardInitialNavigationHistory(); | 212 void DiscardInitialNavigationHistory(); |
210 | 213 |
211 void FinalizeInitializationOnIOThread( | 214 void FinalizeInitializationOnIOThread( |
212 const std::vector<GURL>& urls_to_prefetch, | 215 const std::vector<GURL>& urls_to_prefetch, |
213 base::ListValue* referral_list, | 216 base::ListValue* referral_list, |
214 IOThread* io_thread, | 217 IOThread* io_thread, |
215 bool predictor_enabled); | 218 ProfileIOData* profile_io_data); |
216 | 219 |
217 // During startup, we learn what the first N urls visited are, and then | 220 // During startup, we learn what the first N urls visited are, and then |
218 // resolve the associated hosts ASAP during our next startup. | 221 // resolve the associated hosts ASAP during our next startup. |
219 void LearnAboutInitialNavigation(const GURL& url); | 222 void LearnAboutInitialNavigation(const GURL& url); |
220 | 223 |
221 // Renderer bundles up list and sends to this browser API via IPC. | 224 // Renderer bundles up list and sends to this browser API via IPC. |
222 // TODO(jar): Use UrlList instead to include port and scheme. | 225 // TODO(jar): Use UrlList instead to include port and scheme. |
223 void DnsPrefetchList(const NameList& hostnames); | 226 void DnsPrefetchList(const NameList& hostnames); |
224 | 227 |
225 // May be called from either the IO or UI thread and will PostTask | 228 // May be called from either the IO or UI thread and will PostTask |
226 // to the IO thread if necessary. | 229 // to the IO thread if necessary. |
227 void DnsPrefetchMotivatedList(const UrlList& urls, | 230 void DnsPrefetchMotivatedList(const UrlList& urls, |
228 UrlInfo::ResolutionMotivation motivation); | 231 UrlInfo::ResolutionMotivation motivation); |
229 | 232 |
230 // May be called from either the IO or UI thread and will PostTask | 233 // May be called from either the IO or UI thread and will PostTask |
231 // to the IO thread if necessary. | 234 // to the IO thread if necessary. |
232 void SaveStateForNextStartupAndTrim(PrefService* prefs); | 235 void SaveStateForNextStartupAndTrim(); |
233 | 236 |
234 void SaveDnsPrefetchStateForNextStartupAndTrim( | 237 void SaveDnsPrefetchStateForNextStartupAndTrim( |
235 base::ListValue* startup_list, | 238 base::ListValue* startup_list, |
236 base::ListValue* referral_list, | 239 base::ListValue* referral_list, |
237 base::WaitableEvent* completion); | 240 base::WaitableEvent* completion); |
238 | 241 |
239 // 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 |
240 // to the IO thread if necessary. | 243 // to the IO thread if necessary. |
241 void EnablePredictor(bool enable); | |
242 | |
243 void EnablePredictorOnIOThread(bool enable); | |
244 | |
245 // May be called from either the IO or UI thread and will PostTask | |
246 // to the IO thread if necessary. | |
247 void PreconnectUrl(const GURL& url, const GURL& first_party_for_cookies, | 244 void PreconnectUrl(const GURL& url, const GURL& first_party_for_cookies, |
248 UrlInfo::ResolutionMotivation motivation, int count); | 245 UrlInfo::ResolutionMotivation motivation, int count); |
249 | 246 |
250 void PreconnectUrlOnIOThread(const GURL& url, | 247 void PreconnectUrlOnIOThread(const GURL& url, |
251 const GURL& first_party_for_cookies, | 248 const GURL& first_party_for_cookies, |
252 UrlInfo::ResolutionMotivation motivation, | 249 UrlInfo::ResolutionMotivation motivation, |
253 int count); | 250 int count); |
254 | 251 |
255 // ------------- End IO thread methods. | 252 // ------------- End IO thread methods. |
256 | 253 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
288 } | 285 } |
289 // Used for testing. | 286 // Used for testing. |
290 void SetShutdown(bool shutdown) { | 287 void SetShutdown(bool shutdown) { |
291 shutdown_ = shutdown; | 288 shutdown_ = shutdown; |
292 } | 289 } |
293 // Used for testing. | 290 // Used for testing. |
294 void SetObserver(PredictorObserver* observer) { | 291 void SetObserver(PredictorObserver* observer) { |
295 observer_ = observer; | 292 observer_ = observer; |
296 } | 293 } |
297 | 294 |
298 // Flag setting to use preconnection instead of just DNS pre-fetching. | 295 ProfileIOData* profile_io_data() const { |
296 return profile_io_data_; | |
297 } | |
298 | |
299 bool preconnect_enabled() const { | 299 bool preconnect_enabled() const { |
300 return preconnect_enabled_; | 300 return preconnect_enabled_; |
301 } | 301 } |
302 | 302 |
303 // Flag setting for whether we are prefetching dns lookups. | |
304 bool predictor_enabled() const { | 303 bool predictor_enabled() const { |
305 return predictor_enabled_; | 304 return predictor_enabled_; |
306 } | 305 } |
307 | 306 |
308 | 307 |
309 private: | 308 private: |
310 FRIEND_TEST_ALL_PREFIXES(PredictorTest, BenefitLookupTest); | 309 FRIEND_TEST_ALL_PREFIXES(PredictorTest, BenefitLookupTest); |
311 FRIEND_TEST_ALL_PREFIXES(PredictorTest, ShutdownWhenResolutionIsPendingTest); | 310 FRIEND_TEST_ALL_PREFIXES(PredictorTest, ShutdownWhenResolutionIsPendingTest); |
312 FRIEND_TEST_ALL_PREFIXES(PredictorTest, SingleLookupTest); | 311 FRIEND_TEST_ALL_PREFIXES(PredictorTest, SingleLookupTest); |
313 FRIEND_TEST_ALL_PREFIXES(PredictorTest, ConcurrentLookupTest); | 312 FRIEND_TEST_ALL_PREFIXES(PredictorTest, ConcurrentLookupTest); |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
501 | 500 |
502 // ------------- End IO thread methods. | 501 // ------------- End IO thread methods. |
503 | 502 |
504 scoped_ptr<InitialObserver> initial_observer_; | 503 scoped_ptr<InitialObserver> initial_observer_; |
505 | 504 |
506 // Reference to URLRequestContextGetter from the Profile which owns the | 505 // Reference to URLRequestContextGetter from the Profile which owns the |
507 // predictor. Used by Preconnect. | 506 // predictor. Used by Preconnect. |
508 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_; | 507 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_; |
509 | 508 |
510 // Status of speculative DNS resolution and speculative TCP/IP connection | 509 // Status of speculative DNS resolution and speculative TCP/IP connection |
511 // feature. | 510 // feature. This is false if and only if disabled by a command line switch. |
512 bool predictor_enabled_; | 511 const bool predictor_enabled_; |
battre
2014/07/01 08:27:48
This is a little bit strange in my opinion, becaus
| |
512 | |
513 // This is set by InitNetworkPredictor and used for calling | |
514 // chrome_browser_net::CanPredictNetworkActionsUI. | |
515 PrefService* user_prefs_; | |
516 | |
517 // This is set by InitNetworkPredictor and used for calling | |
518 // chrome_browser_net::CanPredictNetworkActionsIO. | |
519 ProfileIOData* profile_io_data_; | |
513 | 520 |
514 // work_queue_ holds a list of names we need to look up. | 521 // work_queue_ holds a list of names we need to look up. |
515 HostNameQueue work_queue_; | 522 HostNameQueue work_queue_; |
516 | 523 |
517 // results_ contains information for existing/prior prefetches. | 524 // results_ contains information for existing/prior prefetches. |
518 Results results_; | 525 Results results_; |
519 | 526 |
520 std::set<LookupRequest*> pending_lookups_; | 527 std::set<LookupRequest*> pending_lookups_; |
521 | 528 |
522 // For testing, to verify that we don't exceed the limit. | 529 // For testing, to verify that we don't exceed the limit. |
(...skipping 17 matching lines...) Expand all Loading... | |
540 | 547 |
541 // The TransportSecurityState instance we query HSTS redirects from. | 548 // The TransportSecurityState instance we query HSTS redirects from. |
542 net::TransportSecurityState* transport_security_state_; | 549 net::TransportSecurityState* transport_security_state_; |
543 | 550 |
544 // The SSLConfigService we query SNI support from (used in querying HSTS | 551 // The SSLConfigService we query SNI support from (used in querying HSTS |
545 // redirects). | 552 // redirects). |
546 net::SSLConfigService* ssl_config_service_; | 553 net::SSLConfigService* ssl_config_service_; |
547 | 554 |
548 // Are we currently using preconnection, rather than just DNS resolution, for | 555 // Are we currently using preconnection, rather than just DNS resolution, for |
549 // subresources and omni-box search URLs. | 556 // subresources and omni-box search URLs. |
550 bool preconnect_enabled_; | 557 // This is false if and only if disabled by a command line switch. |
558 const bool preconnect_enabled_; | |
551 | 559 |
552 // Most recent suggestion from Omnibox provided via AnticipateOmniboxUrl(). | 560 // Most recent suggestion from Omnibox provided via AnticipateOmniboxUrl(). |
553 std::string last_omnibox_host_; | 561 std::string last_omnibox_host_; |
554 | 562 |
555 // The time when the last preresolve was done for last_omnibox_host_. | 563 // The time when the last preresolve was done for last_omnibox_host_. |
556 base::TimeTicks last_omnibox_preresolve_; | 564 base::TimeTicks last_omnibox_preresolve_; |
557 | 565 |
558 // The number of consecutive requests to AnticipateOmniboxUrl() that suggested | 566 // The number of consecutive requests to AnticipateOmniboxUrl() that suggested |
559 // preconnecting (because it was to a search service). | 567 // preconnecting (because it was to a search service). |
560 int consecutive_omnibox_preconnect_count_; | 568 int consecutive_omnibox_preconnect_count_; |
(...skipping 20 matching lines...) Expand all Loading... | |
581 | 589 |
582 // An observer for testing. | 590 // An observer for testing. |
583 PredictorObserver* observer_; | 591 PredictorObserver* observer_; |
584 | 592 |
585 DISALLOW_COPY_AND_ASSIGN(Predictor); | 593 DISALLOW_COPY_AND_ASSIGN(Predictor); |
586 }; | 594 }; |
587 | 595 |
588 // This version of the predictor is used for testing. | 596 // This version of the predictor is used for testing. |
589 class SimplePredictor : public Predictor { | 597 class SimplePredictor : public Predictor { |
590 public: | 598 public: |
591 explicit SimplePredictor(bool preconnect_enabled) | 599 explicit SimplePredictor(bool preconnect_enabled, bool predictor_enabled) |
592 : Predictor(preconnect_enabled) {} | 600 : Predictor(preconnect_enabled, predictor_enabled) {} |
593 virtual ~SimplePredictor() {} | 601 virtual ~SimplePredictor() {} |
594 virtual void InitNetworkPredictor( | 602 virtual void InitNetworkPredictor( |
595 PrefService* user_prefs, | 603 PrefService* user_prefs, |
596 PrefService* local_state, | 604 PrefService* local_state, |
597 IOThread* io_thread, | 605 IOThread* io_thread, |
598 net::URLRequestContextGetter* getter) OVERRIDE; | 606 net::URLRequestContextGetter* getter, |
607 ProfileIOData* profile_io_data) OVERRIDE; | |
599 virtual void ShutdownOnUIThread() OVERRIDE; | 608 virtual void ShutdownOnUIThread() OVERRIDE; |
600 }; | 609 }; |
601 | 610 |
602 } // namespace chrome_browser_net | 611 } // namespace chrome_browser_net |
603 | 612 |
604 #endif // CHROME_BROWSER_NET_PREDICTOR_H_ | 613 #endif // CHROME_BROWSER_NET_PREDICTOR_H_ |
OLD | NEW |