DownloadProxyMap should keep track of outstanding DownloadProxy objects
authorandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 14 Dec 2012 22:07:32 +0000 (22:07 +0000)
committerandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 14 Dec 2012 22:07:32 +0000 (22:07 +0000)
https://bugs.webkit.org/show_bug.cgi?id=105053

Reviewed by Andreas Kling.

This is more work towards removing the m_downloads map from every WebContext object.

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

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@137768 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

index 1b3ba7b..479b487 100644 (file)
@@ -1,3 +1,25 @@
+2012-12-14  Anders Carlsson  <andersca@apple.com>
+
+        DownloadProxyMap should keep track of outstanding DownloadProxy objects
+        https://bugs.webkit.org/show_bug.cgi?id=105053
+
+        Reviewed by Andreas Kling.
+
+        This is more work towards removing the m_downloads map from every WebContext object.
+
+        * UIProcess/Downloads/DownloadProxy.cpp:
+        (WebKit::DownloadProxy::didFinish):
+        (WebKit::DownloadProxy::didFail):
+        (WebKit::DownloadProxy::didCancel):
+        * UIProcess/Downloads/DownloadProxyMap.cpp:
+        (WebKit::DownloadProxyMap::createDownloadProxy):
+        (WebKit):
+        (WebKit::DownloadProxyMap::downloadFinished):
+        * UIProcess/Downloads/DownloadProxyMap.h:
+        (DownloadProxyMap):
+        * UIProcess/WebContext.cpp:
+        (WebKit::WebContext::createDownloadProxy):
+
 2012-12-14  Mark Lam  <mark.lam@apple.com>
 
         Introducing the DatabaseStrategy and database servers.
index 42d0737..c1eee5a 100644 (file)
@@ -28,6 +28,7 @@
 
 #include "AuthenticationChallengeProxy.h"
 #include "DataReference.h"
+#include "DownloadProxyMap.h"
 #include "WebContext.h"
 #include "WebData.h"
 #include "WebProcessMessages.h"
@@ -156,6 +157,7 @@ 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)
@@ -177,6 +179,7 @@ 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)
@@ -187,6 +190,7 @@ 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 880765d..e039b72 100644 (file)
@@ -46,11 +46,19 @@ DownloadProxyMap::~DownloadProxyMap()
 {
 }
 
-PassRefPtr<DownloadProxy> DownloadProxyMap::createDownloadProxy(WebContext* webContext)
+DownloadProxy* DownloadProxyMap::createDownloadProxy(WebContext* webContext)
 {
     RefPtr<DownloadProxy> downloadProxy = DownloadProxy::create(webContext);
+    m_downloads.set(downloadProxy->downloadID(), downloadProxy);
 
-    return downloadProxy.release();
+    return downloadProxy.get();
+}
+
+void DownloadProxyMap::downloadFinished(DownloadProxy* downloadProxy)
+{
+    ASSERT(m_downloads.contains(downloadProxy->downloadID()));
+
+    m_downloads.remove(downloadProxy->downloadID());
 }
 
 } // namespace WebKit
index 8783c8a..7065dbf 100644 (file)
@@ -26,6 +26,7 @@
 #ifndef DownloadProxyMap_h
 #define DownloadProxyMap_h
 
+#include <wtf/HashMap.h>
 #include <wtf/Noncopyable.h>
 #include <wtf/PassRefPtr.h>
 
@@ -40,11 +41,15 @@ class DownloadProxyMap {
 public:
     static DownloadProxyMap& shared();
 
-    PassRefPtr<DownloadProxy> createDownloadProxy(WebContext*);
+    DownloadProxy* createDownloadProxy(WebContext*);
+
+    void downloadFinished(DownloadProxy*);
 
 private:
     DownloadProxyMap();
     ~DownloadProxyMap();
+
+    HashMap<uint64_t, RefPtr<DownloadProxy> > m_downloads;
 };
 
 } // namespace WebKit
index 39fdaf2..894bc0d 100644 (file)
@@ -836,10 +836,10 @@ void WebContext::addVisitedLinkHash(LinkHash linkHash)
 
 DownloadProxy* WebContext::createDownloadProxy()
 {
-    RefPtr<DownloadProxy> downloadProxy = DownloadProxyMap::shared().createDownloadProxy(this);
+    DownloadProxy* downloadProxy = DownloadProxyMap::shared().createDownloadProxy(this);
     m_downloads.set(downloadProxy->downloadID(), downloadProxy);
     addMessageReceiver(Messages::DownloadProxy::messageReceiverName(), downloadProxy->downloadID(), this);
-    return downloadProxy.get();
+    return downloadProxy;
 }
 
 void WebContext::downloadFinished(DownloadProxy* downloadProxy)