netwerk/base/src/nsIOService.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/netwerk/base/src/nsIOService.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,143 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#ifndef nsIOService_h__
    1.10 +#define nsIOService_h__
    1.11 +
    1.12 +#include "nsStringFwd.h"
    1.13 +#include "nsIIOService2.h"
    1.14 +#include "nsTArray.h"
    1.15 +#include "nsCOMPtr.h"
    1.16 +#include "nsWeakPtr.h"
    1.17 +#include "nsIObserver.h"
    1.18 +#include "nsWeakReference.h"
    1.19 +#include "nsINetUtil.h"
    1.20 +#include "nsIChannelEventSink.h"
    1.21 +#include "nsCategoryCache.h"
    1.22 +#include "nsISpeculativeConnect.h"
    1.23 +#include "mozilla/Attributes.h"
    1.24 +
    1.25 +#define NS_N(x) (sizeof(x)/sizeof(*x))
    1.26 +
    1.27 +// We don't want to expose this observer topic.
    1.28 +// Intended internal use only for remoting offline/inline events.
    1.29 +// See Bug 552829
    1.30 +#define NS_IPC_IOSERVICE_SET_OFFLINE_TOPIC "ipc:network:set-offline"
    1.31 +
    1.32 +static const char gScheme[][sizeof("resource")] =
    1.33 +    {"chrome", "file", "http", "jar", "resource"};
    1.34 +
    1.35 +class nsAsyncRedirectVerifyHelper;
    1.36 +class nsINetworkLinkService;
    1.37 +class nsIPrefBranch;
    1.38 +class nsIProtocolProxyService2;
    1.39 +class nsIProxyInfo;
    1.40 +class nsPIDNSService;
    1.41 +class nsPISocketTransportService;
    1.42 +
    1.43 +class nsIOService MOZ_FINAL : public nsIIOService2
    1.44 +                            , public nsIObserver
    1.45 +                            , public nsINetUtil
    1.46 +                            , public nsISpeculativeConnect
    1.47 +                            , public nsSupportsWeakReference
    1.48 +{
    1.49 +public:
    1.50 +    NS_DECL_THREADSAFE_ISUPPORTS
    1.51 +    NS_DECL_NSIIOSERVICE
    1.52 +    NS_DECL_NSIIOSERVICE2
    1.53 +    NS_DECL_NSIOBSERVER
    1.54 +    NS_DECL_NSINETUTIL
    1.55 +    NS_DECL_NSISPECULATIVECONNECT
    1.56 +
    1.57 +    // Gets the singleton instance of the IO Service, creating it as needed
    1.58 +    // Returns nullptr on out of memory or failure to initialize.
    1.59 +    // Returns an addrefed pointer.
    1.60 +    static nsIOService* GetInstance();
    1.61 +
    1.62 +    NS_HIDDEN_(nsresult) Init();
    1.63 +    NS_HIDDEN_(nsresult) NewURI(const char* aSpec, nsIURI* aBaseURI,
    1.64 +                                nsIURI* *result,
    1.65 +                                nsIProtocolHandler* *hdlrResult);
    1.66 +
    1.67 +    // Called by channels before a redirect happens. This notifies the global
    1.68 +    // redirect observers.
    1.69 +    nsresult AsyncOnChannelRedirect(nsIChannel* oldChan, nsIChannel* newChan,
    1.70 +                                    uint32_t flags,
    1.71 +                                    nsAsyncRedirectVerifyHelper *helper);
    1.72 +
    1.73 +    bool IsOffline() { return mOffline; }
    1.74 +    bool IsLinkUp();
    1.75 +
    1.76 +    bool IsComingOnline() const {
    1.77 +      return mOffline && mSettingOffline && !mSetOfflineValue;
    1.78 +    }
    1.79 +
    1.80 +private:
    1.81 +    // These shouldn't be called directly:
    1.82 +    // - construct using GetInstance
    1.83 +    // - destroy using Release
    1.84 +    nsIOService() NS_HIDDEN;
    1.85 +    ~nsIOService() NS_HIDDEN;
    1.86 +
    1.87 +    NS_HIDDEN_(nsresult) TrackNetworkLinkStatusForOffline();
    1.88 +
    1.89 +    NS_HIDDEN_(nsresult) GetCachedProtocolHandler(const char *scheme,
    1.90 +                                                  nsIProtocolHandler* *hdlrResult,
    1.91 +                                                  uint32_t start=0,
    1.92 +                                                  uint32_t end=0);
    1.93 +    NS_HIDDEN_(nsresult) CacheProtocolHandler(const char *scheme,
    1.94 +                                              nsIProtocolHandler* hdlr);
    1.95 +
    1.96 +    // Prefs wrangling
    1.97 +    NS_HIDDEN_(void) PrefsChanged(nsIPrefBranch *prefs, const char *pref = nullptr);
    1.98 +    NS_HIDDEN_(void) GetPrefBranch(nsIPrefBranch **);
    1.99 +    NS_HIDDEN_(void) ParsePortList(nsIPrefBranch *prefBranch, const char *pref, bool remove);
   1.100 +
   1.101 +    nsresult InitializeSocketTransportService();
   1.102 +    nsresult InitializeNetworkLinkService();
   1.103 +
   1.104 +    // consolidated helper function
   1.105 +    void LookupProxyInfo(nsIURI *aURI, nsIURI *aProxyURI, uint32_t aProxyFlags,
   1.106 +                         nsCString *aScheme, nsIProxyInfo **outPI);
   1.107 +
   1.108 +private:
   1.109 +    bool                                 mOffline;
   1.110 +    bool                                 mOfflineForProfileChange;
   1.111 +    bool                                 mManageOfflineStatus;
   1.112 +
   1.113 +    // Used to handle SetOffline() reentrancy.  See the comment in
   1.114 +    // SetOffline() for more details.
   1.115 +    bool                                 mSettingOffline;
   1.116 +    bool                                 mSetOfflineValue;
   1.117 +
   1.118 +    bool                                 mShutdown;
   1.119 +
   1.120 +    nsCOMPtr<nsPISocketTransportService> mSocketTransportService;
   1.121 +    nsCOMPtr<nsPIDNSService>             mDNSService;
   1.122 +    nsCOMPtr<nsIProtocolProxyService2>   mProxyService;
   1.123 +    nsCOMPtr<nsINetworkLinkService>      mNetworkLinkService;
   1.124 +    bool                                 mNetworkLinkServiceInitialized;
   1.125 +
   1.126 +    // Cached protocol handlers
   1.127 +    nsWeakPtr                            mWeakHandler[NS_N(gScheme)];
   1.128 +
   1.129 +    // cached categories
   1.130 +    nsCategoryCache<nsIChannelEventSink> mChannelEventSinks;
   1.131 +
   1.132 +    nsTArray<int32_t>                    mRestrictedPortList;
   1.133 +
   1.134 +    bool                                 mAutoDialEnabled;
   1.135 +public:
   1.136 +    // Used for all default buffer sizes that necko allocates.
   1.137 +    static uint32_t   gDefaultSegmentSize;
   1.138 +    static uint32_t   gDefaultSegmentCount;
   1.139 +};
   1.140 +
   1.141 +/**
   1.142 + * Reference to the IO service singleton. May be null.
   1.143 + */
   1.144 +extern nsIOService* gIOService;
   1.145 +
   1.146 +#endif // nsIOService_h__

mercurial