Fix terminating a transfer while resolving proxies.

Calling TerminateTransfer() on an HttpFetcher should cancel the current
transfer regardless of where it is sitting. If TerminateTransfer() was
called right after BeginTransfer(), the fetcher would be waiting for
the proxy resolution callback which will kick the download. This patch
fixes this case by releasing the proxy callback when terminating a
transfer.

Bug: 34178297
Test: Added a unittest to trigger this case.
Change-Id: I282d04995bd0d03f9a469c80c1e263f9902e4be2
diff --git a/common/http_fetcher.h b/common/http_fetcher.h
index 9f81879..fb15689 100644
--- a/common/http_fetcher.h
+++ b/common/http_fetcher.h
@@ -134,6 +134,11 @@
   ProxyResolver* proxy_resolver() const { return proxy_resolver_; }
 
  protected:
+  // Cancels a proxy resolution in progress. The callback passed to
+  // ResolveProxiesForUrl() will not be called. Returns whether there was a
+  // pending proxy resolution to be canceled.
+  bool CancelProxyResolution();
+
   // The URL we're actively fetching from
   std::string url_;
 
@@ -170,6 +175,10 @@
   // |proxy_resolver_|.
   void NoProxyResolverCallback();
 
+  // Stores the ongoing proxy request id if there is one, otherwise
+  // kProxyRequestIdNull.
+  ProxyRequestId proxy_request_{kProxyRequestIdNull};
+
   DISALLOW_COPY_AND_ASSIGN(HttpFetcher);
 };