Index: content/renderer/p2p/ipc_socket_factory.cc |
diff --git a/content/renderer/p2p/ipc_socket_factory.cc b/content/renderer/p2p/ipc_socket_factory.cc |
index e0d93d343ba0157db53cdf56e4e46a2d97396c58..4563aa3a8821c938c7003687458eaafb1246dea7 100644 |
--- a/content/renderer/p2p/ipc_socket_factory.cc |
+++ b/content/renderer/p2p/ipc_socket_factory.cc |
@@ -10,13 +10,14 @@ |
#include <list> |
#include "base/compiler_specific.h" |
+#include "base/logging.h" |
#include "base/macros.h" |
-#include "base/message_loop/message_loop.h" |
#include "base/metrics/field_trial.h" |
#include "base/metrics/histogram.h" |
#include "base/strings/string_number_conversions.h" |
#include "base/strings/stringprintf.h" |
#include "base/threading/non_thread_safe.h" |
+#include "base/threading/thread_checker.h" |
#include "base/trace_event/trace_event.h" |
#include "content/renderer/media/webrtc_logging.h" |
#include "content/renderer/p2p/host_address_request.h" |
@@ -155,8 +156,8 @@ class IpcPacketSocket : public rtc::AsyncPacketSocket, |
P2PSocketType type_; |
- // Message loop on which this socket was created and being used. |
- base::MessageLoop* message_loop_; |
+ // Used to verify that a method runs on the thread that created this socket. |
+ base::ThreadChecker thread_checker_; |
// Corresponding P2P socket client. |
scoped_refptr<P2PSocketClient> client_; |
@@ -232,7 +233,6 @@ class AsyncAddressResolverImpl : public base::NonThreadSafe, |
IpcPacketSocket::IpcPacketSocket() |
: type_(P2P_SOCKET_UDP), |
- message_loop_(base::MessageLoop::current()), |
state_(IS_UNINITIALIZED), |
send_bytes_available_(kMaximumInFlightBytes), |
writable_signal_expected_(false), |
@@ -293,7 +293,7 @@ bool IpcPacketSocket::Init(P2PSocketType type, |
P2PSocketClientImpl* client, |
const rtc::SocketAddress& local_address, |
const rtc::SocketAddress& remote_address) { |
- DCHECK_EQ(base::MessageLoop::current(), message_loop_); |
+ DCHECK(thread_checker_.CalledOnValidThread()); |
DCHECK_EQ(state_, IS_UNINITIALIZED); |
type_ = type; |
@@ -341,7 +341,7 @@ void IpcPacketSocket::InitAcceptedTcp( |
P2PSocketClient* client, |
const rtc::SocketAddress& local_address, |
const rtc::SocketAddress& remote_address) { |
- DCHECK_EQ(base::MessageLoop::current(), message_loop_); |
+ DCHECK(thread_checker_.CalledOnValidThread()); |
DCHECK_EQ(state_, IS_UNINITIALIZED); |
client_ = client; |
@@ -354,25 +354,25 @@ void IpcPacketSocket::InitAcceptedTcp( |
// rtc::AsyncPacketSocket interface. |
rtc::SocketAddress IpcPacketSocket::GetLocalAddress() const { |
- DCHECK_EQ(base::MessageLoop::current(), message_loop_); |
+ DCHECK(thread_checker_.CalledOnValidThread()); |
return local_address_; |
} |
rtc::SocketAddress IpcPacketSocket::GetRemoteAddress() const { |
- DCHECK_EQ(base::MessageLoop::current(), message_loop_); |
+ DCHECK(thread_checker_.CalledOnValidThread()); |
return remote_address_; |
} |
int IpcPacketSocket::Send(const void *data, size_t data_size, |
const rtc::PacketOptions& options) { |
- DCHECK_EQ(base::MessageLoop::current(), message_loop_); |
+ DCHECK(thread_checker_.CalledOnValidThread()); |
return SendTo(data, data_size, remote_address_, options); |
} |
int IpcPacketSocket::SendTo(const void *data, size_t data_size, |
const rtc::SocketAddress& address, |
const rtc::PacketOptions& options) { |
- DCHECK_EQ(base::MessageLoop::current(), message_loop_); |
+ DCHECK(thread_checker_.CalledOnValidThread()); |
switch (state_) { |
case IS_UNINITIALIZED: |
@@ -453,7 +453,7 @@ int IpcPacketSocket::SendTo(const void *data, size_t data_size, |
} |
int IpcPacketSocket::Close() { |
- DCHECK_EQ(base::MessageLoop::current(), message_loop_); |
+ DCHECK(thread_checker_.CalledOnValidThread()); |
client_->Close(); |
state_ = IS_CLOSED; |
@@ -462,7 +462,7 @@ int IpcPacketSocket::Close() { |
} |
rtc::AsyncPacketSocket::State IpcPacketSocket::GetState() const { |
- DCHECK_EQ(base::MessageLoop::current(), message_loop_); |
+ DCHECK(thread_checker_.CalledOnValidThread()); |
switch (state_) { |
case IS_UNINITIALIZED: |
@@ -500,7 +500,7 @@ int IpcPacketSocket::GetOption(rtc::Socket::Option option, int* value) { |
} |
int IpcPacketSocket::SetOption(rtc::Socket::Option option, int value) { |
- DCHECK_EQ(base::MessageLoop::current(), message_loop_); |
+ DCHECK(thread_checker_.CalledOnValidThread()); |
P2PSocketOption p2p_socket_option = P2P_SOCKET_OPT_MAX; |
if (!JingleSocketOptionToP2PSocketOption(option, &p2p_socket_option)) { |
@@ -518,7 +518,7 @@ int IpcPacketSocket::SetOption(rtc::Socket::Option option, int value) { |
} |
int IpcPacketSocket::DoSetOption(P2PSocketOption option, int value) { |
- DCHECK_EQ(base::MessageLoop::current(), message_loop_); |
+ DCHECK(thread_checker_.CalledOnValidThread()); |
DCHECK_EQ(state_, IS_OPEN); |
client_->SetOption(option, value); |
@@ -526,18 +526,18 @@ int IpcPacketSocket::DoSetOption(P2PSocketOption option, int value) { |
} |
int IpcPacketSocket::GetError() const { |
- DCHECK_EQ(base::MessageLoop::current(), message_loop_); |
+ DCHECK(thread_checker_.CalledOnValidThread()); |
return error_; |
} |
void IpcPacketSocket::SetError(int error) { |
- DCHECK_EQ(base::MessageLoop::current(), message_loop_); |
+ DCHECK(thread_checker_.CalledOnValidThread()); |
error_ = error; |
} |
void IpcPacketSocket::OnOpen(const net::IPEndPoint& local_address, |
const net::IPEndPoint& remote_address) { |
- DCHECK_EQ(base::MessageLoop::current(), message_loop_); |
+ DCHECK(thread_checker_.CalledOnValidThread()); |
if (!jingle_glue::IPEndPointToSocketAddress(local_address, &local_address_)) { |
// Always expect correct IPv4 address to be allocated. |
@@ -581,7 +581,7 @@ void IpcPacketSocket::OnOpen(const net::IPEndPoint& local_address, |
void IpcPacketSocket::OnIncomingTcpConnection( |
const net::IPEndPoint& address, |
P2PSocketClient* client) { |
- DCHECK_EQ(base::MessageLoop::current(), message_loop_); |
+ DCHECK(thread_checker_.CalledOnValidThread()); |
std::unique_ptr<IpcPacketSocket> socket(new IpcPacketSocket()); |
@@ -595,7 +595,7 @@ void IpcPacketSocket::OnIncomingTcpConnection( |
} |
void IpcPacketSocket::OnSendComplete(const P2PSendPacketMetrics& send_metrics) { |
- DCHECK_EQ(base::MessageLoop::current(), message_loop_); |
+ DCHECK(thread_checker_.CalledOnValidThread()); |
CHECK(!in_flight_packet_records_.empty()); |
@@ -632,7 +632,7 @@ void IpcPacketSocket::OnSendComplete(const P2PSendPacketMetrics& send_metrics) { |
} |
void IpcPacketSocket::OnError() { |
- DCHECK_EQ(base::MessageLoop::current(), message_loop_); |
+ DCHECK(thread_checker_.CalledOnValidThread()); |
bool was_closed = (state_ == IS_ERROR || state_ == IS_CLOSED); |
state_ = IS_ERROR; |
error_ = ECONNABORTED; |
@@ -644,7 +644,7 @@ void IpcPacketSocket::OnError() { |
void IpcPacketSocket::OnDataReceived(const net::IPEndPoint& address, |
const std::vector<char>& data, |
const base::TimeTicks& timestamp) { |
- DCHECK_EQ(base::MessageLoop::current(), message_loop_); |
+ DCHECK(thread_checker_.CalledOnValidThread()); |
rtc::SocketAddress address_lj; |