netwerk/cache/nsCacheSession.cpp

Thu, 15 Jan 2015 15:55:04 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 15:55:04 +0100
branch
TOR_BUG_9701
changeset 9
a63d609f5ebe
permissions
-rw-r--r--

Back out 97036ab72558 which inappropriately compared turds to third parties.

     1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
     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),
    18       mInfo(0)
    19 {
    20   SetStoragePolicy(storagePolicy);
    22   if (streamBased) MarkStreamBased();
    23   else SetStoragePolicy(nsICache::STORE_IN_MEMORY);
    25   MarkPublic();
    27   MarkDoomEntriesIfExpired();
    28 }
    30 nsCacheSession::~nsCacheSession()
    31 {
    32   /* destructor code */
    33     // notify service we are going away?
    34 }
    37 NS_IMETHODIMP nsCacheSession::GetDoomEntriesIfExpired(bool *result)
    38 {
    39     NS_ENSURE_ARG_POINTER(result);
    40     *result = WillDoomEntriesIfExpired();
    41     return NS_OK;
    42 }
    45 NS_IMETHODIMP nsCacheSession::SetProfileDirectory(nsIFile *profileDir)
    46 {
    47   if (StoragePolicy() != nsICache::STORE_OFFLINE && profileDir) {
    48         // Profile directory override is currently implemented only for
    49         // offline cache.  This is an early failure to prevent the request
    50         // being processed before it would fail later because of inability
    51         // to assign a cache base dir.
    52         return NS_ERROR_UNEXPECTED;
    53     }
    55     mProfileDir = profileDir;
    56     return NS_OK;
    57 }
    59 NS_IMETHODIMP nsCacheSession::GetProfileDirectory(nsIFile **profileDir)
    60 {
    61     if (mProfileDir)
    62         NS_ADDREF(*profileDir = mProfileDir);
    63     else
    64         *profileDir = nullptr;
    66     return NS_OK;
    67 }
    70 NS_IMETHODIMP nsCacheSession::SetDoomEntriesIfExpired(bool doomEntriesIfExpired)
    71 {
    72     if (doomEntriesIfExpired)  MarkDoomEntriesIfExpired();
    73     else                       ClearDoomEntriesIfExpired();
    74     return NS_OK;
    75 }
    78 NS_IMETHODIMP
    79 nsCacheSession::OpenCacheEntry(const nsACString &         key, 
    80                                nsCacheAccessMode          accessRequested,
    81                                bool                       blockingMode,
    82                                nsICacheEntryDescriptor ** result)
    83 {
    84     nsresult rv;
    86     if (NS_IsMainThread())
    87         rv = NS_ERROR_NOT_AVAILABLE;
    88     else
    89         rv = nsCacheService::OpenCacheEntry(this,
    90                                             key,
    91                                             accessRequested,
    92                                             blockingMode,
    93                                             nullptr, // no listener
    94                                             result);
    95     return rv;
    96 }
    99 NS_IMETHODIMP nsCacheSession::AsyncOpenCacheEntry(const nsACString & key,
   100                                                   nsCacheAccessMode accessRequested,
   101                                                   nsICacheListener *listener,
   102                                                   bool              noWait)
   103 {
   104     nsresult rv;
   105     rv = nsCacheService::OpenCacheEntry(this,
   106                                         key,
   107                                         accessRequested,
   108                                         !noWait,
   109                                         listener,
   110                                         nullptr); // no result
   112     if (rv == NS_ERROR_CACHE_WAIT_FOR_VALIDATION) rv = NS_OK;
   113     return rv;
   114 }
   116 NS_IMETHODIMP nsCacheSession::EvictEntries()
   117 {
   118     return nsCacheService::EvictEntriesForSession(this);
   119 }
   122 NS_IMETHODIMP nsCacheSession::IsStorageEnabled(bool *result)
   123 {
   125     return nsCacheService::IsStorageEnabledForPolicy(StoragePolicy(), result);
   126 }
   128 NS_IMETHODIMP nsCacheSession::DoomEntry(const nsACString &key,
   129                                         nsICacheListener *listener)
   130 {
   131     return nsCacheService::DoomEntry(this, key, listener);
   132 }
   134 NS_IMETHODIMP nsCacheSession::GetIsPrivate(bool* aPrivate)
   135 {
   136     *aPrivate = IsPrivate();
   137     return NS_OK;
   138 }
   140 NS_IMETHODIMP nsCacheSession::SetIsPrivate(bool aPrivate)
   141 {
   142     if (aPrivate)
   143         MarkPrivate();
   144     else
   145         MarkPublic();
   146     return NS_OK;
   147 }

mercurial