2001-02-26 17:40:22 +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-26 17:40:22 +03:00
|
|
|
|
|
|
|
#include "nsCacheSession.h"
|
|
|
|
#include "nsCacheService.h"
|
2007-05-15 00:09:20 +04:00
|
|
|
#include "nsCRT.h"
|
2012-09-18 22:06:35 +04:00
|
|
|
#include "nsThreadUtils.h"
|
2001-02-26 17:40:22 +03:00
|
|
|
|
2008-08-27 03:09:02 +04:00
|
|
|
NS_IMPL_ISUPPORTS1(nsCacheSession, nsICacheSession)
|
2001-02-26 17:40:22 +03:00
|
|
|
|
2001-02-26 18:53:31 +03:00
|
|
|
nsCacheSession::nsCacheSession(const char * clientID,
|
|
|
|
nsCacheStoragePolicy storagePolicy,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool streamBased)
|
2001-02-26 17:40:22 +03:00
|
|
|
: mClientID(clientID),
|
2001-03-08 08:37:00 +03:00
|
|
|
mInfo(0)
|
2001-02-26 17:40:22 +03:00
|
|
|
{
|
2001-03-08 08:37:00 +03:00
|
|
|
SetStoragePolicy(storagePolicy);
|
|
|
|
|
|
|
|
if (streamBased) MarkStreamBased();
|
|
|
|
else SetStoragePolicy(nsICache::STORE_IN_MEMORY);
|
2001-06-26 11:06:52 +04:00
|
|
|
|
2012-05-24 19:31:53 +04:00
|
|
|
MarkPublic();
|
|
|
|
|
2001-06-26 11:06:52 +04:00
|
|
|
MarkDoomEntriesIfExpired();
|
2001-02-26 17:40:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsCacheSession::~nsCacheSession()
|
|
|
|
{
|
|
|
|
/* destructor code */
|
|
|
|
// notify service we are going away?
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
NS_IMETHODIMP nsCacheSession::GetDoomEntriesIfExpired(bool *result)
|
2001-03-08 08:37:00 +03:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(result);
|
|
|
|
*result = WillDoomEntriesIfExpired();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-06-06 06:08:30 +04:00
|
|
|
NS_IMETHODIMP nsCacheSession::SetProfileDirectory(nsIFile *profileDir)
|
2012-06-04 18:12:24 +04:00
|
|
|
{
|
|
|
|
if (StoragePolicy() != nsICache::STORE_OFFLINE && profileDir) {
|
|
|
|
// Profile directory override is currently implemented only for
|
|
|
|
// offline cache. This is an early failure to prevent the request
|
|
|
|
// being processed before it would fail later because of inability
|
|
|
|
// to assign a cache base dir.
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
mProfileDir = profileDir;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-06-06 06:08:30 +04:00
|
|
|
NS_IMETHODIMP nsCacheSession::GetProfileDirectory(nsIFile **profileDir)
|
2012-06-04 18:12:24 +04:00
|
|
|
{
|
|
|
|
if (mProfileDir)
|
|
|
|
NS_ADDREF(*profileDir = mProfileDir);
|
|
|
|
else
|
2012-07-30 18:20:58 +04:00
|
|
|
*profileDir = nullptr;
|
2012-06-04 18:12:24 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
NS_IMETHODIMP nsCacheSession::SetDoomEntriesIfExpired(bool doomEntriesIfExpired)
|
2001-03-08 08:37:00 +03:00
|
|
|
{
|
|
|
|
if (doomEntriesIfExpired) MarkDoomEntriesIfExpired();
|
|
|
|
else ClearDoomEntriesIfExpired();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-02-26 17:40:22 +03:00
|
|
|
NS_IMETHODIMP
|
2005-01-13 06:25:28 +03:00
|
|
|
nsCacheSession::OpenCacheEntry(const nsACString & key,
|
2001-05-09 07:36:00 +04:00
|
|
|
nsCacheAccessMode accessRequested,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool blockingMode,
|
2001-02-26 17:40:22 +03:00
|
|
|
nsICacheEntryDescriptor ** result)
|
|
|
|
{
|
2001-03-05 10:17:58 +03:00
|
|
|
nsresult rv;
|
2012-09-18 22:06:35 +04:00
|
|
|
|
|
|
|
if (NS_IsMainThread())
|
|
|
|
rv = NS_ERROR_NOT_AVAILABLE;
|
|
|
|
else
|
|
|
|
rv = nsCacheService::OpenCacheEntry(this,
|
|
|
|
key,
|
|
|
|
accessRequested,
|
|
|
|
blockingMode,
|
|
|
|
nullptr, // no listener
|
|
|
|
result);
|
2001-03-05 10:17:58 +03:00
|
|
|
return rv;
|
2001-02-26 17:40:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-01-13 06:25:28 +03:00
|
|
|
NS_IMETHODIMP nsCacheSession::AsyncOpenCacheEntry(const nsACString & key,
|
2001-02-26 17:40:22 +03:00
|
|
|
nsCacheAccessMode accessRequested,
|
2012-03-23 02:53:10 +04:00
|
|
|
nsICacheListener *listener,
|
|
|
|
bool noWait)
|
2001-02-26 17:40:22 +03:00
|
|
|
{
|
2001-03-05 10:17:58 +03:00
|
|
|
nsresult rv;
|
2002-08-07 05:13:29 +04:00
|
|
|
rv = nsCacheService::OpenCacheEntry(this,
|
|
|
|
key,
|
|
|
|
accessRequested,
|
2012-03-23 02:53:10 +04:00
|
|
|
!noWait,
|
2002-08-07 05:13:29 +04:00
|
|
|
listener,
|
2012-07-30 18:20:58 +04:00
|
|
|
nullptr); // no result
|
2001-03-05 10:17:58 +03:00
|
|
|
|
|
|
|
if (rv == NS_ERROR_CACHE_WAIT_FOR_VALIDATION) rv = NS_OK;
|
|
|
|
return rv;
|
2001-02-26 17:40:22 +03:00
|
|
|
}
|
2001-03-29 09:54:58 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP nsCacheSession::EvictEntries()
|
|
|
|
{
|
2002-08-07 05:13:29 +04:00
|
|
|
return nsCacheService::EvictEntriesForSession(this);
|
2001-03-29 09:54:58 +04:00
|
|
|
}
|
2002-01-24 04:25:25 +03:00
|
|
|
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
NS_IMETHODIMP nsCacheSession::IsStorageEnabled(bool *result)
|
2002-01-24 04:25:25 +03:00
|
|
|
{
|
|
|
|
|
|
|
|
return nsCacheService::IsStorageEnabledForPolicy(StoragePolicy(), result);
|
|
|
|
}
|
2012-03-23 02:54:20 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP nsCacheSession::DoomEntry(const nsACString &key,
|
|
|
|
nsICacheListener *listener)
|
|
|
|
{
|
|
|
|
return nsCacheService::DoomEntry(this, key, listener);
|
|
|
|
}
|
2012-05-24 19:31:53 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP nsCacheSession::GetIsPrivate(bool* aPrivate)
|
|
|
|
{
|
|
|
|
*aPrivate = IsPrivate();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsCacheSession::SetIsPrivate(bool aPrivate)
|
|
|
|
{
|
|
|
|
if (aPrivate)
|
|
|
|
MarkPrivate();
|
|
|
|
else
|
|
|
|
MarkPublic();
|
|
|
|
return NS_OK;
|
|
|
|
}
|