Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(594)

Unified Diff: components/dom_distiller/core/distiller.h

Issue 146843010: Add support for multipage distillation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase address comments. Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/dom_distiller/core/distiller.h
diff --git a/components/dom_distiller/core/distiller.h b/components/dom_distiller/core/distiller.h
index adbd41b8cbb294a99f14f15740e6b40c839d767e..193110831c9accde04daa812c2960dda31742720 100644
--- a/components/dom_distiller/core/distiller.h
+++ b/components/dom_distiller/core/distiller.h
@@ -5,16 +5,15 @@
#ifndef COMPONENTS_DOM_DISTILLER_CORE_DISTILLER_H_
#define COMPONENTS_DOM_DISTILLER_CORE_DISTILLER_H_
-#include <map>
#include <string>
+#include <vector>
#include "base/callback.h"
-#include "base/gtest_prod_util.h"
-#include "base/memory/ref_counted.h"
-#include "base/values.h"
-#include "components/dom_distiller/core/distiller_page.h"
+#include "base/containers/hash_tables.h"
+#include "base/memory/scoped_ptr.h"
#include "components/dom_distiller/core/distiller_url_fetcher.h"
-#include "components/dom_distiller/core/proto/distilled_page.pb.h"
+#include "components/dom_distiller/core/page_distiller.h"
+#include "components/dom_distiller/core/proto/distilled_article.pb.h"
#include "net/url_request/url_request_context_getter.h"
#include "url/gurl.h"
@@ -24,8 +23,8 @@ class DistillerImpl;
class Distiller {
public:
- typedef base::Callback<void(
- scoped_ptr<DistilledPageProto>)> DistillerCallback;
+ typedef base::Callback<void(scoped_ptr<DistilledArticleProto>)>
+ DistillerCallback;
virtual ~Distiller() {}
// Distills a page, and asynchrounously returns the article HTML to the
@@ -55,8 +54,7 @@ class DistillerFactoryImpl : public DistillerFactory {
};
// Distills a article from a page and associated pages.
-class DistillerImpl : public Distiller,
- public DistillerPage::Delegate {
+class DistillerImpl : public Distiller {
public:
DistillerImpl(
const DistillerPageFactory& distiller_page_factory,
@@ -70,28 +68,35 @@ class DistillerImpl : public Distiller,
virtual void DistillPage(const GURL& url,
const DistillerCallback& callback) OVERRIDE;
- // PageDistillerContext::Delegate
- virtual void OnLoadURLDone() OVERRIDE;
- virtual void OnExecuteJavaScriptDone(const base::Value* value) OVERRIDE;
+ void OnFetchImageDone(DistilledPageProto* distilled_page_proto,
cjhopman 2014/02/03 23:56:53 nit: should be private
shashi 2014/02/04 01:39:37 Done.
+ const std::string& id,
+ const std::string& response);
- void OnFetchImageDone(const std::string& id, const std::string& response);
+ void OnPageDistillationFinished(const GURL& page_url,
cjhopman 2014/02/03 23:56:53 nit: should be private
shashi 2014/02/04 01:39:37 Done.
+ const DistilledPageInfo& distilled_page,
+ bool distillation_successful);
private:
- virtual void LoadURL(const GURL& url);
- virtual void FetchImage(const std::string& image_id, const std::string& item);
+ virtual void FetchImage(DistilledPageProto* distilled_page_proto,
+ const std::string& image_id,
+ const std::string& item);
- // Injects JavaScript to distill a loaded page down to its important content,
- // e.g., extracting a news article from its surrounding boilerplate.
- void GetDistilledContent();
+ // Distills the page and adds the new page to |article_proto|.
+ void DistillPage(const GURL& url);
+
+ // Checks if all distillation callbacks are finished and runs the
cjhopman 2014/02/03 23:56:53 nit: This reads a little awkward, how about "Runs
shashi 2014/02/04 01:39:37 Done.
+ // |distillation_cb_| if callbacks are finished.
+ void RunDistillerCallbackIfDone();
- const DistillerPageFactory& distiller_page_factory_;
const DistillerURLFetcherFactory& distiller_url_fetcher_factory_;
- scoped_ptr<DistillerPage> distiller_page_;
+ scoped_ptr<PageDistiller> page_distiller_;
DistillerCallback distillation_cb_;
- std::map<std::string, DistillerURLFetcher* > image_fetchers_;
-
- scoped_ptr<DistilledPageProto> proto_;
+ base::hash_map<std::string, DistillerURLFetcher*> image_fetchers_;
+ scoped_ptr<DistilledArticleProto> article_proto_;
+ bool distillation_in_progress_;
+ // Set to keep track of which urls are already seen by the distiller.
+ std::vector<std::string> processed_urls_;
DISALLOW_COPY_AND_ASSIGN(DistillerImpl);
};

Powered by Google App Engine
This is Rietveld 408576698