Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(311)

Unified Diff: remoting/protocol/channel_multiplexer.cc

Issue 1197853003: Add P2PDatagramSocket and P2PStreamSocket interfaces. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « remoting/protocol/channel_multiplexer.h ('k') | remoting/protocol/channel_multiplexer_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: remoting/protocol/channel_multiplexer.cc
diff --git a/remoting/protocol/channel_multiplexer.cc b/remoting/protocol/channel_multiplexer.cc
index 8cdbf0d60af091469c6acb327211529f2e8f2444..e19a9a1229227a4f1ea8363f1efbbdfc80df53ec 100644
--- a/remoting/protocol/channel_multiplexer.cc
+++ b/remoting/protocol/channel_multiplexer.cc
@@ -14,8 +14,8 @@
#include "base/stl_util.h"
#include "base/thread_task_runner_handle.h"
#include "net/base/net_errors.h"
-#include "net/socket/stream_socket.h"
#include "remoting/protocol/message_serialization.h"
+#include "remoting/protocol/p2p_stream_socket.h"
namespace remoting {
namespace protocol {
@@ -77,7 +77,7 @@ class ChannelMultiplexer::MuxChannel {
void set_receive_id(int id) { receive_id_ = id; }
// Called by ChannelMultiplexer.
- scoped_ptr<net::StreamSocket> CreateSocket();
+ scoped_ptr<P2PStreamSocket> CreateSocket();
void OnIncomingPacket(scoped_ptr<MultiplexPacket> packet,
const base::Closure& done_task);
void OnBaseChannelError(int error);
@@ -86,7 +86,7 @@ class ChannelMultiplexer::MuxChannel {
void OnSocketDestroyed();
bool DoWrite(scoped_ptr<MultiplexPacket> packet,
const base::Closure& done_task);
- int DoRead(net::IOBuffer* buffer, int buffer_len);
+ int DoRead(const scoped_refptr<net::IOBuffer>& buffer, int buffer_len);
private:
ChannelMultiplexer* multiplexer_;
@@ -100,7 +100,7 @@ class ChannelMultiplexer::MuxChannel {
DISALLOW_COPY_AND_ASSIGN(MuxChannel);
};
-class ChannelMultiplexer::MuxSocket : public net::StreamSocket,
+class ChannelMultiplexer::MuxSocket : public P2PStreamSocket,
public base::NonThreadSafe,
public base::SupportsWeakPtr<MuxSocket> {
public:
@@ -111,67 +111,12 @@ class ChannelMultiplexer::MuxSocket : public net::StreamSocket,
void OnBaseChannelError(int error);
void OnPacketReceived();
- // net::StreamSocket interface.
- int Read(net::IOBuffer* buffer,
- int buffer_len,
+ // P2PStreamSocket interface.
+ int Read(const scoped_refptr<net::IOBuffer>& buffer, int buffer_len,
const net::CompletionCallback& callback) override;
- int Write(net::IOBuffer* buffer,
- int buffer_len,
+ int Write(const scoped_refptr<net::IOBuffer>& buffer, int buffer_len,
const net::CompletionCallback& callback) override;
- int SetReceiveBufferSize(int32 size) override {
- NOTIMPLEMENTED();
- return net::ERR_NOT_IMPLEMENTED;
- }
- int SetSendBufferSize(int32 size) override {
- NOTIMPLEMENTED();
- return net::ERR_NOT_IMPLEMENTED;
- }
-
- int Connect(const net::CompletionCallback& callback) override {
- NOTIMPLEMENTED();
- return net::ERR_NOT_IMPLEMENTED;
- }
- void Disconnect() override { NOTIMPLEMENTED(); }
- bool IsConnected() const override {
- NOTIMPLEMENTED();
- return true;
- }
- bool IsConnectedAndIdle() const override {
- NOTIMPLEMENTED();
- return false;
- }
- int GetPeerAddress(net::IPEndPoint* address) const override {
- NOTIMPLEMENTED();
- return net::ERR_NOT_IMPLEMENTED;
- }
- int GetLocalAddress(net::IPEndPoint* address) const override {
- NOTIMPLEMENTED();
- return net::ERR_NOT_IMPLEMENTED;
- }
- const net::BoundNetLog& NetLog() const override {
- NOTIMPLEMENTED();
- return net_log_;
- }
- void SetSubresourceSpeculation() override { NOTIMPLEMENTED(); }
- void SetOmniboxSpeculation() override { NOTIMPLEMENTED(); }
- bool WasEverUsed() const override { return true; }
- bool UsingTCPFastOpen() const override { return false; }
- bool WasNpnNegotiated() const override { return false; }
- net::NextProto GetNegotiatedProtocol() const override {
- return net::kProtoUnknown;
- }
- bool GetSSLInfo(net::SSLInfo* ssl_info) override {
- NOTIMPLEMENTED();
- return false;
- }
- void GetConnectionAttempts(net::ConnectionAttempts* out) const override {
- out->clear();
- }
- void ClearConnectionAttempts() override {}
- void AddConnectionAttempts(const net::ConnectionAttempts& attempts) override {
- }
-
private:
MuxChannel* channel_;
@@ -185,8 +130,6 @@ class ChannelMultiplexer::MuxSocket : public net::StreamSocket,
int write_result_;
net::CompletionCallback write_callback_;
- net::BoundNetLog net_log_;
-
DISALLOW_COPY_AND_ASSIGN(MuxSocket);
};
@@ -209,7 +152,7 @@ ChannelMultiplexer::MuxChannel::~MuxChannel() {
STLDeleteElements(&pending_packets_);
}
-scoped_ptr<net::StreamSocket> ChannelMultiplexer::MuxChannel::CreateSocket() {
+scoped_ptr<P2PStreamSocket> ChannelMultiplexer::MuxChannel::CreateSocket() {
DCHECK(!socket_); // Can't create more than one socket per channel.
scoped_ptr<MuxSocket> result(new MuxSocket(this));
socket_ = result.get();
@@ -250,8 +193,9 @@ bool ChannelMultiplexer::MuxChannel::DoWrite(
return multiplexer_->DoWrite(packet.Pass(), done_task);
}
-int ChannelMultiplexer::MuxChannel::DoRead(net::IOBuffer* buffer,
- int buffer_len) {
+int ChannelMultiplexer::MuxChannel::DoRead(
+ const scoped_refptr<net::IOBuffer>& buffer,
+ int buffer_len) {
int pos = 0;
while (buffer_len > 0 && !pending_packets_.empty()) {
DCHECK(!pending_packets_.front()->is_empty());
@@ -280,7 +224,7 @@ ChannelMultiplexer::MuxSocket::~MuxSocket() {
}
int ChannelMultiplexer::MuxSocket::Read(
- net::IOBuffer* buffer, int buffer_len,
+ const scoped_refptr<net::IOBuffer>& buffer, int buffer_len,
const net::CompletionCallback& callback) {
DCHECK(CalledOnValidThread());
DCHECK(read_callback_.is_null());
@@ -299,7 +243,7 @@ int ChannelMultiplexer::MuxSocket::Read(
}
int ChannelMultiplexer::MuxSocket::Write(
- net::IOBuffer* buffer, int buffer_len,
+ const scoped_refptr<net::IOBuffer>& buffer, int buffer_len,
const net::CompletionCallback& callback) {
DCHECK(CalledOnValidThread());
DCHECK(write_callback_.is_null());
@@ -420,7 +364,7 @@ void ChannelMultiplexer::CancelChannelCreation(const std::string& name) {
}
void ChannelMultiplexer::OnBaseChannelReady(
- scoped_ptr<net::StreamSocket> socket) {
+ scoped_ptr<P2PStreamSocket> socket) {
base_channel_factory_ = nullptr;
base_channel_ = socket.Pass();
@@ -429,7 +373,8 @@ void ChannelMultiplexer::OnBaseChannelReady(
reader_.StartReading(base_channel_.get(),
base::Bind(&ChannelMultiplexer::OnBaseChannelError,
base::Unretained(this)));
- writer_.Init(base_channel_.get(),
+ writer_.Init(base::Bind(&P2PStreamSocket::Write,
+ base::Unretained(base_channel_.get())),
base::Bind(&ChannelMultiplexer::OnBaseChannelError,
base::Unretained(this)));
}
@@ -451,7 +396,7 @@ void ChannelMultiplexer::DoCreatePendingChannels() {
PendingChannel c = pending_channels_.front();
pending_channels_.erase(pending_channels_.begin());
- scoped_ptr<net::StreamSocket> socket;
+ scoped_ptr<P2PStreamSocket> socket;
if (base_channel_.get())
socket = GetOrCreateChannel(c.name)->CreateSocket();
c.callback.Run(socket.Pass());
« no previous file with comments | « remoting/protocol/channel_multiplexer.h ('k') | remoting/protocol/channel_multiplexer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698