| OLD | NEW | 
|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be | 
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. | 
| 4 | 4 | 
| 5 #include "remoting/protocol/channel_multiplexer.h" | 5 #include "remoting/protocol/channel_multiplexer.h" | 
| 6 | 6 | 
| 7 #include <string.h> | 7 #include <string.h> | 
| 8 | 8 | 
| 9 #include "base/bind.h" | 9 #include "base/bind.h" | 
| 10 #include "base/callback.h" | 10 #include "base/callback.h" | 
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 207 ChannelMultiplexer::MuxChannel::~MuxChannel() { | 207 ChannelMultiplexer::MuxChannel::~MuxChannel() { | 
| 208   // Socket must be destroyed before the channel. | 208   // Socket must be destroyed before the channel. | 
| 209   DCHECK(!socket_); | 209   DCHECK(!socket_); | 
| 210   STLDeleteElements(&pending_packets_); | 210   STLDeleteElements(&pending_packets_); | 
| 211 } | 211 } | 
| 212 | 212 | 
| 213 scoped_ptr<net::StreamSocket> ChannelMultiplexer::MuxChannel::CreateSocket() { | 213 scoped_ptr<net::StreamSocket> ChannelMultiplexer::MuxChannel::CreateSocket() { | 
| 214   DCHECK(!socket_);  // Can't create more than one socket per channel. | 214   DCHECK(!socket_);  // Can't create more than one socket per channel. | 
| 215   scoped_ptr<MuxSocket> result(new MuxSocket(this)); | 215   scoped_ptr<MuxSocket> result(new MuxSocket(this)); | 
| 216   socket_ = result.get(); | 216   socket_ = result.get(); | 
| 217   return result.PassAs<net::StreamSocket>(); | 217   return result.Pass(); | 
| 218 } | 218 } | 
| 219 | 219 | 
| 220 void ChannelMultiplexer::MuxChannel::OnIncomingPacket( | 220 void ChannelMultiplexer::MuxChannel::OnIncomingPacket( | 
| 221     scoped_ptr<MultiplexPacket> packet, | 221     scoped_ptr<MultiplexPacket> packet, | 
| 222     const base::Closure& done_task) { | 222     const base::Closure& done_task) { | 
| 223   DCHECK_EQ(packet->channel_id(), receive_id_); | 223   DCHECK_EQ(packet->channel_id(), receive_id_); | 
| 224   if (packet->data().size() > 0) { | 224   if (packet->data().size() > 0) { | 
| 225     pending_packets_.push_back(new PendingPacket(packet.Pass(), done_task)); | 225     pending_packets_.push_back(new PendingPacket(packet.Pass(), done_task)); | 
| 226     if (socket_) { | 226     if (socket_) { | 
| 227       // Notify the socket that we have more data. | 227       // Notify the socket that we have more data. | 
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 371 } | 371 } | 
| 372 | 372 | 
| 373 void ChannelMultiplexer::CreateChannel(const std::string& name, | 373 void ChannelMultiplexer::CreateChannel(const std::string& name, | 
| 374                                        const ChannelCreatedCallback& callback) { | 374                                        const ChannelCreatedCallback& callback) { | 
| 375   if (base_channel_.get()) { | 375   if (base_channel_.get()) { | 
| 376     // Already have |base_channel_|. Create new multiplexed channel | 376     // Already have |base_channel_|. Create new multiplexed channel | 
| 377     // synchronously. | 377     // synchronously. | 
| 378     callback.Run(GetOrCreateChannel(name)->CreateSocket()); | 378     callback.Run(GetOrCreateChannel(name)->CreateSocket()); | 
| 379   } else if (!base_channel_.get() && !base_channel_factory_) { | 379   } else if (!base_channel_.get() && !base_channel_factory_) { | 
| 380     // Fail synchronously if we failed to create |base_channel_|. | 380     // Fail synchronously if we failed to create |base_channel_|. | 
| 381     callback.Run(scoped_ptr<net::StreamSocket>()); | 381     callback.Run(nullptr); | 
| 382   } else { | 382   } else { | 
| 383     // Still waiting for the |base_channel_|. | 383     // Still waiting for the |base_channel_|. | 
| 384     pending_channels_.push_back(PendingChannel(name, callback)); | 384     pending_channels_.push_back(PendingChannel(name, callback)); | 
| 385 | 385 | 
| 386     // If this is the first multiplexed channel then create the base channel. | 386     // If this is the first multiplexed channel then create the base channel. | 
| 387     if (pending_channels_.size() == 1U) { | 387     if (pending_channels_.size() == 1U) { | 
| 388       base_channel_factory_->CreateChannel( | 388       base_channel_factory_->CreateChannel( | 
| 389           base_channel_name_, | 389           base_channel_name_, | 
| 390           base::Bind(&ChannelMultiplexer::OnBaseChannelReady, | 390           base::Bind(&ChannelMultiplexer::OnBaseChannelReady, | 
| 391                      base::Unretained(this))); | 391                      base::Unretained(this))); | 
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 503   channel->OnIncomingPacket(packet.Pass(), done_task); | 503   channel->OnIncomingPacket(packet.Pass(), done_task); | 
| 504 } | 504 } | 
| 505 | 505 | 
| 506 bool ChannelMultiplexer::DoWrite(scoped_ptr<MultiplexPacket> packet, | 506 bool ChannelMultiplexer::DoWrite(scoped_ptr<MultiplexPacket> packet, | 
| 507                                  const base::Closure& done_task) { | 507                                  const base::Closure& done_task) { | 
| 508   return writer_.Write(SerializeAndFrameMessage(*packet), done_task); | 508   return writer_.Write(SerializeAndFrameMessage(*packet), done_task); | 
| 509 } | 509 } | 
| 510 | 510 | 
| 511 }  // namespace protocol | 511 }  // namespace protocol | 
| 512 }  // namespace remoting | 512 }  // namespace remoting | 
| OLD | NEW | 
|---|