Index: chrome/browser/extensions/api/socket/socket.h |
diff --git a/chrome/browser/extensions/api/socket/socket.h b/chrome/browser/extensions/api/socket/socket.h |
index d91a9501dcfbe0b5cf40c0b01b8f91394b16c451..b877713b4d22a5174c3b57b5e3910d690acd21e5 100644 |
--- a/chrome/browser/extensions/api/socket/socket.h |
+++ b/chrome/browser/extensions/api/socket/socket.h |
@@ -8,6 +8,7 @@ |
#include <string> |
+#include "base/callback.h" |
#include "base/memory/scoped_ptr.h" |
#include "chrome/browser/extensions/api/api_resource.h" |
#include "net/base/io_buffer.h" |
@@ -20,6 +21,13 @@ class Socket; |
namespace extensions { |
+typedef base::Callback<void(int)> CompletionCallback; |
+typedef base::Callback<void(int, scoped_refptr<net::IOBuffer> io_buffer)> |
+ ReadCompletionCallback; |
+typedef base::Callback< |
+ void(int, scoped_refptr<net::IOBuffer> io_buffer, const std::string&, int)> |
+ RecvFromCompletionCallback; |
+ |
// A Socket wraps a low-level socket and includes housekeeping information that |
// we need to manage it in the context of an extension. |
class Socket : public APIResource { |
@@ -27,36 +35,35 @@ class Socket : public APIResource { |
virtual ~Socket(); |
// Returns net::OK if successful, or an error code otherwise. |
- virtual int Connect(const std::string& address, int port) = 0; |
+ virtual void Connect(const std::string& address, |
+ int port, |
+ const CompletionCallback& callback) = 0; |
virtual void Disconnect() = 0; |
virtual int Bind(const std::string& address, int port) = 0; |
// Returns the number of bytes read into the buffer, or a negative number if |
// an error occurred. |
- virtual int Read(scoped_refptr<net::IOBuffer> io_buffer, |
- int io_buffer_size) = 0; |
+ virtual void Read(int count, |
+ const ReadCompletionCallback& callback) = 0; |
// Returns the number of bytes successfully written, or a negative error |
// code. Note that ERR_IO_PENDING means that the operation blocked, in which |
// case |event_notifier| (supplied at socket creation) will eventually be |
// called with the final result (again, either a nonnegative number of bytes |
// written, or a negative error). |
- virtual int Write(scoped_refptr<net::IOBuffer> io_buffer, |
- int byte_count) = 0; |
- |
- virtual int RecvFrom(scoped_refptr<net::IOBuffer> io_buffer, |
- int io_buffer_size, |
- net::IPEndPoint *address) = 0; |
- virtual int SendTo(scoped_refptr<net::IOBuffer> io_buffer, |
+ virtual void Write(scoped_refptr<net::IOBuffer> io_buffer, |
int byte_count, |
- const std::string& address, |
- int port) = 0; |
+ const CompletionCallback& callback) = 0; |
- virtual void OnDataRead(scoped_refptr<net::IOBuffer> io_buffer, |
- net::IPEndPoint *address, |
- int result); |
- virtual void OnWriteComplete(int result); |
+ virtual void RecvFrom(int count, |
+ const RecvFromCompletionCallback& callback) = 0; |
+ |
+ virtual void SendTo(scoped_refptr<net::IOBuffer> io_buffer, |
+ int byte_count, |
+ const std::string& address, |
+ int port, |
+ const CompletionCallback& callback) = 0; |
static bool StringAndPortToAddressList(const std::string& ip_address_str, |
int port, |
@@ -70,7 +77,6 @@ class Socket : public APIResource { |
protected: |
explicit Socket(APIResourceEventNotifier* event_notifier); |
- |
const std::string address_; |
int port_; |
bool is_connected_; |