fake_ice_connection.cc 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // Copyright 2019 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "remoting/test/fake_ice_connection.h"
  5. #include "remoting/base/logging.h"
  6. #include "remoting/protocol/client_control_dispatcher.h"
  7. #include "remoting/protocol/host_control_dispatcher.h"
  8. #include "remoting/protocol/transport_context.h"
  9. namespace remoting {
  10. namespace test {
  11. FakeIceConnection::FakeIceConnection(
  12. scoped_refptr<protocol::TransportContext> transport_context,
  13. base::OnceClosure on_closed) {
  14. transport_ =
  15. std::make_unique<protocol::IceTransport>(transport_context, this);
  16. on_closed_ = std::move(on_closed);
  17. if (transport_context->role() == protocol::TransportRole::CLIENT) {
  18. control_dispatcher_ = std::make_unique<protocol::ClientControlDispatcher>();
  19. } else {
  20. control_dispatcher_ = std::make_unique<protocol::HostControlDispatcher>();
  21. }
  22. }
  23. FakeIceConnection::~FakeIceConnection() = default;
  24. void FakeIceConnection::OnAuthenticated() {
  25. control_dispatcher_->Init(transport_->GetMultiplexedChannelFactory(), this);
  26. }
  27. void FakeIceConnection::OnIceTransportRouteChange(
  28. const std::string& channel_name,
  29. const protocol::TransportRoute& route) {
  30. HOST_LOG << "Channel: " << channel_name << " changed route:\n"
  31. << "Route type: " << route.type
  32. << ", remote address: " << route.remote_address.ToString()
  33. << ", local address: " << route.local_address.ToString();
  34. }
  35. void FakeIceConnection::OnIceTransportError(protocol::ErrorCode error) {
  36. LOG(ERROR) << "ICE transport error: " << error;
  37. std::move(on_closed_).Run();
  38. }
  39. void FakeIceConnection::OnChannelInitialized(
  40. protocol::ChannelDispatcherBase* channel_dispatcher) {
  41. HOST_LOG << "Channel initialized!";
  42. std::move(on_closed_).Run();
  43. }
  44. void FakeIceConnection::OnChannelClosed(
  45. protocol::ChannelDispatcherBase* channel_dispatcher) {
  46. HOST_LOG << "Channel closed!";
  47. std::move(on_closed_).Run();
  48. }
  49. } // namespace test
  50. } // namespace remoting