summaryrefslogtreecommitdiffstats
path: root/chrome/browser/net/dns_master.cc
diff options
context:
space:
mode:
authorjar@chromium.org <jar@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-17 22:50:14 +0000
committerjar@chromium.org <jar@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-17 22:50:14 +0000
commit03c5e868627fd74ec5c13cb26df3cb110853765f (patch)
treec97563d5255b2ae0de3faf921577130bb346008f /chrome/browser/net/dns_master.cc
parentb7125fd56addf151194b09314c1f7f2c9d03a5b9 (diff)
downloadchromium_src-03c5e868627fd74ec5c13cb26df3cb110853765f.zip
chromium_src-03c5e868627fd74ec5c13cb26df3cb110853765f.tar.gz
chromium_src-03c5e868627fd74ec5c13cb26df3cb110853765f.tar.bz2
Persist info about subresources on pages for DNS pre-resolution
The DNS pre-resolution system already "learns" what domains are commonly needed when rendering sub-resources of a page at a given domain. This patch saves (some of) the information learned into a persistent pref, and restores it on startup. For now, I put in a wimpy pruning of the list each time I save, so that the list will not grow endlessly from session to session. I probably need a better pruning algorithm, such as one that prunes after a given amount of time, rather than only during shutdown. For now, this should get a lot of nice results, and provide slightly larger than needed lists to users that have long lived sessions, which is similar to the current performance, where I didn't persist any info, and only pruned (actually discarded) all learned info at shutdown. r=mbelshe Review URL: http://codereview.chromium.org/21374 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@9912 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/net/dns_master.cc')
-rw-r--r--chrome/browser/net/dns_master.cc46
1 files changed, 46 insertions, 0 deletions
diff --git a/chrome/browser/net/dns_master.cc b/chrome/browser/net/dns_master.cc
index 4d477b0..34efe37 100644
--- a/chrome/browser/net/dns_master.cc
+++ b/chrome/browser/net/dns_master.cc
@@ -537,5 +537,51 @@ void DnsMaster::DiscardAllResults() {
}
}
+void DnsMaster::TrimReferrers() {
+ std::vector<std::string> hosts;
+ AutoLock auto_lock(lock_);
+ for (Referrers::const_iterator it = referrers_.begin();
+ it != referrers_.end(); ++it)
+ hosts.push_back(it->first);
+ for (size_t i = 0; i < hosts.size(); ++i)
+ if (!referrers_[hosts[i]].Trim())
+ referrers_.erase(hosts[i]);
+}
+
+void DnsMaster::SerializeReferrers(ListValue* referral_list) {
+ referral_list->Clear();
+ AutoLock auto_lock(lock_);
+ for (Referrers::const_iterator it = referrers_.begin();
+ it != referrers_.end(); ++it) {
+ // Serialize the list of subresource names.
+ Value* subresource_list(it->second.Serialize());
+
+ // Create a list for each referer.
+ ListValue* motivating_host(new ListValue);
+ motivating_host->Append(new StringValue(it->first));
+ motivating_host->Append(subresource_list);
+
+ referral_list->Append(motivating_host);
+ }
+}
+
+void DnsMaster::DeserializeReferrers(const ListValue& referral_list) {
+ AutoLock auto_lock(lock_);
+ for (size_t i = 0; i < referral_list.GetSize(); ++i) {
+ ListValue* motivating_host;
+ if (!referral_list.GetList(i, &motivating_host))
+ continue;
+ std::string motivating_referrer;
+ if (!motivating_host->GetString(0, &motivating_referrer))
+ continue;
+ Value* subresource_list;
+ if (!motivating_host->Get(1, &subresource_list))
+ continue;
+ if (motivating_referrer.empty())
+ continue;
+ referrers_[motivating_referrer].Deserialize(*subresource_list);
+ }
+}
+
} // namespace chrome_browser_net