| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef COMPONENTS_DOM_DISTILLER_CORE_DISTILLER_H_ | 5 #ifndef COMPONENTS_DOM_DISTILLER_CORE_DISTILLER_H_ |
| 6 #define COMPONENTS_DOM_DISTILLER_CORE_DISTILLER_H_ | 6 #define COMPONENTS_DOM_DISTILLER_CORE_DISTILLER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 | 34 |
| 35 virtual ~Distiller() {} | 35 virtual ~Distiller() {} |
| 36 | 36 |
| 37 // Distills a page, and asynchronously returns the article HTML to the | 37 // Distills a page, and asynchronously returns the article HTML to the |
| 38 // supplied |finished_cb| callback. |update_cb| is invoked whenever article | 38 // supplied |finished_cb| callback. |update_cb| is invoked whenever article |
| 39 // under distillation is updated with more data. | 39 // under distillation is updated with more data. |
| 40 // E.g. when distilling a 2 page article, |update_cb| may be invoked each time | 40 // E.g. when distilling a 2 page article, |update_cb| may be invoked each time |
| 41 // a distilled page is added and |finished_cb| will be invoked once | 41 // a distilled page is added and |finished_cb| will be invoked once |
| 42 // distillation is completed. | 42 // distillation is completed. |
| 43 virtual void DistillPage(const GURL& url, | 43 virtual void DistillPage(const GURL& url, |
| 44 scoped_ptr<DistillerPage> distiller_page, |
| 44 const DistillationFinishedCallback& finished_cb, | 45 const DistillationFinishedCallback& finished_cb, |
| 45 const DistillationUpdateCallback& update_cb) = 0; | 46 const DistillationUpdateCallback& update_cb) = 0; |
| 46 }; | 47 }; |
| 47 | 48 |
| 48 class DistillerFactory { | 49 class DistillerFactory { |
| 49 public: | 50 public: |
| 50 virtual scoped_ptr<Distiller> CreateDistiller() = 0; | 51 virtual scoped_ptr<Distiller> CreateDistiller() = 0; |
| 51 virtual ~DistillerFactory() {} | 52 virtual ~DistillerFactory() {} |
| 52 }; | 53 }; |
| 53 | 54 |
| 54 // Factory for creating a Distiller. | 55 // Factory for creating a Distiller. |
| 55 class DistillerFactoryImpl : public DistillerFactory { | 56 class DistillerFactoryImpl : public DistillerFactory { |
| 56 public: | 57 public: |
| 57 DistillerFactoryImpl( | 58 DistillerFactoryImpl( |
| 58 scoped_ptr<DistillerPageFactory> distiller_page_factory, | |
| 59 scoped_ptr<DistillerURLFetcherFactory> distiller_url_fetcher_factory); | 59 scoped_ptr<DistillerURLFetcherFactory> distiller_url_fetcher_factory); |
| 60 virtual ~DistillerFactoryImpl(); | 60 virtual ~DistillerFactoryImpl(); |
| 61 virtual scoped_ptr<Distiller> CreateDistiller() OVERRIDE; | 61 virtual scoped_ptr<Distiller> CreateDistiller() OVERRIDE; |
| 62 | 62 |
| 63 private: | 63 private: |
| 64 scoped_ptr<DistillerPageFactory> distiller_page_factory_; | |
| 65 scoped_ptr<DistillerURLFetcherFactory> distiller_url_fetcher_factory_; | 64 scoped_ptr<DistillerURLFetcherFactory> distiller_url_fetcher_factory_; |
| 66 }; | 65 }; |
| 67 | 66 |
| 68 // Distills a article from a page and associated pages. | 67 // Distills a article from a page and associated pages. |
| 69 class DistillerImpl : public Distiller { | 68 class DistillerImpl : public Distiller { |
| 70 public: | 69 public: |
| 71 DistillerImpl( | 70 DistillerImpl( |
| 72 const DistillerPageFactory& distiller_page_factory, | |
| 73 const DistillerURLFetcherFactory& distiller_url_fetcher_factory); | 71 const DistillerURLFetcherFactory& distiller_url_fetcher_factory); |
| 74 virtual ~DistillerImpl(); | 72 virtual ~DistillerImpl(); |
| 75 | 73 |
| 76 virtual void DistillPage(const GURL& url, | 74 virtual void DistillPage( |
| 77 const DistillationFinishedCallback& finished_cb, | 75 const GURL& url, |
| 78 const DistillationUpdateCallback& update_cb) | 76 scoped_ptr<DistillerPage> distiller_page, |
| 79 OVERRIDE; | 77 const DistillationFinishedCallback& finished_cb, |
| 78 const DistillationUpdateCallback& update_cb) OVERRIDE; |
| 80 | 79 |
| 81 void SetMaxNumPagesInArticle(size_t max_num_pages); | 80 void SetMaxNumPagesInArticle(size_t max_num_pages); |
| 82 | 81 |
| 83 private: | 82 private: |
| 84 // In case of multiple pages, the Distiller maintains state of multiple pages | 83 // In case of multiple pages, the Distiller maintains state of multiple pages |
| 85 // as page numbers relative to the page number where distillation started. | 84 // as page numbers relative to the page number where distillation started. |
| 86 // E.g. if distillation starts at page 2 for a 3 page article. The relative | 85 // E.g. if distillation starts at page 2 for a 3 page article. The relative |
| 87 // page numbers assigned to pages will be [-1,0,1]. | 86 // page numbers assigned to pages will be [-1,0,1]. |
| 88 | 87 |
| 89 // Class representing the state of a page under distillation. | 88 // Class representing the state of a page under distillation. |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 bool destruction_allowed_; | 178 bool destruction_allowed_; |
| 180 | 179 |
| 181 base::WeakPtrFactory<DistillerImpl> weak_factory_; | 180 base::WeakPtrFactory<DistillerImpl> weak_factory_; |
| 182 | 181 |
| 183 DISALLOW_COPY_AND_ASSIGN(DistillerImpl); | 182 DISALLOW_COPY_AND_ASSIGN(DistillerImpl); |
| 184 }; | 183 }; |
| 185 | 184 |
| 186 } // namespace dom_distiller | 185 } // namespace dom_distiller |
| 187 | 186 |
| 188 #endif // COMPONENTS_DOM_DISTILLER_CORE_DISTILLER_H_ | 187 #endif // COMPONENTS_DOM_DISTILLER_CORE_DISTILLER_H_ |
| OLD | NEW |