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

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: Changed interface to accept ResourceContexts 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
« no previous file with comments | « no previous file | chrome/browser/net/predictor.cc » ('j') | chrome/browser/net/predictor.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 15 matching lines...) Expand all
309 bool PreconnectEnabled() const; 304 bool PreconnectEnabled() const;
310 305
311 // Used only for testing. Overrides command line flag to disable preconnect, 306 // Used only for testing. Overrides command line flag to disable preconnect,
312 // which is added in the browser test fixture. 307 // which is added in the browser test fixture.
313 void SetPreconnectEnabledForTest(bool preconnect_enabled); 308 void SetPreconnectEnabledForTest(bool preconnect_enabled);
314 309
315 net::URLRequestContextGetter* url_request_context_getter_for_test() { 310 net::URLRequestContextGetter* url_request_context_getter_for_test() {
316 return url_request_context_getter_.get(); 311 return url_request_context_getter_.get();
317 } 312 }
318 313
314 void set_url_request_context_getter_for_test(
315 scoped_refptr<net::URLRequestContextGetter> getter) {
316 url_request_context_getter_.swap(getter);
317 }
318
319 private: 319 private:
320 FRIEND_TEST_ALL_PREFIXES(PredictorBrowserTest, 320 FRIEND_TEST_ALL_PREFIXES(PredictorBrowserTest,
321 ShutdownWhenResolutionIsPendingTest); 321 ShutdownWhenResolutionIsPendingTest);
322 FRIEND_TEST_ALL_PREFIXES(PredictorBrowserTest, SingleLookupTest); 322 FRIEND_TEST_ALL_PREFIXES(PredictorBrowserTest, SingleLookupTest);
323 FRIEND_TEST_ALL_PREFIXES(PredictorBrowserTest, ConcurrentLookupTest); 323 FRIEND_TEST_ALL_PREFIXES(PredictorBrowserTest, ConcurrentLookupTest);
324 FRIEND_TEST_ALL_PREFIXES(PredictorBrowserTest, MassiveConcurrentLookupTest); 324 FRIEND_TEST_ALL_PREFIXES(PredictorBrowserTest, MassiveConcurrentLookupTest);
325 FRIEND_TEST_ALL_PREFIXES(PredictorTest, PriorityQueuePushPopTest); 325 FRIEND_TEST_ALL_PREFIXES(PredictorTest, PriorityQueuePushPopTest);
326 FRIEND_TEST_ALL_PREFIXES(PredictorTest, PriorityQueueReorderTest); 326 FRIEND_TEST_ALL_PREFIXES(PredictorTest, PriorityQueueReorderTest);
327 FRIEND_TEST_ALL_PREFIXES(PredictorTest, ReferrerSerializationTrimTest); 327 FRIEND_TEST_ALL_PREFIXES(PredictorTest, ReferrerSerializationTrimTest);
328 FRIEND_TEST_ALL_PREFIXES(PredictorTest, SingleLookupTestWithDisabledAdvisor); 328 FRIEND_TEST_ALL_PREFIXES(PredictorTest, SingleLookupTestWithDisabledAdvisor);
329 FRIEND_TEST_ALL_PREFIXES(PredictorTest, SingleLookupTestWithEnabledAdvisor); 329 FRIEND_TEST_ALL_PREFIXES(PredictorTest, SingleLookupTestWithEnabledAdvisor);
330 FRIEND_TEST_ALL_PREFIXES(PredictorTest, TestSimplePreconnectAdvisor); 330 FRIEND_TEST_ALL_PREFIXES(PredictorTest, TestSimplePreconnectAdvisor);
331 FRIEND_TEST_ALL_PREFIXES(PredictorTest, NoProxyService); 331 FRIEND_TEST_ALL_PREFIXES(PredictorTest, NoProxyService);
332 FRIEND_TEST_ALL_PREFIXES(PredictorTest, ProxyDefinitelyEnabled); 332 FRIEND_TEST_ALL_PREFIXES(PredictorTest, ProxyDefinitelyEnabled);
333 FRIEND_TEST_ALL_PREFIXES(PredictorTest, ProxyDefinitelyNotEnabled); 333 FRIEND_TEST_ALL_PREFIXES(PredictorTest, ProxyDefinitelyNotEnabled);
334 FRIEND_TEST_ALL_PREFIXES(PredictorTest, ProxyMaybeEnabled); 334 FRIEND_TEST_ALL_PREFIXES(PredictorTest, ProxyMaybeEnabled);
335 friend class WaitForResolutionHelper; // For testing. 335 friend class WaitForResolutionHelper; // For testing.
336 friend class PredictorBrowserTest; 336 friend class PredictorBrowserTest;
337 337
338 class LookupRequest;
339
340 // A simple priority queue for handling host names. 338 // A simple priority queue for handling host names.
341 // Some names that are queued up have |motivation| that requires very rapid 339 // 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 340 // 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 341 // 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" 342 // 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 343 // 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 344 // this FIFO queue, the queue can re-order the more important names to service
347 // them sooner (relative to some low priority background resolutions). 345 // them sooner (relative to some low priority background resolutions).
348 class HostNameQueue { 346 class HostNameQueue {
349 public: 347 public:
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 448
451 // ------------- Start IO thread methods. 449 // ------------- Start IO thread methods.
452 450
453 // Perform actual resolution or preconnection to subresources now. This is 451 // Perform actual resolution or preconnection to subresources now. This is
454 // an internal worker method that is reached via a post task from 452 // an internal worker method that is reached via a post task from
455 // PredictFrameSubresources(). 453 // PredictFrameSubresources().
456 void PrepareFrameSubresources(const GURL& url, 454 void PrepareFrameSubresources(const GURL& url,
457 const GURL& first_party_for_cookies); 455 const GURL& first_party_for_cookies);
458 456
459 // Access method for use by async lookup request to pass resolution result. 457 // Access method for use by async lookup request to pass resolution result.
460 void OnLookupFinished(LookupRequest* request, const GURL& url, bool found); 458 void OnLookupFinished(const GURL& url, int result);
461 459
462 // Underlying method for both async and synchronous lookup to update state. 460 // Underlying method for both async and synchronous lookup to update state.
463 void LookupFinished(LookupRequest* request, 461 void LookupFinished(const GURL& url, bool found);
464 const GURL& url, bool found);
465 462
466 // Queue hostname for resolution. If queueing was done, return the pointer 463 // Queue hostname for resolution. If queueing was done, return the pointer
467 // to the queued instance, otherwise return NULL. If the proxy advisor is 464 // 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 465 // 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. 466 // queued as the browser is not expected to fetch it directly.
470 UrlInfo* AppendToResolutionQueue(const GURL& url, 467 UrlInfo* AppendToResolutionQueue(const GURL& url,
471 UrlInfo::ResolutionMotivation motivation); 468 UrlInfo::ResolutionMotivation motivation);
472 469
473 // Check to see if too much queuing delay has been noted for the given info, 470 // 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 471 // 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 529 // This is set by InitNetworkPredictor and used for calling
533 // CanPrefetchAndPrerenderIO and CanPreresolveAndPreconnectIO. 530 // CanPrefetchAndPrerenderIO and CanPreresolveAndPreconnectIO.
534 ProfileIOData* profile_io_data_; 531 ProfileIOData* profile_io_data_;
535 532
536 // work_queue_ holds a list of names we need to look up. 533 // work_queue_ holds a list of names we need to look up.
537 HostNameQueue work_queue_; 534 HostNameQueue work_queue_;
538 535
539 // results_ contains information for existing/prior prefetches. 536 // results_ contains information for existing/prior prefetches.
540 Results results_; 537 Results results_;
541 538
542 std::set<LookupRequest*> pending_lookups_; 539 size_t num_pending_lookups_;
543 540
544 // For testing, to verify that we don't exceed the limit. 541 // For testing, to verify that we don't exceed the limit.
545 size_t peak_pending_lookups_; 542 size_t peak_pending_lookups_;
546 543
547 // When true, we don't make new lookup requests. 544 // When true, we don't make new lookup requests.
548 bool shutdown_; 545 bool shutdown_;
549 546
550 // The number of concurrent speculative lookups currently allowed to be sent 547 // The number of concurrent speculative lookups currently allowed to be sent
551 // to the resolver. Any additional lookups will be queued to avoid exceeding 548 // to the resolver. Any additional lookups will be queued to avoid exceeding
552 // this value. The queue is a priority queue that will accelerate 549 // this value. The queue is a priority queue that will accelerate
553 // sub-resource speculation, and retard resolutions suggested by page scans. 550 // sub-resource speculation, and retard resolutions suggested by page scans.
554 const size_t max_concurrent_dns_lookups_; 551 const size_t max_concurrent_dns_lookups_;
555 552
556 // The maximum queueing delay that is acceptable before we enter congestion 553 // The maximum queueing delay that is acceptable before we enter congestion
557 // reduction mode, and discard all queued (but not yet assigned) resolutions. 554 // reduction mode, and discard all queued (but not yet assigned) resolutions.
558 const base::TimeDelta max_dns_queue_delay_; 555 const base::TimeDelta max_dns_queue_delay_;
559 556
560 // The host resolver we warm DNS entries for.
561 net::HostResolver* host_resolver_;
562
563 // The TransportSecurityState instance we query HSTS redirects from. 557 // The TransportSecurityState instance we query HSTS redirects from.
564 net::TransportSecurityState* transport_security_state_; 558 net::TransportSecurityState* transport_security_state_;
565 559
566 // The SSLConfigService we query SNI support from (used in querying HSTS 560 // The SSLConfigService we query SNI support from (used in querying HSTS
567 // redirects). 561 // redirects).
568 net::SSLConfigService* ssl_config_service_; 562 net::SSLConfigService* ssl_config_service_;
569 563
570 // The ProxyService, used to determine whether preresolve is useful. 564 // The ProxyService, used to determine whether preresolve is useful.
571 net::ProxyService* proxy_service_; 565 net::ProxyService* proxy_service_;
572 566
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
627 621
628 private: 622 private:
629 // These member functions return True for unittests. 623 // These member functions return True for unittests.
630 bool CanPrefetchAndPrerender() const override; 624 bool CanPrefetchAndPrerender() const override;
631 bool CanPreresolveAndPreconnect() const override; 625 bool CanPreresolveAndPreconnect() const override;
632 }; 626 };
633 627
634 } // namespace chrome_browser_net 628 } // namespace chrome_browser_net
635 629
636 #endif // CHROME_BROWSER_NET_PREDICTOR_H_ 630 #endif // CHROME_BROWSER_NET_PREDICTOR_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/net/predictor.cc » ('j') | chrome/browser/net/predictor.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698