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

Side by Side Diff: webrtc/base/fakenetwork.h

Issue 1246913005: TransportController refactoring (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Set media engine on voice channel Created 5 years, 4 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
OLDNEW
1 /* 1 /*
2 * Copyright 2009 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2009 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 14 matching lines...) Expand all
25 const int kFakeIPv4NetworkPrefixLength = 24; 25 const int kFakeIPv4NetworkPrefixLength = 24;
26 const int kFakeIPv6NetworkPrefixLength = 64; 26 const int kFakeIPv6NetworkPrefixLength = 64;
27 27
28 // Fake network manager that allows us to manually specify the IPs to use. 28 // Fake network manager that allows us to manually specify the IPs to use.
29 class FakeNetworkManager : public NetworkManagerBase, 29 class FakeNetworkManager : public NetworkManagerBase,
30 public MessageHandler { 30 public MessageHandler {
31 public: 31 public:
32 FakeNetworkManager() 32 FakeNetworkManager()
33 : thread_(Thread::Current()), 33 : thread_(Thread::Current()),
34 next_index_(0), 34 next_index_(0),
35 started_(false), 35 start_count_(0),
36 sent_first_update_(false) { 36 sent_first_update_(false) {}
37 }
38 37
39 typedef std::vector<SocketAddress> IfaceList; 38 typedef std::vector<SocketAddress> IfaceList;
40 39
41 void AddInterface(const SocketAddress& iface) { 40 void AddInterface(const SocketAddress& iface) {
42 // ensure a unique name for the interface 41 // ensure a unique name for the interface
43 SocketAddress address("test" + rtc::ToString(next_index_++), 0); 42 SocketAddress address("test" + rtc::ToString(next_index_++), 0);
44 address.SetResolvedIP(iface.ipaddr()); 43 address.SetResolvedIP(iface.ipaddr());
45 ifaces_.push_back(address); 44 ifaces_.push_back(address);
46 DoUpdateNetworks(); 45 DoUpdateNetworks();
47 } 46 }
48 47
49 void RemoveInterface(const SocketAddress& iface) { 48 void RemoveInterface(const SocketAddress& iface) {
50 for (IfaceList::iterator it = ifaces_.begin(); 49 for (IfaceList::iterator it = ifaces_.begin();
51 it != ifaces_.end(); ++it) { 50 it != ifaces_.end(); ++it) {
52 if (it->EqualIPs(iface)) { 51 if (it->EqualIPs(iface)) {
53 ifaces_.erase(it); 52 ifaces_.erase(it);
54 break; 53 break;
55 } 54 }
56 } 55 }
57 DoUpdateNetworks(); 56 DoUpdateNetworks();
58 } 57 }
59 58
60 virtual void StartUpdating() { 59 virtual void StartUpdating() {
61 if (started_) { 60 if (start_count_ == 0) {
61 ++start_count_;
62 sent_first_update_ = false;
63 thread_->Post(this);
64 } else {
65 ++start_count_;
62 if (sent_first_update_) 66 if (sent_first_update_)
63 SignalNetworksChanged(); 67 SignalNetworksChanged();
64 return;
65 } 68 }
66
67 started_ = true;
68 sent_first_update_ = false;
69 thread_->Post(this);
70 } 69 }
71 70
72 virtual void StopUpdating() { 71 virtual void StopUpdating() { --start_count_; }
73 started_ = false;
74 }
75 72
76 // MessageHandler interface. 73 // MessageHandler interface.
77 virtual void OnMessage(Message* msg) { 74 virtual void OnMessage(Message* msg) {
78 DoUpdateNetworks(); 75 DoUpdateNetworks();
79 } 76 }
80 77
81 private: 78 private:
82 void DoUpdateNetworks() { 79 void DoUpdateNetworks() {
83 if (!started_) 80 if (start_count_ == 0)
84 return; 81 return;
85 std::vector<Network*> networks; 82 std::vector<Network*> networks;
86 for (IfaceList::iterator it = ifaces_.begin(); 83 for (IfaceList::iterator it = ifaces_.begin();
87 it != ifaces_.end(); ++it) { 84 it != ifaces_.end(); ++it) {
88 int prefix_length = 0; 85 int prefix_length = 0;
89 if (it->ipaddr().family() == AF_INET) { 86 if (it->ipaddr().family() == AF_INET) {
90 prefix_length = kFakeIPv4NetworkPrefixLength; 87 prefix_length = kFakeIPv4NetworkPrefixLength;
91 } else if (it->ipaddr().family() == AF_INET6) { 88 } else if (it->ipaddr().family() == AF_INET6) {
92 prefix_length = kFakeIPv6NetworkPrefixLength; 89 prefix_length = kFakeIPv6NetworkPrefixLength;
93 } 90 }
94 IPAddress prefix = TruncateIP(it->ipaddr(), prefix_length); 91 IPAddress prefix = TruncateIP(it->ipaddr(), prefix_length);
95 scoped_ptr<Network> net(new Network(it->hostname(), 92 scoped_ptr<Network> net(new Network(it->hostname(),
96 it->hostname(), 93 it->hostname(),
97 prefix, 94 prefix,
98 prefix_length)); 95 prefix_length));
99 net->AddIP(it->ipaddr()); 96 net->AddIP(it->ipaddr());
100 networks.push_back(net.release()); 97 networks.push_back(net.release());
101 } 98 }
102 bool changed; 99 bool changed;
103 MergeNetworkList(networks, &changed); 100 MergeNetworkList(networks, &changed);
104 if (changed || !sent_first_update_) { 101 if (changed || !sent_first_update_) {
105 SignalNetworksChanged(); 102 SignalNetworksChanged();
106 sent_first_update_ = true; 103 sent_first_update_ = true;
107 } 104 }
108 } 105 }
109 106
110 Thread* thread_; 107 Thread* thread_;
111 IfaceList ifaces_; 108 IfaceList ifaces_;
112 int next_index_; 109 int next_index_;
113 bool started_; 110 int start_count_;
114 bool sent_first_update_; 111 bool sent_first_update_;
115 }; 112 };
116 113
117 } // namespace rtc 114 } // namespace rtc
118 115
119 #endif // WEBRTC_BASE_FAKENETWORK_H_ 116 #endif // WEBRTC_BASE_FAKENETWORK_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698