summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorericroman@google.com <ericroman@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-17 01:21:26 +0000
committerericroman@google.com <ericroman@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-17 01:21:26 +0000
commitd6c2a1a9a1c6970196482c727dfcabb4ae8ac4f1 (patch)
treef8904c8462e23a1133e18860f636e7ff89deb0c0
parentb04cf7a5d6f2481f711c927bf180f3f01139b08a (diff)
downloadchromium_src-d6c2a1a9a1c6970196482c727dfcabb4ae8ac4f1.zip
chromium_src-d6c2a1a9a1c6970196482c727dfcabb4ae8ac4f1.tar.gz
chromium_src-d6c2a1a9a1c6970196482c727dfcabb4ae8ac4f1.tar.bz2
Re-land a subset of r18520.
The original code review for this change was: <http://codereview.chromium.org/125171> The particular subset is the third bullet point in original description: * Fix a bug where completion notification wasn't being sent when the response was cached. (BUG=14188) Note that the original was rolled-back because something was upsetting valgrind (BUG=14218). Review URL: http://codereview.chromium.org/125227 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@18579 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--net/base/host_resolver.cc7
-rw-r--r--net/base/host_resolver_unittest.cc42
2 files changed, 35 insertions, 14 deletions
diff --git a/net/base/host_resolver.cc b/net/base/host_resolver.cc
index 5a357eb..dd1ffcc 100644
--- a/net/base/host_resolver.cc
+++ b/net/base/host_resolver.cc
@@ -417,7 +417,12 @@ int HostResolver::Resolve(const RequestInfo& info,
info.hostname(), base::TimeTicks::Now());
if (cache_entry) {
addresses->SetFrom(cache_entry->addrlist, info.port());
- return OK;
+ int error = OK;
+
+ // Notify registered observers.
+ NotifyObserversFinishRequest(request_id, info, error);
+
+ return error;
}
}
diff --git a/net/base/host_resolver_unittest.cc b/net/base/host_resolver_unittest.cc
index 9c07c29..195b2fb 100644
--- a/net/base/host_resolver_unittest.cc
+++ b/net/base/host_resolver_unittest.cc
@@ -20,6 +20,7 @@
#include "net/base/completion_callback.h"
#include "net/base/host_resolver_unittest.h"
#include "net/base/net_errors.h"
+#include "net/base/test_completion_callback.h"
#include "testing/gtest/include/gtest/gtest.h"
using net::RuleBasedHostMapper;
@@ -757,25 +758,40 @@ TEST_F(HostResolverTest, Observers) {
// Resolve "host1".
net::HostResolver::RequestInfo info1("host1", 70);
- host_resolver.Resolve(info1, &addrlist, NULL, NULL);
+ int rv = host_resolver.Resolve(info1, &addrlist, NULL, NULL);
+ EXPECT_EQ(net::OK, rv);
EXPECT_EQ(1U, observer.start_log.size());
EXPECT_EQ(1U, observer.finish_log.size());
- EXPECT_TRUE(
- observer.start_log[0] == CapturingObserver::StartEntry(0, info1));
- EXPECT_TRUE(
- observer.finish_log[0] == CapturingObserver::FinishEntry(0, true, info1));
+ EXPECT_TRUE(observer.start_log[0] ==
+ CapturingObserver::StartEntry(0, info1));
+ EXPECT_TRUE(observer.finish_log[0] ==
+ CapturingObserver::FinishEntry(0, true, info1));
+
+ // Resolve "host1" again -- this time it will be served from cache, but it
+ // should still notify of completion.
+ TestCompletionCallback callback;
+ rv = host_resolver.Resolve(info1, &addrlist, &callback, NULL);
+ ASSERT_EQ(net::OK, rv); // Should complete synchronously.
+
+ EXPECT_EQ(2U, observer.start_log.size());
+ EXPECT_EQ(2U, observer.finish_log.size());
+ EXPECT_TRUE(observer.start_log[1] ==
+ CapturingObserver::StartEntry(1, info1));
+ EXPECT_TRUE(observer.finish_log[1] ==
+ CapturingObserver::FinishEntry(1, true, info1));
// Resolve "host2", setting referrer to "http://foobar.com"
net::HostResolver::RequestInfo info2("host2", 70);
info2.set_referrer(GURL("http://foobar.com"));
- host_resolver.Resolve(info2, &addrlist, NULL, NULL);
+ rv = host_resolver.Resolve(info2, &addrlist, NULL, NULL);
+ EXPECT_EQ(net::OK, rv);
- EXPECT_EQ(2U, observer.start_log.size());
- EXPECT_EQ(2U, observer.finish_log.size());
- EXPECT_TRUE(observer.start_log[1] == CapturingObserver::StartEntry(1, info2));
- EXPECT_TRUE(observer.finish_log[1] == CapturingObserver::FinishEntry(
- 1, true, info2));
+ EXPECT_EQ(3U, observer.start_log.size());
+ EXPECT_EQ(3U, observer.finish_log.size());
+ EXPECT_TRUE(observer.start_log[2] == CapturingObserver::StartEntry(2, info2));
+ EXPECT_TRUE(observer.finish_log[2] ==
+ CapturingObserver::FinishEntry(2, true, info2));
// Unregister the observer.
host_resolver.RemoveObserver(&observer);
@@ -785,8 +801,8 @@ TEST_F(HostResolverTest, Observers) {
host_resolver.Resolve(info3, &addrlist, NULL, NULL);
// No effect this time, since observer was removed.
- EXPECT_EQ(2U, observer.start_log.size());
- EXPECT_EQ(2U, observer.finish_log.size());
+ EXPECT_EQ(3U, observer.start_log.size());
+ EXPECT_EQ(3U, observer.finish_log.size());
}
} // namespace