diff options
author | adamk@chromium.org <adamk@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-20 01:24:20 +0000 |
---|---|---|
committer | adamk@chromium.org <adamk@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-20 01:24:20 +0000 |
commit | f98ead6cf97707ff5a13896aa0206364703aa393 (patch) | |
tree | 4d5b8f580f642cbcf7a15dcd71b5c914353b321e /net | |
parent | b9821b183321186dd747e45013cce14ab5b8d3bd (diff) | |
download | chromium_src-f98ead6cf97707ff5a13896aa0206364703aa393.zip chromium_src-f98ead6cf97707ff5a13896aa0206364703aa393.tar.gz chromium_src-f98ead6cf97707ff5a13896aa0206364703aa393.tar.bz2 |
base::Bind conversion for net/http/...
R=willchan@chromium.org
Review URL: http://codereview.chromium.org/8344066
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@106428 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r-- | net/http/http_auth_handler_mock.cc | 13 | ||||
-rw-r--r-- | net/http/http_auth_handler_mock.h | 4 | ||||
-rw-r--r-- | net/http/http_cache.cc | 19 | ||||
-rw-r--r-- | net/http/http_cache.h | 3 | ||||
-rw-r--r-- | net/http/http_cache_unittest.cc | 5 | ||||
-rw-r--r-- | net/http/http_response_body_drainer_unittest.cc | 9 | ||||
-rw-r--r-- | net/http/http_stream_factory_impl_job.cc | 37 | ||||
-rw-r--r-- | net/http/http_stream_factory_impl_job.h | 4 | ||||
-rw-r--r-- | net/http/http_transaction_unittest.cc | 8 | ||||
-rw-r--r-- | net/http/http_transaction_unittest.h | 2 |
10 files changed, 58 insertions, 46 deletions
diff --git a/net/http/http_auth_handler_mock.cc b/net/http/http_auth_handler_mock.cc index c7c70a8..2e5e1e6 100644 --- a/net/http/http_auth_handler_mock.cc +++ b/net/http/http_auth_handler_mock.cc @@ -4,6 +4,7 @@ #include "net/http/http_auth_handler_mock.h" +#include "base/bind.h" #include "base/message_loop.h" #include "base/string_util.h" #include "net/base/net_errors.h" @@ -14,7 +15,7 @@ namespace net { HttpAuthHandlerMock::HttpAuthHandlerMock() : resolve_(RESOLVE_INIT), user_callback_(NULL), - ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)), + ALLOW_THIS_IN_INITIALIZER_LIST(ptr_factory_(this)), generate_async_(false), generate_rv_(OK), auth_token_(NULL), first_round_(true), @@ -58,8 +59,9 @@ int HttpAuthHandlerMock::ResolveCanonicalName(HostResolver* host_resolver, rv = ERR_IO_PENDING; user_callback_ = callback; MessageLoop::current()->PostTask( - FROM_HERE, method_factory_.NewRunnableMethod( - &HttpAuthHandlerMock::OnResolveCanonicalName)); + FROM_HERE, base::Bind( + &HttpAuthHandlerMock::OnResolveCanonicalName, + ptr_factory_.GetWeakPtr())); break; default: NOTREACHED(); @@ -116,8 +118,9 @@ int HttpAuthHandlerMock::GenerateAuthTokenImpl(const string16* username, user_callback_ = callback; auth_token_ = auth_token; MessageLoop::current()->PostTask( - FROM_HERE, method_factory_.NewRunnableMethod( - &HttpAuthHandlerMock::OnGenerateAuthToken)); + FROM_HERE, base::Bind( + &HttpAuthHandlerMock::OnGenerateAuthToken, + ptr_factory_.GetWeakPtr())); return ERR_IO_PENDING; } else { if (generate_rv_ == OK) diff --git a/net/http/http_auth_handler_mock.h b/net/http/http_auth_handler_mock.h index 7d7a2cb..a78b876 100644 --- a/net/http/http_auth_handler_mock.h +++ b/net/http/http_auth_handler_mock.h @@ -9,8 +9,8 @@ #include <string> #include "base/memory/scoped_vector.h" +#include "base/memory/weak_ptr.h" #include "base/string16.h" -#include "base/task.h" #include "googleurl/src/gurl.h" #include "net/http/http_auth_handler.h" #include "net/http/http_auth_handler_factory.h" @@ -110,7 +110,7 @@ class HttpAuthHandlerMock : public HttpAuthHandler { Resolve resolve_; OldCompletionCallback* user_callback_; - ScopedRunnableMethodFactory<HttpAuthHandlerMock> method_factory_; + base::WeakPtrFactory<HttpAuthHandlerMock> ptr_factory_; bool generate_async_; int generate_rv_; std::string* auth_token_; diff --git a/net/http/http_cache.cc b/net/http/http_cache.cc index 23002d8..58fa5cb 100644 --- a/net/http/http_cache.cc +++ b/net/http/http_cache.cc @@ -12,6 +12,7 @@ #include <unistd.h> #endif +#include "base/bind.h" #include "base/callback.h" #include "base/format_macros.h" #include "base/location.h" @@ -347,8 +348,7 @@ HttpCache::HttpCache(HostResolver* host_resolver, http_auth_handler_factory, network_delegate, http_server_properties, - net_log))), - ALLOW_THIS_IN_INITIALIZER_LIST(task_factory_(this)) { + net_log))) { } @@ -361,8 +361,7 @@ HttpCache::HttpCache(HttpNetworkSession* session, ssl_host_info_factory_(new SSLHostInfoFactoryAdaptor( session->cert_verifier(), ALLOW_THIS_IN_INITIALIZER_LIST(this))), - network_layer_(new HttpNetworkLayer(session)), - ALLOW_THIS_IN_INITIALIZER_LIST(task_factory_(this)) { + network_layer_(new HttpNetworkLayer(session)) { } HttpCache::HttpCache(HttpTransactionFactory* network_layer, @@ -372,8 +371,7 @@ HttpCache::HttpCache(HttpTransactionFactory* network_layer, backend_factory_(backend_factory), building_backend_(false), mode_(NORMAL), - network_layer_(network_layer), - ALLOW_THIS_IN_INITIALIZER_LIST(task_factory_(this)) { + network_layer_(network_layer) { } HttpCache::~HttpCache() { @@ -1010,8 +1008,9 @@ void HttpCache::ProcessPendingQueue(ActiveEntry* entry) { MessageLoop::current()->PostTask( FROM_HERE, - task_factory_.NewRunnableMethod(&HttpCache::OnProcessPendingQueue, - entry)); + base::Bind(&HttpCache::OnProcessPendingQueue, + AsWeakPtr(), + entry)); } void HttpCache::OnProcessPendingQueue(ActiveEntry* entry) { @@ -1156,8 +1155,8 @@ void HttpCache::OnBackendCreated(int result, PendingOp* pending_op) { MessageLoop::current()->PostTask( FROM_HERE, - task_factory_.NewRunnableMethod(&HttpCache::OnBackendCreated, - result, pending_op)); + base::Bind(&HttpCache::OnBackendCreated, AsWeakPtr(), + result, pending_op)); } else { building_backend_ = false; DeletePendingOp(pending_op); diff --git a/net/http/http_cache.h b/net/http/http_cache.h index 1a7a51d..df464337 100644 --- a/net/http/http_cache.h +++ b/net/http/http_cache.h @@ -25,7 +25,6 @@ #include "base/memory/scoped_ptr.h" #include "base/memory/weak_ptr.h" #include "base/message_loop_proxy.h" -#include "base/task.h" #include "base/time.h" #include "base/threading/non_thread_safe.h" #include "net/base/cache_type.h" @@ -381,8 +380,6 @@ class NET_EXPORT HttpCache : public HttpTransactionFactory, // The set of entries "under construction". PendingOpsMap pending_ops_; - ScopedRunnableMethodFactory<HttpCache> task_factory_; - scoped_ptr<PlaybackCacheMap> playback_cache_map_; DISALLOW_COPY_AND_ASSIGN(HttpCache); diff --git a/net/http/http_cache_unittest.cc b/net/http/http_cache_unittest.cc index f912dd5..24e625d 100644 --- a/net/http/http_cache_unittest.cc +++ b/net/http/http_cache_unittest.cc @@ -4,6 +4,7 @@ #include "net/http/http_cache.h" +#include "base/bind.h" #include "base/hash_tables.h" #include "base/memory/scoped_vector.h" #include "base/message_loop.h" @@ -312,8 +313,8 @@ class MockDiskEntry : public disk_cache::Entry, void CallbackLater(net::OldCompletionCallback* callback, int result) { if (ignore_callbacks_) return StoreAndDeliverCallbacks(true, this, callback, result); - MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod( - this, &MockDiskEntry::RunCallback, callback, result)); + MessageLoop::current()->PostTask(FROM_HERE, base::Bind( + &MockDiskEntry::RunCallback, this, callback, result)); } void RunCallback(net::OldCompletionCallback* callback, int result) { if (busy_) { diff --git a/net/http/http_response_body_drainer_unittest.cc b/net/http/http_response_body_drainer_unittest.cc index 9db5ec0..f580f946 100644 --- a/net/http/http_response_body_drainer_unittest.cc +++ b/net/http/http_response_body_drainer_unittest.cc @@ -6,9 +6,10 @@ #include <cstring> +#include "base/bind.h" #include "base/compiler_specific.h" +#include "base/memory/weak_ptr.h" #include "base/message_loop.h" -#include "base/task.h" #include "net/base/io_buffer.h" #include "net/base/net_errors.h" #include "net/base/ssl_config_service_defaults.h" @@ -69,7 +70,7 @@ class MockHttpStream : public HttpStream { stall_reads_forever_(false), num_chunks_(0), is_complete_(false), - ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) {} + ALLOW_THIS_IN_INITIALIZER_LIST(ptr_factory_(this)) {} virtual ~MockHttpStream() {} // HttpStream implementation: @@ -139,7 +140,7 @@ class MockHttpStream : public HttpStream { bool stall_reads_forever_; int num_chunks_; bool is_complete_; - ScopedRunnableMethodFactory<MockHttpStream> method_factory_; + base::WeakPtrFactory<MockHttpStream> ptr_factory_; }; int MockHttpStream::ReadResponseBody( @@ -159,7 +160,7 @@ int MockHttpStream::ReadResponseBody( user_callback_ = callback; MessageLoop::current()->PostTask( FROM_HERE, - method_factory_.NewRunnableMethod(&MockHttpStream::CompleteRead)); + base::Bind(&MockHttpStream::CompleteRead, ptr_factory_.GetWeakPtr())); return ERR_IO_PENDING; } diff --git a/net/http/http_stream_factory_impl_job.cc b/net/http/http_stream_factory_impl_job.cc index fe9c5c1..edf83f6 100644 --- a/net/http/http_stream_factory_impl_job.cc +++ b/net/http/http_stream_factory_impl_job.cc @@ -4,6 +4,7 @@ #include "net/http/http_stream_factory_impl_job.h" +#include "base/bind.h" #include "base/logging.h" #include "base/stl_util.h" #include "base/string_util.h" @@ -94,7 +95,7 @@ HttpStreamFactoryImpl::Job::Job(HttpStreamFactoryImpl* stream_factory, num_streams_(0), spdy_session_direct_(false), existing_available_pipeline_(false), - ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { + ALLOW_THIS_IN_INITIALIZER_LIST(ptr_factory_(this)) { DCHECK(stream_factory); DCHECK(session); } @@ -184,8 +185,8 @@ void HttpStreamFactoryImpl::Job::Resume(Job* job) { if (next_state_ == STATE_WAIT_FOR_JOB_COMPLETE) { MessageLoop::current()->PostTask( FROM_HERE, - method_factory_.NewRunnableMethod( - &HttpStreamFactoryImpl::Job::OnIOComplete, OK)); + base::Bind(&HttpStreamFactoryImpl::Job::OnIOComplete, + ptr_factory_.GetWeakPtr(), OK)); } } @@ -341,8 +342,9 @@ int HttpStreamFactoryImpl::Job::RunLoop(int result) { if (IsPreconnecting()) { MessageLoop::current()->PostTask( FROM_HERE, - method_factory_.NewRunnableMethod( - &HttpStreamFactoryImpl::Job::OnPreconnectsComplete)); + base::Bind( + &HttpStreamFactoryImpl::Job::OnPreconnectsComplete, + ptr_factory_.GetWeakPtr())); return ERR_IO_PENDING; } @@ -353,8 +355,9 @@ int HttpStreamFactoryImpl::Job::RunLoop(int result) { next_state_ = STATE_WAITING_USER_ACTION; MessageLoop::current()->PostTask( FROM_HERE, - method_factory_.NewRunnableMethod( + base::Bind( &HttpStreamFactoryImpl::Job::OnCertificateErrorCallback, + ptr_factory_.GetWeakPtr(), result, ssl_info_)); return ERR_IO_PENDING; } @@ -374,8 +377,9 @@ int HttpStreamFactoryImpl::Job::RunLoop(int result) { next_state_ = STATE_WAITING_USER_ACTION; MessageLoop::current()->PostTask( FROM_HERE, - method_factory_.NewRunnableMethod( + base::Bind( &HttpStreamFactoryImpl::Job::OnNeedsProxyAuthCallback, + ptr_factory_.GetWeakPtr(), *tunnel_auth_response, http_proxy_socket->auth_controller())); } @@ -384,8 +388,9 @@ int HttpStreamFactoryImpl::Job::RunLoop(int result) { case ERR_SSL_CLIENT_AUTH_CERT_NEEDED: MessageLoop::current()->PostTask( FROM_HERE, - method_factory_.NewRunnableMethod( + base::Bind( &HttpStreamFactoryImpl::Job::OnNeedsClientAuthCallback, + ptr_factory_.GetWeakPtr(), connection_->ssl_error_response_info().cert_request_info)); return ERR_IO_PENDING; @@ -399,8 +404,9 @@ int HttpStreamFactoryImpl::Job::RunLoop(int result) { static_cast<ProxyClientSocket*>(connection_->socket()); MessageLoop::current()->PostTask( FROM_HERE, - method_factory_.NewRunnableMethod( + base::Bind( &HttpStreamFactoryImpl::Job::OnHttpsProxyTunnelResponseCallback, + ptr_factory_.GetWeakPtr(), *proxy_socket->GetConnectResponseInfo(), proxy_socket->CreateConnectResponseStream())); return ERR_IO_PENDING; @@ -411,21 +417,24 @@ int HttpStreamFactoryImpl::Job::RunLoop(int result) { if (new_spdy_session_) { MessageLoop::current()->PostTask( FROM_HERE, - method_factory_.NewRunnableMethod( - &HttpStreamFactoryImpl::Job::OnSpdySessionReadyCallback)); + base::Bind( + &HttpStreamFactoryImpl::Job::OnSpdySessionReadyCallback, + ptr_factory_.GetWeakPtr())); } else { MessageLoop::current()->PostTask( FROM_HERE, - method_factory_.NewRunnableMethod( - &HttpStreamFactoryImpl::Job::OnStreamReadyCallback)); + base::Bind( + &HttpStreamFactoryImpl::Job::OnStreamReadyCallback, + ptr_factory_.GetWeakPtr())); } return ERR_IO_PENDING; default: MessageLoop::current()->PostTask( FROM_HERE, - method_factory_.NewRunnableMethod( + base::Bind( &HttpStreamFactoryImpl::Job::OnStreamFailedCallback, + ptr_factory_.GetWeakPtr(), result)); return ERR_IO_PENDING; } diff --git a/net/http/http_stream_factory_impl_job.h b/net/http/http_stream_factory_impl_job.h index 50da574..c1c4140 100644 --- a/net/http/http_stream_factory_impl_job.h +++ b/net/http/http_stream_factory_impl_job.h @@ -7,7 +7,7 @@ #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" -#include "base/task.h" +#include "base/memory/weak_ptr.h" #include "net/base/completion_callback.h" #include "net/base/net_log.h" #include "net/base/ssl_config_service.h" @@ -280,7 +280,7 @@ class HttpStreamFactoryImpl::Job { // True if an existing pipeline can handle this job's request. bool existing_available_pipeline_; - ScopedRunnableMethodFactory<Job> method_factory_; + base::WeakPtrFactory<Job> ptr_factory_; DISALLOW_COPY_AND_ASSIGN(Job); }; diff --git a/net/http/http_transaction_unittest.cc b/net/http/http_transaction_unittest.cc index a958d8b..40ea6f0 100644 --- a/net/http/http_transaction_unittest.cc +++ b/net/http/http_transaction_unittest.cc @@ -6,6 +6,7 @@ #include <algorithm> +#include "base/bind.h" #include "base/message_loop.h" #include "base/stringprintf.h" #include "net/base/net_errors.h" @@ -213,7 +214,7 @@ void TestTransactionConsumer::RunWithParams(const Tuple1<int>& params) { MockNetworkTransaction::MockNetworkTransaction(MockNetworkLayer* factory) - : ALLOW_THIS_IN_INITIALIZER_LIST(task_factory_(this)), + : ALLOW_THIS_IN_INITIALIZER_LIST(ptr_factory_(this)), data_cursor_(0), transaction_factory_(factory->AsWeakPtr()) { } @@ -318,8 +319,9 @@ uint64 MockNetworkTransaction::GetUploadProgress() const { void MockNetworkTransaction::CallbackLater(net::OldCompletionCallback* callback, int result) { - MessageLoop::current()->PostTask(FROM_HERE, task_factory_.NewRunnableMethod( - &MockNetworkTransaction::RunCallback, callback, result)); + MessageLoop::current()->PostTask(FROM_HERE, base::Bind( + &MockNetworkTransaction::RunCallback, ptr_factory_.GetWeakPtr(), + callback, result)); } void MockNetworkTransaction::RunCallback(net::OldCompletionCallback* callback, diff --git a/net/http/http_transaction_unittest.h b/net/http/http_transaction_unittest.h index 3573204..825ea53 100644 --- a/net/http/http_transaction_unittest.h +++ b/net/http/http_transaction_unittest.h @@ -190,7 +190,7 @@ class MockNetworkTransaction : public net::HttpTransaction { void CallbackLater(net::OldCompletionCallback* callback, int result); void RunCallback(net::OldCompletionCallback* callback, int result); - ScopedRunnableMethodFactory<MockNetworkTransaction> task_factory_; + base::WeakPtrFactory<MockNetworkTransaction> ptr_factory_; net::HttpResponseInfo response_; std::string data_; int data_cursor_; |