2003-10-06 01:46:31 +00:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is Mozilla.
|
|
|
|
*
|
2003-10-06 09:17:15 +00:00
|
|
|
* The Initial Developer of the Original Code is IBM Corporation.
|
|
|
|
* Portions created by IBM Corporation are Copyright (C) 2003
|
|
|
|
* IBM Corporation. All Rights Reserved.
|
2003-10-06 01:46:31 +00:00
|
|
|
*
|
|
|
|
* Contributor(s):
|
2003-10-06 09:17:15 +00:00
|
|
|
* IBM Corp.
|
2003-10-06 01:46:31 +00:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
Rollup of bug 645263 and bug 646259: Switch to mozilla:: sync primitives. r=cjones,dbaron,doublec,ehsan src=bsmedberg
Bug 645263, part 0: Count sync primitive ctor/dtors. r=dbaron
Bug 645263, part 1: Migrate content/media to mozilla:: sync primitives. r=doublec
Bug 645263, part 2: Migrate modules/plugin to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 3: Migrate nsComponentManagerImpl to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 4: Migrate everything else to mozilla:: sync primitives. r=dbaron
Bug 645263, part 5: Remove nsAutoLock.*. sr=bsmedberg
Bug 645263, part 6: Make editor test be nicer to deadlock detector. r=ehsan
Bug 645263, part 7: Disable tracemalloc backtraces for xpcshell tests. r=dbaron
Bug 646259: Fix nsCacheService to use a CondVar for notifying. r=cjones
2011-04-01 04:29:02 +00:00
|
|
|
#include "mozilla/Mutex.h"
|
2003-10-06 01:46:31 +00:00
|
|
|
#include "nsTransportUtils.h"
|
|
|
|
#include "nsITransport.h"
|
|
|
|
#include "nsProxyRelease.h"
|
2006-05-10 17:30:15 +00:00
|
|
|
#include "nsThreadUtils.h"
|
|
|
|
#include "nsAutoPtr.h"
|
2003-10-06 01:46:31 +00:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
|
Rollup of bug 645263 and bug 646259: Switch to mozilla:: sync primitives. r=cjones,dbaron,doublec,ehsan src=bsmedberg
Bug 645263, part 0: Count sync primitive ctor/dtors. r=dbaron
Bug 645263, part 1: Migrate content/media to mozilla:: sync primitives. r=doublec
Bug 645263, part 2: Migrate modules/plugin to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 3: Migrate nsComponentManagerImpl to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 4: Migrate everything else to mozilla:: sync primitives. r=dbaron
Bug 645263, part 5: Remove nsAutoLock.*. sr=bsmedberg
Bug 645263, part 6: Make editor test be nicer to deadlock detector. r=ehsan
Bug 645263, part 7: Disable tracemalloc backtraces for xpcshell tests. r=dbaron
Bug 646259: Fix nsCacheService to use a CondVar for notifying. r=cjones
2011-04-01 04:29:02 +00:00
|
|
|
using namespace mozilla;
|
|
|
|
|
2003-10-06 01:46:31 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class nsTransportStatusEvent;
|
|
|
|
|
|
|
|
class nsTransportEventSinkProxy : public nsITransportEventSink
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSITRANSPORTEVENTSINK
|
|
|
|
|
|
|
|
nsTransportEventSinkProxy(nsITransportEventSink *sink,
|
|
|
|
nsIEventTarget *target,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool coalesceAll)
|
2003-10-06 01:46:31 +00:00
|
|
|
: mSink(sink)
|
|
|
|
, mTarget(target)
|
Rollup of bug 645263 and bug 646259: Switch to mozilla:: sync primitives. r=cjones,dbaron,doublec,ehsan src=bsmedberg
Bug 645263, part 0: Count sync primitive ctor/dtors. r=dbaron
Bug 645263, part 1: Migrate content/media to mozilla:: sync primitives. r=doublec
Bug 645263, part 2: Migrate modules/plugin to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 3: Migrate nsComponentManagerImpl to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 4: Migrate everything else to mozilla:: sync primitives. r=dbaron
Bug 645263, part 5: Remove nsAutoLock.*. sr=bsmedberg
Bug 645263, part 6: Make editor test be nicer to deadlock detector. r=ehsan
Bug 645263, part 7: Disable tracemalloc backtraces for xpcshell tests. r=dbaron
Bug 646259: Fix nsCacheService to use a CondVar for notifying. r=cjones
2011-04-01 04:29:02 +00:00
|
|
|
, mLock("nsTransportEventSinkProxy.mLock")
|
2003-10-06 01:46:31 +00:00
|
|
|
, mLastEvent(nsnull)
|
|
|
|
, mCoalesceAll(coalesceAll)
|
|
|
|
{
|
|
|
|
NS_ADDREF(mSink);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~nsTransportEventSinkProxy()
|
|
|
|
{
|
|
|
|
// our reference to mSink could be the last, so be sure to release
|
|
|
|
// it on the target thread. otherwise, we could get into trouble.
|
|
|
|
NS_ProxyRelease(mTarget, mSink);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsITransportEventSink *mSink;
|
|
|
|
nsCOMPtr<nsIEventTarget> mTarget;
|
Rollup of bug 645263 and bug 646259: Switch to mozilla:: sync primitives. r=cjones,dbaron,doublec,ehsan src=bsmedberg
Bug 645263, part 0: Count sync primitive ctor/dtors. r=dbaron
Bug 645263, part 1: Migrate content/media to mozilla:: sync primitives. r=doublec
Bug 645263, part 2: Migrate modules/plugin to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 3: Migrate nsComponentManagerImpl to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 4: Migrate everything else to mozilla:: sync primitives. r=dbaron
Bug 645263, part 5: Remove nsAutoLock.*. sr=bsmedberg
Bug 645263, part 6: Make editor test be nicer to deadlock detector. r=ehsan
Bug 645263, part 7: Disable tracemalloc backtraces for xpcshell tests. r=dbaron
Bug 646259: Fix nsCacheService to use a CondVar for notifying. r=cjones
2011-04-01 04:29:02 +00:00
|
|
|
Mutex mLock;
|
2003-10-06 01:46:31 +00:00
|
|
|
nsTransportStatusEvent *mLastEvent;
|
2011-09-29 06:19:26 +00:00
|
|
|
bool mCoalesceAll;
|
2003-10-06 01:46:31 +00:00
|
|
|
};
|
|
|
|
|
2006-05-10 17:30:15 +00:00
|
|
|
class nsTransportStatusEvent : public nsRunnable
|
2003-10-06 01:46:31 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsTransportStatusEvent(nsTransportEventSinkProxy *proxy,
|
|
|
|
nsITransport *transport,
|
|
|
|
nsresult status,
|
2005-01-09 20:43:35 +00:00
|
|
|
PRUint64 progress,
|
|
|
|
PRUint64 progressMax)
|
2006-05-10 17:30:15 +00:00
|
|
|
: mProxy(proxy)
|
|
|
|
, mTransport(transport)
|
2003-10-06 01:46:31 +00:00
|
|
|
, mStatus(status)
|
|
|
|
, mProgress(progress)
|
|
|
|
, mProgressMax(progressMax)
|
2006-05-10 17:30:15 +00:00
|
|
|
{}
|
2003-10-06 01:46:31 +00:00
|
|
|
|
2006-05-10 17:30:15 +00:00
|
|
|
~nsTransportStatusEvent() {}
|
2003-10-06 01:46:31 +00:00
|
|
|
|
2006-05-10 17:30:15 +00:00
|
|
|
NS_IMETHOD Run()
|
2003-10-06 01:46:31 +00:00
|
|
|
{
|
|
|
|
// since this event is being handled, we need to clear the proxy's ref.
|
|
|
|
// if not coalescing all, then last event may not equal self!
|
|
|
|
{
|
Rollup of bug 645263 and bug 646259: Switch to mozilla:: sync primitives. r=cjones,dbaron,doublec,ehsan src=bsmedberg
Bug 645263, part 0: Count sync primitive ctor/dtors. r=dbaron
Bug 645263, part 1: Migrate content/media to mozilla:: sync primitives. r=doublec
Bug 645263, part 2: Migrate modules/plugin to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 3: Migrate nsComponentManagerImpl to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 4: Migrate everything else to mozilla:: sync primitives. r=dbaron
Bug 645263, part 5: Remove nsAutoLock.*. sr=bsmedberg
Bug 645263, part 6: Make editor test be nicer to deadlock detector. r=ehsan
Bug 645263, part 7: Disable tracemalloc backtraces for xpcshell tests. r=dbaron
Bug 646259: Fix nsCacheService to use a CondVar for notifying. r=cjones
2011-04-01 04:29:02 +00:00
|
|
|
MutexAutoLock lock(mProxy->mLock);
|
2006-05-10 17:30:15 +00:00
|
|
|
if (mProxy->mLastEvent == this)
|
|
|
|
mProxy->mLastEvent = nsnull;
|
2003-10-06 01:46:31 +00:00
|
|
|
}
|
|
|
|
|
2006-05-10 17:30:15 +00:00
|
|
|
mProxy->mSink->OnTransportStatus(mTransport, mStatus, mProgress,
|
|
|
|
mProgressMax);
|
2003-10-06 01:46:31 +00:00
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
2006-05-10 17:30:15 +00:00
|
|
|
nsRefPtr<nsTransportEventSinkProxy> mProxy;
|
2003-10-06 01:46:31 +00:00
|
|
|
|
|
|
|
// parameters to OnTransportStatus
|
|
|
|
nsCOMPtr<nsITransport> mTransport;
|
|
|
|
nsresult mStatus;
|
2005-01-09 20:43:35 +00:00
|
|
|
PRUint64 mProgress;
|
|
|
|
PRUint64 mProgressMax;
|
2003-10-06 01:46:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
NS_IMPL_THREADSAFE_ISUPPORTS1(nsTransportEventSinkProxy, nsITransportEventSink)
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTransportEventSinkProxy::OnTransportStatus(nsITransport *transport,
|
|
|
|
nsresult status,
|
2005-01-09 20:43:35 +00:00
|
|
|
PRUint64 progress,
|
|
|
|
PRUint64 progressMax)
|
2003-10-06 01:46:31 +00:00
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
2006-05-10 17:30:15 +00:00
|
|
|
nsRefPtr<nsTransportStatusEvent> event;
|
2003-10-06 01:46:31 +00:00
|
|
|
{
|
Rollup of bug 645263 and bug 646259: Switch to mozilla:: sync primitives. r=cjones,dbaron,doublec,ehsan src=bsmedberg
Bug 645263, part 0: Count sync primitive ctor/dtors. r=dbaron
Bug 645263, part 1: Migrate content/media to mozilla:: sync primitives. r=doublec
Bug 645263, part 2: Migrate modules/plugin to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 3: Migrate nsComponentManagerImpl to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 4: Migrate everything else to mozilla:: sync primitives. r=dbaron
Bug 645263, part 5: Remove nsAutoLock.*. sr=bsmedberg
Bug 645263, part 6: Make editor test be nicer to deadlock detector. r=ehsan
Bug 645263, part 7: Disable tracemalloc backtraces for xpcshell tests. r=dbaron
Bug 646259: Fix nsCacheService to use a CondVar for notifying. r=cjones
2011-04-01 04:29:02 +00:00
|
|
|
MutexAutoLock lock(mLock);
|
2003-10-06 01:46:31 +00:00
|
|
|
|
|
|
|
// try to coalesce events! ;-)
|
|
|
|
if (mLastEvent && (mCoalesceAll || mLastEvent->mStatus == status)) {
|
|
|
|
mLastEvent->mStatus = status;
|
|
|
|
mLastEvent->mProgress = progress;
|
|
|
|
mLastEvent->mProgressMax = progressMax;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
event = new nsTransportStatusEvent(this, transport, status,
|
|
|
|
progress, progressMax);
|
|
|
|
if (!event)
|
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
2006-05-10 17:30:15 +00:00
|
|
|
mLastEvent = event; // weak ref
|
2003-10-06 01:46:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (event) {
|
2006-05-10 17:30:15 +00:00
|
|
|
rv = mTarget->Dispatch(event, NS_DISPATCH_NORMAL);
|
2003-10-06 01:46:31 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_WARNING("unable to post transport status event");
|
|
|
|
|
Rollup of bug 645263 and bug 646259: Switch to mozilla:: sync primitives. r=cjones,dbaron,doublec,ehsan src=bsmedberg
Bug 645263, part 0: Count sync primitive ctor/dtors. r=dbaron
Bug 645263, part 1: Migrate content/media to mozilla:: sync primitives. r=doublec
Bug 645263, part 2: Migrate modules/plugin to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 3: Migrate nsComponentManagerImpl to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 4: Migrate everything else to mozilla:: sync primitives. r=dbaron
Bug 645263, part 5: Remove nsAutoLock.*. sr=bsmedberg
Bug 645263, part 6: Make editor test be nicer to deadlock detector. r=ehsan
Bug 645263, part 7: Disable tracemalloc backtraces for xpcshell tests. r=dbaron
Bug 646259: Fix nsCacheService to use a CondVar for notifying. r=cjones
2011-04-01 04:29:02 +00:00
|
|
|
MutexAutoLock lock(mLock); // cleanup.. don't reference anymore!
|
2003-10-06 01:46:31 +00:00
|
|
|
mLastEvent = nsnull;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
net_NewTransportEventSinkProxy(nsITransportEventSink **result,
|
|
|
|
nsITransportEventSink *sink,
|
|
|
|
nsIEventTarget *target,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool coalesceAll)
|
2003-10-06 01:46:31 +00:00
|
|
|
{
|
|
|
|
*result = new nsTransportEventSinkProxy(sink, target, coalesceAll);
|
|
|
|
if (!*result)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
NS_ADDREF(*result);
|
|
|
|
return NS_OK;
|
|
|
|
}
|