Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/netwerk/protocol/ftp/nsFTPChannel.h
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
/* vim:set ts=4 sw=4 sts=4 et cindent: */
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
#ifndef nsFTPChannel_h___
8
#define nsFTPChannel_h___
9
10
#include "nsBaseChannel.h"
11
12
#include "nsString.h"
13
#include "nsCOMPtr.h"
14
#include "nsIChannelWithDivertableParentListener.h"
15
#include "nsIFTPChannel.h"
16
#include "nsIForcePendingChannel.h"
17
#include "nsIUploadChannel.h"
18
#include "nsIProxyInfo.h"
19
#include "nsIProxiedChannel.h"
20
#include "nsIResumableChannel.h"
21
22
class nsIURI;
23
using mozilla::net::ADivertableParentChannel;
24
25
class nsFtpChannel final : public nsBaseChannel,
26
                           public nsIFTPChannel,
27
                           public nsIUploadChannel,
28
                           public nsIResumableChannel,
29
                           public nsIProxiedChannel,
30
                           public nsIForcePendingChannel,
31
                           public nsIChannelWithDivertableParentListener
32
{
33
public:
34
    NS_DECL_ISUPPORTS_INHERITED
35
    NS_DECL_NSIUPLOADCHANNEL
36
    NS_DECL_NSIRESUMABLECHANNEL
37
    NS_DECL_NSIPROXIEDCHANNEL
38
    NS_DECL_NSICHANNELWITHDIVERTABLEPARENTLISTENER
39
40
    nsFtpChannel(nsIURI *uri, nsIProxyInfo *pi)
41
        : mProxyInfo(pi)
42
        , mStartPos(0)
43
        , mResumeRequested(false)
44
        , mLastModifiedTime(0)
45
        , mForcePending(false)
46
        , mSuspendCount(0)
47
0
    {
48
0
        SetURI(uri);
49
0
    }
50
51
0
    void UpdateURI(nsIURI *aURI) {
52
0
        MOZ_DIAGNOSTIC_ASSERT(NS_IsMainThread(), "Not thread-safe.");
53
0
        mURI = aURI;
54
0
    }
55
56
0
    nsIProxyInfo *ProxyInfo() {
57
0
        return mProxyInfo;
58
0
    }
59
60
    void SetProxyInfo(nsIProxyInfo *pi)
61
0
    {
62
0
        mProxyInfo = pi;
63
0
    }
64
65
    NS_IMETHOD IsPending(bool *result) override;
66
67
    // This is a short-cut to calling nsIRequest::IsPending().
68
    // Overrides Pending in nsBaseChannel.
69
    bool Pending() const override;
70
71
    // Were we asked to resume a download?
72
0
    bool ResumeRequested() { return mResumeRequested; }
73
74
    // Download from this byte offset
75
0
    uint64_t StartPos() { return mStartPos; }
76
77
    // ID of the entity to resume downloading
78
0
    const nsCString &EntityID() {
79
0
        return mEntityID;
80
0
    }
81
0
    void SetEntityID(const nsACString& entityID) {
82
0
        mEntityID = entityID;
83
0
    }
84
85
0
    NS_IMETHOD GetLastModifiedTime(PRTime* lastModifiedTime) override {
86
0
        *lastModifiedTime = mLastModifiedTime;
87
0
        return NS_OK;
88
0
    }
89
90
0
    NS_IMETHOD SetLastModifiedTime(PRTime lastModifiedTime) override {
91
0
        mLastModifiedTime = lastModifiedTime;
92
0
        return NS_OK;
93
0
    }
94
95
    // Data stream to upload
96
0
    nsIInputStream *UploadStream() {
97
0
        return mUploadStream;
98
0
    }
99
100
    // Helper function for getting the nsIFTPEventSink.
101
    void GetFTPEventSink(nsCOMPtr<nsIFTPEventSink> &aResult);
102
103
    NS_IMETHOD Suspend() override;
104
    NS_IMETHOD Resume() override;
105
106
public:
107
    NS_IMETHOD ForcePending(bool aForcePending) override;
108
109
protected:
110
0
    virtual ~nsFtpChannel() = default;
111
    virtual nsresult OpenContentStream(bool async, nsIInputStream **result,
112
                                       nsIChannel** channel) override;
113
    virtual bool GetStatusArg(nsresult status, nsString &statusArg) override;
114
    virtual void OnCallbacksChanged() override;
115
116
private:
117
    nsCOMPtr<nsIProxyInfo>           mProxyInfo;
118
    nsCOMPtr<nsIFTPEventSink>        mFTPEventSink;
119
    nsCOMPtr<nsIInputStream>         mUploadStream;
120
    uint64_t                         mStartPos;
121
    nsCString                        mEntityID;
122
    bool                             mResumeRequested;
123
    PRTime                           mLastModifiedTime;
124
    bool                             mForcePending;
125
    RefPtr<ADivertableParentChannel> mParentChannel;
126
127
    // Current suspension depth for this channel object
128
    uint32_t                          mSuspendCount;
129
};
130
131
#endif /* nsFTPChannel_h___ */