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

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: Fix error with base::Passed 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 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 // instigated this activity. 271 // instigated this activity.
273 void PredictFrameSubresources(const GURL& url, 272 void PredictFrameSubresources(const GURL& url,
274 const GURL& first_party_for_cookies); 273 const GURL& first_party_for_cookies);
275 274
276 // Put URL in canonical form, including a scheme, host, and port. 275 // Put URL in canonical form, including a scheme, host, and port.
277 // Returns GURL::EmptyGURL() if the scheme is not http/https or if the url 276 // Returns GURL::EmptyGURL() if the scheme is not http/https or if the url
278 // cannot be otherwise canonicalized. 277 // cannot be otherwise canonicalized.
279 static GURL CanonicalizeUrl(const GURL& url); 278 static GURL CanonicalizeUrl(const GURL& url);
280 279
281 // Used for testing. 280 // Used for testing.
282 void SetHostResolver(net::HostResolver* host_resolver) {
283 host_resolver_ = host_resolver;
284 }
285 // Used for testing.
286 void SetTransportSecurityState( 281 void SetTransportSecurityState(
287 net::TransportSecurityState* transport_security_state) { 282 net::TransportSecurityState* transport_security_state) {
288 transport_security_state_ = transport_security_state; 283 transport_security_state_ = transport_security_state;
289 } 284 }
290 // Used for testing. 285 // Used for testing.
291 size_t max_concurrent_dns_lookups() const { 286 size_t max_concurrent_dns_lookups() const {
292 return max_concurrent_dns_lookups_; 287 return max_concurrent_dns_lookups_;
293 } 288 }
294 // Used for testing. 289 // Used for testing.
295 void SetShutdown(bool shutdown) { 290 void SetShutdown(bool shutdown) {
(...skipping 29 matching lines...) Expand all
325 FRIEND_TEST_ALL_PREFIXES(PredictorTest, SingleLookupTestWithDisabledAdvisor); 320 FRIEND_TEST_ALL_PREFIXES(PredictorTest, SingleLookupTestWithDisabledAdvisor);
326 FRIEND_TEST_ALL_PREFIXES(PredictorTest, SingleLookupTestWithEnabledAdvisor); 321 FRIEND_TEST_ALL_PREFIXES(PredictorTest, SingleLookupTestWithEnabledAdvisor);
327 FRIEND_TEST_ALL_PREFIXES(PredictorTest, TestSimplePreconnectAdvisor); 322 FRIEND_TEST_ALL_PREFIXES(PredictorTest, TestSimplePreconnectAdvisor);
328 FRIEND_TEST_ALL_PREFIXES(PredictorTest, NoProxyService); 323 FRIEND_TEST_ALL_PREFIXES(PredictorTest, NoProxyService);
329 FRIEND_TEST_ALL_PREFIXES(PredictorTest, ProxyDefinitelyEnabled); 324 FRIEND_TEST_ALL_PREFIXES(PredictorTest, ProxyDefinitelyEnabled);
330 FRIEND_TEST_ALL_PREFIXES(PredictorTest, ProxyDefinitelyNotEnabled); 325 FRIEND_TEST_ALL_PREFIXES(PredictorTest, ProxyDefinitelyNotEnabled);
331 FRIEND_TEST_ALL_PREFIXES(PredictorTest, ProxyMaybeEnabled); 326 FRIEND_TEST_ALL_PREFIXES(PredictorTest, ProxyMaybeEnabled);
332 friend class WaitForResolutionHelper; // For testing. 327 friend class WaitForResolutionHelper; // For testing.
333 friend class PredictorBrowserTest; 328 friend class PredictorBrowserTest;
334 329
335 class LookupRequest;
336
337 // A simple priority queue for handling host names. 330 // A simple priority queue for handling host names.
338 // Some names that are queued up have |motivation| that requires very rapid 331 // Some names that are queued up have |motivation| that requires very rapid
339 // handling. For example, a sub-resource name lookup MUST be done before the 332 // handling. For example, a sub-resource name lookup MUST be done before the
340 // actual sub-resource is fetched. In contrast, a name that was speculatively 333 // actual sub-resource is fetched. In contrast, a name that was speculatively
341 // noted in a page has to be resolved before the user "gets around to" 334 // noted in a page has to be resolved before the user "gets around to"
342 // clicking on a link. By tagging (with a motivation) each push we make into 335 // clicking on a link. By tagging (with a motivation) each push we make into
343 // this FIFO queue, the queue can re-order the more important names to service 336 // this FIFO queue, the queue can re-order the more important names to service
344 // them sooner (relative to some low priority background resolutions). 337 // them sooner (relative to some low priority background resolutions).
345 class HostNameQueue { 338 class HostNameQueue {
346 public: 339 public:
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 421
429 // ------------- Start IO thread methods. 422 // ------------- Start IO thread methods.
430 423
431 // Perform actual resolution or preconnection to subresources now. This is 424 // Perform actual resolution or preconnection to subresources now. This is
432 // an internal worker method that is reached via a post task from 425 // an internal worker method that is reached via a post task from
433 // PredictFrameSubresources(). 426 // PredictFrameSubresources().
434 void PrepareFrameSubresources(const GURL& url, 427 void PrepareFrameSubresources(const GURL& url,
435 const GURL& first_party_for_cookies); 428 const GURL& first_party_for_cookies);
436 429
437 // Access method for use by async lookup request to pass resolution result. 430 // Access method for use by async lookup request to pass resolution result.
438 void OnLookupFinished(LookupRequest* request, const GURL& url, bool found); 431 void OnLookupFinished(const GURL& url, int result);
439 432
440 // Underlying method for both async and synchronous lookup to update state. 433 // Underlying method for both async and synchronous lookup to update state.
441 void LookupFinished(LookupRequest* request, 434 void LookupFinished(const GURL& url, bool found);
442 const GURL& url, bool found);
443 435
444 // Queue hostname for resolution. If queueing was done, return the pointer 436 // Queue hostname for resolution. If queueing was done, return the pointer
eroman 2016/05/31 20:45:27 nit: Queue --> Queues (feel free to save that for
Charlie Harrison 2016/05/31 21:14:47 Done.
445 // to the queued instance, otherwise return NULL. If the proxy advisor is 437 // to the queued instance, otherwise return nullptr. If the proxy advisor is
446 // enabled, and |url| is likely to be proxied, the hostname will not be 438 // enabled, and |url| is likely to be proxied, the hostname will not be
447 // queued as the browser is not expected to fetch it directly. 439 // queued as the browser is not expected to fetch it directly.
448 UrlInfo* AppendToResolutionQueue(const GURL& url, 440 UrlInfo* AppendToResolutionQueue(const GURL& url,
449 UrlInfo::ResolutionMotivation motivation); 441 UrlInfo::ResolutionMotivation motivation);
450 442
451 // Check to see if too much queuing delay has been noted for the given info, 443 // Check to see if too much queuing delay has been noted for the given info,
452 // which indicates that there is "congestion" or growing delay in handling the 444 // which indicates that there is "congestion" or growing delay in handling the
453 // resolution of names. Rather than letting this congestion potentially grow 445 // resolution of names. Rather than letting this congestion potentially grow
454 // without bounds, we abandon our queued efforts at pre-resolutions in such a 446 // without bounds, we abandon our queued efforts at pre-resolutions in such a
455 // case. 447 // case.
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
510 // This is set by InitNetworkPredictor and used for calling 502 // This is set by InitNetworkPredictor and used for calling
511 // CanPrefetchAndPrerenderIO and CanPreresolveAndPreconnectIO. 503 // CanPrefetchAndPrerenderIO and CanPreresolveAndPreconnectIO.
512 ProfileIOData* profile_io_data_; 504 ProfileIOData* profile_io_data_;
513 505
514 // work_queue_ holds a list of names we need to look up. 506 // work_queue_ holds a list of names we need to look up.
515 HostNameQueue work_queue_; 507 HostNameQueue work_queue_;
516 508
517 // results_ contains information for existing/prior prefetches. 509 // results_ contains information for existing/prior prefetches.
518 Results results_; 510 Results results_;
519 511
520 std::set<LookupRequest*> pending_lookups_; 512 size_t num_pending_lookups_;
521 513
522 // For testing, to verify that we don't exceed the limit. 514 // For testing, to verify that we don't exceed the limit.
523 size_t peak_pending_lookups_; 515 size_t peak_pending_lookups_;
524 516
525 // When true, we don't make new lookup requests. 517 // When true, we don't make new lookup requests.
526 bool shutdown_; 518 bool shutdown_;
527 519
528 // The number of concurrent speculative lookups currently allowed to be sent 520 // The number of concurrent speculative lookups currently allowed to be sent
529 // to the resolver. Any additional lookups will be queued to avoid exceeding 521 // to the resolver. Any additional lookups will be queued to avoid exceeding
530 // this value. The queue is a priority queue that will accelerate 522 // this value. The queue is a priority queue that will accelerate
531 // sub-resource speculation, and retard resolutions suggested by page scans. 523 // sub-resource speculation, and retard resolutions suggested by page scans.
532 const size_t max_concurrent_dns_lookups_; 524 const size_t max_concurrent_dns_lookups_;
533 525
534 // The maximum queueing delay that is acceptable before we enter congestion 526 // The maximum queueing delay that is acceptable before we enter congestion
535 // reduction mode, and discard all queued (but not yet assigned) resolutions. 527 // reduction mode, and discard all queued (but not yet assigned) resolutions.
536 const base::TimeDelta max_dns_queue_delay_; 528 const base::TimeDelta max_dns_queue_delay_;
537 529
538 // The host resolver we warm DNS entries for.
539 net::HostResolver* host_resolver_;
540
541 // The TransportSecurityState instance we query HSTS redirects from. 530 // The TransportSecurityState instance we query HSTS redirects from.
542 net::TransportSecurityState* transport_security_state_; 531 net::TransportSecurityState* transport_security_state_;
543 532
544 // The SSLConfigService we query SNI support from (used in querying HSTS 533 // The SSLConfigService we query SNI support from (used in querying HSTS
545 // redirects). 534 // redirects).
546 net::SSLConfigService* ssl_config_service_; 535 net::SSLConfigService* ssl_config_service_;
547 536
548 // The ProxyService, used to determine whether preresolve is useful. 537 // The ProxyService, used to determine whether preresolve is useful.
549 net::ProxyService* proxy_service_; 538 net::ProxyService* proxy_service_;
550 539
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
605 594
606 private: 595 private:
607 // These member functions return True for unittests. 596 // These member functions return True for unittests.
608 bool CanPrefetchAndPrerender() const override; 597 bool CanPrefetchAndPrerender() const override;
609 bool CanPreresolveAndPreconnect() const override; 598 bool CanPreresolveAndPreconnect() const override;
610 }; 599 };
611 600
612 } // namespace chrome_browser_net 601 } // namespace chrome_browser_net
613 602
614 #endif // CHROME_BROWSER_NET_PREDICTOR_H_ 603 #endif // CHROME_BROWSER_NET_PREDICTOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698