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

Side by Side Diff: chrome/browser/extensions/api/socket/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: Remove unrelated changes. Created 8 years, 3 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_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>
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 "chrome/browser/extensions/api/api_resource.h" 14 #include "chrome/browser/extensions/api/api_resource.h"
15 #include "net/base/completion_callback.h" 15 #include "net/base/completion_callback.h"
16 #include "net/base/io_buffer.h" 16 #include "net/base/io_buffer.h"
17 #include "net/base/ip_endpoint.h" 17 #include "net/base/ip_endpoint.h"
18 #include "net/socket/tcp_client_socket.h"
18 19
19 namespace net { 20 namespace net {
20 class AddressList; 21 class AddressList;
21 class IPEndPoint; 22 class IPEndPoint;
22 class Socket; 23 class Socket;
23 } 24 }
24 25
25 namespace extensions { 26 namespace extensions {
26 27
27 typedef base::Callback<void(int)> CompletionCallback; 28 typedef base::Callback<void(int)> CompletionCallback;
28 typedef base::Callback<void(int, scoped_refptr<net::IOBuffer> io_buffer)> 29 typedef base::Callback<void(int, scoped_refptr<net::IOBuffer> io_buffer)>
29 ReadCompletionCallback; 30 ReadCompletionCallback;
30 typedef base::Callback< 31 typedef base::Callback<
31 void(int, scoped_refptr<net::IOBuffer> io_buffer, const std::string&, int)> 32 void(int, scoped_refptr<net::IOBuffer> io_buffer, const std::string&, int)>
32 RecvFromCompletionCallback; 33 RecvFromCompletionCallback;
34 typedef base::Callback<
35 void(int, net::TCPClientSocket*)> AcceptCompletionCallback;
33 36
34 // A Socket wraps a low-level socket and includes housekeeping information that 37 // A Socket wraps a low-level socket and includes housekeeping information that
35 // we need to manage it in the context of an extension. 38 // we need to manage it in the context of an extension.
36 class Socket : public ApiResource { 39 class Socket : public ApiResource {
37 public: 40 public:
38 enum SocketType { 41 enum SocketType {
39 TYPE_TCP, 42 TYPE_TCP,
40 TYPE_UDP, 43 TYPE_UDP,
41 }; 44 };
42 45
(...skipping 18 matching lines...) Expand all
61 virtual void RecvFrom(int count, 64 virtual void RecvFrom(int count,
62 const RecvFromCompletionCallback& callback) = 0; 65 const RecvFromCompletionCallback& callback) = 0;
63 virtual void SendTo(scoped_refptr<net::IOBuffer> io_buffer, 66 virtual void SendTo(scoped_refptr<net::IOBuffer> io_buffer,
64 int byte_count, 67 int byte_count,
65 const std::string& address, 68 const std::string& address,
66 int port, 69 int port,
67 const CompletionCallback& callback) = 0; 70 const CompletionCallback& callback) = 0;
68 71
69 virtual bool SetKeepAlive(bool enable, int delay); 72 virtual bool SetKeepAlive(bool enable, int delay);
70 virtual bool SetNoDelay(bool no_delay); 73 virtual bool SetNoDelay(bool no_delay);
74 virtual int Listen(int backlog, std::string& error_msg);
75 virtual void Accept(const AcceptCompletionCallback &callback);
71 76
72 bool IsConnected(); 77 bool IsConnected();
73 78
74 virtual bool GetPeerAddress(net::IPEndPoint* address) = 0; 79 virtual bool GetPeerAddress(net::IPEndPoint* address) = 0;
75 virtual bool GetLocalAddress(net::IPEndPoint* address) = 0; 80 virtual bool GetLocalAddress(net::IPEndPoint* address) = 0;
76 81
77 virtual SocketType GetSocketType() const = 0; 82 virtual SocketType GetSocketType() const = 0;
78 83
79 static bool StringAndPortToAddressList(const std::string& ip_address_str, 84 static bool StringAndPortToAddressList(const std::string& ip_address_str,
80 int port, 85 int port,
(...skipping 29 matching lines...) Expand all
110 CompletionCallback callback; 115 CompletionCallback callback;
111 int bytes_written; 116 int bytes_written;
112 }; 117 };
113 std::queue<WriteRequest> write_queue_; 118 std::queue<WriteRequest> write_queue_;
114 scoped_refptr<net::IOBuffer> io_buffer_write_; 119 scoped_refptr<net::IOBuffer> io_buffer_write_;
115 }; 120 };
116 121
117 } // namespace extensions 122 } // namespace extensions
118 123
119 #endif // CHROME_BROWSER_EXTENSIONS_API_SOCKET_SOCKET_H_ 124 #endif // CHROME_BROWSER_EXTENSIONS_API_SOCKET_SOCKET_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/api/socket/socket.cc » ('j') | chrome/browser/extensions/api/socket/socket_api.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698