Add a separate class for networking related storage
[WebKit-https.git] / Source / WebKit2 / NetworkProcess / mac / RemoteNetworkingContext.mm
index 3c1e72c..de7e0fc 100644 (file)
@@ -35,7 +35,12 @@ using namespace WebCore;
 
 namespace WebKit {
 
-static CFURLStorageSessionRef privateBrowsingStorageSession;
+static OwnPtr<NetworkStorageSession>& privateBrowsingStorageSession()
+{
+    ASSERT(isMainThread());
+    DEFINE_STATIC_LOCAL(OwnPtr<NetworkStorageSession>, session, ());
+    return session;
+}
 
 RemoteNetworkingContext::RemoteNetworkingContext(bool needsSiteSpecificQuirks, bool localFileContentSniffingEnabled, bool privateBrowsingEnabled)
     : m_needsSiteSpecificQuirks(needsSiteSpecificQuirks)
@@ -63,19 +68,20 @@ bool RemoteNetworkingContext::localFileContentSniffingEnabled() const
     return m_localFileContentSniffingEnabled;
 }
 
-bool RemoteNetworkingContext::inPrivateBrowsingMode() const
+NetworkStorageSession& RemoteNetworkingContext::storageSession() const
 {
-    return m_privateBrowsingEnabled;
+    if (m_privateBrowsingEnabled) {
+        ASSERT(privateBrowsingStorageSession());
+        return *privateBrowsingStorageSession();
+    }
+
+    return NetworkStorageSession::defaultStorageSession();
 }
 
-CFURLStorageSessionRef RemoteNetworkingContext::storageSession() const
+NetworkStorageSession& RemoteNetworkingContext::privateBrowsingSession()
 {
-    if (inPrivateBrowsingMode()) {
-        ASSERT(privateBrowsingStorageSession);
-        return privateBrowsingStorageSession;
-    }
-    // FIXME (NetworkProcess): Return a default session that's used for testing.
-    return 0;
+    ASSERT(privateBrowsingStorageSession());
+    return *privateBrowsingStorageSession();
 }
 
 NSOperationQueue *RemoteNetworkingContext::scheduledOperationQueue() const
@@ -108,23 +114,18 @@ void RemoteNetworkingContext::setPrivateBrowsingStorageSessionIdentifierBase(con
 
 void RemoteNetworkingContext::ensurePrivateBrowsingSession()
 {
-    ASSERT(isMainThread());
-    if (privateBrowsingStorageSession)
+    if (privateBrowsingStorageSession())
         return;
 
     ASSERT(!privateBrowsingStorageSessionIdentifierBase().isNull());
     RetainPtr<CFStringRef> cfIdentifier = String(privateBrowsingStorageSessionIdentifierBase() + ".PrivateBrowsing").createCFString();
 
-    privateBrowsingStorageSession = WKCreatePrivateStorageSession(cfIdentifier.get());
+    privateBrowsingStorageSession() = NetworkStorageSession::createPrivateBrowsingSession(privateBrowsingStorageSessionIdentifierBase());
 }
 
 void RemoteNetworkingContext::destroyPrivateBrowsingSession()
 {
-    if (!privateBrowsingStorageSession)
-        return;
-
-    CFRelease(privateBrowsingStorageSession);
-    privateBrowsingStorageSession = 0;
+    privateBrowsingStorageSession() = nullptr;
 }
 
 }