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 // |address| is a resolved IP address. Call set_hostname() to save the | |
51 // original DNS name of the host if this socket may later get upgraded to | |
52 // TLS (see TLSSocket::UpgradeSocketToTLS()). | |
Ryan Sleevi
2014/02/24 20:06:49
Comment wise, this wording seems a bit on the wish
lally
2014/02/27 17:05:59
Done.
| |
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 DNS name of the host that this socket is connected to, used when |
111 // verifying a TLS certificate. | |
Ryan Sleevi
2014/02/24 20:06:49
// The hostname of the remote host that this socke
lally
2014/02/27 17:05:59
I had to investigate to find out what the upper-la
Ryan Sleevi
2014/03/12 23:35:27
At least the SSLSocket layer expects the canonical
| |
112 std::string hostname_; | |
106 bool is_connected_; | 113 bool is_connected_; |
107 | 114 |
108 private: | 115 private: |
109 friend class ApiResourceManager<Socket>; | 116 friend class ApiResourceManager<Socket>; |
110 static const char* service_name() { | 117 static const char* service_name() { |
111 return "SocketManager"; | 118 return "SocketManager"; |
112 } | 119 } |
113 | 120 |
114 struct WriteRequest { | 121 struct WriteRequest { |
115 WriteRequest(scoped_refptr<net::IOBuffer> io_buffer, | 122 WriteRequest(scoped_refptr<net::IOBuffer> io_buffer, |
116 int byte_count, | 123 int byte_count, |
117 const CompletionCallback& callback); | 124 const CompletionCallback& callback); |
118 ~WriteRequest(); | 125 ~WriteRequest(); |
119 scoped_refptr<net::IOBuffer> io_buffer; | 126 scoped_refptr<net::IOBuffer> io_buffer; |
120 int byte_count; | 127 int byte_count; |
121 CompletionCallback callback; | 128 CompletionCallback callback; |
122 int bytes_written; | 129 int bytes_written; |
123 }; | 130 }; |
124 std::queue<WriteRequest> write_queue_; | 131 std::queue<WriteRequest> write_queue_; |
125 scoped_refptr<net::IOBuffer> io_buffer_write_; | 132 scoped_refptr<net::IOBuffer> io_buffer_write_; |
126 }; | 133 }; |
127 | 134 |
128 } // namespace extensions | 135 } // namespace extensions |
129 | 136 |
130 #endif // CHROME_BROWSER_EXTENSIONS_API_SOCKET_SOCKET_H_ | 137 #endif // CHROME_BROWSER_EXTENSIONS_API_SOCKET_SOCKET_H_ |
OLD | NEW |