shill: Fix timer canceling

The move to new callback closures included the frequent replacement
 of "task_factory_.RevokeAll()" with
"weak_ptr_factory_.InvalidateWeakPtrs()".  The former canceled all
pending timers, whereas the latter also effectively canceled all
I/O callbacks.  This caused both portal detection and the service
proxy to stop working.

This CL creates CancelableClosures for the affected timers, and
cancels these closures instead of invalidating all weak pointers.

BUG=chromium-os:28885
TEST=Manual: Test both passing and failure cases of portal detection,
ensuring that DNS timeouts work correctly.  Use "curl -x" to test
HTTP proxy.

Change-Id: Id61dfb6a1a4ce0defaa08a99e318bc510c6c84b3
Reviewed-on: https://gerrit.chromium.org/gerrit/19644
Reviewed-by: Eric Shienbrood <ers@chromium.org>
Commit-Ready: Paul Stewart <pstew@chromium.org>
Tested-by: Paul Stewart <pstew@chromium.org>
diff --git a/http_proxy.cc b/http_proxy.cc
index 3d2fd0c..d4b31fd 100644
--- a/http_proxy.cc
+++ b/http_proxy.cc
@@ -178,8 +178,9 @@
       dispatcher_->CreateInputHandler(client_socket_,
                                       read_client_callback_));
   // Overall transaction timeout.
-  dispatcher_->PostDelayedTask(Bind(&HTTPProxy::StopClient,
-                                    weak_ptr_factory_.GetWeakPtr()),
+  transaction_timeout_.Reset(Bind(&HTTPProxy::StopClient,
+                                  weak_ptr_factory_.GetWeakPtr()));
+  dispatcher_->PostDelayedTask(transaction_timeout_.callback(),
                                kTransactionTimeoutSeconds * 1000);
 
   state_ = kStateReadClientHeader;
@@ -646,7 +647,7 @@
   dns_client_->Stop();
   server_async_connection_->Stop();
   idle_timeout_.Cancel();
-  weak_ptr_factory_.InvalidateWeakPtrs();
+  transaction_timeout_.Cancel();
   accept_handler_->Start();
   state_ = kStateWaitConnection;
 }