OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 EXTENSIONS_BROWSER_API_SOCKET_SOCKET_H_ | 5 #ifndef EXTENSIONS_BROWSER_API_SOCKET_SOCKET_H_ |
6 #define EXTENSIONS_BROWSER_API_SOCKET_SOCKET_H_ | 6 #define EXTENSIONS_BROWSER_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<void(int, net::TCPClientSocket*)> | 35 typedef base::Callback<void(int, net::TCPClientSocket*)> |
36 AcceptCompletionCallback; | 36 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 { TYPE_TCP, TYPE_UDP, }; | 42 enum SocketType { TYPE_TCP, TYPE_UDP, TYPE_TLS }; |
43 | 43 |
44 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; } | |
Ryan Sleevi
2014/03/26 19:57:40
Seems like the comment from 111-114 should be move
lally
2014/03/28 16:22:51
Done.
| |
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(). | |
45 virtual void Connect(const std::string& address, | 53 virtual void Connect(const std::string& address, |
46 int port, | 54 int port, |
47 const CompletionCallback& callback) = 0; | 55 const CompletionCallback& callback) = 0; |
48 virtual void Disconnect() = 0; | 56 virtual void Disconnect() = 0; |
49 virtual int Bind(const std::string& address, int port) = 0; | 57 virtual int Bind(const std::string& address, int port) = 0; |
50 | 58 |
51 // 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 |
52 // buffer, or a negative number if an error occurred. | 60 // buffer, or a negative number if an error occurred. |
53 virtual void Read(int count, const ReadCompletionCallback& callback) = 0; | 61 virtual void Read(int count, const ReadCompletionCallback& callback) = 0; |
54 | 62 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
93 | 101 |
94 protected: | 102 protected: |
95 explicit Socket(const std::string& owner_extension_id_); | 103 explicit Socket(const std::string& owner_extension_id_); |
96 | 104 |
97 void WriteData(); | 105 void WriteData(); |
98 virtual int WriteImpl(net::IOBuffer* io_buffer, | 106 virtual int WriteImpl(net::IOBuffer* io_buffer, |
99 int io_buffer_size, | 107 int io_buffer_size, |
100 const net::CompletionCallback& callback) = 0; | 108 const net::CompletionCallback& callback) = 0; |
101 virtual void OnWriteComplete(int result); | 109 virtual void OnWriteComplete(int result); |
102 | 110 |
103 const std::string address_; | 111 // The hostname of the remote host that this socket is connected to. Note: |
112 // This may contain an IP literal. In the case of IDNs, this will contain | |
113 // a series of U-LABELs (UTF-8), not A-LABELs. IP literals for IPv6 will | |
114 // be unbracketed. | |
115 std::string hostname_; | |
104 bool is_connected_; | 116 bool is_connected_; |
105 | 117 |
106 private: | 118 private: |
107 friend class ApiResourceManager<Socket>; | 119 friend class ApiResourceManager<Socket>; |
108 static const char* service_name() { return "SocketManager"; } | 120 static const char* service_name() { return "SocketManager"; } |
109 | 121 |
110 struct WriteRequest { | 122 struct WriteRequest { |
111 WriteRequest(scoped_refptr<net::IOBuffer> io_buffer, | 123 WriteRequest(scoped_refptr<net::IOBuffer> io_buffer, |
112 int byte_count, | 124 int byte_count, |
113 const CompletionCallback& callback); | 125 const CompletionCallback& callback); |
114 ~WriteRequest(); | 126 ~WriteRequest(); |
115 scoped_refptr<net::IOBuffer> io_buffer; | 127 scoped_refptr<net::IOBuffer> io_buffer; |
116 int byte_count; | 128 int byte_count; |
117 CompletionCallback callback; | 129 CompletionCallback callback; |
118 int bytes_written; | 130 int bytes_written; |
119 }; | 131 }; |
120 std::queue<WriteRequest> write_queue_; | 132 std::queue<WriteRequest> write_queue_; |
121 scoped_refptr<net::IOBuffer> io_buffer_write_; | 133 scoped_refptr<net::IOBuffer> io_buffer_write_; |
122 }; | 134 }; |
123 | 135 |
124 } // namespace extensions | 136 } // namespace extensions |
125 | 137 |
126 #endif // EXTENSIONS_BROWSER_API_SOCKET_SOCKET_H_ | 138 #endif // EXTENSIONS_BROWSER_API_SOCKET_SOCKET_H_ |
OLD | NEW |