diff options
author | Kristian Monsen <kristianm@google.com> | 2010-07-27 16:54:46 +0100 |
---|---|---|
committer | Kristian Monsen <kristianm@google.com> | 2010-08-03 10:19:20 +0100 |
commit | 5ceb0fecb9c6e4cb97ca46e0e75b56fbb5cbabda (patch) | |
tree | 5322edbb01ac250340a022985d206204e40954d3 | |
parent | 767966411f0c19c445f74d2ff90ab9490c290026 (diff) | |
download | external_webkit-5ceb0fecb9c6e4cb97ca46e0e75b56fbb5cbabda.zip external_webkit-5ceb0fecb9c6e4cb97ca46e0e75b56fbb5cbabda.tar.gz external_webkit-5ceb0fecb9c6e4cb97ca46e0e75b56fbb5cbabda.tar.bz2 |
Removing the list of active loaders
A loader will not be deleted before the WebRequest has called didFinishLoading() now, so there is no longer a need for this.
There was also a problem with that list. If a loader got deleted and a new one created with the same pointer value the deleted one could be mistaken for the new one.
Change-Id: I856519e751f6f1d15cfbd426a2cd2ba71315850b
-rw-r--r-- | WebKit/android/WebCoreSupport/WebUrlLoaderClient.cpp | 46 | ||||
-rw-r--r-- | WebKit/android/WebCoreSupport/WebUrlLoaderClient.h | 7 |
2 files changed, 14 insertions, 39 deletions
diff --git a/WebKit/android/WebCoreSupport/WebUrlLoaderClient.cpp b/WebKit/android/WebCoreSupport/WebUrlLoaderClient.cpp index aabd77d..4bb743b 100644 --- a/WebKit/android/WebCoreSupport/WebUrlLoaderClient.cpp +++ b/WebKit/android/WebCoreSupport/WebUrlLoaderClient.cpp @@ -44,8 +44,6 @@ LoaderData::~LoaderData() m_buffer->Release(); } -std::vector<WebUrlLoaderClient*>* WebUrlLoaderClient::activeLoaders = new std::vector<WebUrlLoaderClient*>(); - base::Thread* WebUrlLoaderClient::ioThread() { static base::Thread* networkThread = 0; @@ -74,33 +72,13 @@ WebUrlLoaderClient::~WebUrlLoaderClient() if (thread) thread->message_loop()->ReleaseSoon(FROM_HERE, m_request); - std::vector<WebUrlLoaderClient*>::iterator iter; - for (iter = activeLoaders->begin(); iter != activeLoaders->end(); ++iter) { - if (*iter == this) { - activeLoaders->erase(iter); - break; - } - } } -bool WebUrlLoaderClient::isActive(const WebUrlLoaderClient* loader) +bool WebUrlLoaderClient::isActive() const { - if (!loader) - return false; - - bool exists = false; - std::vector<WebUrlLoaderClient*>::const_iterator iter; - for (iter = activeLoaders->begin(); iter != activeLoaders->end(); ++iter) - if (*iter == loader) - exists = true; - - if (!exists) + if (m_cancelling) return false; - if (loader->m_cancelling) - return false; - if (!loader->m_resourceHandle) - return false; - if (!loader->m_resourceHandle->client()) + if (!m_resourceHandle->client()) return false; return true; @@ -111,8 +89,6 @@ WebUrlLoaderClient::WebUrlLoaderClient(WebCore::ResourceHandle* resourceHandle, { m_request = new WebRequest(this, m_resourceRequest); m_request->AddRef(); // Matched by ReleaseSoon in destructor - - activeLoaders->push_back(this); } bool WebUrlLoaderClient::start(bool /*sync*/) @@ -137,6 +113,8 @@ void WebUrlLoaderClient::cancel() void WebUrlLoaderClient::finish() { + // This will probably cause this to be deleted as we are the only one holding a reference to + // m_resourceHandle, and it is holding the only reference to this. m_resourceHandle = 0; } @@ -148,7 +126,7 @@ void WebUrlLoaderClient::didReceiveResponse(void* data) const WebUrlLoaderClient* loader = loaderData->m_loader; ResourceResponse* resourceResponse = loaderData->m_resourceResponse.get(); - if (!isActive(loader)) + if (!loader->isActive()) return; loader->m_resourceHandle->client()->didReceiveResponse(loader->m_resourceHandle.get(), *resourceResponse); @@ -161,7 +139,7 @@ void WebUrlLoaderClient::didReceiveData(void* data) const WebUrlLoaderClient* loader = loaderData->m_loader; net::IOBuffer* buf = loaderData->m_buffer; - if (!isActive(loader)) + if (!loader->isActive()) return; if (loader->m_resourceHandle && loader->m_resourceHandle->client()) @@ -175,7 +153,7 @@ void WebUrlLoaderClient::didReceiveDataUrl(void* data) OwnPtr<LoaderData> ld(static_cast<LoaderData*>(data)); const WebUrlLoaderClient* loader = ld->m_loader; - if (!isActive(loader)) + if (!loader->isActive()) return; std::string* str = ld->m_string.get(); @@ -193,7 +171,7 @@ void WebUrlLoaderClient::willSendRequest(void* data) OwnPtr<LoaderData> loaderData(static_cast<LoaderData*>(data)); const WebUrlLoaderClient* loader = loaderData->m_loader; - if (!isActive(loader)) + if (!loader->isActive()) return; WebCore::ResourceResponse* resourceResponse = loaderData->m_resourceResponse.get(); @@ -207,10 +185,10 @@ void WebUrlLoaderClient::didFinishLoading(void* data) OwnPtr<LoaderData> loaderData(static_cast<LoaderData*>(data)); WebUrlLoaderClient* loader = loaderData->m_loader; - if (!isActive(loader)) - return; + if (loader->isActive()) + loader->m_resourceHandle->client()->didFinishLoading(loader->m_resourceHandle.get()); - loader->m_resourceHandle->client()->didFinishLoading(loader->m_resourceHandle.get()); + // Always finish a request, if not it will leak loader->finish(); } diff --git a/WebKit/android/WebCoreSupport/WebUrlLoaderClient.h b/WebKit/android/WebCoreSupport/WebUrlLoaderClient.h index 52fd6e9..df463a4 100644 --- a/WebKit/android/WebCoreSupport/WebUrlLoaderClient.h +++ b/WebKit/android/WebCoreSupport/WebUrlLoaderClient.h @@ -31,7 +31,6 @@ #include "base/ref_counted.h" #include <string> -#include <vector> namespace base { class Thread; @@ -84,10 +83,8 @@ private: // Handle to the chrome IO thread static base::Thread* ioThread(); - // Vector containing all active loader clients - static std::vector<WebUrlLoaderClient*>* activeLoaders; - - static bool isActive(const WebUrlLoaderClient*); + // Check if a request is active + bool isActive() const; }; // A struct to send more than one thing in a void*, needed for callOnMainThread |