ProxyAutoConfigChild.h (2675B)
1 /* -*- Mode: C++; tab-width: 4; 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/. */ 5 6 #ifndef ProxyAutoConfigChild_h__ 7 #define ProxyAutoConfigChild_h__ 8 9 #include "mozilla/LinkedList.h" 10 #include "mozilla/net/PProxyAutoConfigChild.h" 11 #include "mozilla/StaticPtr.h" 12 #include "mozilla/UniquePtr.h" 13 14 namespace mozilla { 15 namespace net { 16 17 class ProxyAutoConfig; 18 19 class ProxyAutoConfigChild final : public PProxyAutoConfigChild { 20 public: 21 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(ProxyAutoConfigChild, final) 22 23 static bool Create(Endpoint<PProxyAutoConfigChild>&& aEndpoint); 24 static bool CreatePACThread(); 25 static void ShutdownPACThread(); 26 27 ProxyAutoConfigChild(); 28 29 void ActorDestroy(ActorDestroyReason aWhy) override; 30 mozilla::ipc::IPCResult RecvConfigurePAC(const nsACString& aPACURI, 31 const nsACString& aPACScriptData, 32 const bool& aIncludePath, 33 const uint32_t& aExtraHeapSize); 34 mozilla::ipc::IPCResult RecvGetProxyForURI( 35 const nsACString& aTestURI, const nsACString& aTestHost, 36 GetProxyForURIResolver&& aResolver); 37 38 void Destroy(); 39 40 private: 41 virtual ~ProxyAutoConfigChild(); 42 void ProcessPendingQ(); 43 bool ProcessPending(); 44 static void BindProxyAutoConfigChild( 45 RefPtr<ProxyAutoConfigChild>&& aActor, 46 Endpoint<PProxyAutoConfigChild>&& aEndpoint); 47 48 UniquePtr<ProxyAutoConfig> mPAC; 49 bool mInProgress{false}; 50 bool mPACLoaded{false}; 51 bool mShutdown{false}; 52 53 class PendingQuery final : public LinkedListElement<RefPtr<PendingQuery>> { 54 public: 55 NS_INLINE_DECL_REFCOUNTING(PendingQuery) 56 57 explicit PendingQuery(const nsACString& aTestURI, 58 const nsACString& aTestHost, 59 GetProxyForURIResolver&& aResolver) 60 : mURI(aTestURI), mHost(aTestHost), mResolver(std::move(aResolver)) {} 61 62 void Resolve(nsresult aStatus, const nsACString& aResult); 63 const nsCString& URI() const { return mURI; } 64 const nsCString& Host() const { return mHost; } 65 66 private: 67 ~PendingQuery() = default; 68 69 nsCString mURI; 70 nsCString mHost; 71 GetProxyForURIResolver mResolver; 72 }; 73 74 LinkedList<RefPtr<PendingQuery>> mPendingQ; 75 76 static StaticRefPtr<nsIThread> sPACThread; 77 static bool sShutdownObserverRegistered; 78 static Atomic<uint32_t> sLiveActorCount; 79 }; 80 81 } // namespace net 82 } // namespace mozilla 83 84 #endif // ProxyAutoConfigChild_h__