Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2169)

Unified Diff: content/test/weburl_loader_mock_factory.cc

Issue 1743783002: Use WeakPtr and do not use pointer equality in WebURLLoaderMockFactory (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@Loader_URLTestHelpers
Patch Set: Rebase. Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/test/weburl_loader_mock_factory.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/test/weburl_loader_mock_factory.cc
diff --git a/content/test/weburl_loader_mock_factory.cc b/content/test/weburl_loader_mock_factory.cc
index 6e0f02b3422ba5f9bd615d160fca81a456e1fa5b..b9ef2be514c32fc72fe05719b7dddc81ac55011b 100644
--- a/content/test/weburl_loader_mock_factory.cc
+++ b/content/test/weburl_loader_mock_factory.cc
@@ -76,8 +76,10 @@ void WebURLLoaderMockFactory::ServeAsynchronousRequests() {
// pending_loaders_ as it might get modified.
while (!pending_loaders_.empty()) {
LoaderToRequestMap::iterator iter = pending_loaders_.begin();
- WebURLLoaderMock* loader = iter->first;
- const WebURLRequest& request = iter->second;
+ base::WeakPtr<WebURLLoaderMock> loader(iter->first->GetWeakPtr());
+ const WebURLRequest request = iter->second;
+ pending_loaders_.erase(loader.get());
+
WebURLResponse response;
WebURLError error;
WebData data;
@@ -86,15 +88,13 @@ void WebURLLoaderMockFactory::ServeAsynchronousRequests() {
while (response.httpStatusCode() >= 300 &&
response.httpStatusCode() < 400) {
WebURLRequest newRequest = loader->ServeRedirect(request, response);
- if (!IsPending(loader) || loader->isDeferred())
+ if (!loader || loader->is_cancelled() || loader->is_deferred())
break;
LoadRequest(newRequest, &response, &error, &data);
}
// Serve the request if the loader is still active.
- if (IsPending(loader) && !loader->isDeferred())
+ if (loader && !loader->is_cancelled() && !loader->is_deferred())
loader->ServeAsynchronousRequest(delegate_, response, data, error);
- // The loader might have already been removed.
- pending_loaders_.erase(loader);
}
base::RunLoop().RunUntilIdle();
}
@@ -152,11 +152,6 @@ void WebURLLoaderMockFactory::LoadRequest(const WebURLRequest& request,
*response = iter->second.response;
}
-bool WebURLLoaderMockFactory::IsPending(WebURLLoaderMock* loader) {
- LoaderToRequestMap::iterator iter = pending_loaders_.find(loader);
- return iter != pending_loaders_.end();
-}
-
// static
bool WebURLLoaderMockFactory::ReadFile(const base::FilePath& file_path,
WebData* data) {
« no previous file with comments | « content/test/weburl_loader_mock_factory.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698