diff options
author | jhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-12 21:18:16 +0000 |
---|---|---|
committer | jhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-12 21:18:16 +0000 |
commit | 31a7eef76caaaa50d57166c26ebe2f9625000642 (patch) | |
tree | 53320dce2e28eef75c0b72fd0c31c2565b5e7b98 /jingle | |
parent | 72b6f8e29c17e3752847dd318821f18968b23dc8 (diff) | |
download | chromium_src-31a7eef76caaaa50d57166c26ebe2f9625000642.zip chromium_src-31a7eef76caaaa50d57166c26ebe2f9625000642.tar.gz chromium_src-31a7eef76caaaa50d57166c26ebe2f9625000642.tar.bz2 |
base::Bind: Convert jingle/.
BUG=none
TEST=none
R=csilv@chromium.org
Review URL: http://codereview.chromium.org/8551004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@109811 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'jingle')
-rw-r--r-- | jingle/glue/fake_network_manager.cc | 7 | ||||
-rw-r--r-- | jingle/glue/fake_network_manager.h | 4 | ||||
-rw-r--r-- | jingle/glue/fake_socket_factory.cc | 5 | ||||
-rw-r--r-- | jingle/glue/pseudotcp_adapter_unittest.cc | 15 | ||||
-rw-r--r-- | jingle/glue/thread_wrapper.cc | 20 | ||||
-rw-r--r-- | jingle/notifier/base/chrome_async_socket.cc | 31 | ||||
-rw-r--r-- | jingle/notifier/base/chrome_async_socket.h | 5 | ||||
-rw-r--r-- | jingle/notifier/base/proxy_resolving_client_socket.cc | 12 | ||||
-rw-r--r-- | jingle/notifier/base/proxy_resolving_client_socket.h | 4 | ||||
-rw-r--r-- | jingle/notifier/base/task_pump.cc | 7 | ||||
-rw-r--r-- | jingle/notifier/base/task_pump.h | 3 | ||||
-rw-r--r-- | jingle/notifier/listener/mediator_thread_impl.cc | 32 |
12 files changed, 70 insertions, 75 deletions
diff --git a/jingle/glue/fake_network_manager.cc b/jingle/glue/fake_network_manager.cc index 26c2fd0..d30aba9 100644 --- a/jingle/glue/fake_network_manager.cc +++ b/jingle/glue/fake_network_manager.cc @@ -4,6 +4,7 @@ #include "jingle/glue/fake_network_manager.h" +#include "base/bind.h" #include "base/logging.h" #include "base/message_loop.h" #include "net/base/ip_endpoint.h" @@ -14,7 +15,7 @@ namespace jingle_glue { FakeNetworkManager::FakeNetworkManager(const net::IPAddressNumber& address) : started_(false), - ALLOW_THIS_IN_INITIALIZER_LIST(task_factory_(this)) { + ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { net::IPEndPoint endpoint(address, 0); talk_base::SocketAddress socket_address; CHECK(IPEndPointToSocketAddress(endpoint, &socket_address)); @@ -28,8 +29,8 @@ FakeNetworkManager::~FakeNetworkManager() { void FakeNetworkManager::StartUpdating() { started_ = true; MessageLoop::current()->PostTask( - FROM_HERE,task_factory_.NewRunnableMethod( - &FakeNetworkManager::SendNetworksChangedSignal)); + FROM_HERE, base::Bind(&FakeNetworkManager::SendNetworksChangedSignal, + weak_factory_.GetWeakPtr())); } void FakeNetworkManager::StopUpdating() { diff --git a/jingle/glue/fake_network_manager.h b/jingle/glue/fake_network_manager.h index ad39e6b..01e2f91 100644 --- a/jingle/glue/fake_network_manager.h +++ b/jingle/glue/fake_network_manager.h @@ -9,7 +9,7 @@ #include "base/compiler_specific.h" #include "base/memory/scoped_ptr.h" -#include "base/task.h" +#include "base/memory/weak_ptr.h" #include "net/base/net_util.h" #include "third_party/libjingle/source/talk/base/network.h" @@ -33,7 +33,7 @@ class FakeNetworkManager : public talk_base::NetworkManager { bool started_; scoped_ptr<talk_base::Network> network_; - ScopedRunnableMethodFactory<FakeNetworkManager> task_factory_; + base::WeakPtrFactory<FakeNetworkManager> weak_factory_; }; } // namespace jingle_glue diff --git a/jingle/glue/fake_socket_factory.cc b/jingle/glue/fake_socket_factory.cc index 95a0fa2..f6812b3 100644 --- a/jingle/glue/fake_socket_factory.cc +++ b/jingle/glue/fake_socket_factory.cc @@ -4,6 +4,7 @@ #include "jingle/glue/fake_socket_factory.h" +#include "base/bind.h" #include "base/message_loop.h" #include "jingle/glue/utils.h" #include "third_party/libjingle/source/talk/base/asyncsocket.h" @@ -125,8 +126,8 @@ void FakeSocketManager::SendPacket(const net::IPEndPoint& from, DCHECK_EQ(MessageLoop::current(), message_loop_); message_loop_->PostTask( - FROM_HERE, NewRunnableMethod(this, &FakeSocketManager::DeliverPacket, - from, to, data)); + FROM_HERE, + base::Bind(&FakeSocketManager::DeliverPacket, this, from, to, data)); } void FakeSocketManager::DeliverPacket(const net::IPEndPoint& from, diff --git a/jingle/glue/pseudotcp_adapter_unittest.cc b/jingle/glue/pseudotcp_adapter_unittest.cc index d418826..65d7a56 100644 --- a/jingle/glue/pseudotcp_adapter_unittest.cc +++ b/jingle/glue/pseudotcp_adapter_unittest.cc @@ -6,6 +6,8 @@ #include <vector> +#include "base/bind.h" +#include "base/bind_helpers.h" #include "jingle/glue/thread_wrapper.h" #include "net/base/io_buffer.h" #include "net/base/net_errors.h" @@ -21,8 +23,6 @@ class FakeSocket; } // namespace } // namespace jingle_glue -DISABLE_RUNNABLE_METHOD_REFCOUNT(jingle_glue::FakeSocket); - namespace jingle_glue { namespace { @@ -136,9 +136,12 @@ class FakeSocket : public net::Socket { net::OldCompletionCallback* callback) OVERRIDE { DCHECK(buf); if (peer_socket_) { - MessageLoop::current()->PostDelayedTask(FROM_HERE, NewRunnableMethod( - peer_socket_, &FakeSocket::AppendInputPacket, - std::vector<char>(buf->data(), buf->data() + buf_len)), latency_ms_); + MessageLoop::current()->PostDelayedTask( + FROM_HERE, + base::Bind(&FakeSocket::AppendInputPacket, + base::Unretained(peer_socket_), + std::vector<char>(buf->data(), buf->data() + buf_len)), + latency_ms_); } return buf_len; @@ -186,7 +189,7 @@ class TCPChannelTester : public base::RefCountedThreadSafe<TCPChannelTester> { void Start() { message_loop_->PostTask( - FROM_HERE, NewRunnableMethod(this, &TCPChannelTester::DoStart)); + FROM_HERE, base::Bind(&TCPChannelTester::DoStart, this)); } void CheckResults() { diff --git a/jingle/glue/thread_wrapper.cc b/jingle/glue/thread_wrapper.cc index 4a47e5d..24ad922 100644 --- a/jingle/glue/thread_wrapper.cc +++ b/jingle/glue/thread_wrapper.cc @@ -4,6 +4,8 @@ #include "jingle/glue/thread_wrapper.h" +#include "base/bind.h" +#include "base/bind_helpers.h" #include "base/lazy_instance.h" #include "base/threading/thread_local.h" @@ -153,8 +155,9 @@ void JingleThreadWrapper::Send(talk_base::MessageHandler *handler, uint32 id, // Need to signal |pending_send_event_| here in case the thread is // sending message to another thread. pending_send_event_.Signal(); - message_loop_->PostTask(FROM_HERE, NewRunnableMethod( - this, &JingleThreadWrapper::ProcessPendingSends)); + message_loop_->PostTask(FROM_HERE, + base::Bind(&JingleThreadWrapper::ProcessPendingSends, + base::Unretained(this))); while (!pending_send.done_event.IsSignaled()) { @@ -204,13 +207,14 @@ void JingleThreadWrapper::PostTaskInternal( } if (delay_ms <= 0) { - message_loop_->PostTask(FROM_HERE, NewRunnableMethod( - this, &JingleThreadWrapper::RunTask, task_id)); + message_loop_->PostTask(FROM_HERE, + base::Bind(&JingleThreadWrapper::RunTask, + base::Unretained(this), task_id)); } else { - message_loop_->PostDelayedTask( - FROM_HERE, - NewRunnableMethod(this, &JingleThreadWrapper::RunTask, task_id), - delay_ms); + message_loop_->PostDelayedTask(FROM_HERE, + base::Bind(&JingleThreadWrapper::RunTask, + base::Unretained(this), task_id), + delay_ms); } } diff --git a/jingle/notifier/base/chrome_async_socket.cc b/jingle/notifier/base/chrome_async_socket.cc index 27f13a5..131f733 100644 --- a/jingle/notifier/base/chrome_async_socket.cc +++ b/jingle/notifier/base/chrome_async_socket.cc @@ -9,6 +9,7 @@ #include <cstdlib> #include "base/basictypes.h" +#include "base/bind.h" #include "base/compiler_specific.h" #include "base/logging.h" #include "base/message_loop.h" @@ -43,8 +44,7 @@ ChromeAsyncSocket::ChromeAsyncSocket( state_(STATE_CLOSED), error_(ERROR_NONE), net_error_(net::OK), - scoped_runnable_method_factory_( - ALLOW_THIS_IN_INITIALIZER_LIST(this)), + ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), read_state_(IDLE), read_buf_(new net::IOBufferWithSize(read_buf_size)), read_start_(0U), @@ -112,8 +112,7 @@ bool ChromeAsyncSocket::Connect(const talk_base::SocketAddress& address) { state_ = STATE_CONNECTING; - DCHECK(scoped_runnable_method_factory_.empty()); - scoped_runnable_method_factory_.RevokeAll(); + DCHECK_EQ(false, weak_factory_.HasWeakPtrs()); net::HostPortPair dest_host_port_pair(address.IPAsString(), address.port()); @@ -128,10 +127,9 @@ bool ChromeAsyncSocket::Connect(const talk_base::SocketAddress& address) { // the connect always happens asynchronously. MessageLoop* message_loop = MessageLoop::current(); CHECK(message_loop); - message_loop->PostTask( - FROM_HERE, - scoped_runnable_method_factory_.NewRunnableMethod( - &ChromeAsyncSocket::ProcessConnectDone, status)); + message_loop->PostTask(FROM_HERE, + base::Bind(&ChromeAsyncSocket::ProcessConnectDone, + weak_factory_.GetWeakPtr(), status)); } return true; } @@ -167,8 +165,7 @@ void ChromeAsyncSocket::PostDoRead() { CHECK(message_loop); message_loop->PostTask( FROM_HERE, - scoped_runnable_method_factory_.NewRunnableMethod( - &ChromeAsyncSocket::DoRead)); + base::Bind(&ChromeAsyncSocket::DoRead, weak_factory_.GetWeakPtr())); read_state_ = POSTED; } @@ -299,8 +296,7 @@ void ChromeAsyncSocket::PostDoWrite() { CHECK(message_loop); message_loop->PostTask( FROM_HERE, - scoped_runnable_method_factory_.NewRunnableMethod( - &ChromeAsyncSocket::DoWrite)); + base::Bind(&ChromeAsyncSocket::DoWrite, weak_factory_.GetWeakPtr())); write_state_ = POSTED; } @@ -367,7 +363,7 @@ bool ChromeAsyncSocket::Close() { // (not STATE_CLOSED) -> STATE_CLOSED void ChromeAsyncSocket::DoClose() { - scoped_runnable_method_factory_.RevokeAll(); + weak_factory_.InvalidateWeakPtrs(); if (transport_socket_.get()) { transport_socket_->Disconnect(); } @@ -404,7 +400,7 @@ bool ChromeAsyncSocket::StartTls(const std::string& domain_name) { DCHECK_EQ(write_end_, 0U); // Clear out any posted DoRead() tasks. - scoped_runnable_method_factory_.RevokeAll(); + weak_factory_.InvalidateWeakPtrs(); DCHECK(transport_socket_.get()); net::ClientSocketHandle* socket_handle = new net::ClientSocketHandle(); @@ -416,10 +412,9 @@ bool ChromeAsyncSocket::StartTls(const std::string& domain_name) { if (status != net::ERR_IO_PENDING) { MessageLoop* message_loop = MessageLoop::current(); CHECK(message_loop); - message_loop->PostTask( - FROM_HERE, - scoped_runnable_method_factory_.NewRunnableMethod( - &ChromeAsyncSocket::ProcessSSLConnectDone, status)); + message_loop->PostTask(FROM_HERE, + base::Bind(&ChromeAsyncSocket::ProcessSSLConnectDone, + weak_factory_.GetWeakPtr(), status)); } return true; } diff --git a/jingle/notifier/base/chrome_async_socket.h b/jingle/notifier/base/chrome_async_socket.h index 2960b6d..75c8873 100644 --- a/jingle/notifier/base/chrome_async_socket.h +++ b/jingle/notifier/base/chrome_async_socket.h @@ -17,7 +17,7 @@ #include "base/basictypes.h" #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_errors.h" #include "talk/xmpp/asyncsocket.h" @@ -189,8 +189,7 @@ class ChromeAsyncSocket : public buzz::AsyncSocket { net::Error net_error_; // Used by read/write loops. - ScopedRunnableMethodFactory<ChromeAsyncSocket> - scoped_runnable_method_factory_; + base::WeakPtrFactory<ChromeAsyncSocket> weak_factory_; // NULL iff state() == STATE_CLOSED. // diff --git a/jingle/notifier/base/proxy_resolving_client_socket.cc b/jingle/notifier/base/proxy_resolving_client_socket.cc index b4cc70c..cc5bcbe 100644 --- a/jingle/notifier/base/proxy_resolving_client_socket.cc +++ b/jingle/notifier/base/proxy_resolving_client_socket.cc @@ -5,6 +5,7 @@ #include "jingle/notifier/base/proxy_resolving_client_socket.h" #include "base/basictypes.h" +#include "base/bind.h" #include "base/compiler_specific.h" #include "base/logging.h" #include "googleurl/src/gurl.h" @@ -35,8 +36,7 @@ ProxyResolvingClientSocket::ProxyResolvingClientSocket( net::BoundNetLog::Make( request_context_getter->GetURLRequestContext()->net_log(), net::NetLog::SOURCE_SOCKET)), - scoped_runnable_method_factory_( - ALLOW_THIS_IN_INITIALIZER_LIST(this)), + ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), user_connect_callback_(NULL) { DCHECK(request_context_getter); net::URLRequestContext* request_context = @@ -117,8 +117,8 @@ int ProxyResolvingClientSocket::Connect(net::OldCompletionCallback* callback) { CHECK(message_loop); message_loop->PostTask( FROM_HERE, - scoped_runnable_method_factory_.NewRunnableMethod( - &ProxyResolvingClientSocket::ProcessProxyResolveDone, status)); + base::Bind(&ProxyResolvingClientSocket::ProcessProxyResolveDone, + weak_factory_.GetWeakPtr(), status)); } user_connect_callback_ = callback; return net::ERR_IO_PENDING; @@ -270,8 +270,8 @@ int ProxyResolvingClientSocket::ReconsiderProxyAfterError(int error) { CHECK(message_loop); message_loop->PostTask( FROM_HERE, - scoped_runnable_method_factory_.NewRunnableMethod( - &ProxyResolvingClientSocket::ProcessProxyResolveDone, rv)); + base::Bind(&ProxyResolvingClientSocket::ProcessProxyResolveDone, + weak_factory_.GetWeakPtr(), rv)); // Since we potentially have another try to go (trying the direct connect) // set the return code code to ERR_IO_PENDING. rv = net::ERR_IO_PENDING; diff --git a/jingle/notifier/base/proxy_resolving_client_socket.h b/jingle/notifier/base/proxy_resolving_client_socket.h index 0cdd533..5ed2216 100644 --- a/jingle/notifier/base/proxy_resolving_client_socket.h +++ b/jingle/notifier/base/proxy_resolving_client_socket.h @@ -11,6 +11,7 @@ #include "base/basictypes.h" #include "base/memory/ref_counted.h" +#include "base/memory/weak_ptr.h" #include "net/base/completion_callback.h" #include "net/base/host_port_pair.h" #include "net/base/net_errors.h" @@ -90,8 +91,7 @@ class ProxyResolvingClientSocket : public net::StreamSocket { net::HostPortPair dest_host_port_pair_; bool tried_direct_connect_fallback_; net::BoundNetLog bound_net_log_; - ScopedRunnableMethodFactory<ProxyResolvingClientSocket> - scoped_runnable_method_factory_; + base::WeakPtrFactory<ProxyResolvingClientSocket> weak_factory_; // The callback passed to Connect(). net::OldCompletionCallback* user_connect_callback_; diff --git a/jingle/notifier/base/task_pump.cc b/jingle/notifier/base/task_pump.cc index 0395314..001f1ab 100644 --- a/jingle/notifier/base/task_pump.cc +++ b/jingle/notifier/base/task_pump.cc @@ -2,14 +2,14 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "base/bind.h" #include "base/message_loop.h" #include "jingle/notifier/base/task_pump.h" namespace notifier { TaskPump::TaskPump() - : scoped_runnable_method_factory_( - ALLOW_THIS_IN_INITIALIZER_LIST(this)), + : ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), posted_wake_(false), stopped_(false) {} @@ -25,8 +25,7 @@ void TaskPump::WakeTasks() { // Do the requested wake up. current_message_loop->PostTask( FROM_HERE, - scoped_runnable_method_factory_.NewRunnableMethod( - &TaskPump::CheckAndRunTasks)); + base::Bind(&TaskPump::CheckAndRunTasks, weak_factory_.GetWeakPtr())); posted_wake_ = true; } } diff --git a/jingle/notifier/base/task_pump.h b/jingle/notifier/base/task_pump.h index 958a152..440dba4 100644 --- a/jingle/notifier/base/task_pump.h +++ b/jingle/notifier/base/task_pump.h @@ -5,6 +5,7 @@ #ifndef JINGLE_NOTIFIER_BASE_TASK_PUMP_H_ #define JINGLE_NOTIFIER_BASE_TASK_PUMP_H_ +#include "base/memory/weak_ptr.h" #include "base/task.h" #include "base/threading/non_thread_safe.h" #include "talk/base/taskrunner.h" @@ -29,7 +30,7 @@ class TaskPump : public talk_base::TaskRunner { void CheckAndRunTasks(); base::NonThreadSafe non_thread_safe_; - ScopedRunnableMethodFactory<TaskPump> scoped_runnable_method_factory_; + base::WeakPtrFactory<TaskPump> weak_factory_; bool posted_wake_; bool stopped_; diff --git a/jingle/notifier/listener/mediator_thread_impl.cc b/jingle/notifier/listener/mediator_thread_impl.cc index 6e89ed6..ba85ac77 100644 --- a/jingle/notifier/listener/mediator_thread_impl.cc +++ b/jingle/notifier/listener/mediator_thread_impl.cc @@ -4,6 +4,7 @@ #include "jingle/notifier/listener/mediator_thread_impl.h" +#include "base/bind.h" #include "base/logging.h" #include "base/memory/scoped_ptr.h" #include "base/memory/weak_ptr.h" @@ -242,9 +243,7 @@ void MediatorThreadImpl::Login(const buzz::XmppClientSettings& settings) { DCHECK(parent_message_loop_proxy_->BelongsToCurrentThread()); io_message_loop_proxy_->PostTask( FROM_HERE, - NewRunnableMethod(core_.get(), - &MediatorThreadImpl::Core::Login, - settings)); + base::Bind(&MediatorThreadImpl::Core::Login, core_.get(), settings)); } void MediatorThreadImpl::Logout() { @@ -256,8 +255,8 @@ void MediatorThreadImpl::ListenForUpdates() { DCHECK(parent_message_loop_proxy_->BelongsToCurrentThread()); io_message_loop_proxy_->PostTask( FROM_HERE, - NewRunnableMethod(core_.get(), - &MediatorThreadImpl::Core::ListenForPushNotifications)); + base::Bind(&MediatorThreadImpl::Core::ListenForPushNotifications, + core_.get())); } void MediatorThreadImpl::SubscribeForUpdates( @@ -265,10 +264,8 @@ void MediatorThreadImpl::SubscribeForUpdates( DCHECK(parent_message_loop_proxy_->BelongsToCurrentThread()); io_message_loop_proxy_->PostTask( FROM_HERE, - NewRunnableMethod( - core_.get(), - &MediatorThreadImpl::Core::SubscribeForPushNotifications, - subscriptions)); + base::Bind(&MediatorThreadImpl::Core::SubscribeForPushNotifications, + core_.get(), subscriptions)); } void MediatorThreadImpl::SendNotification( @@ -276,9 +273,8 @@ void MediatorThreadImpl::SendNotification( DCHECK(parent_message_loop_proxy_->BelongsToCurrentThread()); io_message_loop_proxy_->PostTask( FROM_HERE, - NewRunnableMethod(core_.get(), - &MediatorThreadImpl::Core::SendNotification, - data)); + base::Bind(&MediatorThreadImpl::Core::SendNotification, core_.get(), + data)); } void MediatorThreadImpl::UpdateXmppSettings( @@ -286,9 +282,8 @@ void MediatorThreadImpl::UpdateXmppSettings( DCHECK(parent_message_loop_proxy_->BelongsToCurrentThread()); io_message_loop_proxy_->PostTask( FROM_HERE, - NewRunnableMethod(core_.get(), - &MediatorThreadImpl::Core::UpdateXmppSettings, - settings)); + base::Bind(&MediatorThreadImpl::Core::UpdateXmppSettings, core_.get(), + settings)); } void MediatorThreadImpl::TriggerOnConnectForTest( @@ -296,16 +291,13 @@ void MediatorThreadImpl::TriggerOnConnectForTest( DCHECK(parent_message_loop_proxy_->BelongsToCurrentThread()); io_message_loop_proxy_->PostTask( FROM_HERE, - NewRunnableMethod(core_.get(), - &MediatorThreadImpl::Core::OnConnect, - base_task)); + base::Bind(&MediatorThreadImpl::Core::OnConnect, core_.get(), base_task)); } void MediatorThreadImpl::LogoutImpl() { io_message_loop_proxy_->PostTask( FROM_HERE, - NewRunnableMethod(core_.get(), - &MediatorThreadImpl::Core::Disconnect)); + base::Bind(&MediatorThreadImpl::Core::Disconnect, core_.get())); } } // namespace notifier |