Bug 1688832: part 5) Add `static` `AccessibleCaretManager::GetSelection`, `::GetFrame...
[gecko.git] / netwerk / cache / nsCacheSession.cpp
blob3e4a1f92daefac847577a39979716c96497630c1
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"
9 #include "nsCRT.h"
10 #include "nsThreadUtils.h"
12 NS_IMPL_ISUPPORTS(nsCacheSession, nsICacheSession)
14 nsCacheSession::nsCacheSession(const char* clientID,
15 nsCacheStoragePolicy storagePolicy,
16 bool streamBased)
17 : mClientID(clientID), mInfo(0) {
18 SetStoragePolicy(storagePolicy);
20 if (streamBased)
21 MarkStreamBased();
22 else
23 SetStoragePolicy(nsICache::STORE_IN_MEMORY);
25 MarkPublic();
27 MarkDoomEntriesIfExpired();
30 nsCacheSession::~nsCacheSession() {
31 /* destructor code */
32 // notify service we are going away?
35 NS_IMETHODIMP nsCacheSession::GetDoomEntriesIfExpired(bool* result) {
36 NS_ENSURE_ARG_POINTER(result);
37 *result = WillDoomEntriesIfExpired();
38 return NS_OK;
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;
51 return NS_OK;
54 NS_IMETHODIMP nsCacheSession::GetProfileDirectory(nsIFile** profileDir) {
55 *profileDir = do_AddRef(mProfileDir).take();
56 return NS_OK;
59 NS_IMETHODIMP nsCacheSession::SetDoomEntriesIfExpired(
60 bool doomEntriesIfExpired) {
61 if (doomEntriesIfExpired)
62 MarkDoomEntriesIfExpired();
63 else
64 ClearDoomEntriesIfExpired();
65 return NS_OK;
68 NS_IMETHODIMP
69 nsCacheSession::OpenCacheEntry(const nsACString& key,
70 nsCacheAccessMode accessRequested,
71 bool blockingMode,
72 nsICacheEntryDescriptor** result) {
73 nsresult rv;
75 if (NS_IsMainThread())
76 rv = NS_ERROR_NOT_AVAILABLE;
77 else
78 rv =
79 nsCacheService::OpenCacheEntry(this, key, accessRequested, blockingMode,
80 nullptr, // no listener
81 result);
82 return rv;
85 NS_IMETHODIMP nsCacheSession::AsyncOpenCacheEntry(
86 const nsACString& key, nsCacheAccessMode accessRequested,
87 nsICacheListener* listener, bool noWait) {
88 nsresult rv;
89 rv = nsCacheService::OpenCacheEntry(this, key, accessRequested, !noWait,
90 listener,
91 nullptr); // no result
93 if (rv == NS_ERROR_CACHE_WAIT_FOR_VALIDATION) rv = NS_OK;
94 return rv;
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();
112 return NS_OK;
115 NS_IMETHODIMP nsCacheSession::SetIsPrivate(bool aPrivate) {
116 if (aPrivate)
117 MarkPrivate();
118 else
119 MarkPublic();
120 return NS_OK;