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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 | 51 |
52 DISALLOW_COPY_AND_ASSIGN(PendingPacket); | 52 DISALLOW_COPY_AND_ASSIGN(PendingPacket); |
53 }; | 53 }; |
54 | 54 |
55 } // namespace | 55 } // namespace |
56 | 56 |
57 const char ChannelMultiplexer::kMuxChannelName[] = "mux"; | 57 const char ChannelMultiplexer::kMuxChannelName[] = "mux"; |
58 | 58 |
59 struct ChannelMultiplexer::PendingChannel { | 59 struct ChannelMultiplexer::PendingChannel { |
60 PendingChannel(const std::string& name, | 60 PendingChannel(const std::string& name, |
61 const StreamChannelCallback& callback) | 61 const ChannelCreatedCallback& callback) |
62 : name(name), callback(callback) { | 62 : name(name), callback(callback) { |
63 } | 63 } |
64 std::string name; | 64 std::string name; |
65 StreamChannelCallback callback; | 65 ChannelCreatedCallback callback; |
66 }; | 66 }; |
67 | 67 |
68 class ChannelMultiplexer::MuxChannel { | 68 class ChannelMultiplexer::MuxChannel { |
69 public: | 69 public: |
70 MuxChannel(ChannelMultiplexer* multiplexer, const std::string& name, | 70 MuxChannel(ChannelMultiplexer* multiplexer, const std::string& name, |
71 int send_id); | 71 int send_id); |
72 ~MuxChannel(); | 72 ~MuxChannel(); |
73 | 73 |
74 const std::string& name() { return name_; } | 74 const std::string& name() { return name_; } |
75 int receive_id() { return receive_id_; } | 75 int receive_id() { return receive_id_; } |
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
363 | 363 |
364 ChannelMultiplexer::~ChannelMultiplexer() { | 364 ChannelMultiplexer::~ChannelMultiplexer() { |
365 DCHECK(pending_channels_.empty()); | 365 DCHECK(pending_channels_.empty()); |
366 STLDeleteValues(&channels_); | 366 STLDeleteValues(&channels_); |
367 | 367 |
368 // Cancel creation of the base channel if it hasn't finished. | 368 // Cancel creation of the base channel if it hasn't finished. |
369 if (base_channel_factory_) | 369 if (base_channel_factory_) |
370 base_channel_factory_->CancelChannelCreation(base_channel_name_); | 370 base_channel_factory_->CancelChannelCreation(base_channel_name_); |
371 } | 371 } |
372 | 372 |
373 void ChannelMultiplexer::CreateStreamChannel( | 373 void ChannelMultiplexer::CreateChannel(const std::string& name, |
374 const std::string& name, | 374 const ChannelCreatedCallback& callback) { |
375 const StreamChannelCallback& callback) { | |
376 if (base_channel_.get()) { | 375 if (base_channel_.get()) { |
377 // Already have |base_channel_|. Create new multiplexed channel | 376 // Already have |base_channel_|. Create new multiplexed channel |
378 // synchronously. | 377 // synchronously. |
379 callback.Run(GetOrCreateChannel(name)->CreateSocket()); | 378 callback.Run(GetOrCreateChannel(name)->CreateSocket()); |
380 } else if (!base_channel_.get() && !base_channel_factory_) { | 379 } else if (!base_channel_.get() && !base_channel_factory_) { |
381 // Fail synchronously if we failed to create |base_channel_|. | 380 // Fail synchronously if we failed to create |base_channel_|. |
382 callback.Run(scoped_ptr<net::StreamSocket>()); | 381 callback.Run(scoped_ptr<net::StreamSocket>()); |
383 } else { | 382 } else { |
384 // Still waiting for the |base_channel_|. | 383 // Still waiting for the |base_channel_|. |
385 pending_channels_.push_back(PendingChannel(name, callback)); | 384 pending_channels_.push_back(PendingChannel(name, callback)); |
386 | 385 |
387 // 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. |
388 if (pending_channels_.size() == 1U) { | 387 if (pending_channels_.size() == 1U) { |
389 base_channel_factory_->CreateStreamChannel( | 388 base_channel_factory_->CreateChannel( |
390 base_channel_name_, | 389 base_channel_name_, |
391 base::Bind(&ChannelMultiplexer::OnBaseChannelReady, | 390 base::Bind(&ChannelMultiplexer::OnBaseChannelReady, |
392 base::Unretained(this))); | 391 base::Unretained(this))); |
393 } | 392 } |
394 } | 393 } |
395 } | 394 } |
396 | 395 |
397 void ChannelMultiplexer::CreateDatagramChannel( | |
398 const std::string& name, | |
399 const DatagramChannelCallback& callback) { | |
400 NOTIMPLEMENTED(); | |
401 callback.Run(scoped_ptr<net::Socket>()); | |
402 } | |
403 | |
404 void ChannelMultiplexer::CancelChannelCreation(const std::string& name) { | 396 void ChannelMultiplexer::CancelChannelCreation(const std::string& name) { |
405 for (std::list<PendingChannel>::iterator it = pending_channels_.begin(); | 397 for (std::list<PendingChannel>::iterator it = pending_channels_.begin(); |
406 it != pending_channels_.end(); ++it) { | 398 it != pending_channels_.end(); ++it) { |
407 if (it->name == name) { | 399 if (it->name == name) { |
408 pending_channels_.erase(it); | 400 pending_channels_.erase(it); |
409 return; | 401 return; |
410 } | 402 } |
411 } | 403 } |
412 } | 404 } |
413 | 405 |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
511 channel->OnIncomingPacket(packet.Pass(), done_task); | 503 channel->OnIncomingPacket(packet.Pass(), done_task); |
512 } | 504 } |
513 | 505 |
514 bool ChannelMultiplexer::DoWrite(scoped_ptr<MultiplexPacket> packet, | 506 bool ChannelMultiplexer::DoWrite(scoped_ptr<MultiplexPacket> packet, |
515 const base::Closure& done_task) { | 507 const base::Closure& done_task) { |
516 return writer_.Write(SerializeAndFrameMessage(*packet), done_task); | 508 return writer_.Write(SerializeAndFrameMessage(*packet), done_task); |
517 } | 509 } |
518 | 510 |
519 } // namespace protocol | 511 } // namespace protocol |
520 } // namespace remoting | 512 } // namespace remoting |
OLD | NEW |