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

Side by Side Diff: remoting/test/fake_port_allocator.cc

Issue 1571943002: Simplify PortAllocatorBase and make PortAllocator creation synchronous. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 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/test/fake_port_allocator.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/test/fake_port_allocator.h" 5 #include "remoting/test/fake_port_allocator.h"
6 6
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "remoting/protocol/transport_context.h"
8 #include "remoting/test/fake_network_dispatcher.h" 9 #include "remoting/test/fake_network_dispatcher.h"
9 #include "remoting/test/fake_network_manager.h" 10 #include "remoting/test/fake_network_manager.h"
10 #include "remoting/test/fake_socket_factory.h" 11 #include "remoting/test/fake_socket_factory.h"
11 #include "third_party/webrtc/p2p/client/basicportallocator.h" 12 #include "third_party/webrtc/p2p/client/basicportallocator.h"
12 13
13 namespace remoting { 14 namespace remoting {
14 15
15 namespace { 16 namespace {
16 17
17 class FakePortAllocatorSession : public protocol::PortAllocatorSessionBase { 18 class FakePortAllocatorSession : public cricket::BasicPortAllocatorSession {
18 public: 19 public:
19 FakePortAllocatorSession( 20 FakePortAllocatorSession(FakePortAllocator* allocator,
20 protocol::PortAllocatorBase* allocator, 21 const std::string& content_name,
21 const std::string& content_name, 22 int component,
22 int component, 23 const std::string& ice_username_fragment,
23 const std::string& ice_username_fragment, 24 const std::string& ice_password);
24 const std::string& ice_password,
25 const std::vector<rtc::SocketAddress>& stun_hosts,
26 const std::vector<std::string>& relay_hosts,
27 const std::string& relay);
28 ~FakePortAllocatorSession() override; 25 ~FakePortAllocatorSession() override;
29 26
30 // protocol::PortAllocatorBase overrides.
31 void ConfigReady(cricket::PortConfiguration* config) override;
32 void SendSessionRequest(const std::string& host) override;
33
34 private: 27 private:
35 DISALLOW_COPY_AND_ASSIGN(FakePortAllocatorSession); 28 DISALLOW_COPY_AND_ASSIGN(FakePortAllocatorSession);
36 }; 29 };
37 30
38 FakePortAllocatorSession::FakePortAllocatorSession( 31 FakePortAllocatorSession::FakePortAllocatorSession(
39 protocol::PortAllocatorBase* allocator, 32 FakePortAllocator* allocator,
40 const std::string& content_name, 33 const std::string& content_name,
41 int component, 34 int component,
42 const std::string& ice_username_fragment, 35 const std::string& ice_username_fragment,
43 const std::string& ice_password, 36 const std::string& ice_password)
44 const std::vector<rtc::SocketAddress>& stun_hosts, 37 : BasicPortAllocatorSession(allocator,
45 const std::vector<std::string>& relay_hosts, 38 content_name,
46 const std::string& relay) 39 component,
47 : PortAllocatorSessionBase(allocator, 40 ice_username_fragment,
48 content_name, 41 ice_password) {}
49 component,
50 ice_username_fragment,
51 ice_password,
52 stun_hosts,
53 relay_hosts,
54 relay) {}
55 42
56 FakePortAllocatorSession::~FakePortAllocatorSession() {} 43 FakePortAllocatorSession::~FakePortAllocatorSession() {}
57 44
58 void FakePortAllocatorSession::ConfigReady( 45 } // namespace
59 cricket::PortConfiguration* config) { 46
60 // Filter out non-UDP relay ports, so that we don't try using TCP. 47 FakePortAllocator::FakePortAllocator(
61 for (cricket::PortConfiguration::RelayList::iterator relay = 48 rtc::NetworkManager* network_manager,
62 config->relays.begin(); relay != config->relays.end(); ++relay) { 49 rtc::PacketSocketFactory* socket_factory)
63 cricket::PortList filtered_ports; 50 : BasicPortAllocator(network_manager, socket_factory) {
64 for (cricket::PortList::iterator port = 51 set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
65 relay->ports.begin(); port != relay->ports.end(); ++port) { 52 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
66 if (port->proto == cricket::PROTO_UDP) { 53 cricket::PORTALLOCATOR_ENABLE_IPV6 |
67 filtered_ports.push_back(*port); 54 cricket::PORTALLOCATOR_DISABLE_STUN |
68 } 55 cricket::PORTALLOCATOR_DISABLE_RELAY);
69 }
70 relay->ports = filtered_ports;
71 }
72 cricket::BasicPortAllocatorSession::ConfigReady(config);
73 } 56 }
74 57
75 void FakePortAllocatorSession::SendSessionRequest(const std::string& host) {
76 ReceiveSessionResponse(std::string());
77 }
78
79 } // namespace
80
81 FakePortAllocator::FakePortAllocator(rtc::NetworkManager* network_manager,
82 FakePacketSocketFactory* socket_factory)
83 : PortAllocatorBase(network_manager, socket_factory) {}
84 FakePortAllocator::~FakePortAllocator() {} 58 FakePortAllocator::~FakePortAllocator() {}
85 59
86 cricket::PortAllocatorSession* FakePortAllocator::CreateSessionInternal( 60 cricket::PortAllocatorSession* FakePortAllocator::CreateSessionInternal(
87 const std::string& content_name, 61 const std::string& content_name,
88 int component, 62 int component,
89 const std::string& ice_username_fragment, 63 const std::string& ice_username_fragment,
90 const std::string& ice_password) { 64 const std::string& ice_password) {
91 return new FakePortAllocatorSession( 65 return new FakePortAllocatorSession(this, content_name, component,
92 this, content_name, component, ice_username_fragment, ice_password, 66 ice_username_fragment, ice_password);
93 stun_hosts(), relay_hosts(), relay_token());
94 } 67 }
95 68
96 FakePortAllocatorFactory::FakePortAllocatorFactory( 69 FakePortAllocatorFactory::FakePortAllocatorFactory(
97 scoped_refptr<FakeNetworkDispatcher> fake_network_dispatcher) { 70 scoped_refptr<FakeNetworkDispatcher> fake_network_dispatcher) {
98 socket_factory_.reset( 71 socket_factory_.reset(
99 new FakePacketSocketFactory(fake_network_dispatcher.get())); 72 new FakePacketSocketFactory(fake_network_dispatcher.get()));
100 network_manager_.reset(new FakeNetworkManager(socket_factory_->GetAddress())); 73 network_manager_.reset(new FakeNetworkManager(socket_factory_->GetAddress()));
101 } 74 }
102 75
103 FakePortAllocatorFactory::~FakePortAllocatorFactory() {} 76 FakePortAllocatorFactory::~FakePortAllocatorFactory() {}
104 77
105 scoped_ptr<protocol::PortAllocatorBase> 78 scoped_ptr<cricket::PortAllocator>
106 FakePortAllocatorFactory::CreatePortAllocator() { 79 FakePortAllocatorFactory::CreatePortAllocator(
80 scoped_refptr<protocol::TransportContext> transport_context) {
107 return make_scoped_ptr( 81 return make_scoped_ptr(
108 new FakePortAllocator(network_manager_.get(), socket_factory_.get())); 82 new FakePortAllocator(network_manager_.get(), socket_factory_.get()));
109 } 83 }
110 84
111 } // namespace remoting 85 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/test/fake_port_allocator.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698