Index: components/dom_distiller/core/distiller.h |
diff --git a/components/dom_distiller/core/distiller.h b/components/dom_distiller/core/distiller.h |
index 54907500557dc2f6886a27976e7bec086e59bbe9..3821adf1d3f1c7c86c985869172f5338402b4705 100644 |
--- a/components/dom_distiller/core/distiller.h |
+++ b/components/dom_distiller/core/distiller.h |
@@ -68,36 +68,96 @@ class DistillerImpl : public Distiller { |
virtual void DistillPage(const GURL& url, |
const DistillerCallback& callback) OVERRIDE; |
+ void SetMaxNumPagesInArticle(size_t max_num_pages); |
+ |
private: |
- void OnFetchImageDone(DistilledPageProto* distilled_page_proto, |
+ // In case of multiple pages, the Distiller maintains state of multiple pages |
+ // as relative page numbers. E.g. if distillation starts at page 2 for a 3 |
cjhopman
2014/02/15 02:44:15
nit: relative to what? Might not be needed since i
shashi
2014/02/15 03:15:36
Done.
|
+ // page article. The relative page numbers assigned to pages will be [-1,0,1]. |
+ |
+ // Class representing the state of a page under distillation. |
+ struct DistilledPageData { |
+ DistilledPageData(); |
+ virtual ~DistilledPageData(); |
+ // Relative page number of the page. |
+ int page_num; |
+ std::string title; |
+ ScopedVector<DistillerURLFetcher> image_fetchers_; |
+ scoped_ptr<DistilledPageProto> proto; |
+ |
+ private: |
+ DISALLOW_COPY_AND_ASSIGN(DistilledPageData); |
+ }; |
+ |
+ void OnFetchImageDone(int page_num, |
DistillerURLFetcher* url_fetcher, |
const std::string& id, |
const std::string& response); |
- void OnPageDistillationFinished(const GURL& page_url, |
+ void OnPageDistillationFinished(int page_num, |
+ const GURL& page_url, |
scoped_ptr<DistilledPageInfo> distilled_page, |
bool distillation_successful); |
- virtual void FetchImage(DistilledPageProto* distilled_page_proto, |
+ virtual void FetchImage(int page_num, |
const std::string& image_id, |
const std::string& item); |
- // Distills the page and adds the new page to |article_proto|. |
- void DistillPage(const GURL& url); |
+ // Distills the next page. |
+ void DistillNextPage(); |
+ |
+ // Adds the |url| to |pages_to_be_distilled| if |page_num| is a valid relative |
+ // page number and |url| is valid. Ignores duplicate pages and urls. |
+ void AddToDistillationQueue(int page_num, const GURL& url); |
+ |
+ // Check if |page_num| is a valid relative page number, i.e. page with |
+ // |page_num| is either under distillation or has already completed |
+ // distillation. |
+ bool IsPageNumberInUse(int page_num) const; |
+ |
+ bool AreAllPagesFinished() const; |
+ |
+ // Total number of pages in the article that the distiller knows of, this |
+ // includes pages that are pending distillation. |
+ size_t TotalPageCount() const; |
// Runs |distillation_cb_| if all distillation callbacks and image fetches are |
// complete. |
void RunDistillerCallbackIfDone(); |
+ // Checks if page |distilled_page_data| has finished distillation, including |
+ // all image fetches. |
+ void AddPageIfDone(int page_num); |
+ |
+ DistilledPageData* GetPageAtIndex(size_t index) const; |
+ |
const DistillerURLFetcherFactory& distiller_url_fetcher_factory_; |
scoped_ptr<PageDistiller> page_distiller_; |
DistillerCallback distillation_cb_; |
- ScopedVector<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. |
- base::hash_set<std::string> processed_urls_; |
+ // Set of pages that are under distillation or have finished distillation. |
+ // |started_pages_index_| and |finished_pages_index_| maintains the mapping |
+ // from page number to the indices in |pages_|. |
+ ScopedVector<DistilledPageData> pages_; |
+ |
+ // Maps page numbers of finished pages to the indices in |pages_|. |
+ std::map<int, size_t> finished_pages_index_; |
+ |
+ // The list of pages that are still waiting for distillation to start. |
cjhopman
2014/02/15 02:44:15
Nit: The order of declaration here should be finis
shashi
2014/02/15 03:15:36
Done.
shashi
2014/02/15 03:15:36
Done.
|
+ // This is a map, to make distiller prefer distilling lower page numbers |
+ // first. |
+ std::map<int, GURL> waiting_pages_; |
+ |
+ // Maps page numbers of pages under distillation to the indices in |pages_|. |
+ // If a page is |started_pages_| that means it is still waiting for an action |
+ // (distillation or image fetch) to finish. |
+ base::hash_map<int, size_t> started_pages_index_; |
+ |
+ // Set to keep track of which urls are already seen by the distiller. Used to |
+ // prevent distiller from distilling the same url twice. |
+ base::hash_set<std::string> seen_urls_; |
+ |
+ size_t max_pages_in_article_; |
DISALLOW_COPY_AND_ASSIGN(DistillerImpl); |
}; |