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 11 matching lines...) Expand all Loading... |
22 #include <map> | 22 #include <map> |
23 #include <queue> | 23 #include <queue> |
24 #include <set> | 24 #include <set> |
25 #include <string> | 25 #include <string> |
26 #include <vector> | 26 #include <vector> |
27 | 27 |
28 #include "base/gtest_prod_util.h" | 28 #include "base/gtest_prod_util.h" |
29 #include "base/memory/scoped_ptr.h" | 29 #include "base/memory/scoped_ptr.h" |
30 #include "base/memory/weak_ptr.h" | 30 #include "base/memory/weak_ptr.h" |
31 #include "chrome/browser/net/referrer.h" | 31 #include "chrome/browser/net/referrer.h" |
| 32 #include "chrome/browser/net/timed_cache.h" |
32 #include "chrome/browser/net/url_info.h" | 33 #include "chrome/browser/net/url_info.h" |
33 #include "chrome/common/net/predictor_common.h" | 34 #include "chrome/common/net/predictor_common.h" |
34 #include "net/base/host_port_pair.h" | 35 #include "net/base/host_port_pair.h" |
35 | 36 |
36 class IOThread; | 37 class IOThread; |
37 class PrefService; | 38 class PrefService; |
38 class Profile; | 39 class Profile; |
39 | 40 |
40 namespace base { | 41 namespace base { |
41 class ListValue; | 42 class ListValue; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 // In those odd cases, we may discard some of the later speculative requests | 85 // In those odd cases, we may discard some of the later speculative requests |
85 // mistakenly assuming that the resolutions took too long. | 86 // mistakenly assuming that the resolutions took too long. |
86 static const int kTypicalSpeculativeGroupSize; | 87 static const int kTypicalSpeculativeGroupSize; |
87 | 88 |
88 // The next constant specifies an amount of queueing delay that is | 89 // The next constant specifies an amount of queueing delay that is |
89 // "too large," and indicative of problems with resolutions (perhaps due to | 90 // "too large," and indicative of problems with resolutions (perhaps due to |
90 // an overloaded router, or such). When we exceed this delay, congestion | 91 // an overloaded router, or such). When we exceed this delay, congestion |
91 // avoidance will kick in and all speculations in the queue will be discarded. | 92 // avoidance will kick in and all speculations in the queue will be discarded. |
92 static const int kMaxSpeculativeResolveQueueDelayMs; | 93 static const int kMaxSpeculativeResolveQueueDelayMs; |
93 | 94 |
| 95 // We don't bother learning to preconnect via a GET if the original URL |
| 96 // navigation was so long ago, that a preconnection would have been dropped |
| 97 // anyway. We believe most servers will drop the connection in 10 seconds, so |
| 98 // we currently estimate this time-till-drop at 10 seconds. |
| 99 // TODO(jar): We should do a persistent field trial to validate/optimize this. |
| 100 static const int kMaxUnusedSocketLifetimeSecondsWithoutAGet; |
| 101 |
94 // |max_concurrent| specifies how many concurrent (parallel) prefetches will | 102 // |max_concurrent| specifies how many concurrent (parallel) prefetches will |
95 // be performed. Host lookups will be issued through |host_resolver|. | 103 // be performed. Host lookups will be issued through |host_resolver|. |
96 explicit Predictor(bool preconnect_enabled); | 104 explicit Predictor(bool preconnect_enabled); |
97 | 105 |
98 virtual ~Predictor(); | 106 virtual ~Predictor(); |
99 | 107 |
100 // This function is used to create a predictor. For testing, we can create | 108 // This function is used to create a predictor. For testing, we can create |
101 // a version which does a simpler shutdown. | 109 // a version which does a simpler shutdown. |
102 static Predictor* CreatePredictor(bool preconnect_enabled, | 110 static Predictor* CreatePredictor(bool preconnect_enabled, |
103 bool simple_shutdown); | 111 bool simple_shutdown); |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 base::ListValue* startup_list, | 221 base::ListValue* startup_list, |
214 base::ListValue* referral_list, | 222 base::ListValue* referral_list, |
215 base::WaitableEvent* completion); | 223 base::WaitableEvent* completion); |
216 | 224 |
217 // May be called from either the IO or UI thread and will PostTask | 225 // May be called from either the IO or UI thread and will PostTask |
218 // to the IO thread if necessary. | 226 // to the IO thread if necessary. |
219 void EnablePredictor(bool enable); | 227 void EnablePredictor(bool enable); |
220 | 228 |
221 void EnablePredictorOnIOThread(bool enable); | 229 void EnablePredictorOnIOThread(bool enable); |
222 | 230 |
| 231 // May be called from either the IO or UI thread and will PostTask |
| 232 // to the IO thread if necessary. |
| 233 void PreconnectUrl(const GURL& url, const GURL& first_party_for_cookies, |
| 234 UrlInfo::ResolutionMotivation motivation, int count); |
| 235 |
| 236 void PreconnectUrlOnIOThread(const GURL& url, |
| 237 const GURL& first_party_for_cookies, |
| 238 UrlInfo::ResolutionMotivation motivation, |
| 239 int count); |
| 240 |
| 241 void RecordPreconnectNavigationStats(const GURL& url); |
| 242 |
223 // ------------- End IO thread methods. | 243 // ------------- End IO thread methods. |
224 | 244 |
225 // The following methods may be called on either the IO or UI threads. | 245 // The following methods may be called on either the IO or UI threads. |
226 | 246 |
227 // Instigate pre-connection to any URLs, or pre-resolution of related host, | 247 // Instigate pre-connection to any URLs, or pre-resolution of related host, |
228 // that we predict will be needed after this navigation (typically | 248 // that we predict will be needed after this navigation (typically |
229 // more-embedded resources on a page). This method will actually post a task | 249 // more-embedded resources on a page). This method will actually post a task |
230 // to do the actual work, so as not to jump ahead of the frame navigation that | 250 // to do the actual work, so as not to jump ahead of the frame navigation that |
231 // instigated this activity. | 251 // instigated this activity. |
232 void PredictFrameSubresources(const GURL& url, | 252 void PredictFrameSubresources(const GURL& url, |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
482 // The time when the last preresolve was done for last_omnibox_host_. | 502 // The time when the last preresolve was done for last_omnibox_host_. |
483 base::TimeTicks last_omnibox_preresolve_; | 503 base::TimeTicks last_omnibox_preresolve_; |
484 | 504 |
485 // The number of consecutive requests to AnticipateOmniboxUrl() that suggested | 505 // The number of consecutive requests to AnticipateOmniboxUrl() that suggested |
486 // preconnecting (because it was to a search service). | 506 // preconnecting (because it was to a search service). |
487 int consecutive_omnibox_preconnect_count_; | 507 int consecutive_omnibox_preconnect_count_; |
488 | 508 |
489 // The time when the last preconnection was requested to a search service. | 509 // The time when the last preconnection was requested to a search service. |
490 base::TimeTicks last_omnibox_preconnect_; | 510 base::TimeTicks last_omnibox_preconnect_; |
491 | 511 |
| 512 TimedCache recent_preconnects_; |
| 513 |
492 // For each URL that we might navigate to (that we've "learned about") | 514 // For each URL that we might navigate to (that we've "learned about") |
493 // we have a Referrer list. Each Referrer list has all hostnames we might | 515 // we have a Referrer list. Each Referrer list has all hostnames we might |
494 // need to pre-resolve or pre-connect to when there is a navigation to the | 516 // need to pre-resolve or pre-connect to when there is a navigation to the |
495 // orginial hostname. | 517 // orginial hostname. |
496 Referrers referrers_; | 518 Referrers referrers_; |
497 | 519 |
498 // List of URLs in referrers_ currently being trimmed (scaled down to | 520 // List of URLs in referrers_ currently being trimmed (scaled down to |
499 // eventually be aged out of use). | 521 // eventually be aged out of use). |
500 std::vector<GURL> urls_being_trimmed_; | 522 std::vector<GURL> urls_being_trimmed_; |
501 | 523 |
(...skipping 15 matching lines...) Expand all Loading... |
517 PrefService* user_prefs, | 539 PrefService* user_prefs, |
518 PrefService* local_state, | 540 PrefService* local_state, |
519 IOThread* io_thread, | 541 IOThread* io_thread, |
520 net::URLRequestContextGetter* getter) OVERRIDE; | 542 net::URLRequestContextGetter* getter) OVERRIDE; |
521 virtual void ShutdownOnUIThread(PrefService* user_prefs) OVERRIDE; | 543 virtual void ShutdownOnUIThread(PrefService* user_prefs) OVERRIDE; |
522 }; | 544 }; |
523 | 545 |
524 } // namespace chrome_browser_net | 546 } // namespace chrome_browser_net |
525 | 547 |
526 #endif // CHROME_BROWSER_NET_PREDICTOR_H_ | 548 #endif // CHROME_BROWSER_NET_PREDICTOR_H_ |
OLD | NEW |