Stop using NetworkProcess::singleton
authorachristensen@apple.com <achristensen@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 24 Jan 2019 00:29:48 +0000 (00:29 +0000)
committerachristensen@apple.com <achristensen@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 24 Jan 2019 00:29:48 +0000 (00:29 +0000)
https://bugs.webkit.org/show_bug.cgi?id=193700

Reviewed by Don Olmstead.

This replaces it with a NeverDestroyed<NetworkProcess> and paves the way for more interesting things.

* NetworkProcess/CustomProtocols/soup/LegacyCustomProtocolManagerSoup.cpp:
* NetworkProcess/EntryPoint/mac/XPCService/NetworkServiceEntryPoint.mm:
(WebKit::initializeChildProcess<WebKit::NetworkProcess>):
* NetworkProcess/NetworkProcess.cpp:
(WebKit::NetworkProcess::NetworkProcess):
(WebKit::NetworkProcess::singleton): Deleted.
* NetworkProcess/NetworkProcess.h:
* NetworkProcess/soup/NetworkProcessMainSoup.cpp:
(WebKit::initializeChildProcess<WebKit::NetworkProcess>):
* NetworkProcess/win/NetworkProcessMainWin.cpp:
(WebKit::initializeChildProcess<WebKit::NetworkProcess>):
* Shared/EntryPointUtilities/mac/XPCService/XPCServiceEntryPoint.h:
(WebKit::initializeChildProcess):
(WebKit::XPCServiceInitializer):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@240366 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebKit/ChangeLog
Source/WebKit/NetworkProcess/CustomProtocols/soup/LegacyCustomProtocolManagerSoup.cpp
Source/WebKit/NetworkProcess/EntryPoint/mac/XPCService/NetworkServiceEntryPoint.mm
Source/WebKit/NetworkProcess/NetworkProcess.cpp
Source/WebKit/NetworkProcess/NetworkProcess.h
Source/WebKit/NetworkProcess/soup/NetworkProcessMainSoup.cpp
Source/WebKit/NetworkProcess/win/NetworkProcessMainWin.cpp
Source/WebKit/Shared/EntryPointUtilities/mac/XPCService/XPCServiceEntryPoint.h
Source/WebKit/Shared/unix/ChildProcessMain.h

index 5502dc1..53407f4 100644 (file)
@@ -1,3 +1,27 @@
+2019-01-23  Alex Christensen  <achristensen@webkit.org>
+
+        Stop using NetworkProcess::singleton
+        https://bugs.webkit.org/show_bug.cgi?id=193700
+
+        Reviewed by Don Olmstead.
+
+        This replaces it with a NeverDestroyed<NetworkProcess> and paves the way for more interesting things.
+
+        * NetworkProcess/CustomProtocols/soup/LegacyCustomProtocolManagerSoup.cpp:
+        * NetworkProcess/EntryPoint/mac/XPCService/NetworkServiceEntryPoint.mm:
+        (WebKit::initializeChildProcess<WebKit::NetworkProcess>):
+        * NetworkProcess/NetworkProcess.cpp:
+        (WebKit::NetworkProcess::NetworkProcess):
+        (WebKit::NetworkProcess::singleton): Deleted.
+        * NetworkProcess/NetworkProcess.h:
+        * NetworkProcess/soup/NetworkProcessMainSoup.cpp:
+        (WebKit::initializeChildProcess<WebKit::NetworkProcess>):
+        * NetworkProcess/win/NetworkProcessMainWin.cpp:
+        (WebKit::initializeChildProcess<WebKit::NetworkProcess>):
+        * Shared/EntryPointUtilities/mac/XPCService/XPCServiceEntryPoint.h:
+        (WebKit::initializeChildProcess):
+        (WebKit::XPCServiceInitializer):
+
 2019-01-23  Ryan Haddad  <ryanhaddad@apple.com>
 
         Unreviewed, rolling out r240343.
index 800751f..511dd04 100644 (file)
@@ -74,7 +74,7 @@ private:
     void startRequest(GRefPtr<GTask>&& task) override
     {
         WebKitSoupRequestGeneric* request = WEBKIT_SOUP_REQUEST_GENERIC(g_task_get_source_object(task.get()));
-        auto* customProtocolManager = NetworkProcess::singleton().supplement<LegacyCustomProtocolManager>();
+        auto* customProtocolManager = lastCreatedNetworkProcess()->supplement<LegacyCustomProtocolManager>();
         if (!customProtocolManager)
             return;
 
index 2995de9..38a9a24 100644 (file)
@@ -40,6 +40,12 @@ public:
     }
 };
 
