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_TCP_SOCKET_H_ | 5 #ifndef EXTENSIONS_BROWSER_API_SOCKET_TCP_SOCKET_H_ |
6 #define EXTENSIONS_BROWSER_API_SOCKET_TCP_SOCKET_H_ | 6 #define EXTENSIONS_BROWSER_API_SOCKET_TCP_SOCKET_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "extensions/browser/api/socket/socket.h" | 10 #include "extensions/browser/api/socket/socket.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 public: | 24 public: |
25 explicit TCPSocket(const std::string& owner_extension_id); | 25 explicit TCPSocket(const std::string& owner_extension_id); |
26 TCPSocket(net::TCPClientSocket* tcp_client_socket, | 26 TCPSocket(net::TCPClientSocket* tcp_client_socket, |
27 const std::string& owner_extension_id, | 27 const std::string& owner_extension_id, |
28 bool is_connected = false); | 28 bool is_connected = false); |
29 | 29 |
30 virtual ~TCPSocket(); | 30 virtual ~TCPSocket(); |
31 | 31 |
32 virtual void Connect(const std::string& address, | 32 virtual void Connect(const std::string& address, |
33 int port, | 33 int port, |
34 const CompletionCallback& callback) OVERRIDE; | 34 const CompletionCallback& callback) override; |
35 virtual void Disconnect() OVERRIDE; | 35 virtual void Disconnect() override; |
36 virtual int Bind(const std::string& address, int port) OVERRIDE; | 36 virtual int Bind(const std::string& address, int port) override; |
37 virtual void Read(int count, const ReadCompletionCallback& callback) OVERRIDE; | 37 virtual void Read(int count, const ReadCompletionCallback& callback) override; |
38 virtual void RecvFrom(int count, | 38 virtual void RecvFrom(int count, |
39 const RecvFromCompletionCallback& callback) OVERRIDE; | 39 const RecvFromCompletionCallback& callback) override; |
40 virtual void SendTo(scoped_refptr<net::IOBuffer> io_buffer, | 40 virtual void SendTo(scoped_refptr<net::IOBuffer> io_buffer, |
41 int byte_count, | 41 int byte_count, |
42 const std::string& address, | 42 const std::string& address, |
43 int port, | 43 int port, |
44 const CompletionCallback& callback) OVERRIDE; | 44 const CompletionCallback& callback) override; |
45 virtual bool SetKeepAlive(bool enable, int delay) OVERRIDE; | 45 virtual bool SetKeepAlive(bool enable, int delay) override; |
46 virtual bool SetNoDelay(bool no_delay) OVERRIDE; | 46 virtual bool SetNoDelay(bool no_delay) override; |
47 virtual int Listen(const std::string& address, | 47 virtual int Listen(const std::string& address, |
48 int port, | 48 int port, |
49 int backlog, | 49 int backlog, |
50 std::string* error_msg) OVERRIDE; | 50 std::string* error_msg) override; |
51 virtual void Accept(const AcceptCompletionCallback& callback) OVERRIDE; | 51 virtual void Accept(const AcceptCompletionCallback& callback) override; |
52 | 52 |
53 virtual bool IsConnected() OVERRIDE; | 53 virtual bool IsConnected() override; |
54 | 54 |
55 virtual bool GetPeerAddress(net::IPEndPoint* address) OVERRIDE; | 55 virtual bool GetPeerAddress(net::IPEndPoint* address) override; |
56 virtual bool GetLocalAddress(net::IPEndPoint* address) OVERRIDE; | 56 virtual bool GetLocalAddress(net::IPEndPoint* address) override; |
57 | 57 |
58 // Like Disconnect(), only Release() doesn't delete the underlying stream | 58 // Like Disconnect(), only Release() doesn't delete the underlying stream |
59 // or attempt to close it. Useful when giving away ownership with | 59 // or attempt to close it. Useful when giving away ownership with |
60 // ClientStream(). | 60 // ClientStream(). |
61 virtual void Release(); | 61 virtual void Release(); |
62 | 62 |
63 virtual Socket::SocketType GetSocketType() const OVERRIDE; | 63 virtual Socket::SocketType GetSocketType() const override; |
64 | 64 |
65 static TCPSocket* CreateSocketForTesting( | 65 static TCPSocket* CreateSocketForTesting( |
66 net::TCPClientSocket* tcp_client_socket, | 66 net::TCPClientSocket* tcp_client_socket, |
67 const std::string& owner_extension_id, | 67 const std::string& owner_extension_id, |
68 bool is_connected = false); | 68 bool is_connected = false); |
69 static TCPSocket* CreateServerSocketForTesting( | 69 static TCPSocket* CreateServerSocketForTesting( |
70 net::TCPServerSocket* tcp_server_socket, | 70 net::TCPServerSocket* tcp_server_socket, |
71 const std::string& owner_extension_id); | 71 const std::string& owner_extension_id); |
72 | 72 |
73 // Returns NULL if GetSocketType() isn't TYPE_TCP or if the connection | 73 // Returns NULL if GetSocketType() isn't TYPE_TCP or if the connection |
74 // wasn't set up via Connect() (vs Listen()/Accept()). | 74 // wasn't set up via Connect() (vs Listen()/Accept()). |
75 net::TCPClientSocket* ClientStream(); | 75 net::TCPClientSocket* ClientStream(); |
76 | 76 |
77 // Whether a Read() has been issued, that hasn't come back yet. | 77 // Whether a Read() has been issued, that hasn't come back yet. |
78 bool HasPendingRead() const; | 78 bool HasPendingRead() const; |
79 | 79 |
80 protected: | 80 protected: |
81 virtual int WriteImpl(net::IOBuffer* io_buffer, | 81 virtual int WriteImpl(net::IOBuffer* io_buffer, |
82 int io_buffer_size, | 82 int io_buffer_size, |
83 const net::CompletionCallback& callback) OVERRIDE; | 83 const net::CompletionCallback& callback) override; |
84 | 84 |
85 private: | 85 private: |
86 void RefreshConnectionStatus(); | 86 void RefreshConnectionStatus(); |
87 void OnConnectComplete(int result); | 87 void OnConnectComplete(int result); |
88 void OnReadComplete(scoped_refptr<net::IOBuffer> io_buffer, int result); | 88 void OnReadComplete(scoped_refptr<net::IOBuffer> io_buffer, int result); |
89 void OnAccept(int result); | 89 void OnAccept(int result); |
90 | 90 |
91 TCPSocket(net::TCPServerSocket* tcp_server_socket, | 91 TCPSocket(net::TCPServerSocket* tcp_server_socket, |
92 const std::string& owner_extension_id); | 92 const std::string& owner_extension_id); |
93 | 93 |
(...skipping 15 matching lines...) Expand all Loading... |
109 // socket objects with additional properties related to the behavior defined in | 109 // socket objects with additional properties related to the behavior defined in |
110 // the "sockets.tcp" namespace. | 110 // the "sockets.tcp" namespace. |
111 class ResumableTCPSocket : public TCPSocket { | 111 class ResumableTCPSocket : public TCPSocket { |
112 public: | 112 public: |
113 explicit ResumableTCPSocket(const std::string& owner_extension_id); | 113 explicit ResumableTCPSocket(const std::string& owner_extension_id); |
114 explicit ResumableTCPSocket(net::TCPClientSocket* tcp_client_socket, | 114 explicit ResumableTCPSocket(net::TCPClientSocket* tcp_client_socket, |
115 const std::string& owner_extension_id, | 115 const std::string& owner_extension_id, |
116 bool is_connected); | 116 bool is_connected); |
117 | 117 |
118 // Overriden from ApiResource | 118 // Overriden from ApiResource |
119 virtual bool IsPersistent() const OVERRIDE; | 119 virtual bool IsPersistent() const override; |
120 | 120 |
121 const std::string& name() const { return name_; } | 121 const std::string& name() const { return name_; } |
122 void set_name(const std::string& name) { name_ = name; } | 122 void set_name(const std::string& name) { name_ = name; } |
123 | 123 |
124 bool persistent() const { return persistent_; } | 124 bool persistent() const { return persistent_; } |
125 void set_persistent(bool persistent) { persistent_ = persistent; } | 125 void set_persistent(bool persistent) { persistent_ = persistent; } |
126 | 126 |
127 int buffer_size() const { return buffer_size_; } | 127 int buffer_size() const { return buffer_size_; } |
128 void set_buffer_size(int buffer_size) { buffer_size_ = buffer_size; } | 128 void set_buffer_size(int buffer_size) { buffer_size_ = buffer_size; } |
129 | 129 |
(...skipping 17 matching lines...) Expand all Loading... |
147 }; | 147 }; |
148 | 148 |
149 // TCP Socket instances from the "sockets.tcpServer" namespace. These are | 149 // TCP Socket instances from the "sockets.tcpServer" namespace. These are |
150 // regular socket objects with additional properties related to the behavior | 150 // regular socket objects with additional properties related to the behavior |
151 // defined in the "sockets.tcpServer" namespace. | 151 // defined in the "sockets.tcpServer" namespace. |
152 class ResumableTCPServerSocket : public TCPSocket { | 152 class ResumableTCPServerSocket : public TCPSocket { |
153 public: | 153 public: |
154 explicit ResumableTCPServerSocket(const std::string& owner_extension_id); | 154 explicit ResumableTCPServerSocket(const std::string& owner_extension_id); |
155 | 155 |
156 // Overriden from ApiResource | 156 // Overriden from ApiResource |
157 virtual bool IsPersistent() const OVERRIDE; | 157 virtual bool IsPersistent() const override; |
158 | 158 |
159 const std::string& name() const { return name_; } | 159 const std::string& name() const { return name_; } |
160 void set_name(const std::string& name) { name_ = name; } | 160 void set_name(const std::string& name) { name_ = name; } |
161 | 161 |
162 bool persistent() const { return persistent_; } | 162 bool persistent() const { return persistent_; } |
163 void set_persistent(bool persistent) { persistent_ = persistent; } | 163 void set_persistent(bool persistent) { persistent_ = persistent; } |
164 | 164 |
165 bool paused() const { return paused_; } | 165 bool paused() const { return paused_; } |
166 void set_paused(bool paused) { paused_ = paused; } | 166 void set_paused(bool paused) { paused_ = paused; } |
167 | 167 |
168 private: | 168 private: |
169 friend class ApiResourceManager<ResumableTCPServerSocket>; | 169 friend class ApiResourceManager<ResumableTCPServerSocket>; |
170 static const char* service_name() { | 170 static const char* service_name() { |
171 return "ResumableTCPServerSocketManager"; | 171 return "ResumableTCPServerSocketManager"; |
172 } | 172 } |
173 | 173 |
174 // Application-defined string - see sockets_tcp_server.idl. | 174 // Application-defined string - see sockets_tcp_server.idl. |
175 std::string name_; | 175 std::string name_; |
176 // Flag indicating whether the socket is left open when the application is | 176 // Flag indicating whether the socket is left open when the application is |
177 // suspended - see sockets_tcp_server.idl. | 177 // suspended - see sockets_tcp_server.idl. |
178 bool persistent_; | 178 bool persistent_; |
179 // Flag indicating whether a connected socket blocks its peer from sending | 179 // Flag indicating whether a connected socket blocks its peer from sending |
180 // more data - see sockets_tcp_server.idl. | 180 // more data - see sockets_tcp_server.idl. |
181 bool paused_; | 181 bool paused_; |
182 }; | 182 }; |
183 | 183 |
184 } // namespace extensions | 184 } // namespace extensions |
185 | 185 |
186 #endif // EXTENSIONS_BROWSER_API_SOCKET_TCP_SOCKET_H_ | 186 #endif // EXTENSIONS_BROWSER_API_SOCKET_TCP_SOCKET_H_ |
OLD | NEW |