DownloadProxyMap shouldn't be a singleton after all
authorandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 15 Dec 2012 20:13:41 +0000 (20:13 +0000)
committerandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 15 Dec 2012 20:13:41 +0000 (20:13 +0000)
https://bugs.webkit.org/show_bug.cgi?id=105099

Reviewed by Sam Weinig.

Make the DownloadProxyMap be per context instead, and get rid of the m_downloads hash map from WebContext.

* UIProcess/Downloads/DownloadProxy.cpp:
(WebKit::DownloadProxy::didFinish):
(WebKit::DownloadProxy::didFail):
(WebKit::DownloadProxy::didCancel):
* UIProcess/Downloads/DownloadProxyMap.cpp:
(WebKit::DownloadProxyMap::~DownloadProxyMap):
* UIProcess/Downloads/DownloadProxyMap.h:
(DownloadProxyMap):
(WebKit::DownloadProxyMap::downloads):
* UIProcess/WebContext.cpp:
(WebKit::WebContext::shouldTerminate):
(WebKit::WebContext::disconnectProcess):
(WebKit::WebContext::createDownloadProxy):
(WebKit::WebContext::downloadFinished):
* UIProcess/WebContext.h:
(WebContext):

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

Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/Downloads/DownloadProxy.cpp
Source/WebKit2/UIProcess/Downloads/DownloadProxyMap.cpp
Source/WebKit2/UIProcess/Downloads/DownloadProxyMap.h
Source/WebKit2/UIProcess/WebContext.cpp
Source/WebKit2/UIProcess/WebContext.h

index 5ad7363..54e181b 100644 (file)
@@ -1,3 +1,29 @@
+2012-12-15  Anders Carlsson  <andersca@apple.com>
+
+        DownloadProxyMap shouldn't be a singleton after all
+        https://bugs.webkit.org/show_bug.cgi?id=105099
+
+        Reviewed by Sam Weinig.
+
+        Make the DownloadProxyMap be per context instead, and get rid of the m_downloads hash map from WebContext.
+
+        * UIProcess/Downloads/DownloadProxy.cpp:
+        (WebKit::DownloadProxy::didFinish):
+        (WebKit::DownloadProxy::didFail):
+        (WebKit::DownloadProxy::didCancel):
+        * UIProcess/Downloads/DownloadProxyMap.cpp:
+        (WebKit::DownloadProxyMap::~DownloadProxyMap):
+        * UIProcess/Downloads/DownloadProxyMap.h:
+        (DownloadProxyMap):
+        (WebKit::DownloadProxyMap::downloads):
+        * UIProcess/WebContext.cpp:
+        (WebKit::WebContext::shouldTerminate):
+        (WebKit::WebContext::disconnectProcess):
+        (WebKit::WebContext::createDownloadProxy):
+        (WebKit::WebContext::downloadFinished):
+        * UIProcess/WebContext.h:
+        (WebContext):
+
 2012-12-15  No'am Rosenthal  <noam.rosenthal@nokia.com>
 
         Disambiguate "background color" and "contents as solid color" on GraphicsLayer
index 6739852..4b36e9a 100644 (file)
@@ -167,7 +167,6 @@ void DownloadProxy::didFinish()
 
     // This can cause the DownloadProxy object to be deleted.
     m_webContext->downloadFinished(this);
-    DownloadProxyMap::shared().downloadFinished(this);
 }
 
 static PassRefPtr<WebData> createWebData(const CoreIPC::DataReference& data)
@@ -189,7 +188,6 @@ void DownloadProxy::didFail(const ResourceError& error, const CoreIPC::DataRefer
 
     // This can cause the DownloadProxy object to be deleted.
     m_webContext->downloadFinished(this);
-    DownloadProxyMap::shared().downloadFinished(this);
 }
 
 void DownloadProxy::didCancel(const CoreIPC::DataReference& resumeData)
@@ -200,7 +198,6 @@ void DownloadProxy::didCancel(const CoreIPC::DataReference& resumeData)
 
     // This can cause the DownloadProxy object to be deleted.
     m_webContext->downloadFinished(this);
-    DownloadProxyMap::shared().downloadFinished(this);
 }
 
 #if PLATFORM(QT)
