Move NetworkStorageSession ownership to NetworkProcess
[WebKit-https.git] / Source / WebKit / NetworkProcess / NetworkSession.cpp
index 5986618..ad51538 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2015 Apple Inc. All rights reserved.
+ * Copyright (C) 2015-2019 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
 #include "config.h"
 #include "NetworkSession.h"
 
+#include "NetworkProcess.h"
+#include "NetworkProcessProxyMessages.h"
+#include "WebProcessProxy.h"
+#include "WebResourceLoadStatisticsStore.h"
 #include <WebCore/NetworkStorageSession.h>
 
 #if PLATFORM(COCOA)
 namespace WebKit {
 using namespace WebCore;
 
-Ref<NetworkSession> NetworkSession::create(NetworkSessionCreationParameters&& parameters)
+Ref<NetworkSession> NetworkSession::create(NetworkProcess& networkProcess, NetworkSessionCreationParameters&& parameters)
 {
 #if PLATFORM(COCOA)
-    return NetworkSessionCocoa::create(WTFMove(parameters));
+    return NetworkSessionCocoa::create(networkProcess, WTFMove(parameters));
 #endif
 #if USE(SOUP)
-    return NetworkSessionSoup::create(WTFMove(parameters));
+    return NetworkSessionSoup::create(networkProcess, WTFMove(parameters));
 #endif
 #if USE(CURL)
-    return NetworkSessionCurl::create(WTFMove(parameters));
+    return NetworkSessionCurl::create(networkProcess, WTFMove(parameters));
 #endif
 }
 
 NetworkStorageSession& NetworkSession::networkStorageSession() const
 {
-    auto* storageSession = NetworkStorageSession::storageSession(m_sessionID);
+    auto* storageSession = m_networkProcess->storageSession(m_sessionID);
     RELEASE_ASSERT(storageSession);
     return *storageSession;
 }
 
-NetworkSession::NetworkSession(PAL::SessionID sessionID)
+NetworkSession::NetworkSession(NetworkProcess& networkProcess, PAL::SessionID sessionID)
     : m_sessionID(sessionID)
+    , m_networkProcess(networkProcess)
 {
 }
 
@@ -76,4 +81,44 @@ void NetworkSession::invalidateAndCancel()
         task->invalidateAndCancel();
 }
 
+#if ENABLE(RESOURCE_LOAD_STATISTICS)
+void NetworkSession::setResourceLoadStatisticsEnabled(bool enable)
+{
+    if (!enable) {
+        m_resourceLoadStatistics = nullptr;
+        return;
+    }
+
+    if (m_resourceLoadStatistics)
+        return;
+
+    m_resourceLoadStatistics = WebResourceLoadStatisticsStore::create(*this, m_resourceLoadStatisticsDirectory);
+}
+
+void NetworkSession::notifyResourceLoadStatisticsProcessed()
+{
+    m_networkProcess->parentProcessConnection()->send(Messages::NetworkProcessProxy::NotifyResourceLoadStatisticsProcessed(), 0);
+}
+
+void NetworkSession::logDiagnosticMessageWithValue(const String& message, const String& description, unsigned value, unsigned significantFigures, WebCore::ShouldSample shouldSample)
+{
+    m_networkProcess->parentProcessConnection()->send(Messages::WebPageProxy::LogDiagnosticMessageWithValue(message, description, value, significantFigures, shouldSample), 0);
+}
+
+void NetworkSession::notifyPageStatisticsTelemetryFinished(unsigned totalPrevalentResources, unsigned totalPrevalentResourcesWithUserInteraction, unsigned top3SubframeUnderTopFrameOrigins)
+{
+    m_networkProcess->parentProcessConnection()->send(Messages::NetworkProcessProxy::NotifyResourceLoadStatisticsTelemetryFinished(totalPrevalentResources, totalPrevalentResourcesWithUserInteraction, top3SubframeUnderTopFrameOrigins), 0);
+}
+
+void NetworkSession::deleteWebsiteDataForTopPrivatelyControlledDomainsInAllPersistentDataStores(OptionSet<WebsiteDataType> dataTypes, Vector<String>&& topPrivatelyControlledDomains, bool shouldNotifyPage, CompletionHandler<void(const HashSet<String>&)>&& completionHandler)
+{
+    m_networkProcess->deleteWebsiteDataForTopPrivatelyControlledDomainsInAllPersistentDataStores(m_sessionID, dataTypes, WTFMove(topPrivatelyControlledDomains), shouldNotifyPage, WTFMove(completionHandler));
+}
+
+void NetworkSession::topPrivatelyControlledDomainsWithWebsiteData(OptionSet<WebsiteDataType> dataTypes, bool shouldNotifyPage, CompletionHandler<void(HashSet<String>&&)>&& completionHandler)
+{
+    m_networkProcess->topPrivatelyControlledDomainsWithWebsiteData(m_sessionID, dataTypes, shouldNotifyPage, WTFMove(completionHandler));
+}
+#endif
+
 } // namespace WebKit