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

Side by Side Diff: remoting/protocol/fake_session.cc

Issue 550383002: Cleanup ChannelFactory interface (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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 unified diff | Download patch
« no previous file with comments | « remoting/protocol/fake_session.h ('k') | remoting/protocol/jingle_session.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/fake_session.h" 5 #include "remoting/protocol/fake_session.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "net/base/address_list.h" 9 #include "net/base/address_list.h"
10 #include "net/base/io_buffer.h" 10 #include "net/base/io_buffer.h"
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 } 325 }
326 326
327 ChannelFactory* FakeSession::GetMultiplexedChannelFactory() { 327 ChannelFactory* FakeSession::GetMultiplexedChannelFactory() {
328 return this; 328 return this;
329 } 329 }
330 330
331 void FakeSession::Close() { 331 void FakeSession::Close() {
332 closed_ = true; 332 closed_ = true;
333 } 333 }
334 334
335 void FakeSession::CreateStreamChannel( 335 void FakeSession::CreateChannel(const std::string& name,
336 const std::string& name, 336 const ChannelCreatedCallback& callback) {
337 const StreamChannelCallback& callback) {
338 scoped_ptr<FakeSocket> channel; 337 scoped_ptr<FakeSocket> channel;
339 // If we are in the error state then we put NULL in the channels list, so that 338 // If we are in the error state then we put NULL in the channels list, so that
340 // NotifyStreamChannelCallback() still calls the callback. 339 // NotifyChannelCreated() still calls the callback.
341 if (error_ == OK) 340 if (error_ == OK)
342 channel.reset(new FakeSocket()); 341 channel.reset(new FakeSocket());
343 stream_channels_[name] = channel.release(); 342 stream_channels_[name] = channel.release();
344 343
345 if (async_creation_) { 344 if (async_creation_) {
346 message_loop_->PostTask(FROM_HERE, base::Bind( 345 message_loop_->PostTask(FROM_HERE, base::Bind(
347 &FakeSession::NotifyStreamChannelCallback, weak_factory_.GetWeakPtr(), 346 &FakeSession::NotifyChannelCreated, weak_factory_.GetWeakPtr(),
348 name, callback)); 347 name, callback));
349 } else { 348 } else {
350 NotifyStreamChannelCallback(name, callback); 349 NotifyChannelCreated(name, callback);
351 } 350 }
352 } 351 }
353 352
354 void FakeSession::NotifyStreamChannelCallback( 353 void FakeSession::NotifyChannelCreated(
355 const std::string& name, 354 const std::string& name,
356 const StreamChannelCallback& callback) { 355 const ChannelCreatedCallback& callback) {
357 if (stream_channels_.find(name) != stream_channels_.end()) 356 if (stream_channels_.find(name) != stream_channels_.end())
358 callback.Run(scoped_ptr<net::StreamSocket>(stream_channels_[name])); 357 callback.Run(scoped_ptr<net::StreamSocket>(stream_channels_[name]));
359 } 358 }
360 359
361 void FakeSession::CreateDatagramChannel(
362 const std::string& name,
363 const DatagramChannelCallback& callback) {
364 scoped_ptr<FakeUdpSocket> channel;
365 // If we are in the error state then we put NULL in the channels list, so that
366 // NotifyStreamChannelCallback() still calls the callback.
367 if (error_ == OK)
368 channel.reset(new FakeUdpSocket());
369 datagram_channels_[name] = channel.release();
370
371 if (async_creation_) {
372 message_loop_->PostTask(FROM_HERE, base::Bind(
373 &FakeSession::NotifyDatagramChannelCallback, weak_factory_.GetWeakPtr(),
374 name, callback));
375 } else {
376 NotifyDatagramChannelCallback(name, callback);
377 }
378 }
379
380 void FakeSession::NotifyDatagramChannelCallback(
381 const std::string& name,
382 const DatagramChannelCallback& callback) {
383 if (datagram_channels_.find(name) != datagram_channels_.end())
384 callback.Run(scoped_ptr<net::Socket>(datagram_channels_[name]));
385 }
386
387 void FakeSession::CancelChannelCreation(const std::string& name) { 360 void FakeSession::CancelChannelCreation(const std::string& name) {
388 stream_channels_.erase(name); 361 stream_channels_.erase(name);
389 datagram_channels_.erase(name); 362 datagram_channels_.erase(name);
390 } 363 }
391 364
392 } // namespace protocol 365 } // namespace protocol
393 } // namespace remoting 366 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/protocol/fake_session.h ('k') | remoting/protocol/jingle_session.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698