Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/netwerk/cache/nsDiskCacheStreams.h
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
8
#ifndef _nsDiskCacheStreams_h_
9
#define _nsDiskCacheStreams_h_
10
11
#include "mozilla/MemoryReporting.h"
12
#include "nsDiskCacheBinding.h"
13
14
#include "nsCache.h"
15
16
#include "nsIInputStream.h"
17
#include "nsIOutputStream.h"
18
19
#include "mozilla/Atomics.h"
20
21
class nsDiskCacheDevice;
22
23
class nsDiskCacheStreamIO : public nsIOutputStream {
24
public:
25
    explicit nsDiskCacheStreamIO(nsDiskCacheBinding *   binding);
26
27
    NS_DECL_THREADSAFE_ISUPPORTS
28
    NS_DECL_NSIOUTPUTSTREAM
29
30
    nsresult    GetInputStream(uint32_t offset, nsIInputStream ** inputStream);
31
    nsresult    GetOutputStream(uint32_t offset, nsIOutputStream ** outputStream);
32
33
    nsresult    ClearBinding();
34
35
0
    void        IncrementInputStreamCount() { mInStreamCount++; }
36
    void        DecrementInputStreamCount()
37
0
                {
38
0
                    mInStreamCount--;
39
0
                    NS_ASSERTION(mInStreamCount >= 0, "mInStreamCount has gone negative");
40
0
                }
41
42
    size_t     SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf);
43
44
    // GCC 2.95.2 requires this to be defined, although we never call it.
45
    // and OS/2 requires that it not be private
46
    nsDiskCacheStreamIO()
47
        : mBinding(nullptr),
48
          mDevice(nullptr),
49
          mFD(nullptr),
50
          mStreamEnd(0),
51
          mBufSize(0),
52
          mBuffer(nullptr),
53
          mOutputStreamIsOpen(false)
54
0
    {
55
0
        MOZ_ASSERT_UNREACHABLE("oops");
56
0
    }
57
58
private:
59
    virtual ~nsDiskCacheStreamIO();
60
61
    nsresult    OpenCacheFile(int flags, PRFileDesc ** fd);
62
    nsresult    ReadCacheBlocks(uint32_t bufferSize);
63
    nsresult    FlushBufferToFile();
64
    void        UpdateFileSize();
65
    void        DeleteBuffer();
66
    nsresult    CloseOutputStream();
67
    nsresult    SeekAndTruncate(uint32_t offset);
68
69
    nsDiskCacheBinding *        mBinding;       // not an owning reference
70
    nsDiskCacheDevice *         mDevice;
71
    mozilla::Atomic<int32_t>                     mInStreamCount;
72
    PRFileDesc *                mFD;
73
74
    uint32_t                    mStreamEnd;     // current size of data
75
    uint32_t                    mBufSize;       // current end of buffer
76
    char *                      mBuffer;
77
    bool                        mOutputStreamIsOpen;
78
};
79
80
#endif // _nsDiskCacheStreams_h_