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 27 matching lines...) Expand all Loading... | |
| 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 { |
| 43 TYPE_TCP, | 43 TYPE_TCP, |
| 44 TYPE_UDP, | 44 TYPE_UDP, |
| 45 }; | 45 }; |
| 46 | 46 |
| 47 virtual ~Socket(); | 47 virtual ~Socket(); |
| 48 void SetOriginalHostname(const std::string& original_hostname) { | |
| 49 original_hostname_ = original_hostname; | |
| 50 } | |
| 51 const std::string& OriginalHostname() { | |
| 52 return original_hostname_; | |
| 53 } | |
| 48 virtual void Connect(const std::string& address, | 54 virtual void Connect(const std::string& address, |
| 49 int port, | 55 int port, |
| 50 const CompletionCallback& callback) = 0; | 56 const CompletionCallback& callback) = 0; |
| 51 virtual void Disconnect() = 0; | 57 virtual void Disconnect() = 0; |
| 52 virtual int Bind(const std::string& address, int port) = 0; | 58 virtual int Bind(const std::string& address, int port) = 0; |
| 53 | 59 |
| 54 // The |callback| will be called with the number of bytes read into the | 60 // The |callback| will be called with the number of bytes read into the |
| 55 // buffer, or a negative number if an error occurred. | 61 // buffer, or a negative number if an error occurred. |
| 56 virtual void Read(int count, | 62 virtual void Read(int count, |
| 57 const ReadCompletionCallback& callback) = 0; | 63 const ReadCompletionCallback& callback) = 0; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 95 | 101 |
| 96 protected: | 102 protected: |
| 97 explicit Socket(const std::string& owner_extension_id_); | 103 explicit Socket(const std::string& owner_extension_id_); |
| 98 | 104 |
| 99 void WriteData(); | 105 void WriteData(); |
| 100 virtual int WriteImpl(net::IOBuffer* io_buffer, | 106 virtual int WriteImpl(net::IOBuffer* io_buffer, |
| 101 int io_buffer_size, | 107 int io_buffer_size, |
| 102 const net::CompletionCallback& callback) = 0; | 108 const net::CompletionCallback& callback) = 0; |
| 103 virtual void OnWriteComplete(int result); | 109 virtual void OnWriteComplete(int result); |
| 104 | 110 |
| 105 const std::string address_; | 111 // The name given to Connect(), used when verifying a TLS certificate. |
| 112 std::string original_hostname_; | |
|
Ryan Sleevi
2013/11/25 17:30:13
nit: naming wise, original_hostname_ seems a bit c
Lally Singh
2013/12/05 17:07:12
Fair enough. Changed.
| |
| 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 |