Chromium Code Reviews| 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 21 matching lines...) Expand all Loading... | |
| 32 typedef base::Callback< | 32 typedef base::Callback< |
| 33 void(int, scoped_refptr<net::IOBuffer> io_buffer, const std::string&, int)> | 33 void(int, scoped_refptr<net::IOBuffer> io_buffer, const std::string&, int)> |
| 34 RecvFromCompletionCallback; | 34 RecvFromCompletionCallback; |
| 35 typedef base::Callback< | 35 typedef base::Callback< |
| 36 void(int, net::TCPClientSocket*)> AcceptCompletionCallback; | 36 void(int, net::TCPClientSocket*)> AcceptCompletionCallback; |
| 37 | 37 |
| 38 // A Socket wraps a low-level socket and includes housekeeping information that | 38 // A Socket wraps a low-level socket and includes housekeeping information that |
| 39 // we need to manage it in the context of an extension. | 39 // we need to manage it in the context of an extension. |
| 40 class Socket : public ApiResource { | 40 class Socket : public ApiResource { |
| 41 public: | 41 public: |
| 42 enum SocketType { | 42 enum SocketType { TYPE_TCP, TYPE_UDP, TYPE_TLS }; |
| 43 TYPE_TCP, | |
| 44 TYPE_UDP, | |
| 45 }; | |
| 46 | 43 |
| 47 virtual ~Socket(); | 44 virtual ~Socket(); |
| 45 | |
| 46 const std::string& hostname() const { return hostname_; } | |
| 47 | |
| 48 void set_hostname(const std::string& hostname) { hostname_ = hostname; } | |
| 49 | |
| 50 // Note: |address| contains the resolved IP address, not the hostname of | |
| 51 // the remote endpoint. In order to upgrade this socket to TLS, callers | |
| 52 // must also supply the hostname of the endpoint via |set_hostname()|. | |
| 48 virtual void Connect(const std::string& address, | 53 virtual void Connect(const std::string& address, |
| 49 int port, | 54 int port, |
| 50 const CompletionCallback& callback) = 0; | 55 const CompletionCallback& callback) = 0; |
| 51 virtual void Disconnect() = 0; | 56 virtual void Disconnect() = 0; |
| 52 virtual int Bind(const std::string& address, int port) = 0; | 57 virtual int Bind(const std::string& address, int port) = 0; |
| 53 | 58 |
| 54 // The |callback| will be called with the number of bytes read into the | 59 // The |callback| will be called with the number of bytes read into the |
| 55 // buffer, or a negative number if an error occurred. | 60 // buffer, or a negative number if an error occurred. |
| 56 virtual void Read(int count, | 61 virtual void Read(int count, |
| 57 const ReadCompletionCallback& callback) = 0; | 62 const ReadCompletionCallback& callback) = 0; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 95 | 100 |
| 96 protected: | 101 protected: |
| 97 explicit Socket(const std::string& owner_extension_id_); | 102 explicit Socket(const std::string& owner_extension_id_); |
| 98 | 103 |
| 99 void WriteData(); | 104 void WriteData(); |
| 100 virtual int WriteImpl(net::IOBuffer* io_buffer, | 105 virtual int WriteImpl(net::IOBuffer* io_buffer, |
| 101 int io_buffer_size, | 106 int io_buffer_size, |
| 102 const net::CompletionCallback& callback) = 0; | 107 const net::CompletionCallback& callback) = 0; |
| 103 virtual void OnWriteComplete(int result); | 108 virtual void OnWriteComplete(int result); |
| 104 | 109 |
| 105 const std::string address_; | 110 // The hostname of the remote host that this socket is connected to. Note: |
| 111 // This may contain an IP literal. In the case of IDNs, this will contain | |
|
Ryan Sleevi
2014/03/12 23:35:27
nit
lally
2014/03/17 01:58:06
Done.
| |
| 112 // a series of U-LABELs (UTF-8), not A-LABELs. IP literals for IPv6 will | |
|
Ryan Sleevi
2014/03/12 23:35:27
nit
lally
2014/03/17 01:58:06
Done.
| |
| 113 // be unbracketed. | |
| 114 std::string hostname_; | |
| 106 bool is_connected_; | 115 bool is_connected_; |
| 107 | 116 |
| 108 private: | 117 private: |
| 109 friend class ApiResourceManager<Socket>; | 118 friend class ApiResourceManager<Socket>; |
| 110 static const char* service_name() { | 119 static const char* service_name() { |
| 111 return "SocketManager"; | 120 return "SocketManager"; |
| 112 } | 121 } |
| 113 | 122 |
| 114 struct WriteRequest { | 123 struct WriteRequest { |
| 115 WriteRequest(scoped_refptr<net::IOBuffer> io_buffer, | 124 WriteRequest(scoped_refptr<net::IOBuffer> io_buffer, |
| 116 int byte_count, | 125 int byte_count, |
| 117 const CompletionCallback& callback); | 126 const CompletionCallback& callback); |
| 118 ~WriteRequest(); | 127 ~WriteRequest(); |
| 119 scoped_refptr<net::IOBuffer> io_buffer; | 128 scoped_refptr<net::IOBuffer> io_buffer; |
| 120 int byte_count; | 129 int byte_count; |
| 121 CompletionCallback callback; | 130 CompletionCallback callback; |
| 122 int bytes_written; | 131 int bytes_written; |
| 123 }; | 132 }; |
| 124 std::queue<WriteRequest> write_queue_; | 133 std::queue<WriteRequest> write_queue_; |
| 125 scoped_refptr<net::IOBuffer> io_buffer_write_; | 134 scoped_refptr<net::IOBuffer> io_buffer_write_; |
| 126 }; | 135 }; |
| 127 | 136 |
| 128 } // namespace extensions | 137 } // namespace extensions |
| 129 | 138 |
| 130 #endif // CHROME_BROWSER_EXTENSIONS_API_SOCKET_SOCKET_H_ | 139 #endif // CHROME_BROWSER_EXTENSIONS_API_SOCKET_SOCKET_H_ |
| OLD | NEW |