Chromium Code Reviews| Index: components/dom_distiller/core/dom_distiller_service.cc |
| diff --git a/components/dom_distiller/core/dom_distiller_service.cc b/components/dom_distiller/core/dom_distiller_service.cc |
| index 0661f6e237d40469d493c062971d8307e9c86c2b..9ef75f8bb6469f5632f0a8b7db4cee19f9fd8f56 100644 |
| --- a/components/dom_distiller/core/dom_distiller_service.cc |
| +++ b/components/dom_distiller/core/dom_distiller_service.cc |
| @@ -6,6 +6,7 @@ |
| #include "base/guid.h" |
| #include "base/message_loop/message_loop.h" |
| +#include "components/dom_distiller/core/distilled_content_store.h" |
| #include "components/dom_distiller/core/dom_distiller_store.h" |
| #include "components/dom_distiller/core/proto/distilled_article.pb.h" |
| #include "components/dom_distiller/core/task_tracker.h" |
| @@ -38,7 +39,9 @@ void RunArticleAvailableCallback( |
| DomDistillerService::DomDistillerService( |
| scoped_ptr<DomDistillerStoreInterface> store, |
| scoped_ptr<DistillerFactory> distiller_factory) |
| - : store_(store.Pass()), distiller_factory_(distiller_factory.Pass()) {} |
| + : store_(store.Pass()), |
| + content_store_(new InMemoryContentStore()), |
| + distiller_factory_(distiller_factory.Pass()) {} |
| DomDistillerService::~DomDistillerService() {} |
| @@ -78,7 +81,11 @@ const std::string DomDistillerService::AddToList( |
| if (!is_already_added) { |
| task_tracker->AddSaveCallback(base::Bind( |
| &DomDistillerService::AddDistilledPageToList, base::Unretained(this))); |
| + task_tracker->AddSaveCallback( |
| + base::Bind(&DomDistillerService::AddDistilledContentToStore, |
| + base::Unretained(this))); |
| task_tracker->StartDistiller(distiller_factory_.get()); |
| + task_tracker->StartBlobFetcher(); |
| } |
| return task_tracker->GetEntryId(); |
| @@ -117,7 +124,11 @@ scoped_ptr<ViewerHandle> DomDistillerService::ViewEntry( |
| TaskTracker* task_tracker = GetOrCreateTaskTrackerForEntry(entry); |
| scoped_ptr<ViewerHandle> viewer_handle = task_tracker->AddViewer(delegate); |
| + task_tracker->AddSaveCallback( |
| + base::Bind(&DomDistillerService::AddDistilledContentToStore, |
| + base::Unretained(this))); |
| task_tracker->StartDistiller(distiller_factory_.get()); |
| + task_tracker->StartBlobFetcher(); |
| return viewer_handle.Pass(); |
| } |
| @@ -131,7 +142,11 @@ scoped_ptr<ViewerHandle> DomDistillerService::ViewUrl( |
| TaskTracker* task_tracker = GetOrCreateTaskTrackerForUrl(url); |
| scoped_ptr<ViewerHandle> viewer_handle = task_tracker->AddViewer(delegate); |
| + task_tracker->AddSaveCallback( |
| + base::Bind(&DomDistillerService::AddDistilledContentToStore, |
|
shashi
2014/03/13 00:32:45
Feels like these 3 lines can be now refactored to
|
| + base::Unretained(this))); |
| task_tracker->StartDistiller(distiller_factory_.get()); |
| + task_tracker->StartBlobFetcher(); |
| return viewer_handle.Pass(); |
| } |
| @@ -177,7 +192,8 @@ TaskTracker* DomDistillerService::GetOrCreateTaskTrackerForEntry( |
| TaskTracker* DomDistillerService::CreateTaskTracker(const ArticleEntry& entry) { |
| TaskTracker::CancelCallback cancel_callback = |
| base::Bind(&DomDistillerService::CancelTask, base::Unretained(this)); |
| - TaskTracker* tracker = new TaskTracker(entry, cancel_callback); |
| + TaskTracker* tracker = |
| + new TaskTracker(entry, cancel_callback, content_store_.get()); |
| tasks_.push_back(tracker); |
| return tracker; |
| } |
| @@ -203,6 +219,20 @@ void DomDistillerService::AddDistilledPageToList( |
| } |
| } |
| +void DomDistillerService::AddDistilledContentToStore( |
| + const ArticleEntry& entry, |
| + const DistilledArticleProto* article_proto, |
| + bool distillation_succeeded) { |
| + DCHECK(IsEntryValid(entry)); |
| + if (distillation_succeeded) { |
| + DCHECK(article_proto); |
| + DCHECK_GT(article_proto->pages_size(), 0); |
| + content_store_->SaveContent( |
| + entry, *article_proto, DistilledContentStore::SaveCallback()); |
| + DCHECK_EQ(article_proto->pages_size(), entry.pages_size()); |
| + } |
| +} |
| + |
| void DomDistillerService::AddObserver(DomDistillerObserver* observer) { |
| DCHECK(observer); |
| store_->AddObserver(observer); |