| 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 <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <string> | 10 #include <string> |
| 11 | 11 |
| 12 #include "extensions/browser/api/socket/socket.h" | 12 #include "extensions/browser/api/socket/socket.h" |
| 13 | 13 |
| 14 // This looks like it should be forward-declarable, but it does some tricky | 14 // This looks like it should be forward-declarable, but it does some tricky |
| 15 // moves that make it easier to just include it. | 15 // moves that make it easier to just include it. |
| 16 #include "net/socket/tcp_client_socket.h" | 16 #include "net/socket/tcp_client_socket.h" |
| 17 #include "net/socket/tcp_server_socket.h" | 17 #include "net/socket/tcp_server_socket.h" |
| 18 | 18 |
| 19 namespace net { | 19 namespace net { |
| 20 class Socket; | 20 class Socket; |
| 21 } | 21 } |
| 22 | 22 |
| 23 namespace extensions { | 23 namespace extensions { |
| 24 | 24 |
| 25 class TCPSocket : public Socket { | 25 class TCPSocket : public Socket { |
| 26 public: | 26 public: |
| 27 explicit TCPSocket(const std::string& owner_extension_id); | 27 explicit TCPSocket(const std::string& owner_extension_id); |
| 28 TCPSocket(scoped_ptr<net::TCPClientSocket> tcp_client_socket, | 28 TCPSocket(std::unique_ptr<net::TCPClientSocket> tcp_client_socket, |
| 29 const std::string& owner_extension_id, | 29 const std::string& owner_extension_id, |
| 30 bool is_connected = false); | 30 bool is_connected = false); |
| 31 | 31 |
| 32 ~TCPSocket() override; | 32 ~TCPSocket() override; |
| 33 | 33 |
| 34 void Connect(const net::AddressList& address, | 34 void Connect(const net::AddressList& address, |
| 35 const CompletionCallback& callback) override; | 35 const CompletionCallback& callback) override; |
| 36 void Disconnect() override; | 36 void Disconnect() override; |
| 37 int Bind(const std::string& address, uint16_t port) override; | 37 int Bind(const std::string& address, uint16_t port) override; |
| 38 void Read(int count, const ReadCompletionCallback& callback) override; | 38 void Read(int count, const ReadCompletionCallback& callback) override; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 55 bool GetLocalAddress(net::IPEndPoint* address) override; | 55 bool GetLocalAddress(net::IPEndPoint* address) override; |
| 56 | 56 |
| 57 // Like Disconnect(), only Release() doesn't delete the underlying stream | 57 // Like Disconnect(), only Release() doesn't delete the underlying stream |
| 58 // or attempt to close it. Useful when giving away ownership with | 58 // or attempt to close it. Useful when giving away ownership with |
| 59 // ClientStream(). | 59 // ClientStream(). |
| 60 virtual void Release(); | 60 virtual void Release(); |
| 61 | 61 |
| 62 Socket::SocketType GetSocketType() const override; | 62 Socket::SocketType GetSocketType() const override; |
| 63 | 63 |
| 64 static TCPSocket* CreateSocketForTesting( | 64 static TCPSocket* CreateSocketForTesting( |
| 65 scoped_ptr<net::TCPClientSocket> tcp_client_socket, | 65 std::unique_ptr<net::TCPClientSocket> tcp_client_socket, |
| 66 const std::string& owner_extension_id, | 66 const std::string& owner_extension_id, |
| 67 bool is_connected = false); | 67 bool is_connected = false); |
| 68 static TCPSocket* CreateServerSocketForTesting( | 68 static TCPSocket* CreateServerSocketForTesting( |
| 69 scoped_ptr<net::TCPServerSocket> tcp_server_socket, | 69 std::unique_ptr<net::TCPServerSocket> tcp_server_socket, |
| 70 const std::string& owner_extension_id); | 70 const std::string& owner_extension_id); |
| 71 | 71 |
| 72 // Returns NULL if GetSocketType() isn't TYPE_TCP or if the connection | 72 // Returns NULL if GetSocketType() isn't TYPE_TCP or if the connection |
| 73 // wasn't set up via Connect() (vs Listen()/Accept()). | 73 // wasn't set up via Connect() (vs Listen()/Accept()). |
| 74 net::TCPClientSocket* ClientStream(); | 74 net::TCPClientSocket* ClientStream(); |
| 75 | 75 |
| 76 // Whether a Read() has been issued, that hasn't come back yet. | 76 // Whether a Read() has been issued, that hasn't come back yet. |
| 77 bool HasPendingRead() const; | 77 bool HasPendingRead() const; |
| 78 | 78 |
| 79 protected: | 79 protected: |
| 80 int WriteImpl(net::IOBuffer* io_buffer, | 80 int WriteImpl(net::IOBuffer* io_buffer, |
| 81 int io_buffer_size, | 81 int io_buffer_size, |
| 82 const net::CompletionCallback& callback) override; | 82 const net::CompletionCallback& callback) override; |
| 83 | 83 |
| 84 private: | 84 private: |
| 85 void RefreshConnectionStatus(); | 85 void RefreshConnectionStatus(); |
| 86 void OnConnectComplete(int result); | 86 void OnConnectComplete(int result); |
| 87 void OnReadComplete(scoped_refptr<net::IOBuffer> io_buffer, int result); | 87 void OnReadComplete(scoped_refptr<net::IOBuffer> io_buffer, int result); |
| 88 void OnAccept(int result); | 88 void OnAccept(int result); |
| 89 | 89 |
| 90 TCPSocket(scoped_ptr<net::TCPServerSocket> tcp_server_socket, | 90 TCPSocket(std::unique_ptr<net::TCPServerSocket> tcp_server_socket, |
| 91 const std::string& owner_extension_id); | 91 const std::string& owner_extension_id); |
| 92 | 92 |
| 93 scoped_ptr<net::TCPClientSocket> socket_; | 93 std::unique_ptr<net::TCPClientSocket> socket_; |
| 94 scoped_ptr<net::TCPServerSocket> server_socket_; | 94 std::unique_ptr<net::TCPServerSocket> server_socket_; |
| 95 | 95 |
| 96 enum SocketMode { UNKNOWN = 0, CLIENT, SERVER, }; | 96 enum SocketMode { UNKNOWN = 0, CLIENT, SERVER, }; |
| 97 SocketMode socket_mode_; | 97 SocketMode socket_mode_; |
| 98 | 98 |
| 99 CompletionCallback connect_callback_; | 99 CompletionCallback connect_callback_; |
| 100 | 100 |
| 101 ReadCompletionCallback read_callback_; | 101 ReadCompletionCallback read_callback_; |
| 102 | 102 |
| 103 scoped_ptr<net::StreamSocket> accept_socket_; | 103 std::unique_ptr<net::StreamSocket> accept_socket_; |
| 104 AcceptCompletionCallback accept_callback_; | 104 AcceptCompletionCallback accept_callback_; |
| 105 }; | 105 }; |
| 106 | 106 |
| 107 // TCP Socket instances from the "sockets.tcp" namespace. These are regular | 107 // TCP Socket instances from the "sockets.tcp" namespace. These are regular |
| 108 // socket objects with additional properties related to the behavior defined in | 108 // socket objects with additional properties related to the behavior defined in |
| 109 // the "sockets.tcp" namespace. | 109 // the "sockets.tcp" namespace. |
| 110 class ResumableTCPSocket : public TCPSocket { | 110 class ResumableTCPSocket : public TCPSocket { |
| 111 public: | 111 public: |
| 112 explicit ResumableTCPSocket(const std::string& owner_extension_id); | 112 explicit ResumableTCPSocket(const std::string& owner_extension_id); |
| 113 explicit ResumableTCPSocket( | 113 explicit ResumableTCPSocket( |
| 114 scoped_ptr<net::TCPClientSocket> tcp_client_socket, | 114 std::unique_ptr<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 bool IsPersistent() const override; | 119 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_; } |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 |