2001-02-23 13:18:01 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
|
|
*
|
2012-05-21 11:12:37 +00:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2001-02-23 13:18:01 +00:00
|
|
|
|
|
|
|
#ifndef _nsCacheRequest_h_
|
|
|
|
#define _nsCacheRequest_h_
|
|
|
|
|
|
|
|
#include "nspr.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
|
|
|
#include "mozilla/CondVar.h"
|
|
|
|
#include "mozilla/Mutex.h"
|
2001-02-23 13:18:01 +00:00
|
|
|
#include "nsCOMPtr.h"
|
2001-02-26 14:53:28 +00:00
|
|
|
#include "nsICache.h"
|
2001-02-23 13:18:01 +00:00
|
|
|
#include "nsICacheListener.h"
|
2001-03-08 05:37:00 +00:00
|
|
|
#include "nsCacheSession.h"
|
2006-06-27 23:13:48 +00:00
|
|
|
#include "nsCacheService.h"
|
2001-02-23 13:18:01 +00:00
|
|
|
|
|
|
|
|
2001-03-05 07:17:58 +00:00
|
|
|
class nsCacheRequest : public PRCList
|
2001-02-23 13:18:01 +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
|
|
|
typedef mozilla::CondVar CondVar;
|
|
|
|
typedef mozilla::MutexAutoLock MutexAutoLock;
|
|
|
|
typedef mozilla::Mutex Mutex;
|
|
|
|
|
2001-02-23 13:18:01 +00:00
|
|
|
private:
|
|
|
|
friend class nsCacheService;
|
|
|
|
friend class nsCacheEntry;
|
2010-08-24 01:06:23 +00:00
|
|
|
friend class nsProcessRequestEvent;
|
2001-02-23 13:18:01 +00:00
|
|
|
|
2012-08-08 00:06:06 +00:00
|
|
|
nsCacheRequest( const nsACString & key,
|
2001-02-26 14:53:28 +00:00
|
|
|
nsICacheListener * listener,
|
|
|
|
nsCacheAccessMode accessRequested,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool blockingMode,
|
2001-03-08 05:37:00 +00:00
|
|
|
nsCacheSession * session)
|
2001-02-23 13:18:01 +00:00
|
|
|
: mKey(key),
|
2001-03-05 07:17:58 +00:00
|
|
|
mInfo(0),
|
2001-02-23 13:18:01 +00:00
|
|
|
mListener(listener),
|
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("nsCacheRequest.mLock"),
|
2012-06-04 14:12:24 +00:00
|
|
|
mCondVar(mLock, "nsCacheRequest.mCondVar"),
|
|
|
|
mProfileDir(session->ProfileDir())
|
2001-02-23 13:18:01 +00:00
|
|
|
{
|
2001-11-06 22:51:58 +00:00
|
|
|
MOZ_COUNT_CTOR(nsCacheRequest);
|
2001-03-05 07:17:58 +00:00
|
|
|
PR_INIT_CLIST(this);
|
|
|
|
SetAccessRequested(accessRequested);
|
2001-03-08 05:37:00 +00:00
|
|
|
SetStoragePolicy(session->StoragePolicy());
|
|
|
|
if (session->IsStreamBased()) MarkStreamBased();
|
|
|
|
if (session->WillDoomEntriesIfExpired()) MarkDoomEntriesIfExpired();
|
2012-05-24 15:31:53 +00:00
|
|
|
if (session->IsPrivate()) MarkPrivate();
|
2001-05-09 03:36:00 +00:00
|
|
|
if (blockingMode == nsICache::BLOCKING) MarkBlockingMode();
|
2001-03-06 03:26:13 +00:00
|
|
|
MarkWaitingForValidation();
|
2006-06-27 23:13:48 +00:00
|
|
|
NS_IF_ADDREF(mListener);
|
2001-02-23 13:18:01 +00:00
|
|
|
}
|
|
|
|
|
2001-03-04 00:11:30 +00:00
|
|
|
~nsCacheRequest()
|
2001-02-26 15:53:31 +00:00
|
|
|
{
|
2001-11-06 22:51:58 +00:00
|
|
|
MOZ_COUNT_DTOR(nsCacheRequest);
|
2001-03-05 07:17:58 +00:00
|
|
|
NS_ASSERTION(PR_CLIST_IS_EMPTY(this), "request still on a list");
|
2006-06-27 23:13:48 +00:00
|
|
|
|
|
|
|
if (mListener)
|
|
|
|
nsCacheService::ReleaseObject_Locked(mListener, mThread);
|
2001-02-26 15:53:31 +00:00
|
|
|
}
|
2001-02-23 13:18:01 +00:00
|
|
|
|
2001-03-05 07:17:58 +00:00
|
|
|
/**
|
|
|
|
* Simple Accessors
|
|
|
|
*/
|
|
|
|
enum CacheRequestInfo {
|
2001-03-08 05:37:00 +00:00
|
|
|
eStoragePolicyMask = 0x000000FF,
|
|
|
|
eStreamBasedMask = 0x00000100,
|
2012-05-24 15:31:53 +00:00
|
|
|
ePrivateMask = 0x00000200,
|
2001-03-08 05:37:00 +00:00
|
|
|
eDoomEntriesIfExpiredMask = 0x00001000,
|
2001-05-09 03:36:00 +00:00
|
|
|
eBlockingModeMask = 0x00010000,
|
|
|
|
eWaitingForValidationMask = 0x00100000,
|
2001-03-08 05:37:00 +00:00
|
|
|
eAccessRequestedMask = 0xFF000000
|
2001-03-05 07:17:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void SetAccessRequested(nsCacheAccessMode mode)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(mode <= 0xFF, "too many bits in nsCacheAccessMode");
|
|
|
|
mInfo &= ~eAccessRequestedMask;
|
|
|
|
mInfo |= mode << 24;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCacheAccessMode AccessRequested()
|
|
|
|
{
|
|
|
|
return (nsCacheAccessMode)((mInfo >> 24) & 0xFF);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MarkStreamBased() { mInfo |= eStreamBasedMask; }
|
2011-09-29 06:19:26 +00:00
|
|
|
bool IsStreamBased() { return (mInfo & eStreamBasedMask) != 0; }
|
2001-03-05 07:17:58 +00:00
|
|
|
|
2001-03-08 05:37:00 +00:00
|
|
|
|
2001-05-09 03:36:00 +00:00
|
|
|
void MarkDoomEntriesIfExpired() { mInfo |= eDoomEntriesIfExpiredMask; }
|
2011-09-29 06:19:26 +00:00
|
|
|
bool WillDoomEntriesIfExpired() { return (0 != (mInfo & eDoomEntriesIfExpiredMask)); }
|
2001-05-09 03:36:00 +00:00
|
|
|
|
|
|
|
void MarkBlockingMode() { mInfo |= eBlockingModeMask; }
|
2011-09-29 06:19:26 +00:00
|
|
|
bool IsBlocking() { return (0 != (mInfo & eBlockingModeMask)); }
|
|
|
|
bool IsNonBlocking() { return !(mInfo & eBlockingModeMask); }
|
2001-03-08 05:37:00 +00:00
|
|
|
|
2001-03-05 07:17:58 +00:00
|
|
|
void SetStoragePolicy(nsCacheStoragePolicy policy)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(policy <= 0xFF, "too many bits in nsCacheStoragePolicy");
|
|
|
|
mInfo &= ~eStoragePolicyMask; // clear storage policy bits
|
2001-03-08 05:37:00 +00:00
|
|
|
mInfo |= policy; // or in new bits
|
2001-03-05 07:17:58 +00:00
|
|
|
}
|
2001-02-23 13:18:01 +00:00
|
|
|
|
2001-03-05 07:17:58 +00:00
|
|
|
nsCacheStoragePolicy StoragePolicy()
|
|
|
|
{
|
2012-05-24 15:31:53 +00:00
|
|
|
return (nsCacheStoragePolicy)(mInfo & eStoragePolicyMask);
|
2001-03-05 07:17:58 +00:00
|
|
|
}
|
|
|
|
|
2012-05-24 15:31:53 +00:00
|
|
|
void MarkPrivate() { mInfo |= ePrivateMask; }
|
|
|
|
void MarkPublic() { mInfo &= ~ePrivateMask; }
|
|
|
|
bool IsPrivate() { return (mInfo & ePrivateMask) != 0; }
|
|
|
|
|
2001-03-05 07:17:58 +00:00
|
|
|
void MarkWaitingForValidation() { mInfo |= eWaitingForValidationMask; }
|
|
|
|
void DoneWaitingForValidation() { mInfo &= ~eWaitingForValidationMask; }
|
2011-09-29 06:19:26 +00:00
|
|
|
bool WaitingForValidation()
|
2001-03-05 07:17:58 +00:00
|
|
|
{
|
|
|
|
return (mInfo & eWaitingForValidationMask) != 0;
|
2001-02-23 13:18:01 +00:00
|
|
|
}
|
|
|
|
|
2001-03-05 07:17:58 +00:00
|
|
|
nsresult
|
|
|
|
WaitForValidation(void)
|
|
|
|
{
|
2001-03-06 03:26:13 +00:00
|
|
|
if (!WaitingForValidation()) { // flag already cleared
|
|
|
|
MarkWaitingForValidation(); // set up for next time
|
|
|
|
return NS_OK; // early exit;
|
|
|
|
}
|
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);
|
|
|
|
while (WaitingForValidation()) {
|
|
|
|
mCondVar.Wait();
|
2001-03-05 07:17:58 +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
|
|
|
MarkWaitingForValidation(); // set up for next time
|
|
|
|
}
|
2001-03-05 07:17:58 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-02-23 13:18:01 +00:00
|
|
|
|
2001-03-05 10:45:33 +00:00
|
|
|
void WakeUp(void) {
|
|
|
|
DoneWaitingForValidation();
|
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);
|
|
|
|
mCondVar.Notify();
|
2001-03-05 10:45:33 +00:00
|
|
|
}
|
|
|
|
|
2001-03-05 07:17:58 +00:00
|
|
|
/**
|
|
|
|
* Data members
|
|
|
|
*/
|
2012-08-08 00:06:06 +00:00
|
|
|
nsCString mKey;
|
2001-03-05 07:17:58 +00:00
|
|
|
PRUint32 mInfo;
|
2006-06-27 23:13:48 +00:00
|
|
|
nsICacheListener * mListener; // strong ref
|
2006-05-10 17:30:15 +00:00
|
|
|
nsCOMPtr<nsIThread> mThread;
|
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;
|
|
|
|
CondVar mCondVar;
|
2012-06-06 02:08:30 +00:00
|
|
|
nsCOMPtr<nsIFile> mProfileDir;
|
2001-02-23 13:18:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // _nsCacheRequest_h_
|