| 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 class TransportSecurityState; | 56 class TransportSecurityState; |
| 57 class URLRequestContextGetter; | 57 class URLRequestContextGetter; |
| 58 } | 58 } |
| 59 | 59 |
| 60 namespace user_prefs { | 60 namespace user_prefs { |
| 61 class PrefRegistrySyncable; | 61 class PrefRegistrySyncable; |
| 62 } | 62 } |
| 63 | 63 |
| 64 namespace chrome_browser_net { | 64 namespace chrome_browser_net { |
| 65 | 65 |
| 66 class InitialObserver; |
| 66 typedef std::map<GURL, UrlInfo> Results; | 67 typedef std::map<GURL, UrlInfo> Results; |
| 67 | 68 |
| 68 // An observer for testing. | 69 // An observer for testing. |
| 69 class PredictorObserver { | 70 class PredictorObserver { |
| 70 public: | 71 public: |
| 71 virtual ~PredictorObserver() {} | 72 virtual ~PredictorObserver() {} |
| 72 | 73 |
| 73 virtual void OnPreconnectUrl(const GURL& original_url, | 74 virtual void OnPreconnectUrl(const GURL& original_url, |
| 74 const GURL& first_party_for_cookies, | 75 const GURL& first_party_for_cookies, |
| 75 UrlInfo::ResolutionMotivation motivation, | 76 UrlInfo::ResolutionMotivation motivation, |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 private: | 343 private: |
| 343 // The names in the queue that should be serviced (popped) ASAP. | 344 // The names in the queue that should be serviced (popped) ASAP. |
| 344 std::queue<GURL> rush_queue_; | 345 std::queue<GURL> rush_queue_; |
| 345 // The names in the queue that should only be serviced when rush_queue is | 346 // The names in the queue that should only be serviced when rush_queue is |
| 346 // empty. | 347 // empty. |
| 347 std::queue<GURL> background_queue_; | 348 std::queue<GURL> background_queue_; |
| 348 | 349 |
| 349 DISALLOW_COPY_AND_ASSIGN(HostNameQueue); | 350 DISALLOW_COPY_AND_ASSIGN(HostNameQueue); |
| 350 }; | 351 }; |
| 351 | 352 |
| 352 // The InitialObserver monitors navigations made by the network stack. This | |
| 353 // is only used to identify startup time resolutions (for re-resolution | |
| 354 // during our next process startup). | |
| 355 // TODO(jar): Consider preconnecting at startup, which may be faster than | |
| 356 // waiting for render process to start and request a connection. | |
| 357 class InitialObserver { | |
| 358 public: | |
| 359 InitialObserver(); | |
| 360 ~InitialObserver(); | |
| 361 // Recording of when we observed each navigation. | |
| 362 typedef std::map<GURL, base::TimeTicks> FirstNavigations; | |
| 363 | |
| 364 // Potentially add a new URL to our startup list. | |
| 365 void Append(const GURL& url, Predictor* predictor); | |
| 366 | |
| 367 // Get an HTML version of our current planned first_navigations_. | |
| 368 void GetFirstResolutionsHtml(std::string* output); | |
| 369 | |
| 370 // Persist the current first_navigations_ for storage in a list. | |
| 371 void GetInitialDnsResolutionList(base::ListValue* startup_list); | |
| 372 | |
| 373 // Discards all initial loading history. | |
| 374 void DiscardInitialNavigationHistory() { first_navigations_.clear(); } | |
| 375 | |
| 376 private: | |
| 377 // List of the first N URL resolutions observed in this run. | |
| 378 FirstNavigations first_navigations_; | |
| 379 | |
| 380 // The number of URLs we'll save for pre-resolving at next startup. | |
| 381 static const size_t kStartupResolutionCount = 10; | |
| 382 }; | |
| 383 | |
| 384 // A map that is keyed with the host/port that we've learned were the cause | 353 // A map that is keyed with the host/port that we've learned were the cause |
| 385 // of loading additional URLs. The list of additional targets is held | 354 // of loading additional URLs. The list of additional targets is held |
| 386 // in a Referrer instance, which is a value in this map. | 355 // in a Referrer instance, which is a value in this map. |
| 387 typedef base::MRUCache<GURL, Referrer> Referrers; | 356 typedef base::MRUCache<GURL, Referrer> Referrers; |
| 388 | 357 |
| 389 // Depending on the expected_subresource_use_, we may either make a TCP/IP | 358 // Depending on the expected_subresource_use_, we may either make a TCP/IP |
| 390 // preconnection, or merely pre-resolve the hostname via DNS (or even do | 359 // preconnection, or merely pre-resolve the hostname via DNS (or even do |
| 391 // nothing). The following are the threasholds for taking those actions. | 360 // nothing). The following are the threasholds for taking those actions. |
| 392 static const double kPreconnectWorthyExpectedValue; | 361 static const double kPreconnectWorthyExpectedValue; |
| 393 static const double kDNSPreresolutionWorthyExpectedValue; | 362 static const double kDNSPreresolutionWorthyExpectedValue; |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 561 | 530 |
| 562 private: | 531 private: |
| 563 // These member functions return True for unittests. | 532 // These member functions return True for unittests. |
| 564 bool CanPrefetchAndPrerender() const override; | 533 bool CanPrefetchAndPrerender() const override; |
| 565 bool CanPreresolveAndPreconnect() const override; | 534 bool CanPreresolveAndPreconnect() const override; |
| 566 }; | 535 }; |
| 567 | 536 |
| 568 } // namespace chrome_browser_net | 537 } // namespace chrome_browser_net |
| 569 | 538 |
| 570 #endif // CHROME_BROWSER_NET_PREDICTOR_H_ | 539 #endif // CHROME_BROWSER_NET_PREDICTOR_H_ |
| OLD | NEW |