diff options
author | yfriedman@chromium.org <yfriedman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-11-22 00:36:13 +0000 |
---|---|---|
committer | yfriedman@chromium.org <yfriedman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-11-22 00:36:13 +0000 |
commit | 57644041b1cf2abeef2069e23a6ee00af7974856 (patch) | |
tree | 27a00a3ca7be2d7287e6db6bb192e432cdfa16ac /components/dom_distiller | |
parent | f00708d22aea405199a51c4ed3142fbd1f95b68e (diff) | |
download | chromium_src-57644041b1cf2abeef2069e23a6ee00af7974856.zip chromium_src-57644041b1cf2abeef2069e23a6ee00af7974856.tar.gz chromium_src-57644041b1cf2abeef2069e23a6ee00af7974856.tar.bz2 |
[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
Diffstat (limited to 'components/dom_distiller')
-rw-r--r-- | components/dom_distiller/core/distiller.cc | 11 |
1 files changed, 8 insertions, 3 deletions
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()); |