Bug 1126036: Queue runnables for starting gathering and checking in PCMedia until the proxy lookup is complete. r=mt

--HG--
extra : rebase_source : 3265e13f669d08c663ab908cf96d3fb26a683f16
This commit is contained in:
Byron Campen [:bwc] 2015-01-26 15:24:37 -08:00
parent 737d6f9309
commit 971f76a2b4
3 changed files with 57 additions and 22 deletions

View File

@ -109,6 +109,7 @@ static int nr_stun_server_client_create(nr_stun_server_ctx *ctx, char *client_la
if(r=r_data_copy(&clnt->password,pass))
ABORT(r);
r_log(NR_LOG_STUN,LOG_DEBUG,"STUN-SERVER(%s)/CLIENT(%s): Adding client for %s",ctx->label, client_label, user);
clnt->stun_server_cb=cb;
clnt->cb_arg=cb_arg;

View File

@ -213,6 +213,7 @@ OnProxyAvailable(nsICancelable *request,
CSFLogInfo(logTag, "%s: Proxy Available: %d", __FUNCTION__, (int)result);
if (NS_SUCCEEDED(result) && proxyinfo) {
CSFLogInfo(logTag, "%s: Had proxyinfo", __FUNCTION__);
nsresult rv;
nsCString httpsProxyHost;
int32_t httpsProxyPort;
@ -243,7 +244,7 @@ OnProxyAvailable(nsICancelable *request,
if (result != NS_ERROR_ABORT) {
// NS_ERROR_ABORT means that the PeerConnectionMedia is no longer waiting
pcm_->mProxyResolveCompleted = true;
pcm_->GatherIfReady();
pcm_->FlushIceCtxOperationQueueIfReady();
}
return NS_OK;
@ -261,7 +262,6 @@ PeerConnectionMedia::PeerConnectionMedia(PeerConnectionImpl *parent)
mUuidGen(MakeUnique<PCUuidGenerator>()),
mMainThread(mParent->GetMainThread()),
mSTSThread(mParent->GetSTSThread()),
mTransportsUpdated(false),
mProxyResolveCompleted(false) {
nsresult rv;
@ -400,7 +400,6 @@ PeerConnectionMedia::UpdateTransports(const mozilla::JsepSession& session) {
// TODO(bug 1017888): Need to deal properly with renegotatiation.
// For now just start gathering.
mTransportsUpdated = true;
GatherIfReady();
}
@ -467,16 +466,17 @@ PeerConnectionMedia::StartIceChecks(const mozilla::JsepSession& session) {
}
}
RUN_ON_THREAD(GetSTSThread(),
WrapRunnable(
RefPtr<PeerConnectionMedia>(this),
&PeerConnectionMedia::StartIceChecks_s,
session.IsIceControlling(),
session.RemoteIsIceLite(),
// Copy, just in case API changes to return a ref
std::vector<std::string>(session.GetIceOptions()),
numComponentsByLevel),
NS_DISPATCH_NORMAL);
nsRefPtr<nsIRunnable> runnable(
WrapRunnable(
RefPtr<PeerConnectionMedia>(this),
&PeerConnectionMedia::StartIceChecks_s,
session.IsIceControlling(),
session.RemoteIsIceLite(),
// Copy, just in case API changes to return a ref
std::vector<std::string>(session.GetIceOptions()),
numComponentsByLevel));
PerformOrEnqueueIceCtxOperation(runnable);
}
void
@ -556,17 +556,43 @@ PeerConnectionMedia::AddIceCandidate_s(const std::string& aCandidate,
}
}
void
PeerConnectionMedia::FlushIceCtxOperationQueueIfReady()
{
ASSERT_ON_THREAD(mMainThread);
if (IsIceCtxReady()) {
for (auto i = mQueuedIceCtxOperations.begin();
i != mQueuedIceCtxOperations.end();
++i) {
GetSTSThread()->Dispatch(*i, NS_DISPATCH_NORMAL);
}
mQueuedIceCtxOperations.clear();
}
}
void
PeerConnectionMedia::PerformOrEnqueueIceCtxOperation(
const nsRefPtr<nsIRunnable>& runnable)
{
ASSERT_ON_THREAD(mMainThread);
if (IsIceCtxReady()) {
GetSTSThread()->Dispatch(runnable, NS_DISPATCH_NORMAL);
} else {
mQueuedIceCtxOperations.push_back(runnable);
}
}
void
PeerConnectionMedia::GatherIfReady() {
ASSERT_ON_THREAD(mMainThread);
if (mTransportsUpdated && mProxyResolveCompleted) {
RUN_ON_THREAD(GetSTSThread(),
WrapRunnable(
RefPtr<PeerConnectionMedia>(this),
&PeerConnectionMedia::EnsureIceGathering_s),
NS_DISPATCH_NORMAL);
}
nsRefPtr<nsIRunnable> runnable(WrapRunnable(
RefPtr<PeerConnectionMedia>(this),
&PeerConnectionMedia::EnsureIceGathering_s));
PerformOrEnqueueIceCtxOperation(runnable);
}
void

View File

@ -466,6 +466,8 @@ class PeerConnectionMedia : public sigslot::has_slots<> {
const std::string& aPassword,
const std::vector<std::string>& aCandidateList);
void GatherIfReady();
void FlushIceCtxOperationQueueIfReady();
void PerformOrEnqueueIceCtxOperation(const nsRefPtr<nsIRunnable>& runnable);
void EnsureIceGathering_s();
void StartIceChecks_s(bool aIsControlling,
bool aIsIceLite,
@ -497,6 +499,9 @@ class PeerConnectionMedia : public sigslot::has_slots<> {
void EndOfLocalCandidates_m(const std::string& aDefaultAddr,
uint16_t aDefaultPort,
uint16_t aMLine);
bool IsIceCtxReady() const {
return mProxyResolveCompleted;
}
// The parent PC
@ -539,8 +544,11 @@ class PeerConnectionMedia : public sigslot::has_slots<> {
// The STS thread.
nsCOMPtr<nsIEventTarget> mSTSThread;
// Used to track when transports are updated and are ready to start gathering
bool mTransportsUpdated;
// Used whenever we need to dispatch a runnable to STS to tweak something
// on our ICE ctx, but are not ready to do so at the moment (eg; we are
// waiting to get a callback with our http proxy config before we start
// gathering or start checking)
std::vector<nsRefPtr<nsIRunnable>> mQueuedIceCtxOperations;
// Used to cancel any ongoing proxy request.
nsCOMPtr<nsICancelable> mProxyRequest;