Chromium Code Reviews| Index: net/socket/socket_test_util.h |
| diff --git a/net/socket/socket_test_util.h b/net/socket/socket_test_util.h |
| index 430b5225331c4eaaefdf1cbe413c411d0b44268c..36a344864fbedaf813273665154a7c4407f6654e 100644 |
| --- a/net/socket/socket_test_util.h |
| +++ b/net/socket/socket_test_util.h |
| @@ -190,9 +190,8 @@ struct MockWriteResult { |
| // for getting data about individual reads and writes on the socket. |
| class SocketDataProvider { |
| public: |
| - SocketDataProvider() : socket_(NULL) {} |
| - |
| - virtual ~SocketDataProvider() {} |
| + SocketDataProvider(); |
| + virtual ~SocketDataProvider(); |
| // Returns the buffer and result code for the next simulated read. |
| // If the |MockRead.result| is ERR_IO_PENDING, it informs the caller |
| @@ -204,6 +203,10 @@ class SocketDataProvider { |
| virtual bool AllReadDataConsumed() const = 0; |
| virtual bool AllWriteDataConsumed() const = 0; |
| + // Returns true if the request should be considered idle, for the purposes of |
| + // IsConnectedAndIdle. |
| + virtual bool IsIdle() const; |
| + |
| // Accessor for the socket which is using the SocketDataProvider. |
| AsyncSocket* socket() { return socket_; } |
| void set_socket(AsyncSocket* socket) { socket_ = socket; } |
| @@ -235,6 +238,11 @@ class AsyncSocket { |
| // is called to complete the asynchronous read operation. |
| virtual void OnWriteComplete(int rv) = 0; |
| virtual void OnConnectComplete(const MockConnect& data) = 0; |
| + |
| + // Called when the SocketDataProvider associated with the socket is destroyed. |
| + // The socket may continue to be used after the data provider is destroyed, |
| + // so it should be sure not to dereference the provider after this is called. |
| + virtual void OnDataProviderDestroyed() = 0; |
|
mmenke
2015/12/03 19:37:10
Could use weak ptrs instead, but I think this is a
|
| }; |
| // StaticSocketDataHelper manages a list of reads and writes. |
| @@ -364,10 +372,18 @@ class SequencedSocketData : public SocketDataProvider { |
| void Reset() override; |
| bool AllReadDataConsumed() const override; |
| bool AllWriteDataConsumed() const override; |
| + bool IsIdle() const override; |
| bool IsReadPaused(); |
| void CompleteRead(); |
| + // When true, IsConnectedAndIdle() will return false if the next event in the |
| + // sequence is a synchronous. Otherwise, the socket claims to be idle as |
| + // long as it's connected. Defaults to false. |
| + void set_busy_before_sync_reads(bool busy_before_sync_reads) { |
| + busy_before_sync_reads_ = busy_before_sync_reads; |
| + } |
| + |
| private: |
| // Defines the state for the read or write path. |
| enum IoState { |
| @@ -389,6 +405,8 @@ class SequencedSocketData : public SocketDataProvider { |
| IoState read_state_; |
| IoState write_state_; |
| + bool busy_before_sync_reads_; |
| + |
| base::WeakPtrFactory<SequencedSocketData> weak_factory_; |
| DISALLOW_COPY_AND_ASSIGN(SequencedSocketData); |
| @@ -717,6 +735,7 @@ class MockTCPClientSocket : public MockClientSocket, public AsyncSocket { |
| void OnReadComplete(const MockRead& data) override; |
| void OnWriteComplete(int rv) override; |
| void OnConnectComplete(const MockConnect& data) override; |
| + void OnDataProviderDestroyed() override; |
| private: |
| int CompleteRead(); |
| @@ -898,6 +917,7 @@ class MockSSLClientSocket : public MockClientSocket, public AsyncSocket { |
| int Connect(const CompletionCallback& callback) override; |
| void Disconnect() override; |
| bool IsConnected() const override; |
| + bool IsConnectedAndIdle() const override; |
| bool WasEverUsed() const override; |
| bool UsingTCPFastOpen() const override; |
| int GetPeerAddress(IPEndPoint* address) const override; |
| @@ -911,6 +931,10 @@ class MockSSLClientSocket : public MockClientSocket, public AsyncSocket { |
| void OnReadComplete(const MockRead& data) override; |
| void OnWriteComplete(int rv) override; |
| void OnConnectComplete(const MockConnect& data) override; |
| + // SSL sockets don't need magic to deal with destruction of their data |
| + // provider. |
| + // TODO(mmenke): Probably a good idea to support it, anyways. |
| + void OnDataProviderDestroyed() override {} |
| ChannelIDService* GetChannelIDService() const override; |
| @@ -954,6 +978,7 @@ class MockUDPClientSocket : public DatagramClientSocket, public AsyncSocket { |
| void OnReadComplete(const MockRead& data) override; |
| void OnWriteComplete(int rv) override; |
| void OnConnectComplete(const MockConnect& data) override; |
| + void OnDataProviderDestroyed() override; |
| void set_source_port(uint16 port) { source_port_ = port;} |