Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(92)

Side by Side Diff: chrome/browser/net/predictor.h

Issue 2004453002: Add a Dns preresolve interface in //content (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@predictor_dns_browsertest
Patch Set: safe callbacks Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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> 22 #include <stddef.h>
23 #include <stdint.h> 23 #include <stdint.h>
24 24
25 #include <map> 25 #include <map>
26 #include <memory> 26 #include <memory>
27 #include <queue> 27 #include <queue>
28 #include <set>
29 #include <string> 28 #include <string>
30 #include <vector> 29 #include <vector>
31 30
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/weak_ptr.h" 33 #include "base/memory/weak_ptr.h"
35 #include "chrome/browser/net/prediction_options.h" 34 #include "chrome/browser/net/prediction_options.h"
36 #include "chrome/browser/net/referrer.h" 35 #include "chrome/browser/net/referrer.h"
37 #include "chrome/browser/net/timed_cache.h" 36 #include "chrome/browser/net/timed_cache.h"
38 #include "chrome/browser/net/url_info.h" 37 #include "chrome/browser/net/url_info.h"
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 // instigated this activity. 269 // instigated this activity.
271 void PredictFrameSubresources(const GURL& url, 270 void PredictFrameSubresources(const GURL& url,
272 const GURL& first_party_for_cookies); 271 const GURL& first_party_for_cookies);
273 272
274 // Put URL in canonical form, including a scheme, host, and port. 273 // Put URL in canonical form, including a scheme, host, and port.
275 // Returns GURL::EmptyGURL() if the scheme is not http/https or if the url 274 // Returns GURL::EmptyGURL() if the scheme is not http/https or if the url
276 // cannot be otherwise canonicalized. 275 // cannot be otherwise canonicalized.
277 static GURL CanonicalizeUrl(const GURL& url); 276 static GURL CanonicalizeUrl(const GURL& url);
278 277
279 // Used for testing. 278 // Used for testing.
280 void SetHostResolver(net::HostResolver* host_resolver) {
281 host_resolver_ = host_resolver;
282 }
283 // Used for testing.
284 void SetTransportSecurityState( 279 void SetTransportSecurityState(
285 net::TransportSecurityState* transport_security_state) { 280 net::TransportSecurityState* transport_security_state) {
286 transport_security_state_ = transport_security_state; 281 transport_security_state_ = transport_security_state;
287 } 282 }
288 // Used for testing. 283 // Used for testing.
289 size_t max_concurrent_dns_lookups() const { 284 size_t max_concurrent_dns_lookups() const {
290 return max_concurrent_dns_lookups_; 285 return max_concurrent_dns_lookups_;
291 } 286 }
292 // Used for testing. 287 // Used for testing.
293 void SetShutdown(bool shutdown) { 288 void SetShutdown(bool shutdown) {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 FRIEND_TEST_ALL_PREFIXES(PredictorTest, SingleLookupTestWithDisabledAdvisor); 323 FRIEND_TEST_ALL_PREFIXES(PredictorTest, SingleLookupTestWithDisabledAdvisor);
329 FRIEND_TEST_ALL_PREFIXES(PredictorTest, SingleLookupTestWithEnabledAdvisor); 324 FRIEND_TEST_ALL_PREFIXES(PredictorTest, SingleLookupTestWithEnabledAdvisor);
330 FRIEND_TEST_ALL_PREFIXES(PredictorTest, TestSimplePreconnectAdvisor); 325 FRIEND_TEST_ALL_PREFIXES(PredictorTest, TestSimplePreconnectAdvisor);
331 FRIEND_TEST_ALL_PREFIXES(PredictorTest, NoProxyService); 326 FRIEND_TEST_ALL_PREFIXES(PredictorTest, NoProxyService);
332 FRIEND_TEST_ALL_PREFIXES(PredictorTest, ProxyDefinitelyEnabled); 327 FRIEND_TEST_ALL_PREFIXES(PredictorTest, ProxyDefinitelyEnabled);
333 FRIEND_TEST_ALL_PREFIXES(PredictorTest, ProxyDefinitelyNotEnabled); 328 FRIEND_TEST_ALL_PREFIXES(PredictorTest, ProxyDefinitelyNotEnabled);
334 FRIEND_TEST_ALL_PREFIXES(PredictorTest, ProxyMaybeEnabled); 329 FRIEND_TEST_ALL_PREFIXES(PredictorTest, ProxyMaybeEnabled);
335 friend class WaitForResolutionHelper; // For testing. 330 friend class WaitForResolutionHelper; // For testing.
336 friend class PredictorBrowserTest; 331 friend class PredictorBrowserTest;
337 332
338 class LookupRequest;
339
340 // A simple priority queue for handling host names. 333 // A simple priority queue for handling host names.
341 // Some names that are queued up have |motivation| that requires very rapid 334 // Some names that are queued up have |motivation| that requires very rapid
342 // handling. For example, a sub-resource name lookup MUST be done before the 335 // handling. For example, a sub-resource name lookup MUST be done before the
343 // actual sub-resource is fetched. In contrast, a name that was speculatively 336 // actual sub-resource is fetched. In contrast, a name that was speculatively
344 // noted in a page has to be resolved before the user "gets around to" 337 // noted in a page has to be resolved before the user "gets around to"
345 // clicking on a link. By tagging (with a motivation) each push we make into 338 // clicking on a link. By tagging (with a motivation) each push we make into
346 // this FIFO queue, the queue can re-order the more important names to service 339 // this FIFO queue, the queue can re-order the more important names to service
347 // them sooner (relative to some low priority background resolutions). 340 // them sooner (relative to some low priority background resolutions).
348 class HostNameQueue { 341 class HostNameQueue {
349 public: 342 public:
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 443
451 // ------------- Start IO thread methods. 444 // ------------- Start IO thread methods.
452 445
453 // Perform actual resolution or preconnection to subresources now. This is 446 // Perform actual resolution or preconnection to subresources now. This is
454 // an internal worker method that is reached via a post task from 447 // an internal worker method that is reached via a post task from
455 // PredictFrameSubresources(). 448 // PredictFrameSubresources().
456 void PrepareFrameSubresources(const GURL& url, 449 void PrepareFrameSubresources(const GURL& url,
457 const GURL& first_party_for_cookies); 450 const GURL& first_party_for_cookies);
458 451
459 // Access method for use by async lookup request to pass resolution result. 452 // Access method for use by async lookup request to pass resolution result.
460 void OnLookupFinished(LookupRequest* request, const GURL& url, bool found); 453 void OnLookupFinished(const GURL& url, int result);
461 454
462 // Underlying method for both async and synchronous lookup to update state. 455 // Underlying method for both async and synchronous lookup to update state.
463 void LookupFinished(LookupRequest* request, 456 void LookupFinished(const GURL& url, bool found);
464 const GURL& url, bool found);
465 457
466 // Queue hostname for resolution. If queueing was done, return the pointer 458 // Queue hostname for resolution. If queueing was done, return the pointer
467 // to the queued instance, otherwise return NULL. If the proxy advisor is 459 // to the queued instance, otherwise return NULL. If the proxy advisor is
468 // enabled, and |url| is likely to be proxied, the hostname will not be 460 // enabled, and |url| is likely to be proxied, the hostname will not be
469 // queued as the browser is not expected to fetch it directly. 461 // queued as the browser is not expected to fetch it directly.
470 UrlInfo* AppendToResolutionQueue(const GURL& url, 462 UrlInfo* AppendToResolutionQueue(const GURL& url,
471 UrlInfo::ResolutionMotivation motivation); 463 UrlInfo::ResolutionMotivation motivation);
472 464
473 // Check to see if too much queuing delay has been noted for the given info, 465 // Check to see if too much queuing delay has been noted for the given info,
474 // which indicates that there is "congestion" or growing delay in handling the 466 // which indicates that there is "congestion" or growing delay in handling the
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
532 // This is set by InitNetworkPredictor and used for calling 524 // This is set by InitNetworkPredictor and used for calling
533 // CanPrefetchAndPrerenderIO and CanPreresolveAndPreconnectIO. 525 // CanPrefetchAndPrerenderIO and CanPreresolveAndPreconnectIO.
534 ProfileIOData* profile_io_data_; 526 ProfileIOData* profile_io_data_;
535 527
536 // work_queue_ holds a list of names we need to look up. 528 // work_queue_ holds a list of names we need to look up.
537 HostNameQueue work_queue_; 529 HostNameQueue work_queue_;
538 530
539 // results_ contains information for existing/prior prefetches. 531 // results_ contains information for existing/prior prefetches.
540 Results results_; 532 Results results_;
541 533
542 std::set<LookupRequest*> pending_lookups_; 534 size_t num_pending_lookups_;
543 535
544 // For testing, to verify that we don't exceed the limit. 536 // For testing, to verify that we don't exceed the limit.
545 size_t peak_pending_lookups_; 537 size_t peak_pending_lookups_;
546 538
547 // When true, we don't make new lookup requests. 539 // When true, we don't make new lookup requests.
548 bool shutdown_; 540 bool shutdown_;
549 541
550 // The number of concurrent speculative lookups currently allowed to be sent 542 // The number of concurrent speculative lookups currently allowed to be sent
551 // to the resolver. Any additional lookups will be queued to avoid exceeding 543 // to the resolver. Any additional lookups will be queued to avoid exceeding
552 // this value. The queue is a priority queue that will accelerate 544 // this value. The queue is a priority queue that will accelerate
553 // sub-resource speculation, and retard resolutions suggested by page scans. 545 // sub-resource speculation, and retard resolutions suggested by page scans.
554 const size_t max_concurrent_dns_lookups_; 546 const size_t max_concurrent_dns_lookups_;
555 547
556 // The maximum queueing delay that is acceptable before we enter congestion 548 // The maximum queueing delay that is acceptable before we enter congestion
557 // reduction mode, and discard all queued (but not yet assigned) resolutions. 549 // reduction mode, and discard all queued (but not yet assigned) resolutions.
558 const base::TimeDelta max_dns_queue_delay_; 550 const base::TimeDelta max_dns_queue_delay_;
559 551
560 // The host resolver we warm DNS entries for.
561 net::HostResolver* host_resolver_;
562
563 // The TransportSecurityState instance we query HSTS redirects from. 552 // The TransportSecurityState instance we query HSTS redirects from.
564 net::TransportSecurityState* transport_security_state_; 553 net::TransportSecurityState* transport_security_state_;
565 554
566 // The SSLConfigService we query SNI support from (used in querying HSTS 555 // The SSLConfigService we query SNI support from (used in querying HSTS
567 // redirects). 556 // redirects).
568 net::SSLConfigService* ssl_config_service_; 557 net::SSLConfigService* ssl_config_service_;
569 558
570 // The ProxyService, used to determine whether preresolve is useful. 559 // The ProxyService, used to determine whether preresolve is useful.
571 net::ProxyService* proxy_service_; 560 net::ProxyService* proxy_service_;
572 561
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
627 616
628 private: 617 private:
629 // These member functions return True for unittests. 618 // These member functions return True for unittests.
630 bool CanPrefetchAndPrerender() const override; 619 bool CanPrefetchAndPrerender() const override;
631 bool CanPreresolveAndPreconnect() const override; 620 bool CanPreresolveAndPreconnect() const override;
632 }; 621 };
633 622
634 } // namespace chrome_browser_net 623 } // namespace chrome_browser_net
635 624
636 #endif // CHROME_BROWSER_NET_PREDICTOR_H_ 625 #endif // CHROME_BROWSER_NET_PREDICTOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698