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 24 matching lines...) Expand all Loading... | |
| 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 { |
| 43 TYPE_TCP, | 43 TYPE_TCP, |
| 44 TYPE_UDP, | 44 TYPE_UDP, |
| 45 TYPE_TLS | |
| 45 }; | 46 }; |
| 46 | 47 |
| 47 virtual ~Socket(); | 48 virtual ~Socket(); |
| 49 | |
| 50 void SetHostname(const std::string& hostname) { | |
| 51 hostname_ = hostname; | |
| 52 } | |
|
rpaquay
2013/12/09 23:02:03
The convention for simple accessors is "set_hostna
lally
2013/12/12 02:31:39
Done.
| |
| 53 const std::string& Hostname() { | |
| 54 return hostname_; | |
| 55 } | |
| 56 | |
|
rpaquay
2013/12/09 23:02:03
The convention for simple accessor is "hostname()"
lally
2013/12/12 02:31:39
Done.
| |
| 48 virtual void Connect(const std::string& address, | 57 virtual void Connect(const std::string& address, |
| 49 int port, | 58 int port, |
| 50 const CompletionCallback& callback) = 0; | 59 const CompletionCallback& callback) = 0; |
| 51 virtual void Disconnect() = 0; | 60 virtual void Disconnect() = 0; |
| 52 virtual int Bind(const std::string& address, int port) = 0; | 61 virtual int Bind(const std::string& address, int port) = 0; |
| 53 | 62 |
| 54 // The |callback| will be called with the number of bytes read into the | 63 // The |callback| will be called with the number of bytes read into the |
| 55 // buffer, or a negative number if an error occurred. | 64 // buffer, or a negative number if an error occurred. |
| 56 virtual void Read(int count, | 65 virtual void Read(int count, |
| 57 const ReadCompletionCallback& callback) = 0; | 66 const ReadCompletionCallback& callback) = 0; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 95 | 104 |
| 96 protected: | 105 protected: |
| 97 explicit Socket(const std::string& owner_extension_id_); | 106 explicit Socket(const std::string& owner_extension_id_); |
| 98 | 107 |
| 99 void WriteData(); | 108 void WriteData(); |
| 100 virtual int WriteImpl(net::IOBuffer* io_buffer, | 109 virtual int WriteImpl(net::IOBuffer* io_buffer, |
| 101 int io_buffer_size, | 110 int io_buffer_size, |
| 102 const net::CompletionCallback& callback) = 0; | 111 const net::CompletionCallback& callback) = 0; |
| 103 virtual void OnWriteComplete(int result); | 112 virtual void OnWriteComplete(int result); |
| 104 | 113 |
| 105 const std::string address_; | 114 // The name given to Connect(), used when verifying a TLS certificate. |
| 115 std::string hostname_; | |
| 106 bool is_connected_; | 116 bool is_connected_; |
| 107 | 117 |
| 108 private: | 118 private: |
| 109 friend class ApiResourceManager<Socket>; | 119 friend class ApiResourceManager<Socket>; |
| 110 static const char* service_name() { | 120 static const char* service_name() { |
| 111 return "SocketManager"; | 121 return "SocketManager"; |
| 112 } | 122 } |
| 113 | 123 |
| 114 struct WriteRequest { | 124 struct WriteRequest { |
| 115 WriteRequest(scoped_refptr<net::IOBuffer> io_buffer, | 125 WriteRequest(scoped_refptr<net::IOBuffer> io_buffer, |
| 116 int byte_count, | 126 int byte_count, |
| 117 const CompletionCallback& callback); | 127 const CompletionCallback& callback); |
| 118 ~WriteRequest(); | 128 ~WriteRequest(); |
| 119 scoped_refptr<net::IOBuffer> io_buffer; | 129 scoped_refptr<net::IOBuffer> io_buffer; |
| 120 int byte_count; | 130 int byte_count; |
| 121 CompletionCallback callback; | 131 CompletionCallback callback; |
| 122 int bytes_written; | 132 int bytes_written; |
| 123 }; | 133 }; |
| 124 std::queue<WriteRequest> write_queue_; | 134 std::queue<WriteRequest> write_queue_; |
| 125 scoped_refptr<net::IOBuffer> io_buffer_write_; | 135 scoped_refptr<net::IOBuffer> io_buffer_write_; |
| 126 }; | 136 }; |
| 127 | 137 |
| 128 } // namespace extensions | 138 } // namespace extensions |
| 129 | 139 |
| 130 #endif // CHROME_BROWSER_EXTENSIONS_API_SOCKET_SOCKET_H_ | 140 #endif // CHROME_BROWSER_EXTENSIONS_API_SOCKET_SOCKET_H_ |
| OLD | NEW |