uriloader/prefetch/nsPrefetchService.h

Wed, 31 Dec 2014 07:22:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:22:50 +0100
branch
TOR_BUG_3246
changeset 4
fc2d59ddac77
permissions
-rw-r--r--

Correct previous dual key logic pending first delivery installment.

     1 /* This Source Code Form is subject to the terms of the Mozilla Public
     2  * License, v. 2.0. If a copy of the MPL was not distributed with this
     3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     5 #ifndef nsPrefetchService_h__
     6 #define nsPrefetchService_h__
     8 #include "nsCPrefetchService.h"
     9 #include "nsIObserver.h"
    10 #include "nsIInterfaceRequestor.h"
    11 #include "nsIChannelEventSink.h"
    12 #include "nsIRedirectResultListener.h"
    13 #include "nsIWebProgressListener.h"
    14 #include "nsIStreamListener.h"
    15 #include "nsIChannel.h"
    16 #include "nsIURI.h"
    17 #include "nsWeakReference.h"
    18 #include "nsCOMPtr.h"
    19 #include "nsAutoPtr.h"
    20 #include "mozilla/Attributes.h"
    22 class nsPrefetchService;
    23 class nsPrefetchListener;
    24 class nsPrefetchNode;
    26 //-----------------------------------------------------------------------------
    27 // nsPrefetchService
    28 //-----------------------------------------------------------------------------
    30 class nsPrefetchService MOZ_FINAL : public nsIPrefetchService
    31                                   , public nsIWebProgressListener
    32                                   , public nsIObserver
    33                                   , public nsSupportsWeakReference
    34 {
    35 public:
    36     NS_DECL_ISUPPORTS
    37     NS_DECL_NSIPREFETCHSERVICE
    38     NS_DECL_NSIWEBPROGRESSLISTENER
    39     NS_DECL_NSIOBSERVER
    41     nsPrefetchService();
    43     nsresult Init();
    44     void     ProcessNextURI();
    46     nsPrefetchNode *GetCurrentNode() { return mCurrentNode.get(); }
    47     nsPrefetchNode *GetQueueHead() { return mQueueHead; }
    49     void NotifyLoadRequested(nsPrefetchNode *node);
    50     void NotifyLoadCompleted(nsPrefetchNode *node);
    52 private:
    53     ~nsPrefetchService();
    55     nsresult Prefetch(nsIURI *aURI,
    56                       nsIURI *aReferrerURI,
    57                       nsIDOMNode *aSource,
    58                       bool aExplicit);
    60     void     AddProgressListener();
    61     void     RemoveProgressListener();
    62     nsresult EnqueueURI(nsIURI *aURI, nsIURI *aReferrerURI,
    63                         nsIDOMNode *aSource, nsPrefetchNode **node);
    64     nsresult EnqueueNode(nsPrefetchNode *node);
    65     nsresult DequeueNode(nsPrefetchNode **node);
    66     void     EmptyQueue();
    68     void     StartPrefetching();
    69     void     StopPrefetching();
    71     nsPrefetchNode                   *mQueueHead;
    72     nsPrefetchNode                   *mQueueTail;
    73     nsRefPtr<nsPrefetchNode>          mCurrentNode;
    74     int32_t                           mStopCount;
    75     // true if pending document loads have ever reached zero.
    76     int32_t                           mHaveProcessed;
    77     bool                              mDisabled;
    78 };
    80 //-----------------------------------------------------------------------------
    81 // nsPrefetchNode
    82 //-----------------------------------------------------------------------------
    84 class nsPrefetchNode MOZ_FINAL : public nsIStreamListener
    85                                , public nsIInterfaceRequestor
    86                                , public nsIChannelEventSink
    87                                , public nsIRedirectResultListener
    88 {
    89 public:
    90     NS_DECL_ISUPPORTS
    91     NS_DECL_NSIREQUESTOBSERVER
    92     NS_DECL_NSISTREAMLISTENER
    93     NS_DECL_NSIINTERFACEREQUESTOR
    94     NS_DECL_NSICHANNELEVENTSINK
    95     NS_DECL_NSIREDIRECTRESULTLISTENER
    97     nsPrefetchNode(nsPrefetchService *aPrefetchService,
    98                    nsIURI *aURI,
    99                    nsIURI *aReferrerURI,
   100                    nsIDOMNode *aSource);
   102     ~nsPrefetchNode() {}
   104     nsresult OpenChannel();
   105     nsresult CancelChannel(nsresult error);
   107     nsPrefetchNode             *mNext;
   108     nsCOMPtr<nsIURI>            mURI;
   109     nsCOMPtr<nsIURI>            mReferrerURI;
   110     nsCOMPtr<nsIWeakReference>  mSource;
   112 private:
   113     nsRefPtr<nsPrefetchService> mService;
   114     nsCOMPtr<nsIChannel>        mChannel;
   115     nsCOMPtr<nsIChannel>        mRedirectChannel;
   116     int64_t                     mBytesRead;
   117 };
   119 #endif // !nsPrefetchService_h__

mercurial