Chromium Code Reviews| Index: remoting/protocol/fake_session.h |
| diff --git a/remoting/protocol/fake_session.h b/remoting/protocol/fake_session.h |
| index 90fe0c8d5d7b4fef6b7d37fc9902e6e0568e4e33..7876d255a62cb03b760a01e8c225bd90ceb489a2 100644 |
| --- a/remoting/protocol/fake_session.h |
| +++ b/remoting/protocol/fake_session.h |
| @@ -10,6 +10,7 @@ |
| #include <vector> |
| #include "base/memory/scoped_ptr.h" |
| +#include "base/memory/weak_ptr.h" |
| #include "net/base/completion_callback.h" |
| #include "net/socket/socket.h" |
| #include "net/socket/stream_socket.h" |
| @@ -27,6 +28,15 @@ extern const char kTestJid[]; |
| // Read() reads data from another buffer that can be set with AppendInputData(). |
| // Pending reads are supported, so if there is a pending read AppendInputData() |
| // calls the read callback. |
| +// |
| +// Two fake sockets can be connected to each other using the SetPeer() |
| +// method, e.g.: |
| +// a->SetPeer(b); |
| +// b->SetPeer(a); |
|
Wez
2011/12/13 00:12:38
nit: You could actually have SetPeer() set the pee
Sergey Ulanov
2011/12/13 02:31:55
Done.
|
| +// After this all data written to |a| can be read from |b| and vica |
| +// versa. Two connected sockets |a| and |b| must be created and used on the |
| +// same thread. |
| +// |
| class FakeSocket : public net::StreamSocket { |
| public: |
| FakeSocket(); |
| @@ -34,7 +44,8 @@ class FakeSocket : public net::StreamSocket { |
| const std::string& written_data() const { return written_data_; } |
| - void AppendInputData(const char* data, int data_size); |
| + void AppendInputData(const std::vector<char>& data); |
| + void SetPeer(FakeSocket* peer_socket); |
| int input_pos() const { return input_pos_; } |
| bool read_pending() const { return read_pending_; } |
| @@ -67,6 +78,7 @@ class FakeSocket : public net::StreamSocket { |
| scoped_refptr<net::IOBuffer> read_buffer_; |
| int read_buffer_size_; |
| net::CompletionCallback read_callback_; |
| + base::WeakPtr<FakeSocket> peer_socket_; |
| std::string written_data_; |
| std::string input_data_; |
| @@ -75,6 +87,7 @@ class FakeSocket : public net::StreamSocket { |
| net::BoundNetLog net_log_; |
| MessageLoop* message_loop_; |
| + base::WeakPtrFactory<FakeSocket> weak_factory_; |
| DISALLOW_COPY_AND_ASSIGN(FakeSocket); |
| }; |