index e039b72..9bdedea 100644 (file)
 
 namespace WebKit {
 
-DownloadProxyMap& DownloadProxyMap::shared()
-{
-    DEFINE_STATIC_LOCAL(DownloadProxyMap, downloadProxyMap, ());
-
-    return downloadProxyMap;
-}
-
 DownloadProxyMap::DownloadProxyMap()
 {
 }
 
 DownloadProxyMap::~DownloadProxyMap()
 {
+    ASSERT(m_downloads.isEmpty());
 }
 
 DownloadProxy* DownloadProxyMap::createDownloadProxy(WebContext* webContext)
index 7065dbf..96e929b 100644 (file)
@@ -39,16 +39,16 @@ class DownloadProxyMap {
     WTF_MAKE_NONCOPYABLE(DownloadProxyMap);
 
 public:
-    static DownloadProxyMap& shared();
+    DownloadProxyMap();
+    ~DownloadProxyMap();
 
     DownloadProxy* createDownloadProxy(WebContext*);
-
     void downloadFinished(DownloadProxy*);
 
-private:
-    DownloadProxyMap();
-    ~DownloadProxyMap();
+    // FIXME: Don't fully expose the downloads map like this.
+    HashMap<uint64_t, RefPtr<DownloadProxy> >& downloads() { return m_downloads; }
 
+private:
     HashMap<uint64_t, RefPtr<DownloadProxy> > m_downloads;
 };
 
index 9ea2a30..0067a4e 100644 (file)
@@ -27,7 +27,6 @@
 #include "WebContext.h"
 
 #include "DownloadProxy.h"
-#include "DownloadProxyMap.h"
 #include "DownloadProxyMessages.h"
 #include "ImmutableArray.h"
 #include "Logging.h"
@@ -538,7 +537,7 @@ bool WebContext::shouldTerminate(WebProcessProxy* process)
     if (!m_processTerminationEnabled)
         return false;
 
-    if (!m_downloads.isEmpty())
+    if (!m_downloads.downloads().isEmpty())
         return false;
 
     if (!m_applicationCacheManagerProxy->shouldTerminate(process))
@@ -601,12 +600,12 @@ void WebContext::disconnectProcess(WebProcessProxy* process)
     }
 
     // Invalidate all outstanding downloads.
-    for (HashMap<uint64_t, RefPtr<DownloadProxy> >::iterator::Values it = m_downloads.begin().values(), end = m_downloads.end().values(); it != end; ++it) {
+    for (HashMap<uint64_t, RefPtr<DownloadProxy> >::iterator::Values it = m_downloads.downloads().begin().values(), end = m_downloads.downloads().end().values(); it != end; ++it) {
         (*it)->processDidClose();
         (*it)->invalidate();
     }
 
-    m_downloads.clear();
+    m_downloads.downloads().clear();
 
     m_applicationCacheManagerProxy->invalidate();
 #if ENABLE(BATTERY_STATUS)
@@ -836,19 +835,16 @@ void WebContext::addVisitedLinkHash(LinkHash linkHash)
 
 DownloadProxy* WebContext::createDownloadProxy()
 {
-    DownloadProxy* downloadProxy = DownloadProxyMap::shared().createDownloadProxy(this);
-    m_downloads.set(downloadProxy->downloadID(), downloadProxy);
+    DownloadProxy* downloadProxy = m_downloads.createDownloadProxy(this);
     addMessageReceiver(Messages::DownloadProxy::messageReceiverName(), downloadProxy->downloadID(), downloadProxy);
     return downloadProxy;
 }
 
 void WebContext::downloadFinished(DownloadProxy* downloadProxy)
 {
-    ASSERT(m_downloads.contains(downloadProxy->downloadID()));
-
     downloadProxy->invalidate();
     removeMessageReceiver(Messages::DownloadProxy::messageReceiverName(), downloadProxy->downloadID());
-    m_downloads.remove(downloadProxy->downloadID());
+    m_downloads.downloads().remove(downloadProxy->downloadID());
 }
 
 // FIXME: This is not the ideal place for this function.
index d76ea97..4ce19c3 100644 (file)
@@ -27,6 +27,7 @@
 #define WebContext_h
 
 #include "APIObject.h"
+#include "DownloadProxyMap.h"
 #include "GenericCallback.h"
 #include "MessageReceiver.h"
 #include "MessageReceiverMap.h"
@@ -325,6 +326,8 @@ private:
 
     void addPlugInAutoStartOriginHash(const String& pageOrigin, unsigned plugInOriginHash);
 
+    CoreIPC::MessageReceiverMap m_messageReceiverMap;
+
     ProcessModel m_processModel;
     unsigned m_webProcessCountLimit; // The limit has no effect when process model is ProcessModelSharedSecondaryProcess.
     
@@ -369,7 +372,7 @@ private:
     CacheModel m_cacheModel;
 
     WebDownloadClient m_downloadClient;
-    HashMap<uint64_t, RefPtr<DownloadProxy> > m_downloads;
+    DownloadProxyMap m_downloads;
     
     bool m_memorySamplerEnabled;
     double m_memorySamplerInterval;
@@ -425,8 +428,6 @@ private:
     
     HashMap<uint64_t, RefPtr<DictionaryCallback> > m_dictionaryCallbacks;
 
-    CoreIPC::MessageReceiverMap m_messageReceiverMap;
-
 #if PLATFORM(MAC)
     static bool s_applicationIsOccluded;
 #endif