Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / components / dom_distiller / core / dom_distiller_service.h
index 630b184..f227c73 100644 (file)
@@ -13,6 +13,8 @@
 #include "base/memory/scoped_vector.h"
 #include "base/memory/weak_ptr.h"
 #include "components/dom_distiller/core/article_entry.h"
+#include "components/dom_distiller/core/distilled_page_prefs.h"
+#include "components/dom_distiller/core/distiller_page.h"
 
 class GURL;
 
@@ -23,49 +25,124 @@ class SyncableService;
 namespace dom_distiller {
 
 class DistilledArticleProto;
+class DistilledContentStore;
 class DistillerFactory;
+class DistillerPageFactory;
 class DomDistillerObserver;
 class DomDistillerStoreInterface;
 class TaskTracker;
 class ViewerHandle;
 class ViewRequestDelegate;
 
-// Provide a view of the article list and ways of interacting with it.
-class DomDistillerService {
+// Service for interacting with the Dom Distiller.
+// Construction, destruction, and usage of this service must happen on the same
+// thread. Callbacks will be called on that same thread.
+class DomDistillerServiceInterface {
  public:
   typedef base::Callback<void(bool)> ArticleAvailableCallback;
+  virtual ~DomDistillerServiceInterface() {}
 
-  DomDistillerService(scoped_ptr<DomDistillerStoreInterface> store,
-                      scoped_ptr<DistillerFactory> distiller_factory);
-  ~DomDistillerService();
-
-  syncer::SyncableService* GetSyncableService() const;
+  virtual syncer::SyncableService* GetSyncableService() const = 0;
 
   // Distill the article at |url| and add the resulting entry to the DOM
-  // distiller list. |article_cb| is invoked with true if article is
-  // available offline.
-  const std::string AddToList(const GURL& url,
-                              const ArticleAvailableCallback& article_cb);
+  // distiller list. |article_cb| is always invoked, and the bool argument to it
+  // represents whether the article is available offline.
+  // Use CreateDefaultDistillerPage() to create a default |distiller_page|.
+  // The provided |distiller_page| is only used if there is not already a
+  // distillation task in progress for the given |url|.
+  virtual const std::string AddToList(
+      const GURL& url,
+      scoped_ptr<DistillerPage> distiller_page,
+      const ArticleAvailableCallback& article_cb) = 0;
+
+  // Returns whether an article stored has the given entry id.
+  virtual bool HasEntry(const std::string& entry_id) = 0;
+
+  // Returns the source URL given an entry ID. If the entry ID article has
+  // multiple pages, this will return the URL of the first page. Returns an
+  // empty string if there is no entry associated with the given entry ID.
+  virtual std::string GetUrlForEntry(const std::string& entry_id) = 0;
 
   // Gets the full list of entries.
-  std::vector<ArticleEntry> GetEntries() const;
+  virtual std::vector<ArticleEntry> GetEntries() const = 0;
 
   // Removes the specified entry from the dom distiller store.
-  scoped_ptr<ArticleEntry> RemoveEntry(const std::string& entry_id);
+  virtual scoped_ptr<ArticleEntry> RemoveEntry(const std::string& entry_id) = 0;
 
   // Request to view an article by entry id. Returns a null pointer if no entry
   // with |entry_id| exists. The ViewerHandle should be destroyed before the
   // ViewRequestDelegate. The request will be cancelled when the handle is
-  // destroyed (or when this service is destroyed).
-  scoped_ptr<ViewerHandle> ViewEntry(ViewRequestDelegate* delegate,
-                                     const std::string& entry_id);
+  // destroyed (or when this service is destroyed), which also ensures that
+  // the |delegate| is not called after that.
+  // Use CreateDefaultDistillerPage() to create a default |distiller_page|.
+  // The provided |distiller_page| is only used if there is not already a
+  // distillation task in progress for the given |entry_id|.
+  virtual scoped_ptr<ViewerHandle> ViewEntry(
+      ViewRequestDelegate* delegate,
+      scoped_ptr<DistillerPage> distiller_page,
+      const std::string& entry_id) = 0;
 
   // Request to view an article by url.
-  scoped_ptr<ViewerHandle> ViewUrl(ViewRequestDelegate* delegate,
-                                   const GURL& url);
+  // Use CreateDefaultDistillerPage() to create a default |distiller_page|.
+  // The provided |distiller_page| is only used if there is not already a
+  // distillation task in progress for the given |url|.
+  virtual scoped_ptr<ViewerHandle> ViewUrl(
+      ViewRequestDelegate* delegate,
+      scoped_ptr<DistillerPage> distiller_page,
+      const GURL& url) = 0;
+
+  // Creates a default DistillerPage.
+  virtual scoped_ptr<DistillerPage> CreateDefaultDistillerPage(
+      const gfx::Size& render_view_size) = 0;
+  virtual scoped_ptr<DistillerPage> CreateDefaultDistillerPageWithHandle(
+      scoped_ptr<SourcePageHandle> handle) = 0;
+
+  virtual void AddObserver(DomDistillerObserver* observer) = 0;
+  virtual void RemoveObserver(DomDistillerObserver* observer) = 0;
+
+  // Returns the DistilledPagePrefs owned by the instance of
+  // DomDistillerService.
+  virtual DistilledPagePrefs* GetDistilledPagePrefs() = 0;
+
+ protected:
+  DomDistillerServiceInterface() {}
 
-  void AddObserver(DomDistillerObserver* observer);
-  void RemoveObserver(DomDistillerObserver* observer);
+ private:
+  DISALLOW_COPY_AND_ASSIGN(DomDistillerServiceInterface);
+};
+
+// Provide a view of the article list and ways of interacting with it.
+class DomDistillerService : public DomDistillerServiceInterface {
+ public:
+  DomDistillerService(scoped_ptr<DomDistillerStoreInterface> store,
+                      scoped_ptr<DistillerFactory> distiller_factory,
+                      scoped_ptr<DistillerPageFactory> distiller_page_factory,
+                      scoped_ptr<DistilledPagePrefs> distilled_page_prefs);
+  ~DomDistillerService() override;
+
+  // DomDistillerServiceInterface implementation.
+  syncer::SyncableService* GetSyncableService() const override;
+  const std::string AddToList(
+      const GURL& url,
+      scoped_ptr<DistillerPage> distiller_page,
+      const ArticleAvailableCallback& article_cb) override;
+  bool HasEntry(const std::string& entry_id) override;
+  std::string GetUrlForEntry(const std::string& entry_id) override;
+  std::vector<ArticleEntry> GetEntries() const override;
+  scoped_ptr<ArticleEntry> RemoveEntry(const std::string& entry_id) override;
+  scoped_ptr<ViewerHandle> ViewEntry(ViewRequestDelegate* delegate,
+                                     scoped_ptr<DistillerPage> distiller_page,
+                                     const std::string& entry_id) override;
+  scoped_ptr<ViewerHandle> ViewUrl(ViewRequestDelegate* delegate,
+                                   scoped_ptr<DistillerPage> distiller_page,
+                                   const GURL& url) override;
+  scoped_ptr<DistillerPage> CreateDefaultDistillerPage(
+      const gfx::Size& render_view_size) override;
+  scoped_ptr<DistillerPage> CreateDefaultDistillerPageWithHandle(
+      scoped_ptr<SourcePageHandle> handle) override;
+  void AddObserver(DomDistillerObserver* observer) override;
+  void RemoveObserver(DomDistillerObserver* observer) override;
+  DistilledPagePrefs* GetDistilledPagePrefs() override;
 
  private:
   void CancelTask(TaskTracker* task);
@@ -84,7 +161,10 @@ class DomDistillerService {
   TaskTracker* GetOrCreateTaskTrackerForEntry(const ArticleEntry& entry);
 
   scoped_ptr<DomDistillerStoreInterface> store_;
+  scoped_ptr<DistilledContentStore> content_store_;
   scoped_ptr<DistillerFactory> distiller_factory_;
+  scoped_ptr<DistillerPageFactory> distiller_page_factory_;
+  scoped_ptr<DistilledPagePrefs> distilled_page_prefs_;
 
   typedef ScopedVector<TaskTracker> TaskList;
   TaskList tasks_;