| 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_UDP_SOCKET_H_ | 5 #ifndef EXTENSIONS_BROWSER_API_SOCKET_UDP_SOCKET_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_API_SOCKET_UDP_SOCKET_H_ | 6 #define EXTENSIONS_BROWSER_API_SOCKET_UDP_SOCKET_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "chrome/browser/extensions/api/socket/socket.h" | 11 #include "extensions/browser/api/socket/socket.h" |
| 12 #include "net/udp/udp_socket.h" | 12 #include "net/udp/udp_socket.h" |
| 13 | 13 |
| 14 namespace extensions { | 14 namespace extensions { |
| 15 | 15 |
| 16 class UDPSocket : public Socket { | 16 class UDPSocket : public Socket { |
| 17 public: | 17 public: |
| 18 explicit UDPSocket(const std::string& owner_extension_id); | 18 explicit UDPSocket(const std::string& owner_extension_id); |
| 19 virtual ~UDPSocket(); | 19 virtual ~UDPSocket(); |
| 20 | 20 |
| 21 virtual void Connect(const std::string& address, | 21 virtual void Connect(const std::string& address, |
| 22 int port, | 22 int port, |
| 23 const CompletionCallback& callback) OVERRIDE; | 23 const CompletionCallback& callback) OVERRIDE; |
| 24 virtual void Disconnect() OVERRIDE; | 24 virtual void Disconnect() OVERRIDE; |
| 25 virtual int Bind(const std::string& address, int port) OVERRIDE; | 25 virtual int Bind(const std::string& address, int port) OVERRIDE; |
| 26 virtual void Read(int count, | 26 virtual void Read(int count, const ReadCompletionCallback& callback) OVERRIDE; |
| 27 const ReadCompletionCallback& callback) OVERRIDE; | |
| 28 virtual void RecvFrom(int count, | 27 virtual void RecvFrom(int count, |
| 29 const RecvFromCompletionCallback& callback) OVERRIDE; | 28 const RecvFromCompletionCallback& callback) OVERRIDE; |
| 30 virtual void SendTo(scoped_refptr<net::IOBuffer> io_buffer, | 29 virtual void SendTo(scoped_refptr<net::IOBuffer> io_buffer, |
| 31 int byte_count, | 30 int byte_count, |
| 32 const std::string& address, | 31 const std::string& address, |
| 33 int port, | 32 int port, |
| 34 const CompletionCallback& callback) OVERRIDE; | 33 const CompletionCallback& callback) OVERRIDE; |
| 35 | 34 |
| 36 virtual bool IsConnected() OVERRIDE; | 35 virtual bool IsConnected() OVERRIDE; |
| 37 | 36 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 51 | 50 |
| 52 protected: | 51 protected: |
| 53 virtual int WriteImpl(net::IOBuffer* io_buffer, | 52 virtual int WriteImpl(net::IOBuffer* io_buffer, |
| 54 int io_buffer_size, | 53 int io_buffer_size, |
| 55 const net::CompletionCallback& callback) OVERRIDE; | 54 const net::CompletionCallback& callback) OVERRIDE; |
| 56 | 55 |
| 57 private: | 56 private: |
| 58 // Make net::IPEndPoint can be refcounted | 57 // Make net::IPEndPoint can be refcounted |
| 59 typedef base::RefCountedData<net::IPEndPoint> IPEndPoint; | 58 typedef base::RefCountedData<net::IPEndPoint> IPEndPoint; |
| 60 | 59 |
| 61 void OnReadComplete(scoped_refptr<net::IOBuffer> io_buffer, | 60 void OnReadComplete(scoped_refptr<net::IOBuffer> io_buffer, int result); |
| 62 int result); | |
| 63 void OnRecvFromComplete(scoped_refptr<net::IOBuffer> io_buffer, | 61 void OnRecvFromComplete(scoped_refptr<net::IOBuffer> io_buffer, |
| 64 scoped_refptr<IPEndPoint> address, | 62 scoped_refptr<IPEndPoint> address, |
| 65 int result); | 63 int result); |
| 66 void OnSendToComplete(int result); | 64 void OnSendToComplete(int result); |
| 67 | 65 |
| 68 net::UDPSocket socket_; | 66 net::UDPSocket socket_; |
| 69 | 67 |
| 70 ReadCompletionCallback read_callback_; | 68 ReadCompletionCallback read_callback_; |
| 71 | 69 |
| 72 RecvFromCompletionCallback recv_from_callback_; | 70 RecvFromCompletionCallback recv_from_callback_; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 93 void set_persistent(bool persistent) { persistent_ = persistent; } | 91 void set_persistent(bool persistent) { persistent_ = persistent; } |
| 94 | 92 |
| 95 int buffer_size() const { return buffer_size_; } | 93 int buffer_size() const { return buffer_size_; } |
| 96 void set_buffer_size(int buffer_size) { buffer_size_ = buffer_size; } | 94 void set_buffer_size(int buffer_size) { buffer_size_ = buffer_size; } |
| 97 | 95 |
| 98 bool paused() const { return paused_; } | 96 bool paused() const { return paused_; } |
| 99 void set_paused(bool paused) { paused_ = paused; } | 97 void set_paused(bool paused) { paused_ = paused; } |
| 100 | 98 |
| 101 private: | 99 private: |
| 102 friend class ApiResourceManager<ResumableUDPSocket>; | 100 friend class ApiResourceManager<ResumableUDPSocket>; |
| 103 static const char* service_name() { | 101 static const char* service_name() { return "ResumableUDPSocketManager"; } |
| 104 return "ResumableUDPSocketManager"; | |
| 105 } | |
| 106 | 102 |
| 107 // Application-defined string - see sockets_udp.idl. | 103 // Application-defined string - see sockets_udp.idl. |
| 108 std::string name_; | 104 std::string name_; |
| 109 // Flag indicating whether the socket is left open when the application is | 105 // Flag indicating whether the socket is left open when the application is |
| 110 // suspended - see sockets_udp.idl. | 106 // suspended - see sockets_udp.idl. |
| 111 bool persistent_; | 107 bool persistent_; |
| 112 // The size of the buffer used to receive data - see sockets_udp.idl. | 108 // The size of the buffer used to receive data - see sockets_udp.idl. |
| 113 int buffer_size_; | 109 int buffer_size_; |
| 114 // Flag indicating whether a connected socket blocks its peer from sending | 110 // Flag indicating whether a connected socket blocks its peer from sending |
| 115 // more data - see sockets_udp.idl. | 111 // more data - see sockets_udp.idl. |
| 116 bool paused_; | 112 bool paused_; |
| 117 }; | 113 }; |
| 118 | 114 |
| 119 } // namespace extensions | 115 } // namespace extensions |
| 120 | 116 |
| 121 #endif // CHROME_BROWSER_EXTENSIONS_API_SOCKET_UDP_SOCKET_H_ | 117 #endif // EXTENSIONS_BROWSER_API_SOCKET_UDP_SOCKET_H_ |
| OLD | NEW |