+template<>
+void initializeChildProcess<NetworkProcess>(ChildProcessInitializationParameters&& parameters)
+{
+    static NeverDestroyed<NetworkProcess> networkProcess(WTFMove(parameters));
+}
+
 } // namespace WebKit
 
 using namespace WebKit;
index 456dd08..c6adc9f 100644 (file)
@@ -124,28 +124,11 @@ static void callExitSoon(IPC::Connection*)
     });
 }
 
-NetworkProcess& NetworkProcess::singleton()
-{
-    static NeverDestroyed<Ref<NetworkProcess>> networkProcess(adoptRef(*new NetworkProcess));
-    return networkProcess.get();
-}
-
-NetworkProcess::NetworkProcess()
-    : m_hasSetCacheModel(false)
-    , m_cacheModel(CacheModel::DocumentViewer)
-    , m_diskCacheIsDisabledForTesting(false)
-    , m_canHandleHTTPSServerTrustEvaluation(true)
-    , m_downloadManager(*this)
-#if PLATFORM(COCOA)
-    , m_clearCacheDispatchGroup(0)
-#endif
+NetworkProcess::NetworkProcess(ChildProcessInitializationParameters&& parameters)
+    : m_downloadManager(*this)
 #if ENABLE(CONTENT_EXTENSIONS)
     , m_networkContentRuleListManager(*this)
 #endif
-    , m_storageTaskQueue(WorkQueue::create("com.apple.WebKit.StorageTask"))
-#if ENABLE(INDEXED_DATABASE)
-    , m_idbPerOriginQuota(IDBServer::defaultPerOriginQuota)
-#endif
 {
     NetworkProcessPlatformStrategies::initialize();
 
@@ -172,6 +155,8 @@ NetworkProcess::NetworkProcess()
         for (auto& webProcessConnection : webProcessConnections)
             webProcessConnection->setOnLineState(isOnLine);
     });
+
+    initialize(WTFMove(parameters));
 }
 
 NetworkProcess::~NetworkProcess()
