summaryrefslogtreecommitdiff
path: root/netwerk/cache/nsCacheSession.cpp
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /netwerk/cache/nsCacheSession.cpp
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloaduxp-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
Add m-esr52 at 52.6.0
Diffstat (limited to 'netwerk/cache/nsCacheSession.cpp')
-rw-r--r--netwerk/cache/nsCacheSession.cpp147
1 files changed, 147 insertions, 0 deletions
diff --git a/netwerk/cache/nsCacheSession.cpp b/netwerk/cache/nsCacheSession.cpp
new file mode 100644
index 0000000000..d82203aec1
--- /dev/null
+++ b/netwerk/cache/nsCacheSession.cpp
@@ -0,0 +1,147 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
+ *
+ * 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/. */
+
+#include "nsCacheSession.h"
+#include "nsCacheService.h"
+#include "nsCRT.h"
+#include "nsThreadUtils.h"
+
+NS_IMPL_ISUPPORTS(nsCacheSession, nsICacheSession)
+
+nsCacheSession::nsCacheSession(const char * clientID,
+ nsCacheStoragePolicy storagePolicy,
+ bool streamBased)
+ : mClientID(clientID),
+ mInfo(0)
+{
+ SetStoragePolicy(storagePolicy);
+
+ if (streamBased) MarkStreamBased();
+ else SetStoragePolicy(nsICache::STORE_IN_MEMORY);
+
+ MarkPublic();
+
+ MarkDoomEntriesIfExpired();
+}
+
+nsCacheSession::~nsCacheSession()
+{
+ /* destructor code */
+ // notify service we are going away?
+}
+
+
+NS_IMETHODIMP nsCacheSession::GetDoomEntriesIfExpired(bool *result)
+{
+ NS_ENSURE_ARG_POINTER(result);
+ *result = WillDoomEntriesIfExpired();
+ return NS_OK;
+}
+
+
+NS_IMETHODIMP nsCacheSession::SetProfileDirectory(nsIFile *profileDir)
+{
+ 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;
+}
+
+NS_IMETHODIMP nsCacheSession::GetProfileDirectory(nsIFile **profileDir)
+{
+ if (mProfileDir)
+ NS_ADDREF(*profileDir = mProfileDir);
+ else
+ *profileDir = nullptr;
+
+ return NS_OK;
+}
+
+
+NS_IMETHODIMP nsCacheSession::SetDoomEntriesIfExpired(bool doomEntriesIfExpired)
+{
+ if (doomEntriesIfExpired) MarkDoomEntriesIfExpired();
+ else ClearDoomEntriesIfExpired();
+ return NS_OK;
+}
+
+
+NS_IMETHODIMP
+nsCacheSession::OpenCacheEntry(const nsACString & key,
+ nsCacheAccessMode accessRequested,
+ bool blockingMode,
+ nsICacheEntryDescriptor ** result)
+{
+ nsresult rv;
+
+ if (NS_IsMainThread())
+ rv = NS_ERROR_NOT_AVAILABLE;
+ else
+ rv = nsCacheService::OpenCacheEntry(this,
+ key,
+ accessRequested,
+ blockingMode,
+ nullptr, // no listener
+ result);
+ return rv;
+}
+
+
+NS_IMETHODIMP nsCacheSession::AsyncOpenCacheEntry(const nsACString & key,
+ nsCacheAccessMode accessRequested,
+ nsICacheListener *listener,
+ bool noWait)
+{
+ nsresult rv;
+ rv = nsCacheService::OpenCacheEntry(this,
+ key,
+ accessRequested,
+ !noWait,
+ listener,
+ nullptr); // no result
+
+ if (rv == NS_ERROR_CACHE_WAIT_FOR_VALIDATION) rv = NS_OK;
+ return rv;
+}
+
+NS_IMETHODIMP nsCacheSession::EvictEntries()
+{
+ return nsCacheService::EvictEntriesForSession(this);
+}
+
+
+NS_IMETHODIMP nsCacheSession::IsStorageEnabled(bool *result)
+{
+
+ return nsCacheService::IsStorageEnabledForPolicy(StoragePolicy(), result);
+}
+
+NS_IMETHODIMP nsCacheSession::DoomEntry(const nsACString &key,
+ nsICacheListener *listener)
+{
+ return nsCacheService::DoomEntry(this, key, listener);
+}
+
+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;
+}