Index: net/socket/tcp_client_socket.h |
diff --git a/net/socket/tcp_client_socket.h b/net/socket/tcp_client_socket.h |
index 8981fb066f55c18dcae07fd2bcfef28668ef77b7..81fe5939ac039f76ff1276b5ed7373c6425459d3 100644 |
--- a/net/socket/tcp_client_socket.h |
+++ b/net/socket/tcp_client_socket.h |
@@ -11,6 +11,8 @@ |
#include "base/compiler_specific.h" |
#include "base/macros.h" |
+#include "base/memory/weak_ptr.h" |
+#include "base/power_monitor/power_observer.h" |
#include "net/base/address_list.h" |
#include "net/base/completion_callback.h" |
#include "net/base/net_export.h" |
@@ -25,7 +27,8 @@ struct NetLogSource; |
class SocketPerformanceWatcher; |
// A client socket that uses TCP as the transport layer. |
-class NET_EXPORT TCPClientSocket : public StreamSocket { |
+class NET_EXPORT TCPClientSocket : public StreamSocket, |
+ public base::PowerObserver { |
public: |
// The IP address(es) and port number to connect to. The TCP socket will try |
// each IP address in the list until it succeeds in establishing a |
@@ -61,6 +64,7 @@ class NET_EXPORT TCPClientSocket : public StreamSocket { |
bool WasAlpnNegotiated() const override; |
NextProto GetNegotiatedProtocol() const override; |
bool GetSSLInfo(SSLInfo* ssl_info) override; |
+ void SetFailOnSuspend(bool disconnect_on_suspend) override; |
// Socket implementation. |
// Multiple outstanding requests are not supported. |
@@ -85,6 +89,9 @@ class NET_EXPORT TCPClientSocket : public StreamSocket { |
void AddConnectionAttempts(const ConnectionAttempts& attempts) override; |
int64_t GetTotalReceivedBytes() const override; |
+ // base::PowerObserver methods: |
+ void OnSuspend() override; |
+ |
private: |
// State machine for connecting the socket. |
enum ConnectState { |
@@ -110,8 +117,8 @@ class NET_EXPORT TCPClientSocket : public StreamSocket { |
void DoDisconnect(); |
void DidCompleteConnect(int result); |
- void DidCompleteRead(const CompletionCallback& callback, int result); |
- void DidCompleteWrite(const CompletionCallback& callback, int result); |
+ void DidCompleteRead(int result); |
+ void DidCompleteWrite(int result); |
void DidCompleteReadWrite(const CompletionCallback& callback, int result); |
int OpenSocket(AddressFamily family); |
@@ -139,8 +146,11 @@ class NET_EXPORT TCPClientSocket : public StreamSocket { |
// Where we are in above list. Set to -1 if uninitialized. |
int current_address_index_; |
- // External callback; called when connect is complete. |
+ // External callbacks; called when corresponding operations are complete. |
+ // Cleared when no such operation is pending. |
CompletionCallback connect_callback_; |
+ CompletionCallback read_callback_; |
+ CompletionCallback write_callback_; |
// The next state for the Connect() state machine. |
ConnectState next_connect_state_; |
@@ -158,6 +168,14 @@ class NET_EXPORT TCPClientSocket : public StreamSocket { |
// Total number of bytes received by the socket. |
int64_t total_received_bytes_; |
+ bool disconnect_on_suspend_; |
+ // Set to true if the socket was disconnected due to entering suspend mode. |
+ // Once set, read/write operations return ERR_NETWORK_IO_SUSPENDED, until |
+ // Connect() or Disconnect() is called. |
+ bool was_disconnected_on_suspend_; |
+ |
+ base::WeakPtrFactory<TCPClientSocket> weak_ptr_factory_; |
+ |
DISALLOW_COPY_AND_ASSIGN(TCPClientSocket); |
}; |