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

Unified Diff: content/test/weburl_loader_mock.cc

Issue 293003004: Prevents WebURLLoaderMock to crash when didReceiveResponse calls ::cancel(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@manifest_chrame
Patch Set: remove changes from other cl Created 6 years, 7 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.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.cc
diff --git a/content/test/weburl_loader_mock.cc b/content/test/weburl_loader_mock.cc
index 929c542924b8f2a603519805e126838bbd020291..056564a839cf96be509cab9fb7b6a2f7a71a7cdb 100644
--- a/content/test/weburl_loader_mock.cc
+++ b/content/test/weburl_loader_mock.cc
@@ -16,10 +16,15 @@ WebURLLoaderMock::WebURLLoaderMock(WebURLLoaderMockFactory* factory,
client_(NULL),
default_loader_(default_loader),
using_default_loader_(false),
- is_deferred_(false) {
+ is_deferred_(false),
+ this_deleted_(NULL) {
}
WebURLLoaderMock::~WebURLLoaderMock() {
+ // When |this_deleted_| is not null, there is someone interested to know if
+ // |this| got deleted. We notify them by setting the pointed value to true.
+ if (this_deleted_)
+ *this_deleted_ = true;
}
void WebURLLoaderMock::ServeAsynchronousRequest(
@@ -30,8 +35,17 @@ void WebURLLoaderMock::ServeAsynchronousRequest(
if (!client_)
return;
+ bool this_deleted = false;
+ this_deleted_ = &this_deleted;
client_->didReceiveResponse(this, response);
+ // didReceiveResponse might end up getting ::cancel() to be called which will
+ // make the ResourceLoader to delete |this|. If that happens, |this_deleted|,
+ // created on the stack, will be set to true.
+ if (this_deleted)
+ return;
+ this_deleted_ = NULL;
+
if (error.reason) {
client_->didFail(this, error);
return;
« no previous file with comments | « content/test/weburl_loader_mock.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698