#ifndef COMPONENTS_DOM_DISTILLER_CORE_DOM_DISTILLER_SERVICE_H_
#define COMPONENTS_DOM_DISTILLER_CORE_DOM_DISTILLER_SERVICE_H_
#include <string>
#include <vector>
#include "base/callback.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/scoped_vector.h"
#include "base/memory/weak_ptr.h"
#include "components/dom_distiller/core/article_entry.h"
class GURL;
namespace syncer {
class SyncableService;
}
namespace dom_distiller {
class DistilledArticleProto;
class DistillerFactory;
class DomDistillerObserver;
class DomDistillerStoreInterface;
class TaskTracker;
class ViewerHandle;
class ViewRequestDelegate;
class DomDistillerServiceInterface {
public:
typedef base::Callback<void(bool)> ArticleAvailableCallback;
virtual ~DomDistillerServiceInterface() {}
virtual syncer::SyncableService* GetSyncableService() const = 0;
virtual const std::string AddToList(
const GURL& url,
const ArticleAvailableCallback& article_cb) = 0;
virtual std::vector<ArticleEntry> GetEntries() const = 0;
virtual scoped_ptr<ArticleEntry> RemoveEntry(const std::string& entry_id) = 0;
virtual scoped_ptr<ViewerHandle> ViewEntry(ViewRequestDelegate* delegate,
const std::string& entry_id) = 0;
virtual scoped_ptr<ViewerHandle> ViewUrl(ViewRequestDelegate* delegate,
const GURL& url) = 0;
virtual void AddObserver(DomDistillerObserver* observer) = 0;
virtual void RemoveObserver(DomDistillerObserver* observer) = 0;
protected:
DomDistillerServiceInterface() {}
private:
DISALLOW_COPY_AND_ASSIGN(DomDistillerServiceInterface);
};
class DomDistillerService : public DomDistillerServiceInterface {
public:
DomDistillerService(scoped_ptr<DomDistillerStoreInterface> store,
scoped_ptr<DistillerFactory> distiller_factory);
virtual ~DomDistillerService();
virtual syncer::SyncableService* GetSyncableService() const OVERRIDE;
virtual const std::string AddToList(
const GURL& url,
const ArticleAvailableCallback& article_cb) OVERRIDE;
virtual std::vector<ArticleEntry> GetEntries() const OVERRIDE;
virtual scoped_ptr<ArticleEntry> RemoveEntry(const std::string& entry_id)
OVERRIDE;
virtual scoped_ptr<ViewerHandle> ViewEntry(ViewRequestDelegate* delegate,
const std::string& entry_id)
OVERRIDE;
virtual scoped_ptr<ViewerHandle> ViewUrl(ViewRequestDelegate* delegate,
const GURL& url) OVERRIDE;
virtual void AddObserver(DomDistillerObserver* observer) OVERRIDE;
virtual void RemoveObserver(DomDistillerObserver* observer) OVERRIDE;
private:
void CancelTask(TaskTracker* task);
void AddDistilledPageToList(const ArticleEntry& entry,
const DistilledArticleProto* article_proto,
bool distillation_succeeded);
TaskTracker* CreateTaskTracker(const ArticleEntry& entry);
TaskTracker* GetTaskTrackerForEntry(const ArticleEntry& entry) const;
TaskTracker* GetOrCreateTaskTrackerForUrl(const GURL& url);
TaskTracker* GetOrCreateTaskTrackerForEntry(const ArticleEntry& entry);
scoped_ptr<DomDistillerStoreInterface> store_;
scoped_ptr<DistillerFactory> distiller_factory_;
typedef ScopedVector<TaskTracker> TaskList;
TaskList tasks_;
DISALLOW_COPY_AND_ASSIGN(DomDistillerService);
};
}
#endif