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