From 57644041b1cf2abeef2069e23a6ee00af7974856 Mon Sep 17 00:00:00 2001 From: "yfriedman@chromium.org" Date: Fri, 22 Nov 2013 00:36:13 +0000 Subject: [dom_distiller] Fix two issues with distiller. 1) On pages with no images, ensure that the callback is still called. 2) Fix crash after running the image fetch. Since we were deleting the DistillerURLFetcher which owned the |id| it can be junk before erasing from |image_fetchers_| BUG=321725 Review URL: https://codereview.chromium.org/80213002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@236650 0039d316-1c4b-4281-b951-d872f2087c98 --- components/dom_distiller/core/distiller.cc | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'components/dom_distiller') diff --git a/components/dom_distiller/core/distiller.cc b/components/dom_distiller/core/distiller.cc index 30b0c0b..7d044eb 100644 --- a/components/dom_distiller/core/distiller.cc +++ b/components/dom_distiller/core/distiller.cc @@ -74,6 +74,7 @@ void DistillerImpl::GetDistilledContent() { void DistillerImpl::OnExecuteJavaScriptDone(const base::Value* value) { std::string result; + bool fetched_image = false; const base::ListValue* result_list = NULL; if (!value->GetAsList(&result_list)) { DCHECK(proto_); @@ -99,12 +100,15 @@ void DistillerImpl::OnExecuteJavaScriptDone(const base::Value* value) { int image_number = i - 2; std::string image_id = base::StringPrintf("%d", image_number); FetchImage(image_id, item); + fetched_image = true; } } + if (!fetched_image) + distillation_cb_.Run(proto_.Pass()); } void DistillerImpl::FetchImage(const std::string& image_id, - const std::string& item) { + const std::string& item) { DistillerURLFetcher* fetcher = distiller_url_fetcher_factory_.CreateDistillerURLFetcher(); image_fetchers_[image_id] = fetcher; @@ -114,14 +118,15 @@ void DistillerImpl::FetchImage(const std::string& image_id, } void DistillerImpl::OnFetchImageDone(const std::string& id, - const std::string& response) { + const std::string& response) { DCHECK(proto_); DistilledPageProto_Image* image = proto_->add_image(); image->set_name(id); image->set_data(response); DCHECK(image_fetchers_.end() != image_fetchers_.find(id)); - delete image_fetchers_[id]; + DistillerURLFetcher* fetcher = image_fetchers_[id]; int result = image_fetchers_.erase(id); + delete fetcher; DCHECK_EQ(1, result); if (image_fetchers_.empty()) { distillation_cb_.Run(proto_.Pass()); -- cgit v1.1