Index: chrome/browser/net/predictor.h |
=================================================================== |
--- chrome/browser/net/predictor.h (revision 89645) |
+++ chrome/browser/net/predictor.h (working copy) |
@@ -28,13 +28,20 @@ |
#include "base/gtest_prod_util.h" |
#include "base/memory/ref_counted.h" |
+#include "base/memory/scoped_ptr.h" |
#include "chrome/browser/net/url_info.h" |
#include "chrome/browser/net/referrer.h" |
#include "chrome/common/net/predictor_common.h" |
#include "net/base/host_port_pair.h" |
class ListValue; |
+class PrefService; |
+class Profile; |
+namespace base { |
+class WaitableEvent; |
+} |
+ |
namespace net { |
class HostResolver; |
} // namespace net |
@@ -57,8 +64,10 @@ |
// be performed. Host lookups will be issued through |host_resolver|. |
Predictor(net::HostResolver* host_resolver, |
base::TimeDelta max_queue_delay_ms, size_t max_concurrent, |
- bool preconnect_enabled); |
+ bool preconnect_enabled, bool predictor_enabled); |
+ ~Predictor(); |
+ |
// Cancel pending requests and prevent new ones from being made. |
void Shutdown(); |
@@ -122,19 +131,71 @@ |
void DeserializeReferrersThenDelete(ListValue* referral_list); |
+ void DiscardInitialNavigationHistory(); |
+ |
+ void FinalizeInitialization(const std::vector<GURL>& urls_to_prefetch, |
+ ListValue* referral_list); |
+ |
+ // During startup, we learn what the first N urls visited are, and then |
+ // resolve the associated hosts ASAP during our next startup. |
+ void LearnAboutInitialNavigation(const GURL& url); |
+ |
+ // Renderer bundles up list and sends to this browser API via IPC. |
+ // TODO(jar): Use UrlList instead to include port and scheme. |
+ void DnsPrefetchList(const NameList& hostnames); |
+ |
+ void Predictor::DnsPrefetchMotivatedList( |
+ const UrlList& urls, |
+ UrlInfo::ResolutionMotivation motivation); |
+ |
+ void SaveStateForNextStartupAndTrim(PrefService* prefs, Profile* profile); |
+ |
+ void SaveDnsPrefetchStateForNextStartupAndTrim( |
+ ListValue* startup_list, |
+ ListValue* referral_list, |
+ base::WaitableEvent* completion); |
+ |
// For unit test code only. |
size_t max_concurrent_dns_lookups() const { |
return max_concurrent_dns_lookups_; |
} |
// Flag setting to use preconnection instead of just DNS pre-fetching. |
- bool preconnect_enabled() const { return preconnect_enabled_; } |
+ bool preconnect_enabled() const { |
+ return preconnect_enabled_; |
+ } |
+ // Flag setting for whether we are prefetching dns lookups. |
+ bool predictor_enabled() const { |
+ return predictor_enabled_; |
+ } |
+ |
+ void EnablePredictor(bool enable) { |
+ predictor_enabled_ = enable; |
+ } |
+ |
+ // See variable description for explanation. |
+ bool on_the_record() const { |
+ return on_the_record_; |
+ } |
+ |
+ void SetOnTheRecord(bool on_the_record) { |
+ on_the_record_ = on_the_record; |
+ } |
+ |
+ // Return value indicates whether to go back on the record. |
+ bool HandleIncognitoBrowserClosed(); |
+ |
+ void HandleIncognitoBrowserOpened(); |
+ |
// Put URL in canonical form, including a scheme, host, and port. |
// Returns GURL::EmptyGURL() if the scheme is not http/https or if the url |
// cannot be otherwise canonicalized. |
static GURL CanonicalizeUrl(const GURL& url); |
+ static UrlList GetPredictedUrlListAtStartup(PrefService* user_prefs, |
+ PrefService* local_state); |
+ |
private: |
friend class base::RefCountedThreadSafe<Predictor>; |
FRIEND_TEST_ALL_PREFIXES(PredictorTest, BenefitLookupTest); |
@@ -176,6 +237,36 @@ |
DISALLOW_COPY_AND_ASSIGN(HostNameQueue); |
}; |
+ // The InitialObserver monitors navigations made by the network stack. This |
+ // is only used to identify startup time resolutions (for re-resolution |
+ // during our next process startup). |
+ // TODO(jar): Consider preconnecting at startup, which may be faster than |
+ // waiting for render process to start and request a connection. |
+ class InitialObserver { |
+ public: |
+ // Recording of when we observed each navigation. |
+ typedef std::map<GURL, base::TimeTicks> FirstNavigations; |
+ |
+ // Potentially add a new URL to our startup list. |
+ void Append(const GURL& url, Predictor* predictor); |
+ |
+ // Get an HTML version of our current planned first_navigations_. |
+ void GetFirstResolutionsHtml(std::string* output); |
+ |
+ // Persist the current first_navigations_ for storage in a list. |
+ void GetInitialDnsResolutionList(ListValue* startup_list); |
+ |
+ // Discards all initial loading history. |
+ void DiscardInitialNavigationHistory() { first_navigations_.clear(); } |
+ |
+ private: |
+ // List of the first N URL resolutions observed in this run. |
+ FirstNavigations first_navigations_; |
+ |
+ // The number of URLs we'll save for pre-resolving at next startup. |
+ static const size_t kStartupResolutionCount = 10; |
+ }; |
+ |
// A map that is keyed with the host/port that we've learned were the cause |
// of loading additional URLs. The list of additional targets is held |
// in a Referrer instance, which is a value in this map. |
@@ -204,8 +295,6 @@ |
// Number of referring URLs processed in an incremental trimming. |
static const size_t kUrlsTrimmedPerIncrement; |
- ~Predictor(); |
- |
// Perform actual resolution or preconnection to subresources now. This is |
// an internal worker method that is reached via a post task from |
// PredictFrameSubresources(). |
@@ -275,6 +364,19 @@ |
// continue with them shortly (i.e., it yeilds and continues). |
void IncrementalTrimReferrers(bool trim_all_now); |
+ scoped_ptr<InitialObserver> initial_observer_; |
+ |
+ // Status of speculative DNS resolution and speculative TCP/IP connection |
+ // feature. |
+ bool predictor_enabled_; |
+ |
+ // If there are any incognito windows at all, we don't want to keep prefetch |
+ // information since it would be visible in about:dns, for example. |
+ int off_the_record_windows_count_; |
+ |
+ // Cached inverted copy of the off_the_record pref. |
+ bool on_the_record_; |
+ |
// work_queue_ holds a list of names we need to look up. |
HostNameQueue work_queue_; |