Back to index

lightning-sunbird  0.9+nobinonly
nsIOService.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
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 nsIOService_h__
00039 #define nsIOService_h__
00040 
00041 #include "necko-config.h"
00042 
00043 #include "nsString.h"
00044 #include "nsIIOService2.h"
00045 #include "nsVoidArray.h"
00046 #include "nsPISocketTransportService.h" 
00047 #include "nsPIDNSService.h" 
00048 #include "nsIProtocolProxyService.h"
00049 #include "nsCOMPtr.h"
00050 #include "nsURLHelper.h"
00051 #include "nsWeakPtr.h"
00052 #include "nsIEventQueueService.h"
00053 #include "nsIURLParser.h"
00054 #include "nsSupportsArray.h"
00055 #include "nsIObserver.h"
00056 #include "nsWeakReference.h"
00057 #include "nsINetUtil.h"
00058 #include "nsIChannelEventSink.h"
00059 #include "nsIContentSniffer.h"
00060 #include "nsCategoryCache.h"
00061 #include "nsINetworkLinkService.h"
00062 
00063 #define NS_N(x) (sizeof(x)/sizeof(*x))
00064 
00065 #ifdef NECKO_SMALL_BUFFERS
00066 #define NS_NECKO_BUFFER_CACHE_COUNT (10)  // Max holdings: 10 * 2k = 20k
00067 #else
00068 #define NS_NECKO_BUFFER_CACHE_COUNT (24)  // Max holdings: 24 * 4k = 96k
00069 #endif
00070 #define NS_NECKO_15_MINS (15 * 60)
00071 
00072 static const char gScheme[][sizeof("resource")] =
00073     {"chrome", "file", "http", "jar", "resource"};
00074 
00075 class nsIPrefBranch;
00076 class nsIPrefBranch2;
00077 
00078 class nsIOService : public nsIIOService2
00079                   , public nsIObserver
00080                   , public nsINetUtil
00081                   , public nsSupportsWeakReference
00082 {
00083 public:
00084     NS_DECL_ISUPPORTS
00085     NS_DECL_NSIIOSERVICE
00086     NS_DECL_NSIIOSERVICE2
00087     NS_DECL_NSIOBSERVER
00088     NS_DECL_NSINETUTIL
00089 
00090     // Gets the singleton instance of the IO Service, creating it as needed
00091     // Returns nsnull on out of memory or failure to initialize.
00092     // Returns an addrefed pointer.
00093     static nsIOService* GetInstance();
00094 
00095     NS_HIDDEN_(nsresult) Init();
00096     NS_HIDDEN_(nsresult) NewURI(const char* aSpec, nsIURI* aBaseURI,
00097                                 nsIURI* *result,
00098                                 nsIProtocolHandler* *hdlrResult);
00099 
00100     // Called by channels before a redirect happens. This notifies the global
00101     // redirect observers.
00102     nsresult OnChannelRedirect(nsIChannel* oldChan, nsIChannel* newChan,
00103                                PRUint32 flags);
00104 
00105     // Gets the array of registered content sniffers
00106     const nsCOMArray<nsIContentSniffer_MOZILLA_1_8_BRANCH>&
00107     GetContentSniffers() {
00108       return mContentSniffers.GetEntries();
00109     }
00110 
00111 private:
00112     // These shouldn't be called directly:
00113     // - construct using GetInstance
00114     // - destroy using Release
00115     nsIOService() NS_HIDDEN;
00116     ~nsIOService() NS_HIDDEN;
00117 
00118     NS_HIDDEN_(nsresult) TrackNetworkLinkStatusForOffline();
00119 
00120     NS_HIDDEN_(nsresult) GetCachedProtocolHandler(const char *scheme,
00121                                                   nsIProtocolHandler* *hdlrResult,
00122                                                   PRUint32 start=0,
00123                                                   PRUint32 end=0);
00124     NS_HIDDEN_(nsresult) CacheProtocolHandler(const char *scheme,
00125                                               nsIProtocolHandler* hdlr);
00126 
00127     // Prefs wrangling
00128     NS_HIDDEN_(void) PrefsChanged(nsIPrefBranch *prefs, const char *pref = nsnull);
00129     NS_HIDDEN_(void) GetPrefBranch(nsIPrefBranch2 **);
00130     NS_HIDDEN_(void) ParsePortList(nsIPrefBranch *prefBranch, const char *pref, PRBool remove);
00131 
00132 private:
00133     PRPackedBool                         mOffline;
00134     PRPackedBool                         mOfflineForProfileChange;
00135     PRPackedBool                         mManageOfflineStatus;
00136     nsCOMPtr<nsPISocketTransportService> mSocketTransportService;
00137     nsCOMPtr<nsPIDNSService>             mDNSService;
00138     nsCOMPtr<nsIProtocolProxyService>    mProxyService;
00139     nsCOMPtr<nsIEventQueueService>       mEventQueueService;
00140     nsCOMPtr<nsINetworkLinkService>      mNetworkLinkService;
00141     
00142     // Cached protocol handlers
00143     nsWeakPtr                            mWeakHandler[NS_N(gScheme)];
00144 
00145     // cached categories
00146     nsCategoryCache<nsIChannelEventSink> mChannelEventSinks;
00147     nsCategoryCache<nsIContentSniffer_MOZILLA_1_8_BRANCH> mContentSniffers;
00148 
00149     nsVoidArray                          mRestrictedPortList;
00150 
00151 public:
00152     // Necko buffer cache. Used for all default buffer sizes that necko
00153     // allocates.
00154     static nsIMemory *gBufferCache;
00155 };
00156 
00160 extern nsIOService* gIOService;
00161 
00162 #endif // nsIOService_h__