| Index: net/socket/client_socket_pool_base.h
|
| diff --git a/net/socket/client_socket_pool_base.h b/net/socket/client_socket_pool_base.h
|
| index 8e6eb139aed050a82d973f0c05319c3e12f24075..e56891f04198b339715a6a089d53687cc885c0f5 100644
|
| --- a/net/socket/client_socket_pool_base.h
|
| +++ b/net/socket/client_socket_pool_base.h
|
| @@ -30,6 +30,7 @@
|
| #include <string>
|
|
|
| #include "base/basictypes.h"
|
| +#include "base/prebind.h"
|
| #include "base/ref_counted.h"
|
| #include "base/scoped_ptr.h"
|
| #include "base/task.h"
|
| @@ -165,11 +166,12 @@ class ClientSocketPoolBaseHelper
|
| };
|
|
|
| typedef uint32 Flags;
|
| + typedef base::Thunk<void(int)> Tr1CompletionCallback;
|
|
|
| class Request {
|
| public:
|
| Request(ClientSocketHandle* handle,
|
| - CompletionCallback* callback,
|
| + Tr1CompletionCallback callback,
|
| RequestPriority priority,
|
| Flags flags,
|
| const BoundNetLog& net_log);
|
| @@ -177,14 +179,14 @@ class ClientSocketPoolBaseHelper
|
| virtual ~Request();
|
|
|
| ClientSocketHandle* handle() const { return handle_; }
|
| - CompletionCallback* callback() const { return callback_; }
|
| + Tr1CompletionCallback callback() const { return callback_; }
|
| RequestPriority priority() const { return priority_; }
|
| Flags flags() const { return flags_; }
|
| const BoundNetLog& net_log() const { return net_log_; }
|
|
|
| private:
|
| ClientSocketHandle* const handle_;
|
| - CompletionCallback* const callback_;
|
| + Tr1CompletionCallback const callback_;
|
| const RequestPriority priority_;
|
| const Flags flags_;
|
| BoundNetLog net_log_;
|
| @@ -346,10 +348,10 @@ class ClientSocketPoolBaseHelper
|
| return pending_requests_.front()->priority();
|
| }
|
|
|
| - bool HasBackupJob() const { return !method_factory_.empty(); }
|
| + bool HasBackupJob() const { return !thunk_canceller_.empty(); }
|
|
|
| void CleanupBackupJob() {
|
| - method_factory_.RevokeAll();
|
| + thunk_canceller_.RevokeAll();
|
| }
|
|
|
| // Set a timer to create a backup socket if it takes too long to create one.
|
| @@ -385,7 +387,7 @@ class ClientSocketPoolBaseHelper
|
| RequestQueue pending_requests_;
|
| int active_socket_count_; // number of active sockets used by clients
|
| // A factory to pin the backup_job tasks.
|
| - ScopedRunnableMethodFactory<Group> method_factory_;
|
| + base::ThunkCanceller thunk_canceller_;
|
| };
|
|
|
| typedef std::map<std::string, Group*> GroupMap;
|
| @@ -394,10 +396,10 @@ class ClientSocketPoolBaseHelper
|
|
|
| struct CallbackResultPair {
|
| CallbackResultPair() : callback(NULL), result(OK) {}
|
| - CallbackResultPair(CompletionCallback* callback_in, int result_in)
|
| + CallbackResultPair(Tr1CompletionCallback callback_in, int result_in)
|
| : callback(callback_in), result(result_in) {}
|
|
|
| - CompletionCallback* callback;
|
| + Tr1CompletionCallback callback;
|
| int result;
|
| };
|
|
|
| @@ -493,7 +495,7 @@ class ClientSocketPoolBaseHelper
|
| // current message loop. Inserts |callback| into |pending_callback_map_|,
|
| // keyed by |handle|.
|
| void InvokeUserCallbackLater(
|
| - ClientSocketHandle* handle, CompletionCallback* callback, int rv);
|
| + ClientSocketHandle* handle, Tr1CompletionCallback callback, int rv);
|
|
|
| // Invokes the user callback for |handle|. By the time this task has run,
|
| // it's possible that the request has been cancelled, so |handle| may not
|
| @@ -541,7 +543,7 @@ class ClientSocketPoolBaseHelper
|
| // make sure that they are discarded rather than reused.
|
| int pool_generation_number_;
|
|
|
| - ScopedRunnableMethodFactory<ClientSocketPoolBaseHelper> method_factory_;
|
| + base::ThunkCanceller thunk_canceller_;
|
|
|
| DISALLOW_COPY_AND_ASSIGN(ClientSocketPoolBaseHelper);
|
| };
|
| @@ -556,6 +558,20 @@ class ClientSocketPoolBase {
|
| public:
|
| class Request : public internal::ClientSocketPoolBaseHelper::Request {
|
| public:
|
| + // Do a hacky type transition from the CompletionCallback to
|
| + // Tr1CompletionCallback by binding the method. This is complicated
|
| + // by the fact that the function we're wrapper has overloads which
|
| + // screws up the type inference. This should not be an issue in most
|
| + // of the our code since overloads are discouraged by the style guide.
|
| + //
|
| + // Also note that we don't need to keep a reference to the callback
|
| + // because the API does not take ownership. One plus of Tr1 callback is
|
| + // that there is no such ownership ambiguity. But the downside is
|
| + // refcounting in the callback.
|
| + static void RunCallback(CompletionCallback* c, int n) {
|
| + c->Run(n);
|
| + }
|
| +
|
| Request(ClientSocketHandle* handle,
|
| CompletionCallback* callback,
|
| RequestPriority priority,
|
| @@ -563,7 +579,10 @@ class ClientSocketPoolBase {
|
| const scoped_refptr<SocketParams>& params,
|
| const BoundNetLog& net_log)
|
| : internal::ClientSocketPoolBaseHelper::Request(
|
| - handle, callback, priority, flags, net_log),
|
| + handle,
|
| + base::Prebind(&Request::RunCallback, callback),
|
| + priority,
|
| + flags, net_log),
|
| params_(params) {}
|
|
|
| const scoped_refptr<SocketParams>& params() const { return params_; }
|
|
|