diff options
Diffstat (limited to 'remoting')
58 files changed, 236 insertions, 217 deletions
diff --git a/remoting/client/chromoting_client.cc b/remoting/client/chromoting_client.cc index 22569625..7251bd6 100644 --- a/remoting/client/chromoting_client.cc +++ b/remoting/client/chromoting_client.cc @@ -14,6 +14,14 @@ namespace remoting { +ChromotingClient::QueuedVideoPacket::QueuedVideoPacket( + const VideoPacket* packet, const base::Closure& done) + : packet(packet), done(done) { +} + +ChromotingClient::QueuedVideoPacket::~QueuedVideoPacket() { +} + ChromotingClient::ChromotingClient(const ClientConfig& config, ClientContext* context, protocol::ConnectionToHost* connection, @@ -82,14 +90,13 @@ void ChromotingClient::Repaint() { } void ChromotingClient::ProcessVideoPacket(const VideoPacket* packet, - Task* done) { + const base::Closure& done) { DCHECK(message_loop()->BelongsToCurrentThread()); // If the video packet is empty then drop it. Empty packets are used to // maintain activity on the network. if (!packet->has_data() || packet->data().size() == 0) { - done->Run(); - delete done; + done.Run(); return; } @@ -172,8 +179,7 @@ void ChromotingClient::OnPacketDone(bool last_packet, (base::Time::Now() - decode_start).InMilliseconds()); } - received_packets_.front().done->Run(); - delete received_packets_.front().done; + received_packets_.front().done.Run(); received_packets_.pop_front(); packet_being_processed_ = false; @@ -199,7 +205,7 @@ void ChromotingClient::Initialize() { //////////////////////////////////////////////////////////////////////////// // ClientStub control channel interface. void ChromotingClient::BeginSessionResponse( - const protocol::LocalLoginStatus* msg, Task* done) { + const protocol::LocalLoginStatus* msg, const base::Closure& done) { if (!message_loop()->BelongsToCurrentThread()) { thread_proxy_.PostTask(FROM_HERE, base::Bind( &ChromotingClient::BeginSessionResponse, base::Unretained(this), @@ -216,8 +222,7 @@ void ChromotingClient::BeginSessionResponse( } view_->UpdateLoginStatus(msg->success(), msg->error_info()); - done->Run(); - delete done; + done.Run(); } } // namespace remoting diff --git a/remoting/client/chromoting_client.h b/remoting/client/chromoting_client.h index 5d18448..252a2bc 100644 --- a/remoting/client/chromoting_client.h +++ b/remoting/client/chromoting_client.h @@ -66,20 +66,19 @@ class ChromotingClient : public protocol::ConnectionToHost::HostEventCallback, // ClientStub implementation. virtual void BeginSessionResponse(const protocol::LocalLoginStatus* msg, - Task* done) OVERRIDE; + const base::Closure& done) OVERRIDE; // VideoStub implementation. virtual void ProcessVideoPacket(const VideoPacket* packet, - Task* done) OVERRIDE; + const base::Closure& done) OVERRIDE; virtual int GetPendingPackets() OVERRIDE; private: struct QueuedVideoPacket { - QueuedVideoPacket(const VideoPacket* packet, Task* done) - : packet(packet), done(done) { - } + QueuedVideoPacket(const VideoPacket* packet, const base::Closure& done); + ~QueuedVideoPacket(); const VideoPacket* packet; - Task* done; + base::Closure done; }; base::MessageLoopProxy* message_loop(); diff --git a/remoting/client/plugin/chromoting_instance.cc b/remoting/client/plugin/chromoting_instance.cc index 44c9d18..6a32a0b 100644 --- a/remoting/client/plugin/chromoting_instance.cc +++ b/remoting/client/plugin/chromoting_instance.cc @@ -318,7 +318,7 @@ void ChromotingInstance::SubmitLoginInfo(const std::string& username, host_connection_->host_stub()->BeginSessionRequest( credentials, - new DeleteTask<protocol::LocalLoginCredentials>(credentials)); + base::Bind(&DeletePointer<protocol::LocalLoginCredentials>, credentials)); } void ChromotingInstance::SetScaleToFit(bool scale_to_fit) { diff --git a/remoting/host/chromoting_host.cc b/remoting/host/chromoting_host.cc index 8eb6b33..7d738d8 100644 --- a/remoting/host/chromoting_host.cc +++ b/remoting/host/chromoting_host.cc @@ -465,7 +465,7 @@ void ChromotingHost::AddAuthenticatedClient( protocol::LocalLoginStatus* status = new protocol::LocalLoginStatus(); status->set_success(true); connection->client_stub()->BeginSessionResponse( - status, new DeleteTask<protocol::LocalLoginStatus>(status)); + status, base::Bind(&DeletePointer<protocol::LocalLoginStatus>, status)); // Disconnect all other clients. // Iterate over a copy of the list of clients, to avoid mutating the list @@ -526,7 +526,7 @@ void ChromotingHost::LocalLoginFailed( protocol::LocalLoginStatus* status = new protocol::LocalLoginStatus(); status->set_success(false); connection->client_stub()->BeginSessionResponse( - status, new DeleteTask<protocol::LocalLoginStatus>(status)); + status, base::Bind(&DeletePointer<protocol::LocalLoginStatus>, status)); } void ChromotingHost::ProcessPreAuthentication( diff --git a/remoting/host/chromoting_host_unittest.cc b/remoting/host/chromoting_host_unittest.cc index 2ae5ee4..4f48e53 100644 --- a/remoting/host/chromoting_host_unittest.cc +++ b/remoting/host/chromoting_host_unittest.cc @@ -50,8 +50,7 @@ void PostQuitTask(MessageLoop* message_loop) { // Run the task and delete it afterwards. This action is used to deal with // done callbacks. ACTION(RunDoneTask) { - arg1->Run(); - delete arg1; + arg1.Run(); } ACTION_P(QuitMainMessageLoop, message_loop) { @@ -118,11 +117,9 @@ class ChromotingHostTest : public testing::Test { session_config2_ = SessionConfig::GetDefault(); ON_CALL(video_stub_, ProcessVideoPacket(_, _)) - .WillByDefault( - DoAll(DeleteArg<0>(), DeleteArg<1>())); + .WillByDefault(DeleteArg<0>()); ON_CALL(video_stub2_, ProcessVideoPacket(_, _)) - .WillByDefault( - DoAll(DeleteArg<0>(), DeleteArg<1>())); + .WillByDefault(DeleteArg<0>()); ON_CALL(*connection_.get(), video_stub()) .WillByDefault(Return(&video_stub_)); ON_CALL(*connection_.get(), client_stub()) @@ -191,7 +188,7 @@ class ChromotingHostTest : public testing::Test { NewRunnableMethod(client.get(), &ClientSession::BeginSessionRequest, &credentials_, - NewRunnableFunction(&DummyDoneTask))); + base::Bind(&DummyDoneTask))); } // Helper method to remove a client connection from ChromotingHost. @@ -501,4 +498,5 @@ TEST_F(ChromotingHostTest, CurtainModeIT2Me) { host_->set_it2me(false); EXPECT_THAT(curtain_activated, false); } + } // namespace remoting diff --git a/remoting/host/client_session.cc b/remoting/host/client_session.cc index 36bb89c..78dcddf 100644 --- a/remoting/host/client_session.cc +++ b/remoting/host/client_session.cc @@ -48,10 +48,11 @@ ClientSession::~ClientSession() { } void ClientSession::BeginSessionRequest( - const protocol::LocalLoginCredentials* credentials, Task* done) { + const protocol::LocalLoginCredentials* credentials, + const base::Closure& done) { DCHECK(event_handler_); - base::ScopedTaskRunner done_runner(done); + base::ScopedClosureRunner done_runner(done); bool success = false; switch (credentials->type()) { diff --git a/remoting/host/client_session.h b/remoting/host/client_session.h index bc35a45..013dc57 100644 --- a/remoting/host/client_session.h +++ b/remoting/host/client_session.h @@ -50,7 +50,8 @@ class ClientSession : public protocol::HostStub, // protocol::HostStub interface. virtual void BeginSessionRequest( - const protocol::LocalLoginCredentials* credentials, Task* done); + const protocol::LocalLoginCredentials* credentials, + const base::Closure& done); // protocol::InputStub interface. virtual void InjectKeyEvent(const protocol::KeyEvent& event); diff --git a/remoting/host/client_session_unittest.cc b/remoting/host/client_session_unittest.cc index be66a80..d7e1124 100644 --- a/remoting/host/client_session_unittest.cc +++ b/remoting/host/client_session_unittest.cc @@ -9,16 +9,6 @@ namespace remoting { -namespace { - -// A task that does nothing. -class DummyTask : public Task { - public: - void Run() {} -}; - -} // namespace - using protocol::MockConnectionToClient; using protocol::MockConnectionToClientEventHandler; using protocol::MockHostStub; @@ -131,7 +121,7 @@ TEST_F(ClientSessionTest, InputStubFilter) { // because the client isn't authenticated yet. client_session_->InjectKeyEvent(key_event1); client_session_->InjectMouseEvent(mouse_event1); - client_session_->BeginSessionRequest(&credentials, new DummyTask()); + client_session_->BeginSessionRequest(&credentials, base::Closure()); // These events should get through to the input stub. client_session_->InjectKeyEvent(key_event2_down); client_session_->InjectKeyEvent(key_event2_up); @@ -166,7 +156,7 @@ TEST_F(ClientSessionTest, LocalInputTest) { EXPECT_CALL(input_stub_, InjectMouseEvent(EqualsMouseEvent(100, 101))); EXPECT_CALL(input_stub_, InjectMouseEvent(EqualsMouseEvent(200, 201))); - client_session_->BeginSessionRequest(&credentials, new DummyTask()); + client_session_->BeginSessionRequest(&credentials, base::Closure()); // This event should get through to the input stub. client_session_->InjectMouseEvent(mouse_event1); // This one should too because the local event echoes the remote one. @@ -219,7 +209,7 @@ TEST_F(ClientSessionTest, ClampMouseEvents) { EXPECT_CALL(*user_authenticator_, Authenticate(_, _)) .WillOnce(Return(true)); EXPECT_CALL(session_event_handler_, LocalLoginSucceeded(_)); - client_session_->BeginSessionRequest(&credentials, new DummyTask()); + client_session_->BeginSessionRequest(&credentials, base::Closure()); int input_x[3] = { -999, 100, 999 }; int expected_x[3] = { 0, 100, 199 }; diff --git a/remoting/host/screen_recorder.cc b/remoting/host/screen_recorder.cc index cca7c37..98266e3 100644 --- a/remoting/host/screen_recorder.cc +++ b/remoting/host/screen_recorder.cc @@ -268,17 +268,16 @@ void ScreenRecorder::DoSendVideoPacket(VideoPacket* packet) { for (ConnectionToClientList::const_iterator i = connections_.begin(); i < connections_.end(); ++i) { - Task* done_task = NULL; + base::Closure done_task; // Call FrameSentCallback() only for the last packet in the first // connection. if (last && i == connections_.begin()) { - done_task = NewRunnableMethod(this, &ScreenRecorder::FrameSentCallback, - packet); + done_task = base::Bind(&ScreenRecorder::FrameSentCallback, this, packet); } else { // TODO(hclam): Fix this code since it causes multiple deletion if there's // more than one connection. - done_task = new DeleteTask<VideoPacket>(packet); + done_task = base::Bind(&DeletePointer<VideoPacket>, packet); } (*i)->video_stub()->ProcessVideoPacket(packet, done_task); diff --git a/remoting/host/screen_recorder_unittest.cc b/remoting/host/screen_recorder_unittest.cc index 4a821e9..05c0904 100644 --- a/remoting/host/screen_recorder_unittest.cc +++ b/remoting/host/screen_recorder_unittest.cc @@ -48,8 +48,7 @@ ACTION(FinishEncode) { } ACTION(FinishSend) { - arg1->Run(); - delete arg1; + arg1.Run(); } // Helper method to quit the main message loop. @@ -131,7 +130,7 @@ TEST_F(ScreenRecorderTest, OneRecordCycle) { // Expect the client be notified. EXPECT_CALL(video_stub, ProcessVideoPacket(_, _)) .Times(1) - .WillOnce(DoAll(DeleteArg<0>(), DeleteArg<1>())); + .WillOnce(DeleteArg<0>()); EXPECT_CALL(video_stub, GetPendingPackets()) .Times(AtLeast(0)) .WillRepeatedly(Return(0)); diff --git a/remoting/protocol/buffered_socket_writer.cc b/remoting/protocol/buffered_socket_writer.cc index c89a50e..ce8dd87 100644 --- a/remoting/protocol/buffered_socket_writer.cc +++ b/remoting/protocol/buffered_socket_writer.cc @@ -4,6 +4,7 @@ #include "remoting/protocol/buffered_socket_writer.h" +#include "base/bind.h" #include "base/location.h" #include "base/message_loop_proxy.h" #include "base/stl_util.h" @@ -14,13 +15,14 @@ namespace protocol { class BufferedSocketWriterBase::PendingPacket { public: - PendingPacket(scoped_refptr<net::IOBufferWithSize> data, Task* done_task) + PendingPacket(scoped_refptr<net::IOBufferWithSize> data, + const base::Closure& done_task) : data_(data), done_task_(done_task) { } ~PendingPacket() { - if (done_task_.get()) - done_task_->Run(); + if (!done_task_.is_null()) + done_task_.Run(); } net::IOBufferWithSize* data() { @@ -29,7 +31,7 @@ class BufferedSocketWriterBase::PendingPacket { private: scoped_refptr<net::IOBufferWithSize> data_; - scoped_ptr<Task> done_task_; + base::Closure done_task_; DISALLOW_COPY_AND_ASSIGN(PendingPacket); }; @@ -48,22 +50,22 @@ BufferedSocketWriterBase::BufferedSocketWriterBase( BufferedSocketWriterBase::~BufferedSocketWriterBase() { } void BufferedSocketWriterBase::Init(net::Socket* socket, - WriteFailedCallback* callback) { - // TODO(garykac) Save copy of WriteFailedCallback. - base::AutoLock auto_lock(lock_); + const WriteFailedCallback& callback) { + DCHECK(message_loop_->BelongsToCurrentThread()); + DCHECK(socket); socket_ = socket; - DCHECK(socket_); + write_failed_callback_ = callback; } bool BufferedSocketWriterBase::Write( - scoped_refptr<net::IOBufferWithSize> data, Task* done_task) { + scoped_refptr<net::IOBufferWithSize> data, const base::Closure& done_task) { { base::AutoLock auto_lock(lock_); queue_.push_back(new PendingPacket(data, done_task)); buffer_size_ += data->size(); } message_loop_->PostTask( - FROM_HERE, NewRunnableMethod(this, &BufferedSocketWriterBase::DoWrite)); + FROM_HERE, base::Bind(&BufferedSocketWriterBase::DoWrite, this)); return true; } @@ -101,8 +103,8 @@ void BufferedSocketWriterBase::DoWrite() { write_pending_ = true; } else { HandleError(result); - if (write_failed_callback_.get()) - write_failed_callback_->Run(result); + if (!write_failed_callback_.is_null()) + write_failed_callback_.Run(result); } return; } @@ -115,8 +117,8 @@ void BufferedSocketWriterBase::OnWritten(int result) { if (result < 0) { HandleError(result); - if (write_failed_callback_.get()) - write_failed_callback_->Run(result); + if (!write_failed_callback_.is_null()) + write_failed_callback_.Run(result); return; } diff --git a/remoting/protocol/buffered_socket_writer.h b/remoting/protocol/buffered_socket_writer.h index ebdc200..4fd7f79 100644 --- a/remoting/protocol/buffered_socket_writer.h +++ b/remoting/protocol/buffered_socket_writer.h @@ -7,6 +7,7 @@ #include <list> +#include "base/callback.h" #include "base/memory/ref_counted.h" #include "base/synchronization/lock.h" #include "net/base/io_buffer.h" @@ -37,7 +38,7 @@ namespace protocol { class BufferedSocketWriterBase : public base::RefCountedThreadSafe<BufferedSocketWriterBase> { public: - typedef Callback1<int>::Type WriteFailedCallback; + typedef base::Callback<void(int)> WriteFailedCallback; explicit BufferedSocketWriterBase(base::MessageLoopProxy* message_loop); virtual ~BufferedSocketWriterBase(); @@ -46,11 +47,12 @@ class BufferedSocketWriterBase // to access the socket in the future. |callback| will be called after each // failed write. Caller retains ownership of |socket|. // TODO(sergeyu): Change it so that it take ownership of |socket|. - void Init(net::Socket* socket, WriteFailedCallback* callback); + void Init(net::Socket* socket, const WriteFailedCallback& callback); // Puts a new data chunk in the buffer. Returns false and doesn't enqueue // the data if called before Init(). Can be called on any thread. - bool Write(scoped_refptr<net::IOBufferWithSize> buffer, Task* done_task); + bool Write(scoped_refptr<net::IOBufferWithSize> buffer, + const base::Closure& done_task); // Returns current size of the buffer. Can be called on any thread. int GetBufferSize(); @@ -95,7 +97,7 @@ class BufferedSocketWriterBase net::Socket* socket_; scoped_refptr<base::MessageLoopProxy> message_loop_; - scoped_ptr<WriteFailedCallback> write_failed_callback_; + WriteFailedCallback write_failed_callback_; bool write_pending_; diff --git a/remoting/protocol/client_control_sender.cc b/remoting/protocol/client_control_sender.cc index aa7549a..1c16cf3 100644 --- a/remoting/protocol/client_control_sender.cc +++ b/remoting/protocol/client_control_sender.cc @@ -19,17 +19,17 @@ namespace protocol { ClientControlSender::ClientControlSender(base::MessageLoopProxy* message_loop, net::Socket* socket) : buffered_writer_(new BufferedSocketWriter(message_loop)) { - buffered_writer_->Init(socket, NULL); + buffered_writer_->Init(socket, BufferedSocketWriter::WriteFailedCallback()); } ClientControlSender::~ClientControlSender() { } void ClientControlSender::BeginSessionResponse(const LocalLoginStatus* msg, - Task* done) { + const base::Closure& done) { protocol::ControlMessage message; - message.mutable_begin_session_response()->mutable_login_status()->CopyFrom( - *msg); + message.mutable_begin_session_response()->mutable_login_status()-> + CopyFrom(*msg); buffered_writer_->Write(SerializeAndFrameMessage(message), done); } diff --git a/remoting/protocol/client_control_sender.h b/remoting/protocol/client_control_sender.h index 47911d5..4668a05 100644 --- a/remoting/protocol/client_control_sender.h +++ b/remoting/protocol/client_control_sender.h @@ -42,7 +42,7 @@ class ClientControlSender : public ClientStub { virtual ~ClientControlSender(); virtual void BeginSessionResponse(const LocalLoginStatus* msg, - Task* done) OVERRIDE; + const base::Closure& done) OVERRIDE; // Stop writing. Must be called on the network thread when the // underlying socket is being destroyed. diff --git a/remoting/protocol/client_message_dispatcher.cc b/remoting/protocol/client_message_dispatcher.cc index 68bf4617..3112306 100644 --- a/remoting/protocol/client_message_dispatcher.cc +++ b/remoting/protocol/client_message_dispatcher.cc @@ -33,12 +33,13 @@ void ClientMessageDispatcher::Initialize( control_message_reader_->Init( session->control_channel(), - NewCallback(this, &ClientMessageDispatcher::OnControlMessageReceived)); + base::Bind(&ClientMessageDispatcher::OnControlMessageReceived, + base::Unretained(this))); return; } void ClientMessageDispatcher::OnControlMessageReceived( - ControlMessage* message, Task* done_task) { + ControlMessage* message, const base::Closure& done_task) { if (message->has_begin_session_response()) { const BeginSessionResponse& response = message->begin_session_response(); if (response.has_login_status() && @@ -51,8 +52,7 @@ void ClientMessageDispatcher::OnControlMessageReceived( LOG(WARNING) << "Invalid control message received."; - done_task->Run(); - delete done_task; + done_task.Run(); } } // namespace protocol diff --git a/remoting/protocol/client_message_dispatcher.h b/remoting/protocol/client_message_dispatcher.h index 1c9cbe4..47227af 100644 --- a/remoting/protocol/client_message_dispatcher.h +++ b/remoting/protocol/client_message_dispatcher.h @@ -7,7 +7,6 @@ #include "base/basictypes.h" #include "base/memory/scoped_ptr.h" -#include "base/task.h" #include "remoting/protocol/message_reader.h" namespace remoting { @@ -40,7 +39,8 @@ class ClientMessageDispatcher { void Initialize(protocol::Session* session, ClientStub* client_stub); private: - void OnControlMessageReceived(ControlMessage* message, Task* done_task); + void OnControlMessageReceived(ControlMessage* message, + const base::Closure& done_task); // MessageReader that runs on the control channel. It runs a loop // that parses data on the channel and then calls the corresponding handler diff --git a/remoting/protocol/client_stub.h b/remoting/protocol/client_stub.h index 21b3219..49b6740f 100644 --- a/remoting/protocol/client_stub.h +++ b/remoting/protocol/client_stub.h @@ -11,8 +11,7 @@ #define REMOTING_PROTOCOL_CLIENT_STUB_H_ #include "base/basictypes.h" - -class Task; +#include "base/callback.h" namespace remoting { namespace protocol { @@ -26,7 +25,7 @@ class ClientStub { virtual ~ClientStub() {} virtual void BeginSessionResponse(const LocalLoginStatus* msg, - Task* done) = 0; + const base::Closure& done) = 0; private: DISALLOW_COPY_AND_ASSIGN(ClientStub); diff --git a/remoting/protocol/connection_to_client.cc b/remoting/protocol/connection_to_client.cc index c83e161..4f8a46b 100644 --- a/remoting/protocol/connection_to_client.cc +++ b/remoting/protocol/connection_to_client.cc @@ -46,7 +46,8 @@ void ConnectionToClient::Init(protocol::Session* session) { DCHECK(message_loop_->BelongsToCurrentThread()); session_.reset(session); session_->SetStateChangeCallback( - NewCallback(this, &ConnectionToClient::OnSessionStateChange)); + base::Bind(&ConnectionToClient::OnSessionStateChange, + base::Unretained(this))); } protocol::Session* ConnectionToClient::session() { diff --git a/remoting/protocol/connection_to_client_unittest.cc b/remoting/protocol/connection_to_client_unittest.cc index 4199a02..ce14b96 100644 --- a/remoting/protocol/connection_to_client_unittest.cc +++ b/remoting/protocol/connection_to_client_unittest.cc @@ -2,6 +2,7 @@ // 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 "base/message_loop_proxy.h" #include "remoting/base/base_mock_objects.h" @@ -35,9 +36,9 @@ class ConnectionToClientTest : public testing::Test { viewer_->set_input_stub(&input_stub_); viewer_->Init(session_); EXPECT_CALL(handler_, OnConnectionOpened(viewer_.get())); - session_->state_change_callback()->Run( + session_->state_change_callback().Run( protocol::Session::CONNECTED); - session_->state_change_callback()->Run( + session_->state_change_callback().Run( protocol::Session::CONNECTED_CHANNELS); message_loop_.RunAllPending(); } @@ -59,7 +60,7 @@ TEST_F(ConnectionToClientTest, SendUpdateStream) { // Then send the actual data. VideoPacket* packet = new VideoPacket(); viewer_->video_stub()->ProcessVideoPacket( - packet, new DeleteTask<VideoPacket>(packet)); + packet, base::Bind(&DeletePointer<VideoPacket>, packet)); message_loop_.RunAllPending(); @@ -79,7 +80,7 @@ TEST_F(ConnectionToClientTest, NoWriteAfterDisconnect) { // Then send the actual data. VideoPacket* packet = new VideoPacket(); viewer_->video_stub()->ProcessVideoPacket( - packet, new DeleteTask<VideoPacket>(packet)); + packet, base::Bind(&DeletePointer<VideoPacket>, packet)); // And then close the connection to ConnectionToClient. viewer_->Disconnect(); @@ -92,11 +93,11 @@ TEST_F(ConnectionToClientTest, NoWriteAfterDisconnect) { TEST_F(ConnectionToClientTest, StateChange) { EXPECT_CALL(handler_, OnConnectionClosed(viewer_.get())); - session_->state_change_callback()->Run(protocol::Session::CLOSED); + session_->state_change_callback().Run(protocol::Session::CLOSED); message_loop_.RunAllPending(); EXPECT_CALL(handler_, OnConnectionFailed(viewer_.get())); - session_->state_change_callback()->Run(protocol::Session::FAILED); + session_->state_change_callback().Run(protocol::Session::FAILED); message_loop_.RunAllPending(); } diff --git a/remoting/protocol/connection_to_host.cc b/remoting/protocol/connection_to_host.cc index e2fe74a..fd5463c 100644 --- a/remoting/protocol/connection_to_host.cc +++ b/remoting/protocol/connection_to_host.cc @@ -140,7 +140,8 @@ void ConnectionToHost::OnSessionManagerInitialized() { protocol::GenerateSupportAuthToken(local_jid_, access_code_); session_.reset(session_manager_->Connect( host_jid_, host_public_key_, client_token, candidate_config, - NewCallback(this, &ConnectionToHost::OnSessionStateChange))); + base::Bind(&ConnectionToHost::OnSessionStateChange, + base::Unretained(this)))); // Set the shared-secret for securing SSL channels. session_->set_shared_secret(access_code_); diff --git a/remoting/protocol/fake_session.cc b/remoting/protocol/fake_session.cc index 0cda8bb..a794e41 100644 --- a/remoting/protocol/fake_session.cc +++ b/remoting/protocol/fake_session.cc @@ -220,8 +220,8 @@ FakeUdpSocket* FakeSession::GetDatagramChannel(const std::string& name) { return datagram_channels_[name]; } -void FakeSession::SetStateChangeCallback(StateChangeCallback* callback) { - callback_.reset(callback); +void FakeSession::SetStateChangeCallback(const StateChangeCallback& callback) { + callback_ = callback; } Session::Error FakeSession::error() { diff --git a/remoting/protocol/fake_session.h b/remoting/protocol/fake_session.h index 0e098b4..de56176 100644 --- a/remoting/protocol/fake_session.h +++ b/remoting/protocol/fake_session.h @@ -124,7 +124,7 @@ class FakeSession : public Session { FakeSession(); virtual ~FakeSession(); - StateChangeCallback* state_change_callback() { return callback_.get(); } + const StateChangeCallback& state_change_callback() { return callback_; } void set_message_loop(MessageLoop* message_loop) { message_loop_ = message_loop; @@ -138,7 +138,7 @@ class FakeSession : public Session { FakeUdpSocket* GetDatagramChannel(const std::string& name); // Session interface. - virtual void SetStateChangeCallback(StateChangeCallback* callback); + virtual void SetStateChangeCallback(const StateChangeCallback& callback); virtual Session::Error error(); @@ -167,7 +167,7 @@ class FakeSession : public Session { virtual void Close(); public: - scoped_ptr<StateChangeCallback> callback_; + StateChangeCallback callback_; scoped_ptr<const CandidateSessionConfig> candidate_config_; SessionConfig config_; MessageLoop* message_loop_; diff --git a/remoting/protocol/host_control_sender.cc b/remoting/protocol/host_control_sender.cc index 6e71341..bdf1b95 100644 --- a/remoting/protocol/host_control_sender.cc +++ b/remoting/protocol/host_control_sender.cc @@ -19,14 +19,14 @@ namespace protocol { HostControlSender::HostControlSender(base::MessageLoopProxy* message_loop, net::Socket* socket) : buffered_writer_(new BufferedSocketWriter(message_loop)) { - buffered_writer_->Init(socket, NULL); + buffered_writer_->Init(socket, BufferedSocketWriter::WriteFailedCallback()); } HostControlSender::~HostControlSender() { } void HostControlSender::BeginSessionRequest(const LocalLoginCredentials* msg, - Task* done) { + const base::Closure& done) { protocol::ControlMessage message; message.mutable_begin_session_request()->mutable_credentials()->CopyFrom( *msg); diff --git a/remoting/protocol/host_control_sender.h b/remoting/protocol/host_control_sender.h index c1425da..b1e15b4 100644 --- a/remoting/protocol/host_control_sender.h +++ b/remoting/protocol/host_control_sender.h @@ -13,11 +13,10 @@ #define REMOTING_PROTOCOL_HOST_STUB_IMPL_H_ #include "base/basictypes.h" +#include "base/callback.h" #include "base/memory/ref_counted.h" #include "remoting/protocol/host_stub.h" -class Task; - namespace base { class MessageLoopProxy; } // namespace base @@ -41,7 +40,7 @@ class HostControlSender : public HostStub { virtual ~HostControlSender(); virtual void BeginSessionRequest( - const LocalLoginCredentials* credentials, Task* done); + const LocalLoginCredentials* credentials, const base::Closure& done); // Stop writing. Must be called on the network thread when the // underlying socket is being destroyed. diff --git a/remoting/protocol/host_message_dispatcher.cc b/remoting/protocol/host_message_dispatcher.cc index 1e395da..7af2cc1 100644 --- a/remoting/protocol/host_message_dispatcher.cc +++ b/remoting/protocol/host_message_dispatcher.cc @@ -44,14 +44,16 @@ void HostMessageDispatcher::Initialize( // Initialize the readers on the sockets provided by channels. event_message_reader_->Init( connection->session()->event_channel(), - NewCallback(this, &HostMessageDispatcher::OnEventMessageReceived)); + base::Bind(&HostMessageDispatcher::OnEventMessageReceived, + base::Unretained(this))); control_message_reader_->Init( connection->session()->control_channel(), - NewCallback(this, &HostMessageDispatcher::OnControlMessageReceived)); + base::Bind(&HostMessageDispatcher::OnControlMessageReceived, + base::Unretained(this))); } void HostMessageDispatcher::OnControlMessageReceived( - ControlMessage* message, Task* done_task) { + ControlMessage* message, const base::Closure& done_task) { if (message->has_begin_session_request()) { const BeginSessionRequest& request = message->begin_session_request(); if (request.has_credentials() && request.credentials().has_type()) { @@ -61,13 +63,12 @@ void HostMessageDispatcher::OnControlMessageReceived( } LOG(WARNING) << "Invalid control message received."; - done_task->Run(); - delete done_task; + done_task.Run(); } void HostMessageDispatcher::OnEventMessageReceived( - EventMessage* message, Task* done_task) { - base::ScopedTaskRunner done_runner(done_task); + EventMessage* message, const base::Closure& done_task) { + base::ScopedClosureRunner done_runner(done_task); connection_->UpdateSequenceNumber(message->sequence_number()); diff --git a/remoting/protocol/host_message_dispatcher.h b/remoting/protocol/host_message_dispatcher.h index 2a55474..0b95e46 100644 --- a/remoting/protocol/host_message_dispatcher.h +++ b/remoting/protocol/host_message_dispatcher.h @@ -48,11 +48,13 @@ class HostMessageDispatcher { private: // This method is called by |control_channel_reader_| when a control // message is received. - void OnControlMessageReceived(ControlMessage* message, Task* done_task); + void OnControlMessageReceived(ControlMessage* message, + const base::Closure& done_task); // This method is called by |event_channel_reader_| when a event // message is received. - void OnEventMessageReceived(EventMessage* message, Task* done_task); + void OnEventMessageReceived(EventMessage* message, + const base::Closure& done_task); // MessageReader that runs on the control channel. It runs a loop // that parses data on the channel and then delegates the message to this diff --git a/remoting/protocol/host_stub.h b/remoting/protocol/host_stub.h index 52a7cf7c..43175e8 100644 --- a/remoting/protocol/host_stub.h +++ b/remoting/protocol/host_stub.h @@ -24,7 +24,7 @@ class HostStub { virtual ~HostStub() {}; virtual void BeginSessionRequest( - const LocalLoginCredentials* credentials, Task* done) = 0; + const LocalLoginCredentials* credentials, const base::Closure& done) = 0; private: DISALLOW_COPY_AND_ASSIGN(HostStub); diff --git a/remoting/protocol/input_sender.cc b/remoting/protocol/input_sender.cc index b02956a..0ab2923b 100644 --- a/remoting/protocol/input_sender.cc +++ b/remoting/protocol/input_sender.cc @@ -22,7 +22,7 @@ InputSender::InputSender(base::MessageLoopProxy* message_loop, : buffered_writer_(new BufferedSocketWriter(message_loop)) { // TODO(garykac) Set write failed callback. DCHECK(socket); - buffered_writer_->Init(socket, NULL); + buffered_writer_->Init(socket, BufferedSocketWriter::WriteFailedCallback()); } InputSender::~InputSender() { @@ -32,14 +32,14 @@ void InputSender::InjectKeyEvent(const KeyEvent& event) { EventMessage message; message.set_sequence_number(base::Time::Now().ToInternalValue()); message.mutable_key_event()->CopyFrom(event); - buffered_writer_->Write(SerializeAndFrameMessage(message), NULL); + buffered_writer_->Write(SerializeAndFrameMessage(message), base::Closure()); } void InputSender::InjectMouseEvent(const MouseEvent& event) { EventMessage message; message.set_sequence_number(base::Time::Now().ToInternalValue()); message.mutable_mouse_event()->CopyFrom(event); - buffered_writer_->Write(SerializeAndFrameMessage(message), NULL); + buffered_writer_->Write(SerializeAndFrameMessage(message), base::Closure()); } void InputSender::Close() { diff --git a/remoting/protocol/jingle_session.cc b/remoting/protocol/jingle_session.cc index 611f97c..b510ae8a 100644 --- a/remoting/protocol/jingle_session.cc +++ b/remoting/protocol/jingle_session.cc @@ -66,7 +66,7 @@ JingleSession::JingleSession( JingleSession::~JingleSession() { // Reset the callback so that it's not called from Close(). - state_change_callback_.reset(); + state_change_callback_.Reset(); Close(); jingle_session_manager_->SessionDestroyed(this); } @@ -127,10 +127,11 @@ cricket::Session* JingleSession::ReleaseSession() { return session; } -void JingleSession::SetStateChangeCallback(StateChangeCallback* callback) { +void JingleSession::SetStateChangeCallback( + const StateChangeCallback& callback) { DCHECK(CalledOnValidThread()); - DCHECK(callback); - state_change_callback_.reset(callback); + DCHECK(!callback.is_null()); + state_change_callback_ = callback; } Session::Error JingleSession::error() { @@ -466,8 +467,8 @@ void JingleSession::SetState(State new_state) { DCHECK_NE(state_, FAILED); state_ = new_state; - if (state_change_callback_.get()) - state_change_callback_->Run(new_state); + if (!state_change_callback_.is_null()) + state_change_callback_.Run(new_state); } } diff --git a/remoting/protocol/jingle_session.h b/remoting/protocol/jingle_session.h index cd467a1..4bff001 100644 --- a/remoting/protocol/jingle_session.h +++ b/remoting/protocol/jingle_session.h @@ -27,7 +27,8 @@ class JingleSession : public protocol::Session, public sigslot::has_slots<> { public: // Session interface. - virtual void SetStateChangeCallback(StateChangeCallback* callback) OVERRIDE; + virtual void SetStateChangeCallback( + const StateChangeCallback& callback) OVERRIDE; virtual Error error() OVERRIDE; virtual void CreateStreamChannel( const std::string& name, @@ -149,7 +150,7 @@ class JingleSession : public protocol::Session, std::string shared_secret_; State state_; - scoped_ptr<StateChangeCallback> state_change_callback_; + StateChangeCallback state_change_callback_; Error error_; diff --git a/remoting/protocol/jingle_session_manager.cc b/remoting/protocol/jingle_session_manager.cc index fcb9005..70c3827 100644 --- a/remoting/protocol/jingle_session_manager.cc +++ b/remoting/protocol/jingle_session_manager.cc @@ -132,7 +132,7 @@ Session* JingleSessionManager::Connect( const std::string& host_public_key, const std::string& receiver_token, CandidateSessionConfig* candidate_config, - Session::StateChangeCallback* state_change_callback) { + const Session::StateChangeCallback& state_change_callback) { DCHECK(CalledOnValidThread()); // Can be called from any thread. diff --git a/remoting/protocol/jingle_session_manager.h b/remoting/protocol/jingle_session_manager.h index f8326c7..73f2530 100644 --- a/remoting/protocol/jingle_session_manager.h +++ b/remoting/protocol/jingle_session_manager.h @@ -51,7 +51,7 @@ class JingleSessionManager const std::string& host_public_key, const std::string& client_token, CandidateSessionConfig* config, - Session::StateChangeCallback* state_change_callback) OVERRIDE; + const Session::StateChangeCallback& state_change_callback) OVERRIDE; virtual void Close() OVERRIDE; void set_allow_local_ips(bool allow_local_ips); diff --git a/remoting/protocol/jingle_session_unittest.cc b/remoting/protocol/jingle_session_unittest.cc index 35e4181..ef5eb78 100644 --- a/remoting/protocol/jingle_session_unittest.cc +++ b/remoting/protocol/jingle_session_unittest.cc @@ -121,8 +121,8 @@ class JingleSessionTest : public testing::Test { DCHECK(session); host_session_.reset(session); host_session_->SetStateChangeCallback( - NewCallback(&host_connection_callback_, - &MockSessionCallback::OnStateChange)); + base::Bind(&MockSessionCallback::OnStateChange, + base::Unretained(&host_connection_callback_))); session->set_config(SessionConfig::GetDefault()); session->set_shared_secret(kTestSharedSecret); @@ -278,8 +278,8 @@ class JingleSessionTest : public testing::Test { client_session_.reset(client_server_->Connect( kHostJid, kTestHostPublicKey, kTestToken, CandidateSessionConfig::CreateDefault(), - NewCallback(&client_connection_callback_, - &MockSessionCallback::OnStateChange))); + base::Bind(&MockSessionCallback::OnStateChange, + base::Unretained(&client_connection_callback_)))); client_session_->set_shared_secret(shared_secret); @@ -698,8 +698,8 @@ TEST_F(JingleSessionTest, RejectConnection) { client_session_.reset(client_server_->Connect( kHostJid, kTestHostPublicKey, kTestToken, CandidateSessionConfig::CreateDefault(), - NewCallback(&client_connection_callback_, - &MockSessionCallback::OnStateChange))); + base::Bind(&MockSessionCallback::OnStateChange, + base::Unretained(&client_connection_callback_)))); ASSERT_TRUE(RunMessageLoopWithTimeout(TestTimeouts::action_max_timeout_ms())); } diff --git a/remoting/protocol/message_reader.cc b/remoting/protocol/message_reader.cc index f2902e0..82a3c80 100644 --- a/remoting/protocol/message_reader.cc +++ b/remoting/protocol/message_reader.cc @@ -32,8 +32,8 @@ MessageReader::~MessageReader() { } void MessageReader::Init(net::Socket* socket, - MessageReceivedCallback* callback) { - message_received_callback_.reset(callback); + const MessageReceivedCallback& callback) { + message_received_callback_ = callback; DCHECK(socket); socket_ = socket; DoRead(); @@ -96,9 +96,9 @@ void MessageReader::OnDataReceived(net::IOBuffer* data, int data_size) { // plugin thread if this code is compiled into a separate binary. Fix this. for (std::vector<CompoundBuffer*>::iterator it = new_messages.begin(); it != new_messages.end(); ++it) { - message_received_callback_->Run(*it, NewRunnableMethod( - this, &MessageReader::OnMessageDone, *it, - base::MessageLoopProxy::current())); + message_received_callback_.Run(*it, base::Bind( + &MessageReader::OnMessageDone, this, + *it, base::MessageLoopProxy::current())); } } diff --git a/remoting/protocol/message_reader.h b/remoting/protocol/message_reader.h index 8a8abda..fb89f91 100644 --- a/remoting/protocol/message_reader.h +++ b/remoting/protocol/message_reader.h @@ -5,11 +5,11 @@ #ifndef REMOTING_PROTOCOL_MESSAGE_READER_H_ #define REMOTING_PROTOCOL_MESSAGE_READER_H_ +#include "base/bind.h" #include "base/callback.h" #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" #include "base/message_loop_proxy.h" -#include "base/task.h" #include "net/base/completion_callback.h" #include "remoting/base/compound_buffer.h" #include "remoting/protocol/message_decoder.h" @@ -41,14 +41,15 @@ class MessageReader : public base::RefCountedThreadSafe<MessageReader> { // (|done_task|). The buffer (first argument) is owned by // MessageReader and is freed when the task specified by the second // argument is called. - typedef Callback2<CompoundBuffer*, Task*>::Type MessageReceivedCallback; + typedef base::Callback<void(CompoundBuffer*, const base::Closure&)> + MessageReceivedCallback; MessageReader(); virtual ~MessageReader(); // Initialize the MessageReader with a socket. If a message is received // |callback| is called. - void Init(net::Socket* socket, MessageReceivedCallback* callback); + void Init(net::Socket* socket, const MessageReceivedCallback& callback); private: void DoRead(); @@ -77,7 +78,7 @@ class MessageReader : public base::RefCountedThreadSafe<MessageReader> { MessageDecoder message_decoder_; // Callback is called when a message is received. - scoped_ptr<MessageReceivedCallback> message_received_callback_; + MessageReceivedCallback message_received_callback_; }; // Version of MessageReader for protocol buffer messages, that parses @@ -85,20 +86,23 @@ class MessageReader : public base::RefCountedThreadSafe<MessageReader> { template <class T> class ProtobufMessageReader { public: - typedef typename Callback2<T*, Task*>::Type MessageReceivedCallback; + typedef typename base::Callback<void(T*, const base::Closure&)> + MessageReceivedCallback; ProtobufMessageReader() { }; ~ProtobufMessageReader() { }; - void Init(net::Socket* socket, MessageReceivedCallback* callback) { - message_received_callback_.reset(callback); + void Init(net::Socket* socket, const MessageReceivedCallback& callback) { + DCHECK(!callback.is_null()); + message_received_callback_ = callback; message_reader_ = new MessageReader(); message_reader_->Init( - socket, NewCallback(this, &ProtobufMessageReader<T>::OnNewData)); + socket, base::Bind(&ProtobufMessageReader<T>::OnNewData, + base::Unretained(this))); } private: - void OnNewData(CompoundBuffer* buffer, Task* done_task) { + void OnNewData(CompoundBuffer* buffer, const base::Closure& done_task) { T* message = new T(); CompoundBufferInputStream stream(buffer); bool ret = message->ParseFromZeroCopyStream(&stream); @@ -107,20 +111,18 @@ class ProtobufMessageReader { delete message; } else { DCHECK_EQ(stream.position(), buffer->total_bytes()); - message_received_callback_->Run( - message, NewRunnableFunction( - &ProtobufMessageReader<T>::OnDone, message, done_task)); + message_received_callback_.Run(message, base::Bind( + &ProtobufMessageReader<T>::OnDone, message, done_task)); } } - static void OnDone(T* message, Task* done_task) { + static void OnDone(T* message, const base::Closure& done_task) { delete message; - done_task->Run(); - delete done_task; + done_task.Run(); } scoped_refptr<MessageReader> message_reader_; - scoped_ptr<MessageReceivedCallback> message_received_callback_; + MessageReceivedCallback message_received_callback_; }; } // namespace protocol diff --git a/remoting/protocol/message_reader_unittest.cc b/remoting/protocol/message_reader_unittest.cc index 9aba90a..bbd57e4 100644 --- a/remoting/protocol/message_reader_unittest.cc +++ b/remoting/protocol/message_reader_unittest.cc @@ -6,6 +6,7 @@ #include "base/bind.h" #include "base/bind_helpers.h" +#include "base/callback.h" #include "base/message_loop.h" #include "base/synchronization/waitable_event.h" #include "base/threading/thread.h" @@ -29,14 +30,13 @@ const char kTestMessage1[] = "Message1"; const char kTestMessage2[] = "Message2"; ACTION(CallDoneTask) { - arg1->Run(); - delete arg1; + arg1.Run(); } } class MockMessageReceivedCallback { public: - MOCK_METHOD2(OnMessage, void(CompoundBuffer*, Task*)); + MOCK_METHOD2(OnMessage, void(CompoundBuffer*, const base::Closure&)); }; class MessageReaderTest : public testing::Test { @@ -46,12 +46,12 @@ class MessageReaderTest : public testing::Test { run_task_finished_(false, false) { } - void RunDoneTaskOnOtherThread(CompoundBuffer* buffer, Task* done_task) { + void RunDoneTaskOnOtherThread(CompoundBuffer* buffer, + const base::Closure& done_task) { other_thread_.message_loop()->PostTask( FROM_HERE, base::Bind(&MessageReaderTest::RunAndDeleteTask, - base::Unretained(this), - done_task)); + base::Unretained(this), done_task)); } protected: @@ -60,8 +60,8 @@ class MessageReaderTest : public testing::Test { } void InitReader() { - reader_->Init(&socket_, NewCallback( - &callback_, &MockMessageReceivedCallback::OnMessage)); + reader_->Init(&socket_, base::Bind( + &MockMessageReceivedCallback::OnMessage, base::Unretained(&callback_))); } void AddMessage(const std::string& message) { @@ -77,9 +77,8 @@ class MessageReaderTest : public testing::Test { return result == expected; } - void RunAndDeleteTask(Task* task) { - task->Run(); - delete task; + void RunAndDeleteTask(const base::Closure& task) { + task.Run(); run_task_finished_.Signal(); } @@ -94,7 +93,7 @@ class MessageReaderTest : public testing::Test { // Receive one message and process it with delay TEST_F(MessageReaderTest, OneMessage_Delay) { CompoundBuffer* buffer; - Task* done_task; + base::Closure done_task; AddMessage(kTestMessage1); @@ -135,9 +134,9 @@ TEST_F(MessageReaderTest, OneMessage_Instant) { // Receive two messages in one packet. TEST_F(MessageReaderTest, TwoMessages_Together) { CompoundBuffer* buffer1; - Task* done_task1; + base::Closure done_task1; CompoundBuffer* buffer2; - Task* done_task2; + base::Closure done_task2; AddMessage(kTestMessage1); AddMessage(kTestMessage2); @@ -174,7 +173,7 @@ TEST_F(MessageReaderTest, TwoMessages_Together) { // instantly. TEST_F(MessageReaderTest, TwoMessages_Instant) { CompoundBuffer* buffer2; - Task* done_task2; + base::Closure done_task2; AddMessage(kTestMessage1); AddMessage(kTestMessage2); @@ -220,7 +219,7 @@ TEST_F(MessageReaderTest, TwoMessages_Instant2) { // Receive two messages in separate packets. TEST_F(MessageReaderTest, TwoMessages_Separately) { CompoundBuffer* buffer; - Task* done_task; + base::Closure done_task; AddMessage(kTestMessage1); @@ -280,7 +279,7 @@ TEST_F(MessageReaderTest, UseSocketOnCorrectThread) { // Write another message and verify that we receive it. CompoundBuffer* buffer; - Task* done_task; + base::Closure done_task; EXPECT_CALL(callback_, OnMessage(_, _)) .Times(1) .WillOnce(DoAll(SaveArg<0>(&buffer), diff --git a/remoting/protocol/pepper_session.cc b/remoting/protocol/pepper_session.cc index 509440e..5e971bd 100644 --- a/remoting/protocol/pepper_session.cc +++ b/remoting/protocol/pepper_session.cc @@ -44,9 +44,10 @@ PepperSession::~PepperSession() { session_manager_->SessionDestroyed(this); } -void PepperSession::SetStateChangeCallback(StateChangeCallback* callback) { +void PepperSession::SetStateChangeCallback( + const StateChangeCallback& callback) { DCHECK(CalledOnValidThread()); - state_change_callback_.reset(callback); + state_change_callback_ = callback; } Session::Error PepperSession::error() { @@ -59,14 +60,14 @@ void PepperSession::StartConnection( const std::string& peer_public_key, const std::string& client_token, CandidateSessionConfig* config, - Session::StateChangeCallback* state_change_callback) { + const StateChangeCallback& state_change_callback) { DCHECK(CalledOnValidThread()); peer_jid_ = peer_jid; peer_public_key_ = peer_public_key; initiator_token_ = client_token; candidate_config_.reset(config); - state_change_callback_.reset(state_change_callback); + state_change_callback_ = state_change_callback; // Generate random session ID. There are usually not more than 1 // concurrent session per host, so a random 64-bit integer provides @@ -382,8 +383,8 @@ void PepperSession::SetState(State new_state) { DCHECK_NE(state_, FAILED); state_ = new_state; - if (state_change_callback_.get()) - state_change_callback_->Run(new_state); + if (!state_change_callback_.is_null()) + state_change_callback_.Run(new_state); } } diff --git a/remoting/protocol/pepper_session.h b/remoting/protocol/pepper_session.h index ab0a26d9..271d6c1 100644 --- a/remoting/protocol/pepper_session.h +++ b/remoting/protocol/pepper_session.h @@ -46,7 +46,8 @@ class PepperSession : public Session { virtual ~PepperSession(); // Session interface. - virtual void SetStateChangeCallback(StateChangeCallback* callback) OVERRIDE; + virtual void SetStateChangeCallback( + const StateChangeCallback& callback) OVERRIDE; virtual Error error() OVERRIDE; virtual void CreateStreamChannel( const std::string& name, @@ -81,7 +82,7 @@ class PepperSession : public Session { const std::string& peer_public_key, const std::string& client_token, CandidateSessionConfig* config, - Session::StateChangeCallback* state_change_callback); + const StateChangeCallback& state_change_callback); // Handler for session-initiate response. void OnSessionInitiateResponse(const buzz::XmlElement* response); @@ -124,7 +125,7 @@ class PepperSession : public Session { std::string peer_jid_; std::string peer_public_key_; scoped_ptr<CandidateSessionConfig> candidate_config_; - scoped_ptr<StateChangeCallback> state_change_callback_; + StateChangeCallback state_change_callback_; std::string session_id_; State state_; diff --git a/remoting/protocol/pepper_session_manager.cc b/remoting/protocol/pepper_session_manager.cc index e732511..7e7fe69 100644 --- a/remoting/protocol/pepper_session_manager.cc +++ b/remoting/protocol/pepper_session_manager.cc @@ -78,7 +78,7 @@ Session* PepperSessionManager::Connect( const std::string& host_public_key, const std::string& client_token, CandidateSessionConfig* config, - Session::StateChangeCallback* state_change_callback) { + const Session::StateChangeCallback& state_change_callback) { PepperSession* session = new PepperSession(this); session->StartConnection(host_jid, host_public_key, client_token, config, state_change_callback); diff --git a/remoting/protocol/pepper_session_manager.h b/remoting/protocol/pepper_session_manager.h index b8f7166..8c9bfee 100644 --- a/remoting/protocol/pepper_session_manager.h +++ b/remoting/protocol/pepper_session_manager.h @@ -58,7 +58,7 @@ class PepperSessionManager : public SessionManager, const std::string& host_public_key, const std::string& client_token, CandidateSessionConfig* config, - Session::StateChangeCallback* state_change_callback) OVERRIDE; + const Session::StateChangeCallback& state_change_callback) OVERRIDE; virtual void Close() OVERRIDE; // SignalStrategy::Listener interface. diff --git a/remoting/protocol/protobuf_video_reader.cc b/remoting/protocol/protobuf_video_reader.cc index 08b1828..cf5d1a9 100644 --- a/remoting/protocol/protobuf_video_reader.cc +++ b/remoting/protocol/protobuf_video_reader.cc @@ -40,11 +40,13 @@ void ProtobufVideoReader::OnChannelReady(net::StreamSocket* socket) { DCHECK(!channel_.get()); channel_.reset(socket); - reader_.Init(socket, NewCallback(this, &ProtobufVideoReader::OnNewData)); + reader_.Init(socket, base::Bind(&ProtobufVideoReader::OnNewData, + base::Unretained(this))); initialized_callback_.Run(true); } -void ProtobufVideoReader::OnNewData(VideoPacket* packet, Task* done_task) { +void ProtobufVideoReader::OnNewData(VideoPacket* packet, + const base::Closure& done_task) { video_stub_->ProcessVideoPacket(packet, done_task); } diff --git a/remoting/protocol/protobuf_video_reader.h b/remoting/protocol/protobuf_video_reader.h index a8d646c..29dd5df 100644 --- a/remoting/protocol/protobuf_video_reader.h +++ b/remoting/protocol/protobuf_video_reader.h @@ -31,7 +31,7 @@ class ProtobufVideoReader : public VideoReader { private: void OnChannelReady(net::StreamSocket* socket); - void OnNewData(VideoPacket* packet, Task* done_task); + void OnNewData(VideoPacket* packet, const base::Closure& done_task); InitializedCallback initialized_callback_; diff --git a/remoting/protocol/protobuf_video_writer.cc b/remoting/protocol/protobuf_video_writer.cc index cb4399b..88941c4 100644 --- a/remoting/protocol/protobuf_video_writer.cc +++ b/remoting/protocol/protobuf_video_writer.cc @@ -40,7 +40,7 @@ void ProtobufVideoWriter::OnChannelReady(net::StreamSocket* socket) { DCHECK(!channel_.get()); channel_.reset(socket); // TODO(sergeyu): Provide WriteFailedCallback for the buffered writer. - buffered_writer_->Init(socket, NULL); + buffered_writer_->Init(socket, BufferedSocketWriter::WriteFailedCallback()); initialized_callback_.Run(true); } @@ -51,7 +51,7 @@ void ProtobufVideoWriter::Close() { } void ProtobufVideoWriter::ProcessVideoPacket(const VideoPacket* packet, - Task* done) { + const base::Closure& done) { buffered_writer_->Write(SerializeAndFrameMessage(*packet), done); } diff --git a/remoting/protocol/protobuf_video_writer.h b/remoting/protocol/protobuf_video_writer.h index 587ceab..ab353db 100644 --- a/remoting/protocol/protobuf_video_writer.h +++ b/remoting/protocol/protobuf_video_writer.h @@ -38,7 +38,7 @@ class ProtobufVideoWriter : public VideoWriter { // VideoStub interface. virtual void ProcessVideoPacket(const VideoPacket* packet, - Task* done) OVERRIDE; + const base::Closure& done) OVERRIDE; virtual int GetPendingPackets() OVERRIDE; private: diff --git a/remoting/protocol/protocol_mock_objects.h b/remoting/protocol/protocol_mock_objects.h index 814e61b..6bc97d6 100644 --- a/remoting/protocol/protocol_mock_objects.h +++ b/remoting/protocol/protocol_mock_objects.h @@ -70,7 +70,8 @@ class MockHostStub : public HostStub { ~MockHostStub(); MOCK_METHOD2(BeginSessionRequest, - void(const LocalLoginCredentials* credentials, Task* done)); + void(const LocalLoginCredentials* credentials, + const base::Closure& done)); private: DISALLOW_COPY_AND_ASSIGN(MockHostStub); @@ -82,9 +83,9 @@ class MockClientStub : public ClientStub { virtual ~MockClientStub(); MOCK_METHOD2(NotifyResolution, void(const NotifyResolutionRequest* msg, - Task* done)); + const base::Closure& done)); MOCK_METHOD2(BeginSessionResponse, void(const LocalLoginStatus* msg, - Task* done)); + const base::Closure& done)); private: DISALLOW_COPY_AND_ASSIGN(MockClientStub); @@ -96,7 +97,7 @@ class MockVideoStub : public VideoStub { virtual ~MockVideoStub(); MOCK_METHOD2(ProcessVideoPacket, void(const VideoPacket* video_packet, - Task* done)); + const base::Closure& done)); MOCK_METHOD0(GetPendingPackets, int()); private: @@ -108,7 +109,8 @@ class MockSession : public Session { MockSession(); virtual ~MockSession(); - MOCK_METHOD1(SetStateChangeCallback, void(StateChangeCallback* callback)); + MOCK_METHOD1(SetStateChangeCallback, + void(const StateChangeCallback& callback)); MOCK_METHOD0(error, Session::Error()); MOCK_METHOD2(CreateStreamChannel, void( const std::string& name, const StreamChannelCallback& callback)); diff --git a/remoting/protocol/protocol_test_client.cc b/remoting/protocol/protocol_test_client.cc index bfcb496..49fd2bc 100644 --- a/remoting/protocol/protocol_test_client.cc +++ b/remoting/protocol/protocol_test_client.cc @@ -296,7 +296,7 @@ void ProtocolTestClient::OnSessionManagerInitialized() { connection->Init(session_manager_->Connect( host_jid_, "", kDummyAuthToken, CandidateSessionConfig::CreateDefault(), - NewCallback(connection, &ProtocolTestConnection::OnStateChange))); + base::Bind(&ProtocolTestConnection::OnStateChange, connection))); connections_.push_back(make_scoped_refptr(connection)); } } @@ -311,7 +311,7 @@ void ProtocolTestClient::OnIncomingSession( ProtocolTestConnection* test_connection = new ProtocolTestConnection(this); session->SetStateChangeCallback( - NewCallback(test_connection, &ProtocolTestConnection::OnStateChange)); + base::Bind(&ProtocolTestConnection::OnStateChange, test_connection)); test_connection->Init(session); base::AutoLock auto_lock(connections_lock_); connections_.push_back(make_scoped_refptr(test_connection)); diff --git a/remoting/protocol/rtcp_writer.cc b/remoting/protocol/rtcp_writer.cc index f8b8b76..f039ec5 100644 --- a/remoting/protocol/rtcp_writer.cc +++ b/remoting/protocol/rtcp_writer.cc @@ -27,7 +27,8 @@ void RtcpWriter::Close() { // Initializes the writer. Must be called on the thread the sockets // belong to. void RtcpWriter::Init(net::Socket* socket) { - buffered_rtcp_writer_->Init(socket, NULL); + buffered_rtcp_writer_->Init( + socket, BufferedSocketWriter::WriteFailedCallback()); } void RtcpWriter::SendReport(const RtcpReceiverReport& report) { @@ -37,7 +38,7 @@ void RtcpWriter::SendReport(const RtcpReceiverReport& report) { PackRtcpReceiverReport(report, reinterpret_cast<uint8*>(buffer->data()), size); - buffered_rtcp_writer_->Write(buffer, NULL); + buffered_rtcp_writer_->Write(buffer, base::Closure()); } } // namespace protocol diff --git a/remoting/protocol/rtp_reader.cc b/remoting/protocol/rtp_reader.cc index e99472f..50c2d82 100644 --- a/remoting/protocol/rtp_reader.cc +++ b/remoting/protocol/rtp_reader.cc @@ -36,8 +36,9 @@ RtpReader::~RtpReader() { } void RtpReader::Init(net::Socket* socket, - OnMessageCallback* on_message_callback) { - on_message_callback_.reset(on_message_callback); + const OnMessageCallback& on_message_callback) { + DCHECK(!on_message_callback.is_null()); + on_message_callback_ = on_message_callback; SocketReaderBase::Init(socket); } @@ -90,7 +91,7 @@ void RtpReader::OnDataReceived(net::IOBuffer* buffer, int data_size) { ++total_packets_received_; - on_message_callback_->Run(packet); + on_message_callback_.Run(packet); } void RtpReader::GetReceiverReport(RtcpReceiverReport* report) { diff --git a/remoting/protocol/rtp_reader.h b/remoting/protocol/rtp_reader.h index d932d48..175c108 100644 --- a/remoting/protocol/rtp_reader.h +++ b/remoting/protocol/rtp_reader.h @@ -5,6 +5,7 @@ #ifndef REMOTING_PROTOCOL_RTP_READER_H_ #define REMOTING_PROTOCOL_RTP_READER_H_ +#include "base/callback.h" #include "base/memory/scoped_ptr.h" #include "remoting/base/compound_buffer.h" #include "remoting/protocol/rtp_utils.h" @@ -52,13 +53,13 @@ class RtpReader : public SocketReaderBase { // The OnMessageCallback is called whenever a new message is received. // Ownership of the message is passed the callback. - typedef Callback1<const RtpPacket*>::Type OnMessageCallback; + typedef base::Callback<void(const RtpPacket*)> OnMessageCallback; // Initialize the reader and start reading. Must be called on the thread // |socket| belongs to. The callback will be called when a new message is // received. RtpReader owns |on_message_callback|, doesn't own // |socket|. - void Init(net::Socket* socket, OnMessageCallback* on_message_callback); + void Init(net::Socket* socket, const OnMessageCallback& on_message_callback); void GetReceiverReport(RtcpReceiverReport* report); @@ -68,7 +69,7 @@ class RtpReader : public SocketReaderBase { virtual void OnDataReceived(net::IOBuffer* buffer, int data_size); private: - scoped_ptr<OnMessageCallback> on_message_callback_; + OnMessageCallback on_message_callback_; uint16 max_sequence_number_; uint16 wrap_around_count_; diff --git a/remoting/protocol/rtp_video_reader.cc b/remoting/protocol/rtp_video_reader.cc index 28babd8..91f608a 100644 --- a/remoting/protocol/rtp_video_reader.cc +++ b/remoting/protocol/rtp_video_reader.cc @@ -62,7 +62,8 @@ void RtpVideoReader::OnChannelReady(bool rtp, net::Socket* socket) { if (rtp) { DCHECK(!rtp_channel_.get()); rtp_channel_.reset(socket); - rtp_reader_.Init(socket, NewCallback(this, &RtpVideoReader::OnRtpPacket)); + rtp_reader_.Init(socket, base::Bind(&RtpVideoReader::OnRtpPacket, + base::Unretained(this))); } else { DCHECK(!rtcp_channel_.get()); rtcp_channel_.reset(socket); @@ -204,7 +205,8 @@ void RtpVideoReader::RebuildVideoPacket(const PacketsQueue::iterator& first, // Set format. packet->mutable_format()->set_encoding(VideoPacketFormat::ENCODING_VP8); - video_stub_->ProcessVideoPacket(packet, new DeleteTask<VideoPacket>(packet)); + video_stub_->ProcessVideoPacket( + packet, base::Bind(&DeletePointer<VideoPacket>, packet)); SendReceiverReportIf(); } diff --git a/remoting/protocol/rtp_video_reader_unittest.cc b/remoting/protocol/rtp_video_reader_unittest.cc index 8c70b3e9..fc1f79f 100644 --- a/remoting/protocol/rtp_video_reader_unittest.cc +++ b/remoting/protocol/rtp_video_reader_unittest.cc @@ -26,11 +26,10 @@ class RtpVideoReaderTest : public testing::Test, public: // VideoStub interface. virtual void ProcessVideoPacket(const VideoPacket* video_packet, - Task* done) { + const base::Closure& done) { received_packets_.push_back(VideoPacket()); received_packets_.back() = *video_packet; - done->Run(); - delete done; + done.Run(); } virtual int GetPendingPackets() { diff --git a/remoting/protocol/rtp_video_writer.cc b/remoting/protocol/rtp_video_writer.cc index ae85f83..c188d66 100644 --- a/remoting/protocol/rtp_video_writer.cc +++ b/remoting/protocol/rtp_video_writer.cc @@ -74,7 +74,8 @@ void RtpVideoWriter::Close() { rtcp_channel_.reset(); } -void RtpVideoWriter::ProcessVideoPacket(const VideoPacket* packet, Task* done) { +void RtpVideoWriter::ProcessVideoPacket(const VideoPacket* packet, + const base::Closure& done) { CHECK(packet->format().encoding() == VideoPacketFormat::ENCODING_VP8) << "Only VP8 is supported in RTP."; @@ -128,8 +129,7 @@ void RtpVideoWriter::ProcessVideoPacket(const VideoPacket* packet, Task* done) { } DCHECK_EQ(position, payload.total_bytes()); - done->Run(); - delete done; + done.Run(); } int RtpVideoWriter::GetPendingPackets() { diff --git a/remoting/protocol/rtp_video_writer.h b/remoting/protocol/rtp_video_writer.h index bb8ddc7..93d2a64 100644 --- a/remoting/protocol/rtp_video_writer.h +++ b/remoting/protocol/rtp_video_writer.h @@ -30,7 +30,7 @@ class RtpVideoWriter : public VideoWriter { // VideoStub interface. virtual void ProcessVideoPacket(const VideoPacket* packet, - Task* done) OVERRIDE; + const base::Closure& done) OVERRIDE; virtual int GetPendingPackets() OVERRIDE; private: diff --git a/remoting/protocol/rtp_video_writer_unittest.cc b/remoting/protocol/rtp_video_writer_unittest.cc index e80d4fb..e993e5a 100644 --- a/remoting/protocol/rtp_video_writer_unittest.cc +++ b/remoting/protocol/rtp_video_writer_unittest.cc @@ -131,7 +131,8 @@ class RtpVideoWriterTest : public testing::Test { TEST_F(RtpVideoWriterTest, NotFragmented_FirstPacket) { InitPacket(1024, true, false); - writer_.ProcessVideoPacket(packet_, new DeleteTask<VideoPacket>(packet_)); + writer_.ProcessVideoPacket( + packet_, base::Bind(&DeletePointer<VideoPacket>, packet_)); message_loop_.RunAllPending(); ExpectedPacket expected[] = { @@ -142,7 +143,8 @@ TEST_F(RtpVideoWriterTest, NotFragmented_FirstPacket) { TEST_F(RtpVideoWriterTest, NotFragmented_LastPackes) { InitPacket(1024, false, true); - writer_.ProcessVideoPacket(packet_, new DeleteTask<VideoPacket>(packet_)); + writer_.ProcessVideoPacket( + packet_, base::Bind(&DeletePointer<VideoPacket>, packet_)); message_loop_.RunAllPending(); ExpectedPacket expected[] = { @@ -153,7 +155,8 @@ TEST_F(RtpVideoWriterTest, NotFragmented_LastPackes) { TEST_F(RtpVideoWriterTest, TwoFragments_FirstPacket) { InitPacket(2000, true, false); - writer_.ProcessVideoPacket(packet_, new DeleteTask<VideoPacket>(packet_)); + writer_.ProcessVideoPacket( + packet_, base::Bind(&DeletePointer<VideoPacket>, packet_)); message_loop_.RunAllPending(); ExpectedPacket expected[] = { @@ -165,7 +168,8 @@ TEST_F(RtpVideoWriterTest, TwoFragments_FirstPacket) { TEST_F(RtpVideoWriterTest, TwoFragments_LastPacket) { InitPacket(2000, false, true); - writer_.ProcessVideoPacket(packet_, new DeleteTask<VideoPacket>(packet_)); + writer_.ProcessVideoPacket( + packet_, base::Bind(&DeletePointer<VideoPacket>, packet_)); message_loop_.RunAllPending(); ExpectedPacket expected[] = { @@ -177,7 +181,8 @@ TEST_F(RtpVideoWriterTest, TwoFragments_LastPacket) { TEST_F(RtpVideoWriterTest, ThreeFragments) { InitPacket(3000, true, true); - writer_.ProcessVideoPacket(packet_, new DeleteTask<VideoPacket>(packet_)); + writer_.ProcessVideoPacket( + packet_, base::Bind(&DeletePointer<VideoPacket>, packet_)); message_loop_.RunAllPending(); ExpectedPacket expected[] = { diff --git a/remoting/protocol/rtp_writer.cc b/remoting/protocol/rtp_writer.cc index a672c1e..9b57ea0 100644 --- a/remoting/protocol/rtp_writer.cc +++ b/remoting/protocol/rtp_writer.cc @@ -26,7 +26,8 @@ RtpWriter::~RtpWriter() { } // Initializes the writer. Must be called on the thread the sockets belong // to. void RtpWriter::Init(net::Socket* rtp_socket) { - buffered_rtp_writer_->Init(rtp_socket, NULL); + buffered_rtp_writer_->Init( + rtp_socket, BufferedSocketWriter::WriteFailedCallback()); } void RtpWriter::Close() { @@ -73,7 +74,7 @@ void RtpWriter::SendPacket(uint32 timestamp, bool marker, payload_size); // And write the packet. - buffered_rtp_writer_->Write(buffer, NULL); + buffered_rtp_writer_->Write(buffer, base::Closure()); } int RtpWriter::GetPendingPackets() { diff --git a/remoting/protocol/session.h b/remoting/protocol/session.h index aaecbf9..27558d7 100644 --- a/remoting/protocol/session.h +++ b/remoting/protocol/session.h @@ -58,7 +58,7 @@ class Session : public base::NonThreadSafe { CHANNEL_CONNECTION_ERROR, }; - typedef Callback1<State>::Type StateChangeCallback; + typedef base::Callback<void(State)> StateChangeCallback; // TODO(sergeyu): Specify connection error code when channel // connection fails. @@ -70,7 +70,7 @@ class Session : public base::NonThreadSafe { // Set callback that is called when state of the connection is changed. // Must be called on the jingle thread only. - virtual void SetStateChangeCallback(StateChangeCallback* callback) = 0; + virtual void SetStateChangeCallback(const StateChangeCallback& callback) = 0; // Returns error code for a failed session. virtual Error error() = 0; diff --git a/remoting/protocol/session_manager.h b/remoting/protocol/session_manager.h index 81a1fad..65f6649 100644 --- a/remoting/protocol/session_manager.h +++ b/remoting/protocol/session_manager.h @@ -135,7 +135,7 @@ class SessionManager : public base::NonThreadSafe { const std::string& host_public_key, const std::string& client_token, CandidateSessionConfig* config, - Session::StateChangeCallback* state_change_callback) = 0; + const Session::StateChangeCallback& state_change_callback) = 0; // Close session manager. Can be called only after all corresponding // sessions are destroyed. No callbacks are called after this method diff --git a/remoting/protocol/video_stub.h b/remoting/protocol/video_stub.h index d9c3714..16e4677 100644 --- a/remoting/protocol/video_stub.h +++ b/remoting/protocol/video_stub.h @@ -5,7 +5,7 @@ #ifndef REMOTING_PROTOCOL_VIDEO_STUB_H_ #define REMOTING_PROTOCOL_VIDEO_STUB_H_ -class Task; +#include "base/callback.h" namespace remoting { @@ -21,7 +21,7 @@ class VideoStub { // video packets in protobuf stream. It should not be used here. Add another // struct and use it to represent video packets internally. virtual void ProcessVideoPacket(const VideoPacket* video_packet, - Task* done) = 0; + const base::Closure& done) = 0; // Returns number of packets currently pending in the buffer. virtual int GetPendingPackets() = 0; |