Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef nsIOService_h__
7 #define nsIOService_h__
9 #include "nsStringFwd.h"
10 #include "nsIIOService2.h"
11 #include "nsTArray.h"
12 #include "nsCOMPtr.h"
13 #include "nsWeakPtr.h"
14 #include "nsIObserver.h"
15 #include "nsWeakReference.h"
16 #include "nsINetUtil.h"
17 #include "nsIChannelEventSink.h"
18 #include "nsCategoryCache.h"
19 #include "nsISpeculativeConnect.h"
20 #include "mozilla/Attributes.h"
22 #define NS_N(x) (sizeof(x)/sizeof(*x))
24 // We don't want to expose this observer topic.
25 // Intended internal use only for remoting offline/inline events.
26 // See Bug 552829
27 #define NS_IPC_IOSERVICE_SET_OFFLINE_TOPIC "ipc:network:set-offline"
29 static const char gScheme[][sizeof("resource")] =
30 {"chrome", "file", "http", "jar", "resource"};
32 class nsAsyncRedirectVerifyHelper;
33 class nsINetworkLinkService;
34 class nsIPrefBranch;
35 class nsIProtocolProxyService2;
36 class nsIProxyInfo;
37 class nsPIDNSService;
38 class nsPISocketTransportService;
40 class nsIOService MOZ_FINAL : public nsIIOService2
41 , public nsIObserver
42 , public nsINetUtil
43 , public nsISpeculativeConnect
44 , public nsSupportsWeakReference
45 {
46 public:
47 NS_DECL_THREADSAFE_ISUPPORTS
48 NS_DECL_NSIIOSERVICE
49 NS_DECL_NSIIOSERVICE2
50 NS_DECL_NSIOBSERVER
51 NS_DECL_NSINETUTIL
52 NS_DECL_NSISPECULATIVECONNECT
54 // Gets the singleton instance of the IO Service, creating it as needed
55 // Returns nullptr on out of memory or failure to initialize.
56 // Returns an addrefed pointer.
57 static nsIOService* GetInstance();
59 NS_HIDDEN_(nsresult) Init();
60 NS_HIDDEN_(nsresult) NewURI(const char* aSpec, nsIURI* aBaseURI,
61 nsIURI* *result,
62 nsIProtocolHandler* *hdlrResult);
64 // Called by channels before a redirect happens. This notifies the global
65 // redirect observers.
66 nsresult AsyncOnChannelRedirect(nsIChannel* oldChan, nsIChannel* newChan,
67 uint32_t flags,
68 nsAsyncRedirectVerifyHelper *helper);
70 bool IsOffline() { return mOffline; }
71 bool IsLinkUp();
73 bool IsComingOnline() const {
74 return mOffline && mSettingOffline && !mSetOfflineValue;
75 }
77 private:
78 // These shouldn't be called directly:
79 // - construct using GetInstance
80 // - destroy using Release
81 nsIOService() NS_HIDDEN;
82 ~nsIOService() NS_HIDDEN;
84 NS_HIDDEN_(nsresult) TrackNetworkLinkStatusForOffline();
86 NS_HIDDEN_(nsresult) GetCachedProtocolHandler(const char *scheme,
87 nsIProtocolHandler* *hdlrResult,
88 uint32_t start=0,
89 uint32_t end=0);
90 NS_HIDDEN_(nsresult) CacheProtocolHandler(const char *scheme,
91 nsIProtocolHandler* hdlr);
93 // Prefs wrangling
94 NS_HIDDEN_(void) PrefsChanged(nsIPrefBranch *prefs, const char *pref = nullptr);
95 NS_HIDDEN_(void) GetPrefBranch(nsIPrefBranch **);
96 NS_HIDDEN_(void) ParsePortList(nsIPrefBranch *prefBranch, const char *pref, bool remove);
98 nsresult InitializeSocketTransportService();
99 nsresult InitializeNetworkLinkService();
101 // consolidated helper function
102 void LookupProxyInfo(nsIURI *aURI, nsIURI *aProxyURI, uint32_t aProxyFlags,
103 nsCString *aScheme, nsIProxyInfo **outPI);
105 private:
106 bool mOffline;
107 bool mOfflineForProfileChange;
108 bool mManageOfflineStatus;
110 // Used to handle SetOffline() reentrancy. See the comment in
111 // SetOffline() for more details.
112 bool mSettingOffline;
113 bool mSetOfflineValue;
115 bool mShutdown;
117 nsCOMPtr<nsPISocketTransportService> mSocketTransportService;
118 nsCOMPtr<nsPIDNSService> mDNSService;
119 nsCOMPtr<nsIProtocolProxyService2> mProxyService;
120 nsCOMPtr<nsINetworkLinkService> mNetworkLinkService;
121 bool mNetworkLinkServiceInitialized;
123 // Cached protocol handlers
124 nsWeakPtr mWeakHandler[NS_N(gScheme)];
126 // cached categories
127 nsCategoryCache<nsIChannelEventSink> mChannelEventSinks;
129 nsTArray<int32_t> mRestrictedPortList;
131 bool mAutoDialEnabled;
132 public:
133 // Used for all default buffer sizes that necko allocates.
134 static uint32_t gDefaultSegmentSize;
135 static uint32_t gDefaultSegmentCount;
136 };
138 /**
139 * Reference to the IO service singleton. May be null.
140 */
141 extern nsIOService* gIOService;
143 #endif // nsIOService_h__