diff options
author | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-01-26 15:10:43 +0000 |
---|---|---|
committer | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-01-26 15:10:43 +0000 |
commit | fdc58a9963abb0a9f4cac157b2f3f1eac8e4160d (patch) | |
tree | 889dd032162f3c876c2bdcaa84a8b3717f134995 /net | |
parent | 9127ca05f3d1cc8308a35429876b18090814ae73 (diff) | |
download | chromium_src-fdc58a9963abb0a9f4cac157b2f3f1eac8e4160d.zip chromium_src-fdc58a9963abb0a9f4cac157b2f3f1eac8e4160d.tar.gz chromium_src-fdc58a9963abb0a9f4cac157b2f3f1eac8e4160d.tar.bz2 |
Clean up dns prefetch code, and also port it.
BUG=5687, 6683
Review URL: http://codereview.chromium.org/15076
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@8625 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r-- | net/base/host_resolver.h | 9 | ||||
-rw-r--r-- | net/base/scoped_host_mapper.h | 25 |
2 files changed, 26 insertions, 8 deletions
diff --git a/net/base/host_resolver.h b/net/base/host_resolver.h index 1f649f8..fa07708 100644 --- a/net/base/host_resolver.h +++ b/net/base/host_resolver.h @@ -41,10 +41,9 @@ class HostResolver { // // When callback is null, the operation completes synchronously. // - // When callback is non-null, ERR_IO_PENDING is returned if the operation - // could not be completed synchronously, in which case the result code will - // be passed to the callback when available. - // + // When callback is non-null, the operation will be performed asynchronously. + // ERR_IO_PENDING is returned if it has been scheduled successfully. Real + // result code will be passed to the completion callback. int Resolve(const std::string& hostname, int port, AddressList* addresses, CompletionCallback* callback); @@ -74,7 +73,7 @@ class HostMapper { // function while there are no outstanding HostResolver instances. // // NOTE: In most cases, you should use ScopedHostMapper instead, which is -// defined in host_resolver_unittest.h +// defined in scoped_host_resolver.h. // HostMapper* SetHostMapper(HostMapper* host_mapper); #endif diff --git a/net/base/scoped_host_mapper.h b/net/base/scoped_host_mapper.h index 836cb34..8b623b9 100644 --- a/net/base/scoped_host_mapper.h +++ b/net/base/scoped_host_mapper.h @@ -39,6 +39,7 @@ #include <list> #include "base/string_util.h" +#include "base/platform_thread.h" #include "net/base/host_resolver.h" #include "net/base/net_errors.h" @@ -63,12 +64,22 @@ class ScopedHostMapper : public HostMapper { rules_.push_back(Rule(host_pattern, replacement)); } + void AddRuleWithLatency(const char* host_pattern, const char* replacement, + int latency) { + rules_.push_back(Rule(host_pattern, replacement, latency)); + } + private: std::string Map(const std::string& host) { - RuleList::const_iterator r; + RuleList::iterator r; for (r = rules_.begin(); r != rules_.end(); ++r) { - if (MatchPattern(host, r->host_pattern)) + if (MatchPattern(host, r->host_pattern)) { + if (r->latency != 0) { + PlatformThread::Sleep(r->latency); + r->latency = 1; // Simulate cache warmup. + } return r->replacement; + } } return previous_host_mapper_ ? previous_host_mapper_->Map(host) : host; } @@ -76,7 +87,15 @@ class ScopedHostMapper : public HostMapper { struct Rule { std::string host_pattern; std::string replacement; - Rule(const char* h, const char* r) : host_pattern(h), replacement(r) {} + int latency; // in milliseconds + Rule(const char* h, const char* r) + : host_pattern(h), + replacement(r), + latency(0) {} + Rule(const char* h, const char* r, const int l) + : host_pattern(h), + replacement(r), + latency(l) {} }; typedef std::list<Rule> RuleList; |