Back to index

lightning-sunbird  0.9+nobinonly
nsPrefetchService.h
Go to the documentation of this file.
00001 /* ***** BEGIN LICENSE BLOCK *****
00002  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00003  *
00004  * The contents of this file are subject to the Mozilla Public License Version
00005  * 1.1 (the "License"); you may not use this file except in compliance with
00006  * the License. You may obtain a copy of the License at
00007  * http://www.mozilla.org/MPL/
00008  *
00009  * Software distributed under the License is distributed on an "AS IS" basis,
00010  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00011  * for the specific language governing rights and limitations under the
00012  * License.
00013  *
00014  * The Original Code is Mozilla.
00015  *
00016  * The Initial Developer of the Original Code is
00017  * Netscape Communications Corporation.
00018  * Portions created by the Initial Developer are Copyright (C) 2002
00019  * the Initial Developer. All Rights Reserved.
00020  *
00021  * Contributor(s):
00022  *   Darin Fisher <darin@netscape.com> (original author)
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #ifndef nsPrefetchService_h__
00039 #define nsPrefetchService_h__
00040 
00041 #include "nsCPrefetchService.h"
00042 #include "nsIGenericFactory.h"
00043 #include "nsIObserver.h"
00044 #include "nsIInterfaceRequestor.h"
00045 #include "nsIChannelEventSink.h"
00046 #include "nsIWebProgressListener.h"
00047 #include "nsIStreamListener.h"
00048 #include "nsIChannel.h"
00049 #include "nsIURI.h"
00050 #include "nsWeakReference.h"
00051 #include "nsCOMPtr.h"
00052 
00053 class nsPrefetchService;
00054 class nsPrefetchListener;
00055 class nsPrefetchNode;
00056 
00057 //-----------------------------------------------------------------------------
00058 // nsPrefetchService
00059 //-----------------------------------------------------------------------------
00060 
00061 class nsPrefetchService : public nsIPrefetchService
00062                         , public nsIWebProgressListener
00063                         , public nsIObserver
00064                         , public nsSupportsWeakReference
00065 {
00066 public:
00067     NS_DECL_ISUPPORTS
00068     NS_DECL_NSIPREFETCHSERVICE
00069     NS_DECL_NSIWEBPROGRESSLISTENER
00070     NS_DECL_NSIOBSERVER
00071 
00072     nsPrefetchService();
00073 
00074     nsresult Init();
00075     void     ProcessNextURI();
00076     void     UpdateCurrentChannel(nsIChannel *c) { mCurrentChannel = c; }
00077 
00078 private:
00079     ~nsPrefetchService();
00080 
00081     void     AddProgressListener();
00082     void     RemoveProgressListener();
00083     nsresult EnqueueURI(nsIURI *aURI, nsIURI *aReferrerURI);
00084     nsresult DequeueURI(nsIURI **aURI, nsIURI **aReferrerURI);
00085     void     EmptyQueue();
00086     void     StartPrefetching();
00087     void     StopPrefetching();
00088 
00089     nsPrefetchNode      *mQueueHead;
00090     nsPrefetchNode      *mQueueTail;
00091     nsCOMPtr<nsIChannel> mCurrentChannel;
00092     PRInt32              mStopCount;
00093     PRBool               mDisabled;
00094 };
00095 
00096 //-----------------------------------------------------------------------------
00097 // nsPrefetchListener
00098 //-----------------------------------------------------------------------------
00099 
00100 class nsPrefetchListener : public nsIStreamListener
00101                          , public nsIInterfaceRequestor
00102                          , public nsIChannelEventSink
00103 {
00104 public:
00105     NS_DECL_ISUPPORTS
00106     NS_DECL_NSIREQUESTOBSERVER
00107     NS_DECL_NSISTREAMLISTENER
00108     NS_DECL_NSIINTERFACEREQUESTOR
00109     NS_DECL_NSICHANNELEVENTSINK
00110 
00111     nsPrefetchListener(nsPrefetchService *aPrefetchService);
00112 
00113 private:
00114     ~nsPrefetchListener();
00115 
00116     static NS_METHOD ConsumeSegments(nsIInputStream *, void *, const char *,
00117                                      PRUint32, PRUint32, PRUint32 *);
00118 
00119     nsPrefetchService *mService;
00120 };
00121 
00122 //-----------------------------------------------------------------------------
00123 // nsPrefetchNode
00124 //-----------------------------------------------------------------------------
00125 
00126 class nsPrefetchNode
00127 {
00128 public:
00129     nsPrefetchNode(nsIURI *aURI,
00130                    nsIURI *aReferrerURI)
00131         : mNext(nsnull)
00132         , mURI(aURI)
00133         , mReferrerURI(aReferrerURI)
00134         { }
00135 
00136     nsPrefetchNode  *mNext;
00137     nsCOMPtr<nsIURI> mURI;
00138     nsCOMPtr<nsIURI> mReferrerURI;
00139 };
00140 
00141 #endif // !nsPrefetchService_h__