diff options
author | sergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-07 05:07:40 +0000 |
---|---|---|
committer | sergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-07 05:07:40 +0000 |
commit | 9e2a3137641bc104980e13388b6088d3f4a9b52f (patch) | |
tree | 353e7915a047c43b466f2d4de514605a71691b45 /remoting/protocol/message_reader.h | |
parent | 7feba7ed4d88f95d041abd6bea7a2ba93d9a9f3a (diff) | |
download | chromium_src-9e2a3137641bc104980e13388b6088d3f4a9b52f.zip chromium_src-9e2a3137641bc104980e13388b6088d3f4a9b52f.tar.gz chromium_src-9e2a3137641bc104980e13388b6088d3f4a9b52f.tar.bz2 |
Switch remoting/protocol to new callbacks
There is still some code that uses old callbacks (particularly unittests) - I will convert them in a separate CL.
BUG=None
TEST=Unittests
Review URL: http://codereview.chromium.org/8116021
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@104440 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting/protocol/message_reader.h')
-rw-r--r-- | remoting/protocol/message_reader.h | 34 |
1 files changed, 18 insertions, 16 deletions
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 |