Fix URLRequestHttpJob to use ScopedRunnableMethodFactory.

This will prevent us from leaking SSLClientSockets on shutdown since the certificate related functions complete asynchronously.  There's no reason to keep the URLRequestHttpJob alive, since Kill() will cancel the delegates appropriately, so we use ScopedRunnableMethodFactory to avoid AddRef()'ing when we PostTask().

BUG=63692
TEST=existing

Review URL: http://codereview.chromium.org/5556004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@68153 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/net/url_request/url_request_http_job.cc b/net/url_request/url_request_http_job.cc
index 70e43fe7..888e94cb 100644
--- a/net/url_request/url_request_http_job.cc
+++ b/net/url_request/url_request_http_job.cc
@@ -98,7 +98,8 @@
       sdch_dictionary_advertised_(false),
       sdch_test_activated_(false),
       sdch_test_control_(false),
-      is_cached_content_(false) {
+      is_cached_content_(false),
+      ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) {
 }
 
 URLRequestHttpJob::~URLRequestHttpJob() {
@@ -369,8 +370,10 @@
   //
   // We have to do this via InvokeLater to avoid "recursing" the consumer.
   //
-  MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod(
-      this, &URLRequestHttpJob::OnStartCompleted, net::OK));
+  MessageLoop::current()->PostTask(
+      FROM_HERE,
+      method_factory_.NewRunnableMethod(
+          &URLRequestHttpJob::OnStartCompleted, net::OK));
 }
 
 void URLRequestHttpJob::ContinueWithCertificate(
@@ -389,8 +392,10 @@
 
   // The transaction started synchronously, but we need to notify the
   // net::URLRequest delegate via the message loop.
-  MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod(
-      this, &URLRequestHttpJob::OnStartCompleted, rv));
+  MessageLoop::current()->PostTask(
+      FROM_HERE,
+      method_factory_.NewRunnableMethod(
+          &URLRequestHttpJob::OnStartCompleted, rv));
 }
 
 void URLRequestHttpJob::ContinueDespiteLastError() {
@@ -410,8 +415,10 @@
 
   // The transaction started synchronously, but we need to notify the
   // net::URLRequest delegate via the message loop.
-  MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod(
-      this, &URLRequestHttpJob::OnStartCompleted, rv));
+  MessageLoop::current()->PostTask(
+      FROM_HERE,
+      method_factory_.NewRunnableMethod(
+          &URLRequestHttpJob::OnStartCompleted, rv));
 }
 
 bool URLRequestHttpJob::ReadRawData(net::IOBuffer* buf, int buf_size,
@@ -660,8 +667,10 @@
 
   // The transaction started synchronously, but we need to notify the
   // net::URLRequest delegate via the message loop.
-  MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod(
-      this, &URLRequestHttpJob::OnStartCompleted, rv));
+  MessageLoop::current()->PostTask(
+      FROM_HERE,
+      method_factory_.NewRunnableMethod(
+          &URLRequestHttpJob::OnStartCompleted, rv));
 }
 
 void URLRequestHttpJob::AddExtraHeaders() {
diff --git a/net/url_request/url_request_http_job.h b/net/url_request/url_request_http_job.h
index c9139b0..471b406 100644
--- a/net/url_request/url_request_http_job.h
+++ b/net/url_request/url_request_http_job.h
@@ -11,6 +11,7 @@
 
 #include "base/scoped_ptr.h"
 #include "base/string16.h"
+#include "base/task.h"
 #include "net/base/auth.h"
 #include "net/base/completion_callback.h"
 #include "net/http/http_request_info.h"
@@ -135,6 +136,8 @@
  private:
   virtual ~URLRequestHttpJob();
 
+  ScopedRunnableMethodFactory<URLRequestHttpJob> method_factory_;
+
   DISALLOW_COPY_AND_ASSIGN(URLRequestHttpJob);
 };