| 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_UDP_SOCKET_H_ | 5 #ifndef EXTENSIONS_BROWSER_API_SOCKET_UDP_SOCKET_H_ |
| 6 #define EXTENSIONS_BROWSER_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 "extensions/browser/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, const ReadCompletionCallback& callback) OVERRIDE; | 26 virtual void Read(int count, const ReadCompletionCallback& callback) override; |
| 27 virtual void RecvFrom(int count, | 27 virtual void RecvFrom(int count, |
| 28 const RecvFromCompletionCallback& callback) OVERRIDE; | 28 const RecvFromCompletionCallback& callback) override; |
| 29 virtual void SendTo(scoped_refptr<net::IOBuffer> io_buffer, | 29 virtual void SendTo(scoped_refptr<net::IOBuffer> io_buffer, |
| 30 int byte_count, | 30 int byte_count, |
| 31 const std::string& address, | 31 const std::string& address, |
| 32 int port, | 32 int port, |
| 33 const CompletionCallback& callback) OVERRIDE; | 33 const CompletionCallback& callback) override; |
| 34 | 34 |
| 35 virtual bool IsConnected() OVERRIDE; | 35 virtual bool IsConnected() override; |
| 36 | 36 |
| 37 virtual bool GetPeerAddress(net::IPEndPoint* address) OVERRIDE; | 37 virtual bool GetPeerAddress(net::IPEndPoint* address) override; |
| 38 virtual bool GetLocalAddress(net::IPEndPoint* address) OVERRIDE; | 38 virtual bool GetLocalAddress(net::IPEndPoint* address) override; |
| 39 virtual Socket::SocketType GetSocketType() const OVERRIDE; | 39 virtual Socket::SocketType GetSocketType() const override; |
| 40 | 40 |
| 41 bool IsBound(); | 41 bool IsBound(); |
| 42 | 42 |
| 43 int JoinGroup(const std::string& address); | 43 int JoinGroup(const std::string& address); |
| 44 int LeaveGroup(const std::string& address); | 44 int LeaveGroup(const std::string& address); |
| 45 | 45 |
| 46 int SetMulticastTimeToLive(int ttl); | 46 int SetMulticastTimeToLive(int ttl); |
| 47 int SetMulticastLoopbackMode(bool loopback); | 47 int SetMulticastLoopbackMode(bool loopback); |
| 48 | 48 |
| 49 const std::vector<std::string>& GetJoinedGroups() const; | 49 const std::vector<std::string>& GetJoinedGroups() const; |
| 50 | 50 |
| 51 protected: | 51 protected: |
| 52 virtual int WriteImpl(net::IOBuffer* io_buffer, | 52 virtual int WriteImpl(net::IOBuffer* io_buffer, |
| 53 int io_buffer_size, | 53 int io_buffer_size, |
| 54 const net::CompletionCallback& callback) OVERRIDE; | 54 const net::CompletionCallback& callback) override; |
| 55 | 55 |
| 56 private: | 56 private: |
| 57 // Make net::IPEndPoint can be refcounted | 57 // Make net::IPEndPoint can be refcounted |
| 58 typedef base::RefCountedData<net::IPEndPoint> IPEndPoint; | 58 typedef base::RefCountedData<net::IPEndPoint> IPEndPoint; |
| 59 | 59 |
| 60 void OnReadComplete(scoped_refptr<net::IOBuffer> io_buffer, int result); | 60 void OnReadComplete(scoped_refptr<net::IOBuffer> io_buffer, int result); |
| 61 void OnRecvFromComplete(scoped_refptr<net::IOBuffer> io_buffer, | 61 void OnRecvFromComplete(scoped_refptr<net::IOBuffer> io_buffer, |
| 62 scoped_refptr<IPEndPoint> address, | 62 scoped_refptr<IPEndPoint> address, |
| 63 int result); | 63 int result); |
| 64 void OnSendToComplete(int result); | 64 void OnSendToComplete(int result); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 75 }; | 75 }; |
| 76 | 76 |
| 77 // UDP Socket instances from the "sockets.udp" namespace. These are regular | 77 // UDP Socket instances from the "sockets.udp" namespace. These are regular |
| 78 // socket objects with additional properties related to the behavior defined in | 78 // socket objects with additional properties related to the behavior defined in |
| 79 // the "sockets.udp" namespace. | 79 // the "sockets.udp" namespace. |
| 80 class ResumableUDPSocket : public UDPSocket { | 80 class ResumableUDPSocket : public UDPSocket { |
| 81 public: | 81 public: |
| 82 explicit ResumableUDPSocket(const std::string& owner_extension_id); | 82 explicit ResumableUDPSocket(const std::string& owner_extension_id); |
| 83 | 83 |
| 84 // Overriden from ApiResource | 84 // Overriden from ApiResource |
| 85 virtual bool IsPersistent() const OVERRIDE; | 85 virtual bool IsPersistent() const override; |
| 86 | 86 |
| 87 const std::string& name() const { return name_; } | 87 const std::string& name() const { return name_; } |
| 88 void set_name(const std::string& name) { name_ = name; } | 88 void set_name(const std::string& name) { name_ = name; } |
| 89 | 89 |
| 90 bool persistent() const { return persistent_; } | 90 bool persistent() const { return persistent_; } |
| 91 void set_persistent(bool persistent) { persistent_ = persistent; } | 91 void set_persistent(bool persistent) { persistent_ = persistent; } |
| 92 | 92 |
| 93 int buffer_size() const { return buffer_size_; } | 93 int buffer_size() const { return buffer_size_; } |
| 94 void set_buffer_size(int buffer_size) { buffer_size_ = buffer_size; } | 94 void set_buffer_size(int buffer_size) { buffer_size_ = buffer_size; } |
| 95 | 95 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 108 // 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. |
| 109 int buffer_size_; | 109 int buffer_size_; |
| 110 // Flag indicating whether a connected socket blocks its peer from sending | 110 // Flag indicating whether a connected socket blocks its peer from sending |
| 111 // more data - see sockets_udp.idl. | 111 // more data - see sockets_udp.idl. |
| 112 bool paused_; | 112 bool paused_; |
| 113 }; | 113 }; |
| 114 | 114 |
| 115 } // namespace extensions | 115 } // namespace extensions |
| 116 | 116 |
| 117 #endif // EXTENSIONS_BROWSER_API_SOCKET_UDP_SOCKET_H_ | 117 #endif // EXTENSIONS_BROWSER_API_SOCKET_UDP_SOCKET_H_ |
| OLD | NEW |