2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
|
|
*
|
2012-05-21 04:12:37 -07: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/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#include "nsCacheSession.h"
|
|
|
|
#include "nsCacheService.h"
|
2007-05-14 13:09:20 -07:00
|
|
|
#include "nsCRT.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-08-26 16:09:02 -07:00
|
|
|
NS_IMPL_ISUPPORTS1(nsCacheSession, nsICacheSession)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsCacheSession::nsCacheSession(const char * clientID,
|
|
|
|
nsCacheStoragePolicy storagePolicy,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool streamBased)
|
2007-03-22 10:30:00 -07:00
|
|
|
: mClientID(clientID),
|
|
|
|
mInfo(0)
|
|
|
|
{
|
|
|
|
SetStoragePolicy(storagePolicy);
|
|
|
|
|
|
|
|
if (streamBased) MarkStreamBased();
|
|
|
|
else SetStoragePolicy(nsICache::STORE_IN_MEMORY);
|
|
|
|
|
|
|
|
MarkDoomEntriesIfExpired();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCacheSession::~nsCacheSession()
|
|
|
|
{
|
|
|
|
/* destructor code */
|
|
|
|
// notify service we are going away?
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
NS_IMETHODIMP nsCacheSession::GetDoomEntriesIfExpired(bool *result)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(result);
|
|
|
|
*result = WillDoomEntriesIfExpired();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
NS_IMETHODIMP nsCacheSession::SetDoomEntriesIfExpired(bool doomEntriesIfExpired)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (doomEntriesIfExpired) MarkDoomEntriesIfExpired();
|
|
|
|
else ClearDoomEntriesIfExpired();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCacheSession::OpenCacheEntry(const nsACString & key,
|
|
|
|
nsCacheAccessMode accessRequested,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool blockingMode,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsICacheEntryDescriptor ** result)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
rv = nsCacheService::OpenCacheEntry(this,
|
|
|
|
key,
|
|
|
|
accessRequested,
|
|
|
|
blockingMode,
|
|
|
|
nsnull, // no listener
|
|
|
|
result);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsCacheSession::AsyncOpenCacheEntry(const nsACString & key,
|
|
|
|
nsCacheAccessMode accessRequested,
|
2012-03-22 15:53:10 -07:00
|
|
|
nsICacheListener *listener,
|
|
|
|
bool noWait)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
rv = nsCacheService::OpenCacheEntry(this,
|
|
|
|
key,
|
|
|
|
accessRequested,
|
2012-03-22 15:53:10 -07:00
|
|
|
!noWait,
|
2007-03-22 10:30:00 -07:00
|
|
|
listener,
|
|
|
|
nsnull); // no result
|
|
|
|
|
|
|
|
if (rv == NS_ERROR_CACHE_WAIT_FOR_VALIDATION) rv = NS_OK;
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsCacheSession::EvictEntries()
|
|
|
|
{
|
|
|
|
return nsCacheService::EvictEntriesForSession(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
NS_IMETHODIMP nsCacheSession::IsStorageEnabled(bool *result)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
|
|
|
|
return nsCacheService::IsStorageEnabledForPolicy(StoragePolicy(), result);
|
|
|
|
}
|
2012-03-22 15:54:20 -07:00
|
|
|
|
|
|
|
NS_IMETHODIMP nsCacheSession::DoomEntry(const nsACString &key,
|
|
|
|
nsICacheListener *listener)
|
|
|
|
{
|
|
|
|
return nsCacheService::DoomEntry(this, key, listener);
|
|
|
|
}
|