Chromium Code Reviews| Index: components/dom_distiller/core/task_tracker.cc |
| diff --git a/components/dom_distiller/core/task_tracker.cc b/components/dom_distiller/core/task_tracker.cc |
| index 5dd17d3a598b6976caabd263374948ae3f358c58..754f4fd585dd5fd5d7f36df50ee3a6ab7cd701a3 100644 |
| --- a/components/dom_distiller/core/task_tracker.cc |
| +++ b/components/dom_distiller/core/task_tracker.cc |
| @@ -6,6 +6,7 @@ |
| #include "base/auto_reset.h" |
| #include "base/message_loop/message_loop.h" |
| +#include "components/dom_distiller/core/distilled_content_store.h" |
| #include "components/dom_distiller/core/proto/distilled_article.pb.h" |
| #include "components/dom_distiller/core/proto/distilled_page.pb.h" |
| @@ -20,8 +21,11 @@ ViewerHandle::~ViewerHandle() { |
| } |
| } |
| -TaskTracker::TaskTracker(const ArticleEntry& entry, CancelCallback callback) |
| +TaskTracker::TaskTracker(const ArticleEntry& entry, |
| + CancelCallback callback, |
| + DistilledContentStore* content_store) |
| : cancel_callback_(callback), |
| + content_store_(content_store), |
| entry_(entry), |
| distilled_article_(), |
| content_ready_(false), |
| @@ -40,7 +44,6 @@ void TaskTracker::StartDistiller(DistillerFactory* factory) { |
| if (entry_.pages_size() == 0) { |
| return; |
| } |
| - |
| GURL url(entry_.pages(0).url()); |
| DCHECK(url.is_valid()); |
| @@ -53,9 +56,11 @@ void TaskTracker::StartDistiller(DistillerFactory* factory) { |
| } |
| void TaskTracker::StartBlobFetcher() { |
| - // TODO(cjhopman): There needs to be some local storage for the distilled |
| - // blob. When that happens, this should start some task to fetch the blob for |
| - // |entry_| and asynchronously notify |this| when it is done. |
| + if (content_store_) { |
| + content_store_->LoadContent(entry_, |
| + base::Bind(&TaskTracker::OnBlobFetched, |
| + weak_ptr_factory_.GetWeakPtr())); |
| + } |
| } |
| void TaskTracker::AddSaveCallback(const SaveCallback& callback) { |
| @@ -146,11 +151,23 @@ void TaskTracker::NotifyViewer(ViewRequestDelegate* delegate) { |
| void TaskTracker::OnDistillerFinished( |
| scoped_ptr<DistilledArticleProto> distilled_article) { |
| - OnDistilledArticleReady(distilled_article.Pass()); |
| + if (!content_ready_) { |
| + OnDistilledArticleReady(distilled_article.Pass()); |
| + } |
| +} |
| + |
| +void TaskTracker::OnBlobFetched( |
| + bool success, |
| + scoped_ptr<DistilledArticleProto> distilled_article) { |
| + if (!content_ready_ && success) { |
| + OnDistilledArticleReady(distilled_article.Pass()); |
| + } |
| } |
| void TaskTracker::OnDistilledArticleReady( |
| scoped_ptr<DistilledArticleProto> distilled_article) { |
| + DCHECK(!content_ready_); |
| + content_ready_ = true; |
| distilled_article_ = distilled_article.Pass(); |
| bool distillation_successful = false; |
|
nyquist
2014/04/10 19:00:13
how about bool distillation_successful = distilled
cjhopman
2014/04/11 22:37:21
Done.
|
| if (distilled_article_->pages_size() > 0) { |
| @@ -164,7 +181,11 @@ void TaskTracker::OnDistilledArticleReady( |
| } |
| } |
| - content_ready_ = true; |
| + if (distillation_successful) { |
|
shashi
2014/03/18 21:14:57
Can OnDistillerFinished determine if the distillat
nyquist
2014/04/10 19:00:13
Or how about just adding a param |store_if_valid|
cjhopman
2014/04/11 22:37:21
So this should be more correct now.
|
| + // TODO(cjhopman): If this article came from the blob fetcher, there is no |
| + // reason to store it back there. |
| + AddDistilledContentToStore(); |
| + } |
| for (size_t i = 0; i < viewers_.size(); ++i) { |
| NotifyViewer(viewers_[i]); |
| @@ -181,4 +202,12 @@ void TaskTracker::OnArticleDistillationUpdated( |
| } |
| } |
| +void TaskTracker::AddDistilledContentToStore() { |
| + if (content_store_) { |
| + content_store_->SaveContent( |
| + entry_, *distilled_article_, DistilledContentStore::SaveCallback()); |
| + } |
| +} |
| + |
| + |
| } // namespace dom_distiller |