| 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> |
| 11 | 11 |
| 12 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "extensions/browser/api/api_resource.h" | 14 #include "extensions/browser/api/api_resource.h" |
| 15 #include "extensions/browser/api/api_resource_manager.h" | 15 #include "extensions/browser/api/api_resource_manager.h" |
| 16 #include "net/base/completion_callback.h" | 16 #include "net/base/completion_callback.h" |
| 17 #include "net/base/io_buffer.h" | 17 #include "net/base/io_buffer.h" |
| 18 #include "net/base/ip_endpoint.h" | 18 #include "net/base/ip_endpoint.h" |
| 19 #include "net/socket/tcp_client_socket.h" | 19 #include "net/socket/tcp_client_socket.h" |
| 20 | 20 |
| 21 #if defined(OS_CHROMEOS) |
| 22 #include "chromeos/network/firewall_hole.h" |
| 23 #endif // OS_CHROMEOS |
| 24 |
| 21 namespace net { | 25 namespace net { |
| 22 class AddressList; | 26 class AddressList; |
| 23 class IPEndPoint; | 27 class IPEndPoint; |
| 24 class Socket; | 28 class Socket; |
| 25 } | 29 } |
| 26 | 30 |
| 27 namespace extensions { | 31 namespace extensions { |
| 28 | 32 |
| 29 typedef base::Callback<void(int)> CompletionCallback; | 33 typedef base::Callback<void(int)> CompletionCallback; |
| 30 typedef base::Callback<void(int, scoped_refptr<net::IOBuffer> io_buffer)> | 34 typedef base::Callback<void(int, scoped_refptr<net::IOBuffer> io_buffer)> |
| (...skipping 17 matching lines...) Expand all Loading... |
| 48 // may be the empty string if the client does not intend to ever upgrade the | 52 // may be the empty string if the client does not intend to ever upgrade the |
| 49 // socket to TLS, and thusly has not invoked set_hostname(). | 53 // socket to TLS, and thusly has not invoked set_hostname(). |
| 50 const std::string& hostname() const { return hostname_; } | 54 const std::string& hostname() const { return hostname_; } |
| 51 | 55 |
| 52 // Set the hostname of the remote host that this socket is connected to. | 56 // Set the hostname of the remote host that this socket is connected to. |
| 53 // Note: This may be an IP literal. In the case of IDNs, this should be a | 57 // Note: This may be an IP literal. In the case of IDNs, this should be a |
| 54 // series of U-LABELs (UTF-8), not A-LABELs. IP literals for IPv6 will be | 58 // series of U-LABELs (UTF-8), not A-LABELs. IP literals for IPv6 will be |
| 55 // unbracketed. | 59 // unbracketed. |
| 56 void set_hostname(const std::string& hostname) { hostname_ = hostname; } | 60 void set_hostname(const std::string& hostname) { hostname_ = hostname; } |
| 57 | 61 |
| 62 #if defined(OS_CHROMEOS) |
| 63 void set_firewall_hole(scoped_ptr<chromeos::FirewallHole> firewall_hole) { |
| 64 firewall_hole_.reset(firewall_hole.release()); |
| 65 } |
| 66 #endif // OS_CHROMEOS |
| 67 |
| 58 // Note: |address| contains the resolved IP address, not the hostname of | 68 // Note: |address| contains the resolved IP address, not the hostname of |
| 59 // the remote endpoint. In order to upgrade this socket to TLS, callers | 69 // the remote endpoint. In order to upgrade this socket to TLS, callers |
| 60 // must also supply the hostname of the endpoint via set_hostname(). | 70 // must also supply the hostname of the endpoint via set_hostname(). |
| 61 virtual void Connect(const std::string& address, | 71 virtual void Connect(const std::string& address, |
| 62 uint16 port, | 72 uint16 port, |
| 63 const CompletionCallback& callback) = 0; | 73 const CompletionCallback& callback) = 0; |
| 64 virtual void Disconnect() = 0; | 74 virtual void Disconnect() = 0; |
| 65 virtual int Bind(const std::string& address, uint16 port) = 0; | 75 virtual int Bind(const std::string& address, uint16 port) = 0; |
| 66 | 76 |
| 67 // The |callback| will be called with the number of bytes read into the | 77 // The |callback| will be called with the number of bytes read into the |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 int byte_count, | 138 int byte_count, |
| 129 const CompletionCallback& callback); | 139 const CompletionCallback& callback); |
| 130 ~WriteRequest(); | 140 ~WriteRequest(); |
| 131 scoped_refptr<net::IOBuffer> io_buffer; | 141 scoped_refptr<net::IOBuffer> io_buffer; |
| 132 int byte_count; | 142 int byte_count; |
| 133 CompletionCallback callback; | 143 CompletionCallback callback; |
| 134 int bytes_written; | 144 int bytes_written; |
| 135 }; | 145 }; |
| 136 std::queue<WriteRequest> write_queue_; | 146 std::queue<WriteRequest> write_queue_; |
| 137 scoped_refptr<net::IOBuffer> io_buffer_write_; | 147 scoped_refptr<net::IOBuffer> io_buffer_write_; |
| 148 |
| 149 #if defined(OS_CHROMEOS) |
| 150 // Represents a hole punched in the system firewall for this socket. |
| 151 scoped_ptr<chromeos::FirewallHole, content::BrowserThread::DeleteOnUIThread> |
| 152 firewall_hole_; |
| 153 #endif // OS_CHROMEOS |
| 138 }; | 154 }; |
| 139 | 155 |
| 140 } // namespace extensions | 156 } // namespace extensions |
| 141 | 157 |
| 142 #endif // EXTENSIONS_BROWSER_API_SOCKET_SOCKET_H_ | 158 #endif // EXTENSIONS_BROWSER_API_SOCKET_SOCKET_H_ |
| OLD | NEW |