index cf0d481..43d6842 100644 (file)
@@ -108,8 +108,8 @@ class NetworkProcess : public ChildProcess, private DownloadManager::Client, pub
 {
     WTF_MAKE_NONCOPYABLE(NetworkProcess);
 public:
+    NetworkProcess(ChildProcessInitializationParameters&&);
     ~NetworkProcess();
-    static NetworkProcess& singleton();
     static constexpr ProcessType processType = ProcessType::Network;
 
     template <typename T>
@@ -288,8 +288,6 @@ public:
     void requestCacheStorageSpace(PAL::SessionID, const WebCore::ClientOrigin&, uint64_t quota, uint64_t currentSize, uint64_t spaceRequired, CompletionHandler<void(Optional<uint64_t>)>&&);
 
 private:
-    NetworkProcess();
-
     void platformInitializeNetworkProcess(const NetworkProcessCreationParameters&);
     std::unique_ptr<WebCore::NetworkStorageSession> platformCreateDefaultStorageSession() const;
 
@@ -425,11 +423,11 @@ private:
     Vector<RefPtr<NetworkConnectionToWebProcess>> m_webProcessConnections;
 
     String m_diskCacheDirectory;
-    bool m_hasSetCacheModel;
-    CacheModel m_cacheModel;
+    bool m_hasSetCacheModel { false };
+    CacheModel m_cacheModel { CacheModel::DocumentViewer };
     bool m_suppressMemoryPressureHandler { false };
-    bool m_diskCacheIsDisabledForTesting;
-    bool m_canHandleHTTPSServerTrustEvaluation;
+    bool m_diskCacheIsDisabledForTesting { false };
+    bool m_canHandleHTTPSServerTrustEvaluation { true };
     String m_uiProcessBundleIdentifier;
     DownloadManager m_downloadManager;
 
@@ -453,7 +451,7 @@ private:
     // FIXME: We'd like to be able to do this without the #ifdef, but WorkQueue + BinarySemaphore isn't good enough since
     // multiple requests to clear the cache can come in before previous requests complete, and we need to wait for all of them.
     // In the future using WorkQueue and a counting semaphore would work, as would WorkQueue supporting the libdispatch concept of "work groups".
-    dispatch_group_t m_clearCacheDispatchGroup;
+    dispatch_group_t m_clearCacheDispatchGroup { nullptr };
 
     bool m_suppressesConnectionTerminationOnSystemChange { false };
 #endif
@@ -462,12 +460,12 @@ private:
     NetworkContentRuleListManager m_networkContentRuleListManager;
 #endif
 
-    Ref<WorkQueue> m_storageTaskQueue;
+    Ref<WorkQueue> m_storageTaskQueue { WorkQueue::create("com.apple.WebKit.StorageTask") };
 
 #if ENABLE(INDEXED_DATABASE)
     HashMap<PAL::SessionID, String> m_idbDatabasePaths;
     HashMap<PAL::SessionID, RefPtr<WebCore::IDBServer::IDBServer>> m_idbServers;
-    uint64_t m_idbPerOriginQuota;
+    uint64_t m_idbPerOriginQuota { WebCore::IDBServer::defaultPerOriginQuota };
 #endif
 
     Deque<CrossThreadTask> m_storageTasks;
index f76ba79..5f5972e 100644 (file)
 
 namespace WebKit {
 
+static RefPtr<NetworkProcess> globalNetworkProcess;
+
 class NetworkProcessMain final: public ChildProcessMainBase {
 public:
     void platformFinalize() override
     {
         // Needed to destroy the SoupSession and SoupCookieJar, e.g. to avoid
         // leaking SQLite temporary journaling files.
-        NetworkProcess::singleton().defaultStorageSession().clearSoupNetworkSession();
+        globalNetworkProcess->defaultStorageSession().clearSoupNetworkSession();
     }
 };
 
+template<>
+void initializeChildProcess<NetworkProcess>(ChildProcessInitializationParameters&& parameters)
+{
+    static NeverDestroyed<NetworkProcess> networkProcess(WTFMove(parameters));
+    globalNetworkProcess = &networkProcess.get();
+}
+    
 int NetworkProcessMainUnix(int argc, char** argv)
 {
     return ChildProcessMain<NetworkProcess, NetworkProcessMain>(argc, argv);
index dfd3206..e03efee 100644 (file)
 
 namespace WebKit {
 
+template<>
+void initializeChildProcess<NetworkProcess>(ChildProcessInitializationParameters&& parameters)
+{
+    static NeverDestroyed<NetworkProcess> networkProcess(WTFMove(parameters));
+}
+
 int NetworkProcessMainWin(int argc, char** argv)
 {
     return ChildProcessMain<NetworkProcess, ChildProcessMainBase>(argc, argv);
index 352fd7a..4f32b31 100644 (file)
@@ -67,6 +67,12 @@ protected:
     xpc_object_t m_initializerMessage;
 };
 
+template<typename XPCServiceType>
+void initializeChildProcess(ChildProcessInitializationParameters&& parameters)
+{
+    XPCServiceType::singleton().initialize(WTFMove(parameters));
+}
+
 template<typename XPCServiceType, typename XPCServiceInitializerDelegateType>
 void XPCServiceInitializer(OSObjectPtr<xpc_connection_t> connection, xpc_object_t initializerMessage, xpc_object_t priorityBoostMessage)
 {
@@ -119,7 +125,7 @@ ALLOW_DEPRECATED_DECLARATIONS_END
 
     parameters.processType = XPCServiceType::processType;
 
-    XPCServiceType::singleton().initialize(parameters);
+    initializeChildProcess<XPCServiceType>(WTFMove(parameters));
 }
 
 int XPCServiceMain(int, const char**);
index 7b90294..89a4b87 100644 (file)
@@ -23,8 +23,7 @@
  * THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef ChildProcessMain_h
-#define ChildProcessMain_h
+#pragma once
 
 #include "ChildProcess.h"
 #include "WebKit2Initialize.h"
@@ -38,12 +37,18 @@ public:
     virtual bool parseCommandLine(int argc, char** argv);
     virtual void platformFinalize() { }
 
-    const ChildProcessInitializationParameters& initializationParameters() const { return m_parameters; }
+    ChildProcessInitializationParameters&& takeInitializationParameters() { return WTFMove(m_parameters); }
 
 protected:
     ChildProcessInitializationParameters m_parameters;
 };
 
+template<typename ChildProcessType>
+void initializeChildProcess(ChildProcessInitializationParameters&& parameters)
+{
+    ChildProcessType::singleton().initialize(WTFMove(parameters));
+}
+
 template<typename ChildProcessType, typename ChildProcessMainType>
 int ChildProcessMain(int argc, char** argv)
 {
@@ -57,7 +62,7 @@ int ChildProcessMain(int argc, char** argv)
     if (!childMain.parseCommandLine(argc, argv))
         return EXIT_FAILURE;
 
-    ChildProcessType::singleton().initialize(childMain.initializationParameters());
+    initializeChildProcess<ChildProcessType>(childMain.takeInitializationParameters());
     RunLoop::run();
     childMain.platformFinalize();
 
@@ -65,5 +70,3 @@ int ChildProcessMain(int argc, char** argv)
 }
 
 } // namespace WebKit
-
-#endif // ChildProcessMain_h