Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(69)

Side by Side Diff: chrome/browser/extensions/api/socket/tcp_socket.h

Issue 10827390: Implement chrome.socket.bind/listen/accept for TCP server socket. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix tests Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_TCP_SOCKET_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_SOCKET_TCP_SOCKET_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_SOCKET_TCP_SOCKET_H_ 6 #define CHROME_BROWSER_EXTENSIONS_API_SOCKET_TCP_SOCKET_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "chrome/browser/extensions/api/socket/socket.h" 10 #include "chrome/browser/extensions/api/socket/socket.h"
11 11
12 // This looks like it should be forward-declarable, but it does some tricky 12 // This looks like it should be forward-declarable, but it does some tricky
13 // moves that make it easier to just include it. 13 // moves that make it easier to just include it.
14 #include "net/socket/tcp_client_socket.h" 14 #include "net/socket/tcp_client_socket.h"
15 #include "net/socket/tcp_server_socket.h"
15 16
16 namespace net { 17 namespace net {
17 class Socket; 18 class Socket;
18 } 19 }
19 20
20 namespace extensions { 21 namespace extensions {
21 22
22 class ApiResourceEventNotifier; 23 class ApiResourceEventNotifier;
23 24
24 class TCPSocket : public Socket { 25 class TCPSocket : public Socket {
25 public: 26 public:
26 TCPSocket(const std::string& owner_extension_id, 27 TCPSocket(const std::string& owner_extension_id,
27 ApiResourceEventNotifier* event_notifier); 28 ApiResourceEventNotifier* event_notifier);
29 TCPSocket(net::TCPClientSocket* tcp_client_socket,
30 const std::string& owner_extension_id,
31 ApiResourceEventNotifier* event_notifier,
32 bool is_connected = false);
33
28 virtual ~TCPSocket(); 34 virtual ~TCPSocket();
29 35
30 virtual void Connect(const std::string& address, 36 virtual void Connect(const std::string& address,
31 int port, 37 int port,
32 const CompletionCallback& callback) OVERRIDE; 38 const CompletionCallback& callback) OVERRIDE;
33 virtual void Disconnect() OVERRIDE; 39 virtual void Disconnect() OVERRIDE;
34 virtual int Bind(const std::string& address, int port) OVERRIDE; 40 virtual int Bind(const std::string& address, int port) OVERRIDE;
35 virtual void Read(int count, 41 virtual void Read(int count,
36 const ReadCompletionCallback& callback) OVERRIDE; 42 const ReadCompletionCallback& callback) OVERRIDE;
37 virtual void RecvFrom(int count, 43 virtual void RecvFrom(int count,
38 const RecvFromCompletionCallback& callback) OVERRIDE; 44 const RecvFromCompletionCallback& callback) OVERRIDE;
39 virtual void SendTo(scoped_refptr<net::IOBuffer> io_buffer, 45 virtual void SendTo(scoped_refptr<net::IOBuffer> io_buffer,
40 int byte_count, 46 int byte_count,
41 const std::string& address, 47 const std::string& address,
42 int port, 48 int port,
43 const CompletionCallback& callback) OVERRIDE; 49 const CompletionCallback& callback) OVERRIDE;
44 virtual bool SetKeepAlive(bool enable, int delay) OVERRIDE; 50 virtual bool SetKeepAlive(bool enable, int delay) OVERRIDE;
45 virtual bool SetNoDelay(bool no_delay) OVERRIDE; 51 virtual bool SetNoDelay(bool no_delay) OVERRIDE;
52 virtual int Listen(const std::string& address, int port,
53 int backlog, std::string* error_msg) OVERRIDE;
54 virtual void Accept(const AcceptCompletionCallback &callback) OVERRIDE;
55
46 virtual bool GetPeerAddress(net::IPEndPoint* address) OVERRIDE; 56 virtual bool GetPeerAddress(net::IPEndPoint* address) OVERRIDE;
47 virtual bool GetLocalAddress(net::IPEndPoint* address) OVERRIDE; 57 virtual bool GetLocalAddress(net::IPEndPoint* address) OVERRIDE;
48 virtual Socket::SocketType GetSocketType() const OVERRIDE; 58 virtual Socket::SocketType GetSocketType() const OVERRIDE;
49 59
50 static TCPSocket* CreateSocketForTesting( 60 static TCPSocket* CreateSocketForTesting(
51 net::TCPClientSocket* tcp_client_socket, 61 net::TCPClientSocket* tcp_client_socket,
52 const std::string& owner_extension_id, 62 const std::string& owner_extension_id,
53 ApiResourceEventNotifier* event_notifier); 63 ApiResourceEventNotifier* event_notifier);
64 static TCPSocket* CreateServerSocketForTesting(
65 net::TCPServerSocket* tcp_server_socket,
66 const std::string& owner_extension_id);
54 67
55 protected: 68 protected:
56 virtual int WriteImpl(net::IOBuffer* io_buffer, 69 virtual int WriteImpl(net::IOBuffer* io_buffer,
57 int io_buffer_size, 70 int io_buffer_size,
58 const net::CompletionCallback& callback) OVERRIDE; 71 const net::CompletionCallback& callback) OVERRIDE;
59 72
60 private: 73 private:
61 void OnConnectComplete(int result); 74 void OnConnectComplete(int result);
62 void OnReadComplete(scoped_refptr<net::IOBuffer> io_buffer, 75 void OnReadComplete(scoped_refptr<net::IOBuffer> io_buffer,
63 int result); 76 int result);
77 void OnAccept(int result);
64 78
65 TCPSocket(net::TCPClientSocket* tcp_client_socket, 79 TCPSocket(net::TCPServerSocket* tcp_server_socket,
66 const std::string& owner_extension_id, 80 const std::string& owner_extension_id);
67 ApiResourceEventNotifier* event_notifier);
68 81
69 scoped_ptr<net::TCPClientSocket> socket_; 82 scoped_ptr<net::TCPClientSocket> socket_;
83 scoped_ptr<net::TCPServerSocket> server_socket_;
84
85 enum SocketMode {
86 UNKNOWN = 0,
87 CLIENT,
88 SERVER,
89 };
90 SocketMode socket_mode_;
70 91
71 CompletionCallback connect_callback_; 92 CompletionCallback connect_callback_;
72 93
73 ReadCompletionCallback read_callback_; 94 ReadCompletionCallback read_callback_;
95
96 scoped_ptr<net::StreamSocket> accept_socket_;
97 AcceptCompletionCallback accept_callback_;
74 }; 98 };
75 99
76 } // namespace extensions 100 } // namespace extensions
77 101
78 #endif // CHROME_BROWSER_EXTENSIONS_API_SOCKET_TCP_SOCKET_H_ 102 #endif // CHROME_BROWSER_EXTENSIONS_API_SOCKET_TCP_SOCKET_H_
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/socket/socket_apitest.cc ('k') | chrome/browser/extensions/api/socket/tcp_socket.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698