| 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 <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <queue> | 10 #include <queue> |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 | 33 |
| 34 namespace extensions { | 34 namespace extensions { |
| 35 | 35 |
| 36 typedef base::Callback<void(int)> CompletionCallback; | 36 typedef base::Callback<void(int)> CompletionCallback; |
| 37 typedef base::Callback<void(int, scoped_refptr<net::IOBuffer> io_buffer)> | 37 typedef base::Callback<void(int, scoped_refptr<net::IOBuffer> io_buffer)> |
| 38 ReadCompletionCallback; | 38 ReadCompletionCallback; |
| 39 typedef base::Callback<void(int, | 39 typedef base::Callback<void(int, |
| 40 scoped_refptr<net::IOBuffer> io_buffer, | 40 scoped_refptr<net::IOBuffer> io_buffer, |
| 41 const std::string&, | 41 const std::string&, |
| 42 uint16_t)> RecvFromCompletionCallback; | 42 uint16_t)> RecvFromCompletionCallback; |
| 43 typedef base::Callback<void(int, scoped_ptr<net::TCPClientSocket>)> | 43 typedef base::Callback<void(int, std::unique_ptr<net::TCPClientSocket>)> |
| 44 AcceptCompletionCallback; | 44 AcceptCompletionCallback; |
| 45 | 45 |
| 46 // A Socket wraps a low-level socket and includes housekeeping information that | 46 // A Socket wraps a low-level socket and includes housekeeping information that |
| 47 // we need to manage it in the context of an extension. | 47 // we need to manage it in the context of an extension. |
| 48 class Socket : public ApiResource { | 48 class Socket : public ApiResource { |
| 49 public: | 49 public: |
| 50 enum SocketType { TYPE_TCP, TYPE_UDP, TYPE_TLS }; | 50 enum SocketType { TYPE_TCP, TYPE_UDP, TYPE_TLS }; |
| 51 | 51 |
| 52 ~Socket() override; | 52 ~Socket() override; |
| 53 | 53 |
| 54 // The hostname of the remote host that this socket is connected to. This | 54 // The hostname of the remote host that this socket is connected to. This |
| 55 // may be the empty string if the client does not intend to ever upgrade the | 55 // may be the empty string if the client does not intend to ever upgrade the |
| 56 // socket to TLS, and thusly has not invoked set_hostname(). | 56 // socket to TLS, and thusly has not invoked set_hostname(). |
| 57 const std::string& hostname() const { return hostname_; } | 57 const std::string& hostname() const { return hostname_; } |
| 58 | 58 |
| 59 // Set the hostname of the remote host that this socket is connected to. | 59 // Set the hostname of the remote host that this socket is connected to. |
| 60 // Note: This may be an IP literal. In the case of IDNs, this should be a | 60 // Note: This may be an IP literal. In the case of IDNs, this should be a |
| 61 // series of U-LABELs (UTF-8), not A-LABELs. IP literals for IPv6 will be | 61 // series of U-LABELs (UTF-8), not A-LABELs. IP literals for IPv6 will be |
| 62 // unbracketed. | 62 // unbracketed. |
| 63 void set_hostname(const std::string& hostname) { hostname_ = hostname; } | 63 void set_hostname(const std::string& hostname) { hostname_ = hostname; } |
| 64 | 64 |
| 65 #if defined(OS_CHROMEOS) | 65 #if defined(OS_CHROMEOS) |
| 66 void set_firewall_hole( | 66 void set_firewall_hole( |
| 67 scoped_ptr<AppFirewallHole, content::BrowserThread::DeleteOnUIThread> | 67 std::unique_ptr<AppFirewallHole, content::BrowserThread::DeleteOnUIThread> |
| 68 firewall_hole) { | 68 firewall_hole) { |
| 69 firewall_hole_ = std::move(firewall_hole); | 69 firewall_hole_ = std::move(firewall_hole); |
| 70 } | 70 } |
| 71 #endif // OS_CHROMEOS | 71 #endif // OS_CHROMEOS |
| 72 | 72 |
| 73 // Note: |address| contains the resolved IP address, not the hostname of | 73 // Note: |address| contains the resolved IP address, not the hostname of |
| 74 // the remote endpoint. In order to upgrade this socket to TLS, callers | 74 // the remote endpoint. In order to upgrade this socket to TLS, callers |
| 75 // must also supply the hostname of the endpoint via set_hostname(). | 75 // must also supply the hostname of the endpoint via set_hostname(). |
| 76 virtual void Connect(const net::AddressList& address, | 76 virtual void Connect(const net::AddressList& address, |
| 77 const CompletionCallback& callback) = 0; | 77 const CompletionCallback& callback) = 0; |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 scoped_refptr<net::IOBuffer> io_buffer; | 142 scoped_refptr<net::IOBuffer> io_buffer; |
| 143 int byte_count; | 143 int byte_count; |
| 144 CompletionCallback callback; | 144 CompletionCallback callback; |
| 145 int bytes_written; | 145 int bytes_written; |
| 146 }; | 146 }; |
| 147 std::queue<WriteRequest> write_queue_; | 147 std::queue<WriteRequest> write_queue_; |
| 148 scoped_refptr<net::IOBuffer> io_buffer_write_; | 148 scoped_refptr<net::IOBuffer> io_buffer_write_; |
| 149 | 149 |
| 150 #if defined(OS_CHROMEOS) | 150 #if defined(OS_CHROMEOS) |
| 151 // Represents a hole punched in the system firewall for this socket. | 151 // Represents a hole punched in the system firewall for this socket. |
| 152 scoped_ptr<AppFirewallHole, content::BrowserThread::DeleteOnUIThread> | 152 std::unique_ptr<AppFirewallHole, content::BrowserThread::DeleteOnUIThread> |
| 153 firewall_hole_; | 153 firewall_hole_; |
| 154 #endif // OS_CHROMEOS | 154 #endif // OS_CHROMEOS |
| 155 }; | 155 }; |
| 156 | 156 |
| 157 } // namespace extensions | 157 } // namespace extensions |
| 158 | 158 |
| 159 #endif // EXTENSIONS_BROWSER_API_SOCKET_SOCKET_H_ | 159 #endif // EXTENSIONS_BROWSER_API_SOCKET_SOCKET_H_ |
| OLD | NEW |