shill: Prepare DNSClient and HTTPRequest for destroy-on-callback
Refactor both classes so that it's okay for the callback to destroy
the object (i.e., do nothing to the object after the callback is
called). As a part of this, clean up some of the callback semantics,
so, for example, DNSClient callbacks are passed an Error reference
and an IP Address instead of having to use a getter. Additionally
remove the blemish where an immediate timeout in Start() both returned
failure and called the callback.
BUG=chromium-os:23318
TEST=Fixed unit tests, manual
Change-Id: Ib7787a7aa6f7f3d00caa539d6b0221ff5f3d60b3
Reviewed-on: https://gerrit.chromium.org/gerrit/16435
Commit-Ready: Paul Stewart <pstew@chromium.org>
Reviewed-by: Paul Stewart <pstew@chromium.org>
Tested-by: Paul Stewart <pstew@chromium.org>
diff --git a/http_proxy_unittest.cc b/http_proxy_unittest.cc
index 6fba3f7..5318b0b 100644
--- a/http_proxy_unittest.cc
+++ b/http_proxy_unittest.cc
@@ -273,13 +273,9 @@
EXPECT_EQ(line, proxy_.client_headers_[0] + "\r\n");
}
void ExpectDNSRequest(const string &host, bool return_value) {
- EXPECT_CALL(*dns_client_, Start(StrEq(host)))
+ EXPECT_CALL(*dns_client_, Start(StrEq(host), _))
.WillOnce(Return(return_value));
}
- void ExpectDNSFailure(const string &error) {
- EXPECT_CALL(*dns_client_, error())
- .WillOnce(ReturnRef(error));
- }
void ExpectAsyncConnect(const string &address, int port,
bool return_value) {
EXPECT_CALL(*server_async_connection_, Start(IsIPAddress(address), port))
@@ -354,8 +350,14 @@
void AcceptClient(int fd) {
proxy_.AcceptClient(fd);
}
- void GetDNSResult(bool result) {
- proxy_.GetDNSResult(result);
+ void GetDNSResultFailure(const string &error_msg) {
+ Error error(Error::kOperationFailed, error_msg);
+ IPAddress address(IPAddress::kFamilyUnknown);
+ proxy_.GetDNSResult(error, address);
+ }
+ void GetDNSResultSuccess(const IPAddress &address) {
+ Error error;
+ proxy_.GetDNSResult(error, address);
}
void OnConnectCompletion(bool result, int sockfd) {
proxy_.OnConnectCompletion(result, sockfd);
@@ -411,9 +413,7 @@
ReadFromClient(CreateRequest(url, http_version, extra_lines));
IPAddress addr(IPAddress::kFamilyIPv4);
EXPECT_TRUE(addr.SetAddressFromString(kServerAddress));
- EXPECT_CALL(*dns_client_, address())
- .WillOnce(ReturnRef(addr));;
- GetDNSResult(true);
+ GetDNSResultSuccess(addr);
}
void SetupConnect() {
SetupConnectWithRequest("/", "1.1", "Host: www.chromium.org:40506");
@@ -617,8 +617,7 @@
ReadFromClient(CreateRequest("/", "1.1", "Host: www.chromium.org:40506"));
ExpectClientResult();
const std::string not_found_error(DNSClient::kErrorNotFound);
- ExpectDNSFailure(not_found_error);
- GetDNSResult(false);
+ GetDNSResultFailure(not_found_error);
ExpectClientError(502, string("Could not resolve hostname: ") +
not_found_error);
}