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 |
11 // before it is really needed, and hence reduce latency in the standard lookup | 11 // before it is really needed, and hence reduce latency in the standard lookup |
12 // paths. | 12 // paths. |
13 // Subresource relationships are usually acquired from the referrer field in a | 13 // Subresource relationships are usually acquired from the referrer field in a |
14 // navigation. A subresource URL may be associated with a referrer URL. Later | 14 // navigation. A subresource URL may be associated with a referrer URL. Later |
15 // navigations may, if the likelihood of needing the subresource is high enough, | 15 // navigations may, if the likelihood of needing the subresource is high enough, |
16 // cause this module to speculatively create a TCP/IP connection. If there is | 16 // cause this module to speculatively create a TCP/IP connection. If there is |
17 // only a low likelihood, then a DNS pre-resolution operation may be performed. | 17 // only a low likelihood, then a DNS pre-resolution operation may be performed. |
18 | 18 |
19 #ifndef CHROME_BROWSER_NET_PREDICTOR_H_ | 19 #ifndef CHROME_BROWSER_NET_PREDICTOR_H_ |
20 #define CHROME_BROWSER_NET_PREDICTOR_H_ | 20 #define CHROME_BROWSER_NET_PREDICTOR_H_ |
21 | 21 |
| 22 #include <stddef.h> |
| 23 #include <stdint.h> |
| 24 |
22 #include <map> | 25 #include <map> |
23 #include <queue> | 26 #include <queue> |
24 #include <set> | 27 #include <set> |
25 #include <string> | 28 #include <string> |
26 #include <vector> | 29 #include <vector> |
27 | 30 |
28 #include <stddef.h> | |
29 | |
30 #include <stdint.h> | |
31 | |
32 #include "base/gtest_prod_util.h" | 31 #include "base/gtest_prod_util.h" |
33 #include "base/macros.h" | 32 #include "base/macros.h" |
34 #include "base/memory/scoped_ptr.h" | 33 #include "base/memory/scoped_ptr.h" |
35 #include "base/memory/weak_ptr.h" | 34 #include "base/memory/weak_ptr.h" |
36 #include "chrome/browser/net/prediction_options.h" | 35 #include "chrome/browser/net/prediction_options.h" |
37 #include "chrome/browser/net/referrer.h" | 36 #include "chrome/browser/net/referrer.h" |
38 #include "chrome/browser/net/timed_cache.h" | 37 #include "chrome/browser/net/timed_cache.h" |
39 #include "chrome/browser/net/url_info.h" | 38 #include "chrome/browser/net/url_info.h" |
40 #include "components/network_hints/common/network_hints_common.h" | 39 #include "components/network_hints/common/network_hints_common.h" |
41 #include "net/base/host_port_pair.h" | 40 #include "net/base/host_port_pair.h" |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 // a version which does a simpler shutdown. | 129 // a version which does a simpler shutdown. |
131 static Predictor* CreatePredictor(bool preconnect_enabled, | 130 static Predictor* CreatePredictor(bool preconnect_enabled, |
132 bool predictor_enabled, | 131 bool predictor_enabled, |
133 bool simple_shutdown); | 132 bool simple_shutdown); |
134 | 133 |
135 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); | 134 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); |
136 | 135 |
137 // ------------- Start UI thread methods. | 136 // ------------- Start UI thread methods. |
138 | 137 |
139 virtual void InitNetworkPredictor(PrefService* user_prefs, | 138 virtual void InitNetworkPredictor(PrefService* user_prefs, |
140 PrefService* local_state, | |
141 IOThread* io_thread, | 139 IOThread* io_thread, |
142 net::URLRequestContextGetter* getter, | 140 net::URLRequestContextGetter* getter, |
143 ProfileIOData* profile_io_data); | 141 ProfileIOData* profile_io_data); |
144 | 142 |
145 // The Omnibox has proposed a given url to the user, and if it is a search | 143 // The Omnibox has proposed a given url to the user, and if it is a search |
146 // URL, then it also indicates that this is preconnectable (i.e., we could | 144 // URL, then it also indicates that this is preconnectable (i.e., we could |
147 // preconnect to the search server). | 145 // preconnect to the search server). |
148 void AnticipateOmniboxUrl(const GURL& url, bool preconnectable); | 146 void AnticipateOmniboxUrl(const GURL& url, bool preconnectable); |
149 | 147 |
150 // Preconnect a URL and all of its subresource domains. | 148 // Preconnect a URL and all of its subresource domains. |
151 void PreconnectUrlAndSubresources(const GURL& url, | 149 void PreconnectUrlAndSubresources(const GURL& url, |
152 const GURL& first_party_for_cookies); | 150 const GURL& first_party_for_cookies); |
153 | 151 |
154 static UrlList GetPredictedUrlListAtStartup(PrefService* user_prefs, | 152 static UrlList GetPredictedUrlListAtStartup(PrefService* user_prefs); |
155 PrefService* local_state); | |
156 | 153 |
157 static void set_max_queueing_delay(int max_queueing_delay_ms); | 154 static void set_max_queueing_delay(int max_queueing_delay_ms); |
158 | 155 |
159 static void set_max_parallel_resolves(size_t max_parallel_resolves); | 156 static void set_max_parallel_resolves(size_t max_parallel_resolves); |
160 | 157 |
161 virtual void ShutdownOnUIThread(); | 158 virtual void ShutdownOnUIThread(); |
162 | 159 |
163 // ------------- End UI thread methods. | 160 // ------------- End UI thread methods. |
164 | 161 |
165 // ------------- Start IO thread methods. | 162 // ------------- Start IO thread methods. |
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
603 DISALLOW_COPY_AND_ASSIGN(Predictor); | 600 DISALLOW_COPY_AND_ASSIGN(Predictor); |
604 }; | 601 }; |
605 | 602 |
606 // This version of the predictor is used for testing. | 603 // This version of the predictor is used for testing. |
607 class SimplePredictor : public Predictor { | 604 class SimplePredictor : public Predictor { |
608 public: | 605 public: |
609 explicit SimplePredictor(bool preconnect_enabled, bool predictor_enabled) | 606 explicit SimplePredictor(bool preconnect_enabled, bool predictor_enabled) |
610 : Predictor(preconnect_enabled, predictor_enabled) {} | 607 : Predictor(preconnect_enabled, predictor_enabled) {} |
611 ~SimplePredictor() override {} | 608 ~SimplePredictor() override {} |
612 void InitNetworkPredictor(PrefService* user_prefs, | 609 void InitNetworkPredictor(PrefService* user_prefs, |
613 PrefService* local_state, | |
614 IOThread* io_thread, | 610 IOThread* io_thread, |
615 net::URLRequestContextGetter* getter, | 611 net::URLRequestContextGetter* getter, |
616 ProfileIOData* profile_io_data) override; | 612 ProfileIOData* profile_io_data) override; |
617 void ShutdownOnUIThread() override; | 613 void ShutdownOnUIThread() override; |
618 | 614 |
619 private: | 615 private: |
620 // These member functions return True for unittests. | 616 // These member functions return True for unittests. |
621 bool CanPrefetchAndPrerender() const override; | 617 bool CanPrefetchAndPrerender() const override; |
622 bool CanPreresolveAndPreconnect() const override; | 618 bool CanPreresolveAndPreconnect() const override; |
623 }; | 619 }; |
624 | 620 |
625 } // namespace chrome_browser_net | 621 } // namespace chrome_browser_net |
626 | 622 |
627 #endif // CHROME_BROWSER_NET_PREDICTOR_H_ | 623 #endif // CHROME_BROWSER_NET_PREDICTOR_H_ |
OLD | NEW |