Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/netwerk/cache/nsCacheSession.cpp
Line
Count
Source (jump to first uncovered line)
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/. */
6
7
#include "nsCacheSession.h"
8
#include "nsCacheService.h"
9
#include "nsCRT.h"
10
#include "nsThreadUtils.h"
11
12
NS_IMPL_ISUPPORTS(nsCacheSession, nsICacheSession)
13
14
nsCacheSession::nsCacheSession(const char *         clientID,
15
                               nsCacheStoragePolicy storagePolicy,
16
                               bool                 streamBased)
17
    : mClientID(clientID),
18
      mInfo(0)
19
0
{
20
0
  SetStoragePolicy(storagePolicy);
21
0
22
0
  if (streamBased) MarkStreamBased();
23
0
  else SetStoragePolicy(nsICache::STORE_IN_MEMORY);
24
0
25
0
  MarkPublic();
26
0
27
0
  MarkDoomEntriesIfExpired();
28
0
}
29
30
nsCacheSession::~nsCacheSession()
31
0
{
32
0
  /* destructor code */
33
0
    // notify service we are going away?
34
0
}
35
36
37
NS_IMETHODIMP nsCacheSession::GetDoomEntriesIfExpired(bool *result)
38
0
{
39
0
    NS_ENSURE_ARG_POINTER(result);
40
0
    *result = WillDoomEntriesIfExpired();
41
0
    return NS_OK;
42
0
}
43
44
45
NS_IMETHODIMP nsCacheSession::SetProfileDirectory(nsIFile *profileDir)
46
0
{
47
0
  if (StoragePolicy() != nsICache::STORE_OFFLINE && profileDir) {
48
0
        // Profile directory override is currently implemented only for
49
0
        // offline cache.  This is an early failure to prevent the request
50
0
        // being processed before it would fail later because of inability
51
0
        // to assign a cache base dir.
52
0
        return NS_ERROR_UNEXPECTED;
53
0
    }
54
0
55
0
    mProfileDir = profileDir;
56
0
    return NS_OK;
57
0
}
58
59
NS_IMETHODIMP nsCacheSession::GetProfileDirectory(nsIFile **profileDir)
60
0
{
61
0
    if (mProfileDir)
62
0
        NS_ADDREF(*profileDir = mProfileDir);
63
0
    else
64
0
        *profileDir = nullptr;
65
0
66
0
    return NS_OK;
67
0
}
68
69
70
NS_IMETHODIMP nsCacheSession::SetDoomEntriesIfExpired(bool doomEntriesIfExpired)
71
0
{
72
0
    if (doomEntriesIfExpired)  MarkDoomEntriesIfExpired();
73
0
    else                       ClearDoomEntriesIfExpired();
74
0
    return NS_OK;
75
0
}
76
77
78
NS_IMETHODIMP
79
nsCacheSession::OpenCacheEntry(const nsACString &         key,
80
                               nsCacheAccessMode          accessRequested,
81
                               bool                       blockingMode,
82
                               nsICacheEntryDescriptor ** result)
83
0
{
84
0
    nsresult rv;
85
0
86
0
    if (NS_IsMainThread())
87
0
        rv = NS_ERROR_NOT_AVAILABLE;
88
0
    else
89
0
        rv = nsCacheService::OpenCacheEntry(this,
90
0
                                            key,
91
0
                                            accessRequested,
92
0
                                            blockingMode,
93
0
                                            nullptr, // no listener
94
0
                                            result);
95
0
    return rv;
96
0
}
97
98
99
NS_IMETHODIMP nsCacheSession::AsyncOpenCacheEntry(const nsACString & key,
100
                                                  nsCacheAccessMode accessRequested,
101
                                                  nsICacheListener *listener,
102
                                                  bool              noWait)
103
0
{
104
0
    nsresult rv;
105
0
    rv = nsCacheService::OpenCacheEntry(this,
106
0
                                        key,
107
0
                                        accessRequested,
108
0
                                        !noWait,
109
0
                                        listener,
110
0
                                        nullptr); // no result
111
0
112
0
    if (rv == NS_ERROR_CACHE_WAIT_FOR_VALIDATION) rv = NS_OK;
113
0
    return rv;
114
0
}
115
116
NS_IMETHODIMP nsCacheSession::EvictEntries()
117
0
{
118
0
    return nsCacheService::EvictEntriesForSession(this);
119
0
}
120
121
122
NS_IMETHODIMP nsCacheSession::IsStorageEnabled(bool *result)
123
0
{
124
0
125
0
    return nsCacheService::IsStorageEnabledForPolicy(StoragePolicy(), result);
126
0
}
127
128
NS_IMETHODIMP nsCacheSession::DoomEntry(const nsACString &key,
129
                                        nsICacheListener *listener)
130
0
{
131
0
    return nsCacheService::DoomEntry(this, key, listener);
132
0
}
133
134
NS_IMETHODIMP nsCacheSession::GetIsPrivate(bool* aPrivate)
135
0
{
136
0
    *aPrivate = IsPrivate();
137
0
    return NS_OK;
138
0
}
139
140
NS_IMETHODIMP nsCacheSession::SetIsPrivate(bool aPrivate)
141
0
{
142
0
    if (aPrivate)
143
0
        MarkPrivate();
144
0
    else
145
0
        MarkPublic();
146
0
    return NS_OK;
147
0
}