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

Side by Side Diff: jingle/glue/fake_socket_factory.cc

Issue 14307021: jingle: Use base::MessageLoop. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 8 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "jingle/glue/fake_socket_factory.h" 5 #include "jingle/glue/fake_socket_factory.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "jingle/glue/utils.h" 9 #include "jingle/glue/utils.h"
10 #include "third_party/libjingle/source/talk/base/asyncsocket.h" 10 #include "third_party/libjingle/source/talk/base/asyncsocket.h"
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 // We should always be able to convert address here because we 108 // We should always be able to convert address here because we
109 // don't expect IPv6 address on IPv4 connections. 109 // don't expect IPv6 address on IPv4 connections.
110 NOTREACHED(); 110 NOTREACHED();
111 return; 111 return;
112 } 112 }
113 113
114 SignalReadPacket(this, &data[0], data.size(), address); 114 SignalReadPacket(this, &data[0], data.size(), address);
115 } 115 }
116 116
117 FakeSocketManager::FakeSocketManager() 117 FakeSocketManager::FakeSocketManager()
118 : message_loop_(MessageLoop::current()) { 118 : message_loop_(base::MessageLoop::current()) {}
119 }
120 119
121 FakeSocketManager::~FakeSocketManager() { } 120 FakeSocketManager::~FakeSocketManager() { }
122 121
123 void FakeSocketManager::SendPacket(const net::IPEndPoint& from, 122 void FakeSocketManager::SendPacket(const net::IPEndPoint& from,
124 const net::IPEndPoint& to, 123 const net::IPEndPoint& to,
125 const std::vector<char>& data) { 124 const std::vector<char>& data) {
126 DCHECK_EQ(MessageLoop::current(), message_loop_); 125 DCHECK_EQ(base::MessageLoop::current(), message_loop_);
127 126
128 message_loop_->PostTask( 127 message_loop_->PostTask(
129 FROM_HERE, 128 FROM_HERE,
130 base::Bind(&FakeSocketManager::DeliverPacket, this, from, to, data)); 129 base::Bind(&FakeSocketManager::DeliverPacket, this, from, to, data));
131 } 130 }
132 131
133 void FakeSocketManager::DeliverPacket(const net::IPEndPoint& from, 132 void FakeSocketManager::DeliverPacket(const net::IPEndPoint& from,
134 const net::IPEndPoint& to, 133 const net::IPEndPoint& to,
135 const std::vector<char>& data) { 134 const std::vector<char>& data) {
136 DCHECK_EQ(MessageLoop::current(), message_loop_); 135 DCHECK_EQ(base::MessageLoop::current(), message_loop_);
137 136
138 std::map<net::IPEndPoint, FakeUDPPacketSocket*>::iterator it = 137 std::map<net::IPEndPoint, FakeUDPPacketSocket*>::iterator it =
139 endpoints_.find(to); 138 endpoints_.find(to);
140 if (it == endpoints_.end()) { 139 if (it == endpoints_.end()) {
141 LOG(WARNING) << "Dropping packet with unknown destination: " 140 LOG(WARNING) << "Dropping packet with unknown destination: "
142 << to.ToString(); 141 << to.ToString();
143 return; 142 return;
144 } 143 }
145 it->second->DeliverPacket(from, data); 144 it->second->DeliverPacket(from, data);
146 } 145 }
147 146
148 void FakeSocketManager::AddSocket(FakeUDPPacketSocket* socket_factory) { 147 void FakeSocketManager::AddSocket(FakeUDPPacketSocket* socket_factory) {
149 DCHECK_EQ(MessageLoop::current(), message_loop_); 148 DCHECK_EQ(base::MessageLoop::current(), message_loop_);
150 149
151 endpoints_[socket_factory->endpoint()] = socket_factory; 150 endpoints_[socket_factory->endpoint()] = socket_factory;
152 } 151 }
153 152
154 void FakeSocketManager::RemoveSocket(FakeUDPPacketSocket* socket_factory) { 153 void FakeSocketManager::RemoveSocket(FakeUDPPacketSocket* socket_factory) {
155 DCHECK_EQ(MessageLoop::current(), message_loop_); 154 DCHECK_EQ(base::MessageLoop::current(), message_loop_);
156 155
157 endpoints_.erase(socket_factory->endpoint()); 156 endpoints_.erase(socket_factory->endpoint());
158 } 157 }
159 158
160 FakeSocketFactory::FakeSocketFactory(FakeSocketManager* socket_manager, 159 FakeSocketFactory::FakeSocketFactory(FakeSocketManager* socket_manager,
161 const net::IPAddressNumber& address) 160 const net::IPAddressNumber& address)
162 : socket_manager_(socket_manager), 161 : socket_manager_(socket_manager),
163 address_(address), 162 address_(address),
164 last_allocated_port_(0) { 163 last_allocated_port_(0) {
165 } 164 }
(...skipping 21 matching lines...) Expand all
187 const talk_base::SocketAddress& local_address, 186 const talk_base::SocketAddress& local_address,
188 const talk_base::SocketAddress& remote_address, 187 const talk_base::SocketAddress& remote_address,
189 const talk_base::ProxyInfo& proxy_info, const std::string& user_agent, 188 const talk_base::ProxyInfo& proxy_info, const std::string& user_agent,
190 bool ssl) { 189 bool ssl) {
191 // TODO(sergeyu): Implement fake TCP sockets. 190 // TODO(sergeyu): Implement fake TCP sockets.
192 NOTIMPLEMENTED(); 191 NOTIMPLEMENTED();
193 return NULL; 192 return NULL;
194 } 193 }
195 194
196 } // namespace jingle_glue 195 } // namespace jingle_glue
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698