Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / components / dom_distiller / core / dom_distiller_service.cc
index 797827b..0661f6e 100644 (file)
@@ -7,6 +7,7 @@
 #include "base/guid.h"
 #include "base/message_loop/message_loop.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"
 #include "url/gurl.h"
 
@@ -27,7 +28,7 @@ ArticleEntry CreateSkeletonEntryForUrl(const GURL& url) {
 void RunArticleAvailableCallback(
     const DomDistillerService::ArticleAvailableCallback& article_cb,
     const ArticleEntry& entry,
-    DistilledPageProto* proto,
+    const DistilledArticleProto* article_proto,
     bool distillation_succeeded) {
   article_cb.Run(distillation_succeeded);
 }
@@ -90,15 +91,16 @@ std::vector<ArticleEntry> DomDistillerService::GetEntries() const {
 scoped_ptr<ArticleEntry> DomDistillerService::RemoveEntry(
     const std::string& entry_id) {
   scoped_ptr<ArticleEntry> entry(new ArticleEntry);
-  if (!store_->GetEntryById(entry_id, entry.get())) {
-    return scoped_ptr<ArticleEntry>();
-  }
-
+  entry->set_entry_id(entry_id);
   TaskTracker* task_tracker = GetTaskTrackerForEntry(*entry);
   if (task_tracker != NULL) {
     task_tracker->CancelSaveCallbacks();
   }
 
+  if (!store_->GetEntryById(entry_id, entry.get())) {
+    return scoped_ptr<ArticleEntry>();
+  }
+
   if (store_->RemoveEntry(*entry)) {
     return entry.Pass();
   }
@@ -149,7 +151,6 @@ TaskTracker* DomDistillerService::GetOrCreateTaskTrackerForUrl(
 
   ArticleEntry skeleton_entry = CreateSkeletonEntryForUrl(url);
   TaskTracker* task_tracker = CreateTaskTracker(skeleton_entry);
-  store_->AddEntry(skeleton_entry);
   return task_tracker;
 }
 
@@ -189,13 +190,16 @@ void DomDistillerService::CancelTask(TaskTracker* task) {
   }
 }
 
-void DomDistillerService::AddDistilledPageToList(const ArticleEntry& entry,
-                                                 DistilledPageProto* proto,
-                                                 bool distillation_succeeded) {
+void DomDistillerService::AddDistilledPageToList(
+    const ArticleEntry& entry,
+    const DistilledArticleProto* article_proto,
+    bool distillation_succeeded) {
   DCHECK(IsEntryValid(entry));
   if (distillation_succeeded) {
-    DCHECK(proto);
-    store_->UpdateEntry(entry);
+    DCHECK(article_proto);
+    DCHECK_GT(article_proto->pages_size(), 0);
+    store_->AddEntry(entry);
+    DCHECK_EQ(article_proto->pages_size(), entry.pages_size());
   }
 }