summaryrefslogtreecommitdiffstats
path: root/remoting/protocol/fake_connection.h
diff options
context:
space:
mode:
authorsergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-06 22:46:00 +0000
committersergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-06 22:46:00 +0000
commitc3af26f3314bf48f478cec8128b5c15cc3f98940 (patch)
tree0d3d0802a3a9b8e05487626f90c7dbf0dcecdea9 /remoting/protocol/fake_connection.h
parent5bcab699da1cedb4fc666c9f5d0099574a27c2fe (diff)
downloadchromium_src-c3af26f3314bf48f478cec8128b5c15cc3f98940.zip
chromium_src-c3af26f3314bf48f478cec8128b5c15cc3f98940.tar.gz
chromium_src-c3af26f3314bf48f478cec8128b5c15cc3f98940.tar.bz2
Use new Chromotocol code in host andclient.
1. ProtocolDecoder renamed to MessagesDecoder and moved to remoting/protocol. 2. base/protocol_util.[h|cc] split into base/util.[h|cc] and protocol/util.[h|cc]. 3. Added StreamReader and StreamWriter classes for events and video channels. 4. Client and host changed to use the new protocol code. BUG=None TEST=Unittests Review URL: http://codereview.chromium.org/3595012 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@61723 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting/protocol/fake_connection.h')
-rw-r--r--remoting/protocol/fake_connection.h94
1 files changed, 94 insertions, 0 deletions
diff --git a/remoting/protocol/fake_connection.h b/remoting/protocol/fake_connection.h
new file mode 100644
index 0000000..cabce4a
--- /dev/null
+++ b/remoting/protocol/fake_connection.h
@@ -0,0 +1,94 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef REMOTING_PROTOCOL_FAKE_CONNECTION_H_
+#define REMOTING_PROTOCOL_FAKE_CONNECTION_H_
+
+#include <vector>
+
+#include "base/scoped_ptr.h"
+#include "net/socket/socket.h"
+#include "remoting/protocol/chromoting_connection.h"
+
+namespace remoting {
+
+extern const char kTestJid[];
+
+// FakeSocket implement net::Socket interface for FakeConnection. All data
+// written to FakeSocket is stored in a buffer returned by written_data().
+// 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.
+class FakeSocket : public net::Socket {
+ public:
+ FakeSocket();
+ virtual ~FakeSocket();
+
+ const std::vector<char>& written_data() { return written_data_; }
+
+ void AppendInputData(char* data, int data_size);
+ int input_pos() { return input_pos_; }
+
+ // net::Socket interface.
+ virtual int Read(net::IOBuffer* buf, int buf_len,
+ net::CompletionCallback* callback);
+ virtual int Write(net::IOBuffer* buf, int buf_len,
+ net::CompletionCallback* callback);
+
+ virtual bool SetReceiveBufferSize(int32 size);
+ virtual bool SetSendBufferSize(int32 size);
+
+ private:
+ bool read_pending_;
+ scoped_refptr<net::IOBuffer> read_buffer_;
+ int read_buffer_size_;
+ net::CompletionCallback* read_callback_;
+
+ std::vector<char> written_data_;
+ std::vector<char> input_data_;
+ int input_pos_;
+};
+
+// FakeChromotingConnection is a dummy ChromotingConnection that uses
+// FakeSocket for all channels.
+class FakeChromotingConnection : public ChromotingConnection {
+ public:
+ FakeChromotingConnection();
+ virtual ~FakeChromotingConnection();
+
+ StateChangeCallback* get_state_change_callback() { return callback_.get(); }
+
+ void set_message_loop(MessageLoop* message_loop) {
+ message_loop_ = message_loop;
+ }
+
+ bool is_closed() { return closed_; }
+
+ virtual void SetStateChangeCallback(StateChangeCallback* callback);
+
+ virtual FakeSocket* GetVideoChannel();
+ virtual FakeSocket* GetEventsChannel();
+
+ virtual FakeSocket* GetVideoRtpChannel();
+ virtual FakeSocket* GetVideoRtcpChannel();
+
+ virtual const std::string& jid();
+
+ virtual MessageLoop* message_loop();
+ virtual void Close(Task* closed_task);
+
+ public:
+ scoped_ptr<StateChangeCallback> callback_;
+ MessageLoop* message_loop_;
+ FakeSocket video_channel_;
+ FakeSocket events_channel_;
+ FakeSocket video_rtp_channel_;
+ FakeSocket video_rtcp_channel_;
+ std::string jid_;
+ bool closed_;
+};
+
+} // namespace remoting
+
+#endif // REMOTING_PROTOCOL_FAKE_CONNECTION_H_