| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_SOCKET_SOCKET_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_SOCKET_SOCKET_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_API_SOCKET_SOCKET_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_API_SOCKET_SOCKET_H_ |
| 7 | 7 |
| 8 #include <queue> | 8 #include <queue> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 | 25 |
| 26 typedef base::Callback<void(int)> CompletionCallback; | 26 typedef base::Callback<void(int)> CompletionCallback; |
| 27 typedef base::Callback<void(int, scoped_refptr<net::IOBuffer> io_buffer)> | 27 typedef base::Callback<void(int, scoped_refptr<net::IOBuffer> io_buffer)> |
| 28 ReadCompletionCallback; | 28 ReadCompletionCallback; |
| 29 typedef base::Callback< | 29 typedef base::Callback< |
| 30 void(int, scoped_refptr<net::IOBuffer> io_buffer, const std::string&, int)> | 30 void(int, scoped_refptr<net::IOBuffer> io_buffer, const std::string&, int)> |
| 31 RecvFromCompletionCallback; | 31 RecvFromCompletionCallback; |
| 32 | 32 |
| 33 // A Socket wraps a low-level socket and includes housekeeping information that | 33 // A Socket wraps a low-level socket and includes housekeeping information that |
| 34 // we need to manage it in the context of an extension. | 34 // we need to manage it in the context of an extension. |
| 35 class Socket : public APIResource { | 35 class Socket : public ApiResource { |
| 36 public: | 36 public: |
| 37 virtual ~Socket(); | 37 virtual ~Socket(); |
| 38 virtual void Connect(const std::string& address, | 38 virtual void Connect(const std::string& address, |
| 39 int port, | 39 int port, |
| 40 const CompletionCallback& callback) = 0; | 40 const CompletionCallback& callback) = 0; |
| 41 virtual void Disconnect() = 0; | 41 virtual void Disconnect() = 0; |
| 42 virtual int Bind(const std::string& address, int port) = 0; | 42 virtual int Bind(const std::string& address, int port) = 0; |
| 43 | 43 |
| 44 // The |callback| will be called with the number of bytes read into the | 44 // The |callback| will be called with the number of bytes read into the |
| 45 // buffer, or a negative number if an error occurred. | 45 // buffer, or a negative number if an error occurred. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 67 int port, | 67 int port, |
| 68 net::AddressList* address_list); | 68 net::AddressList* address_list); |
| 69 static bool StringAndPortToIPEndPoint(const std::string& ip_address_str, | 69 static bool StringAndPortToIPEndPoint(const std::string& ip_address_str, |
| 70 int port, | 70 int port, |
| 71 net::IPEndPoint* ip_end_point); | 71 net::IPEndPoint* ip_end_point); |
| 72 static void IPEndPointToStringAndPort(const net::IPEndPoint& address, | 72 static void IPEndPointToStringAndPort(const net::IPEndPoint& address, |
| 73 std::string* ip_address_str, | 73 std::string* ip_address_str, |
| 74 int* port); | 74 int* port); |
| 75 | 75 |
| 76 protected: | 76 protected: |
| 77 explicit Socket(APIResourceEventNotifier* event_notifier); | 77 explicit Socket(ApiResourceEventNotifier* event_notifier); |
| 78 | 78 |
| 79 void WriteData(); | 79 void WriteData(); |
| 80 virtual int WriteImpl(net::IOBuffer* io_buffer, | 80 virtual int WriteImpl(net::IOBuffer* io_buffer, |
| 81 int io_buffer_size, | 81 int io_buffer_size, |
| 82 const net::CompletionCallback& callback) = 0; | 82 const net::CompletionCallback& callback) = 0; |
| 83 virtual void OnWriteComplete(int result); | 83 virtual void OnWriteComplete(int result); |
| 84 | 84 |
| 85 const std::string address_; | 85 const std::string address_; |
| 86 int port_; | 86 int port_; |
| 87 bool is_connected_; | 87 bool is_connected_; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 101 CompletionCallback callback; | 101 CompletionCallback callback; |
| 102 int bytes_written; | 102 int bytes_written; |
| 103 }; | 103 }; |
| 104 std::queue<WriteRequest> write_queue_; | 104 std::queue<WriteRequest> write_queue_; |
| 105 scoped_refptr<net::IOBuffer> io_buffer_write_; | 105 scoped_refptr<net::IOBuffer> io_buffer_write_; |
| 106 }; | 106 }; |
| 107 | 107 |
| 108 } // namespace extensions | 108 } // namespace extensions |
| 109 | 109 |
| 110 #endif // CHROME_BROWSER_EXTENSIONS_API_SOCKET_SOCKET_H_ | 110 #endif // CHROME_BROWSER_EXTENSIONS_API_SOCKET_SOCKET_H_ |
| OLD | NEW |