netwerk/cache/nsCacheSession.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/netwerk/cache/nsCacheSession.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,147 @@
     1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
     1.5 + *
     1.6 + * This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +#include "nsCacheSession.h"
    1.11 +#include "nsCacheService.h"
    1.12 +#include "nsCRT.h"
    1.13 +#include "nsThreadUtils.h"
    1.14 +
    1.15 +NS_IMPL_ISUPPORTS(nsCacheSession, nsICacheSession)
    1.16 +
    1.17 +nsCacheSession::nsCacheSession(const char *         clientID,
    1.18 +                               nsCacheStoragePolicy storagePolicy,
    1.19 +                               bool                 streamBased)
    1.20 +    : mClientID(clientID),
    1.21 +      mInfo(0)
    1.22 +{
    1.23 +  SetStoragePolicy(storagePolicy);
    1.24 +
    1.25 +  if (streamBased) MarkStreamBased();
    1.26 +  else SetStoragePolicy(nsICache::STORE_IN_MEMORY);
    1.27 +
    1.28 +  MarkPublic();
    1.29 +
    1.30 +  MarkDoomEntriesIfExpired();
    1.31 +}
    1.32 +
    1.33 +nsCacheSession::~nsCacheSession()
    1.34 +{
    1.35 +  /* destructor code */
    1.36 +    // notify service we are going away?
    1.37 +}
    1.38 +
    1.39 +
    1.40 +NS_IMETHODIMP nsCacheSession::GetDoomEntriesIfExpired(bool *result)
    1.41 +{
    1.42 +    NS_ENSURE_ARG_POINTER(result);
    1.43 +    *result = WillDoomEntriesIfExpired();
    1.44 +    return NS_OK;
    1.45 +}
    1.46 +
    1.47 +
    1.48 +NS_IMETHODIMP nsCacheSession::SetProfileDirectory(nsIFile *profileDir)
    1.49 +{
    1.50 +  if (StoragePolicy() != nsICache::STORE_OFFLINE && profileDir) {
    1.51 +        // Profile directory override is currently implemented only for
    1.52 +        // offline cache.  This is an early failure to prevent the request
    1.53 +        // being processed before it would fail later because of inability
    1.54 +        // to assign a cache base dir.
    1.55 +        return NS_ERROR_UNEXPECTED;
    1.56 +    }
    1.57 +
    1.58 +    mProfileDir = profileDir;
    1.59 +    return NS_OK;
    1.60 +}
    1.61 +
    1.62 +NS_IMETHODIMP nsCacheSession::GetProfileDirectory(nsIFile **profileDir)
    1.63 +{
    1.64 +    if (mProfileDir)
    1.65 +        NS_ADDREF(*profileDir = mProfileDir);
    1.66 +    else
    1.67 +        *profileDir = nullptr;
    1.68 +
    1.69 +    return NS_OK;
    1.70 +}
    1.71 +
    1.72 +
    1.73 +NS_IMETHODIMP nsCacheSession::SetDoomEntriesIfExpired(bool doomEntriesIfExpired)
    1.74 +{
    1.75 +    if (doomEntriesIfExpired)  MarkDoomEntriesIfExpired();
    1.76 +    else                       ClearDoomEntriesIfExpired();
    1.77 +    return NS_OK;
    1.78 +}
    1.79 +
    1.80 +
    1.81 +NS_IMETHODIMP
    1.82 +nsCacheSession::OpenCacheEntry(const nsACString &         key, 
    1.83 +                               nsCacheAccessMode          accessRequested,
    1.84 +                               bool                       blockingMode,
    1.85 +                               nsICacheEntryDescriptor ** result)
    1.86 +{
    1.87 +    nsresult rv;
    1.88 +
    1.89 +    if (NS_IsMainThread())
    1.90 +        rv = NS_ERROR_NOT_AVAILABLE;
    1.91 +    else
    1.92 +        rv = nsCacheService::OpenCacheEntry(this,
    1.93 +                                            key,
    1.94 +                                            accessRequested,
    1.95 +                                            blockingMode,
    1.96 +                                            nullptr, // no listener
    1.97 +                                            result);
    1.98 +    return rv;
    1.99 +}
   1.100 +
   1.101 +
   1.102 +NS_IMETHODIMP nsCacheSession::AsyncOpenCacheEntry(const nsACString & key,
   1.103 +                                                  nsCacheAccessMode accessRequested,
   1.104 +                                                  nsICacheListener *listener,
   1.105 +                                                  bool              noWait)
   1.106 +{
   1.107 +    nsresult rv;
   1.108 +    rv = nsCacheService::OpenCacheEntry(this,
   1.109 +                                        key,
   1.110 +                                        accessRequested,
   1.111 +                                        !noWait,
   1.112 +                                        listener,
   1.113 +                                        nullptr); // no result
   1.114 +
   1.115 +    if (rv == NS_ERROR_CACHE_WAIT_FOR_VALIDATION) rv = NS_OK;
   1.116 +    return rv;
   1.117 +}
   1.118 +
   1.119 +NS_IMETHODIMP nsCacheSession::EvictEntries()
   1.120 +{
   1.121 +    return nsCacheService::EvictEntriesForSession(this);
   1.122 +}
   1.123 +
   1.124 +
   1.125 +NS_IMETHODIMP nsCacheSession::IsStorageEnabled(bool *result)
   1.126 +{
   1.127 +
   1.128 +    return nsCacheService::IsStorageEnabledForPolicy(StoragePolicy(), result);
   1.129 +}
   1.130 +
   1.131 +NS_IMETHODIMP nsCacheSession::DoomEntry(const nsACString &key,
   1.132 +                                        nsICacheListener *listener)
   1.133 +{
   1.134 +    return nsCacheService::DoomEntry(this, key, listener);
   1.135 +}
   1.136 +
   1.137 +NS_IMETHODIMP nsCacheSession::GetIsPrivate(bool* aPrivate)
   1.138 +{
   1.139 +    *aPrivate = IsPrivate();
   1.140 +    return NS_OK;
   1.141 +}
   1.142 +
   1.143 +NS_IMETHODIMP nsCacheSession::SetIsPrivate(bool aPrivate)
   1.144 +{
   1.145 +    if (aPrivate)
   1.146 +        MarkPrivate();
   1.147 +    else
   1.148 +        MarkPublic();
   1.149 +    return NS_OK;
   1.150 +}

mercurial