1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "nsCacheSession.h"
8 #include "nsCacheService.h"
10 #include "nsThreadUtils.h"
12 NS_IMPL_ISUPPORTS(nsCacheSession
, nsICacheSession
)
14 nsCacheSession::nsCacheSession(const char* clientID
,
15 nsCacheStoragePolicy storagePolicy
,
17 : mClientID(clientID
), mInfo(0) {
18 SetStoragePolicy(storagePolicy
);
23 SetStoragePolicy(nsICache::STORE_IN_MEMORY
);
27 MarkDoomEntriesIfExpired();
30 nsCacheSession::~nsCacheSession() {
32 // notify service we are going away?
35 NS_IMETHODIMP
nsCacheSession::GetDoomEntriesIfExpired(bool* result
) {
36 NS_ENSURE_ARG_POINTER(result
);
37 *result
= WillDoomEntriesIfExpired();
41 NS_IMETHODIMP
nsCacheSession::SetProfileDirectory(nsIFile
* profileDir
) {
42 if (StoragePolicy() != nsICache::STORE_OFFLINE
&& profileDir
) {
43 // Profile directory override is currently implemented only for
44 // offline cache. This is an early failure to prevent the request
45 // being processed before it would fail later because of inability
46 // to assign a cache base dir.
47 return NS_ERROR_UNEXPECTED
;
50 mProfileDir
= profileDir
;
54 NS_IMETHODIMP
nsCacheSession::GetProfileDirectory(nsIFile
** profileDir
) {
55 *profileDir
= do_AddRef(mProfileDir
).take();
59 NS_IMETHODIMP
nsCacheSession::SetDoomEntriesIfExpired(
60 bool doomEntriesIfExpired
) {
61 if (doomEntriesIfExpired
)
62 MarkDoomEntriesIfExpired();
64 ClearDoomEntriesIfExpired();
69 nsCacheSession::OpenCacheEntry(const nsACString
& key
,
70 nsCacheAccessMode accessRequested
,
72 nsICacheEntryDescriptor
** result
) {
75 if (NS_IsMainThread())
76 rv
= NS_ERROR_NOT_AVAILABLE
;
79 nsCacheService::OpenCacheEntry(this, key
, accessRequested
, blockingMode
,
80 nullptr, // no listener
85 NS_IMETHODIMP
nsCacheSession::AsyncOpenCacheEntry(
86 const nsACString
& key
, nsCacheAccessMode accessRequested
,
87 nsICacheListener
* listener
, bool noWait
) {
89 rv
= nsCacheService::OpenCacheEntry(this, key
, accessRequested
, !noWait
,
91 nullptr); // no result
93 if (rv
== NS_ERROR_CACHE_WAIT_FOR_VALIDATION
) rv
= NS_OK
;
97 NS_IMETHODIMP
nsCacheSession::EvictEntries() {
98 return nsCacheService::EvictEntriesForSession(this);
101 NS_IMETHODIMP
nsCacheSession::IsStorageEnabled(bool* result
) {
102 return nsCacheService::IsStorageEnabledForPolicy(StoragePolicy(), result
);
105 NS_IMETHODIMP
nsCacheSession::DoomEntry(const nsACString
& key
,
106 nsICacheListener
* listener
) {
107 return nsCacheService::DoomEntry(this, key
, listener
);
110 NS_IMETHODIMP
nsCacheSession::GetIsPrivate(bool* aPrivate
) {
111 *aPrivate
= IsPrivate();
115 NS_IMETHODIMP
nsCacheSession::SetIsPrivate(bool aPrivate
) {