summaryrefslogtreecommitdiffstats
path: root/remoting/protocol
diff options
context:
space:
mode:
Diffstat (limited to 'remoting/protocol')
-rw-r--r--remoting/protocol/fake_session.cc4
-rw-r--r--remoting/protocol/fake_session.h9
-rw-r--r--remoting/protocol/pepper_transport_socket_adapter.cc40
-rw-r--r--remoting/protocol/pepper_transport_socket_adapter.h8
4 files changed, 49 insertions, 12 deletions
diff --git a/remoting/protocol/fake_session.cc b/remoting/protocol/fake_session.cc
index c09a62a5..3b5499a 100644
--- a/remoting/protocol/fake_session.cc
+++ b/remoting/protocol/fake_session.cc
@@ -80,6 +80,10 @@ int FakeSocket::Connect(net::OldCompletionCallback* callback) {
EXPECT_EQ(message_loop_, MessageLoop::current());
return net::OK;
}
+int FakeSocket::Connect(const net::CompletionCallback& callback) {
+ EXPECT_EQ(message_loop_, MessageLoop::current());
+ return net::OK;
+}
void FakeSocket::Disconnect() {
NOTIMPLEMENTED();
diff --git a/remoting/protocol/fake_session.h b/remoting/protocol/fake_session.h
index 7eaab6b..2faa554 100644
--- a/remoting/protocol/fake_session.h
+++ b/remoting/protocol/fake_session.h
@@ -37,7 +37,7 @@ class FakeSocket : public net::StreamSocket {
int input_pos() const { return input_pos_; }
bool read_pending() const { return read_pending_; }
- // net::Socket interface.
+ // net::Socket implementation.
virtual int Read(net::IOBuffer* buf, int buf_len,
net::OldCompletionCallback* callback) OVERRIDE;
virtual int Write(net::IOBuffer* buf, int buf_len,
@@ -46,8 +46,9 @@ class FakeSocket : public net::StreamSocket {
virtual bool SetReceiveBufferSize(int32 size) OVERRIDE;
virtual bool SetSendBufferSize(int32 size) OVERRIDE;
- // net::StreamSocket interface.
+ // net::StreamSocket implementation.
virtual int Connect(net::OldCompletionCallback* callback) OVERRIDE;
+ virtual int Connect(const net::CompletionCallback& callback) OVERRIDE;
virtual void Disconnect() OVERRIDE;
virtual bool IsConnected() const OVERRIDE;
virtual bool IsConnectedAndIdle() const OVERRIDE;
@@ -93,7 +94,7 @@ class FakeUdpSocket : public net::Socket {
void AppendInputPacket(const char* data, int data_size);
int input_pos() const { return input_pos_; }
- // net::Socket interface.
+ // net::Socket implementation.
virtual int Read(net::IOBuffer* buf, int buf_len,
net::OldCompletionCallback* callback) OVERRIDE;
virtual int Write(net::IOBuffer* buf, int buf_len,
@@ -137,7 +138,7 @@ class FakeSession : public Session {
FakeSocket* GetStreamChannel(const std::string& name);
FakeUdpSocket* GetDatagramChannel(const std::string& name);
- // Session interface.
+ // Session implementation.
virtual void SetStateChangeCallback(
const StateChangeCallback& callback) OVERRIDE;
diff --git a/remoting/protocol/pepper_transport_socket_adapter.cc b/remoting/protocol/pepper_transport_socket_adapter.cc
index 6acb8e3..a48afce 100644
--- a/remoting/protocol/pepper_transport_socket_adapter.cc
+++ b/remoting/protocol/pepper_transport_socket_adapter.cc
@@ -123,7 +123,31 @@ bool PepperTransportSocketAdapter::SetSendBufferSize(int32 size) {
return false;
}
-int PepperTransportSocketAdapter::Connect(net::OldCompletionCallback* callback) {
+int PepperTransportSocketAdapter::Connect(
+ net::OldCompletionCallback* callback) {
+ DCHECK(CalledOnValidThread());
+
+ if (!transport_.get())
+ return net::ERR_UNEXPECTED;
+
+ old_connect_callback_ = callback;
+
+ // This will return false when GetNextAddress() returns an
+ // error. This helps to detect when the P2P Transport API is not
+ // supported.
+ int result = ProcessCandidates();
+ if (result != net::OK)
+ return result;
+
+ result = transport_->Connect(
+ callback_factory_.NewRequiredCallback(
+ &PepperTransportSocketAdapter::OnConnect));
+ DCHECK_EQ(result, PP_OK_COMPLETIONPENDING);
+
+ return net::ERR_IO_PENDING;
+}
+int PepperTransportSocketAdapter::Connect(
+ const net::CompletionCallback& callback) {
DCHECK(CalledOnValidThread());
if (!transport_.get())
@@ -254,14 +278,20 @@ void PepperTransportSocketAdapter::OnNextAddress(int32_t result) {
void PepperTransportSocketAdapter::OnConnect(int result) {
DCHECK(CalledOnValidThread());
- DCHECK(connect_callback_);
+ DCHECK(old_connect_callback_ || !connect_callback_.is_null());
if (result == PP_OK)
connected_ = true;
- net::OldCompletionCallback* callback = connect_callback_;
- connect_callback_ = NULL;
- callback->Run(PPErrorToNetError(result));
+ if (old_connect_callback_) {
+ net::OldCompletionCallback* callback = old_connect_callback_;
+ old_connect_callback_ = NULL;
+ callback->Run(PPErrorToNetError(result));
+ } else {
+ net::CompletionCallback callback = connect_callback_;
+ connect_callback_.Reset();
+ callback.Run(PPErrorToNetError(result));
+ }
}
void PepperTransportSocketAdapter::OnRead(int32_t result) {
diff --git a/remoting/protocol/pepper_transport_socket_adapter.h b/remoting/protocol/pepper_transport_socket_adapter.h
index 881d612..c25506d 100644
--- a/remoting/protocol/pepper_transport_socket_adapter.h
+++ b/remoting/protocol/pepper_transport_socket_adapter.h
@@ -47,7 +47,7 @@ class PepperTransportSocketAdapter : public base::NonThreadSafe,
// Adds candidate received from the peer.
void AddRemoteCandidate(const std::string& candidate);
- // net::Socket interface.
+ // net::Socket implementation.
virtual int Read(net::IOBuffer* buf, int buf_len,
net::OldCompletionCallback* callback) OVERRIDE;
virtual int Write(net::IOBuffer* buf, int buf_len,
@@ -55,8 +55,9 @@ class PepperTransportSocketAdapter : public base::NonThreadSafe,
virtual bool SetReceiveBufferSize(int32 size) OVERRIDE;
virtual bool SetSendBufferSize(int32 size) OVERRIDE;
- // net::StreamSocket interface.
+ // net::StreamSocket implementation.
virtual int Connect(net::OldCompletionCallback* callback) OVERRIDE;
+ virtual int Connect(const net::CompletionCallback& callback) OVERRIDE;
virtual void Disconnect() OVERRIDE;
virtual bool IsConnected() const OVERRIDE;
virtual bool IsConnectedAndIdle() const OVERRIDE;
@@ -84,7 +85,8 @@ class PepperTransportSocketAdapter : public base::NonThreadSafe,
scoped_ptr<pp::Transport_Dev> transport_;
- net::OldCompletionCallback* connect_callback_;
+ net::OldCompletionCallback* old_connect_callback_;
+ net::CompletionCallback connect_callback_;
bool connected_;
bool get_address_pending_;