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_DOM_DISTILLER_SERVICE_H_ | 5 #ifndef COMPONENTS_DOM_DISTILLER_CORE_DOM_DISTILLER_SERVICE_H_ |
6 #define COMPONENTS_DOM_DISTILLER_CORE_DOM_DISTILLER_SERVICE_H_ | 6 #define COMPONENTS_DOM_DISTILLER_CORE_DOM_DISTILLER_SERVICE_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 12 matching lines...) Expand all Loading... |
23 namespace dom_distiller { | 23 namespace dom_distiller { |
24 | 24 |
25 class DistilledArticleProto; | 25 class DistilledArticleProto; |
26 class DistillerFactory; | 26 class DistillerFactory; |
27 class DomDistillerObserver; | 27 class DomDistillerObserver; |
28 class DomDistillerStoreInterface; | 28 class DomDistillerStoreInterface; |
29 class TaskTracker; | 29 class TaskTracker; |
30 class ViewerHandle; | 30 class ViewerHandle; |
31 class ViewRequestDelegate; | 31 class ViewRequestDelegate; |
32 | 32 |
33 // Provide a view of the article list and ways of interacting with it. | 33 // Service for interacting with the Dom Distiller. |
34 class DomDistillerService { | 34 // Construction, destruction, and usage of this service must happen on the same |
| 35 // thread. Callbacks will be called on that same thread. |
| 36 class DomDistillerServiceInterface { |
35 public: | 37 public: |
36 typedef base::Callback<void(bool)> ArticleAvailableCallback; | 38 typedef base::Callback<void(bool)> ArticleAvailableCallback; |
| 39 virtual ~DomDistillerServiceInterface() {} |
37 | 40 |
38 DomDistillerService(scoped_ptr<DomDistillerStoreInterface> store, | 41 virtual syncer::SyncableService* GetSyncableService() const = 0; |
39 scoped_ptr<DistillerFactory> distiller_factory); | |
40 ~DomDistillerService(); | |
41 | |
42 syncer::SyncableService* GetSyncableService() const; | |
43 | 42 |
44 // Distill the article at |url| and add the resulting entry to the DOM | 43 // Distill the article at |url| and add the resulting entry to the DOM |
45 // distiller list. |article_cb| is invoked with true if article is | 44 // distiller list. |article_cb| is always invoked, and the bool argument to it |
46 // available offline. | 45 // represents whether the article is available offline. |
47 const std::string AddToList(const GURL& url, | 46 virtual const std::string AddToList( |
48 const ArticleAvailableCallback& article_cb); | 47 const GURL& url, |
| 48 const ArticleAvailableCallback& article_cb) = 0; |
49 | 49 |
50 // Gets the full list of entries. | 50 // Gets the full list of entries. |
51 std::vector<ArticleEntry> GetEntries() const; | 51 virtual std::vector<ArticleEntry> GetEntries() const = 0; |
52 | 52 |
53 // Removes the specified entry from the dom distiller store. | 53 // Removes the specified entry from the dom distiller store. |
54 scoped_ptr<ArticleEntry> RemoveEntry(const std::string& entry_id); | 54 virtual scoped_ptr<ArticleEntry> RemoveEntry(const std::string& entry_id) = 0; |
55 | 55 |
56 // Request to view an article by entry id. Returns a null pointer if no entry | 56 // Request to view an article by entry id. Returns a null pointer if no entry |
57 // with |entry_id| exists. The ViewerHandle should be destroyed before the | 57 // with |entry_id| exists. The ViewerHandle should be destroyed before the |
58 // ViewRequestDelegate. The request will be cancelled when the handle is | 58 // ViewRequestDelegate. The request will be cancelled when the handle is |
59 // destroyed (or when this service is destroyed). | 59 // destroyed (or when this service is destroyed), which also ensures that |
60 scoped_ptr<ViewerHandle> ViewEntry(ViewRequestDelegate* delegate, | 60 // the |delegate| is not called after that. |
61 const std::string& entry_id); | 61 virtual scoped_ptr<ViewerHandle> ViewEntry(ViewRequestDelegate* delegate, |
| 62 const std::string& entry_id) = 0; |
62 | 63 |
63 // Request to view an article by url. | 64 // Request to view an article by url. |
64 scoped_ptr<ViewerHandle> ViewUrl(ViewRequestDelegate* delegate, | 65 virtual scoped_ptr<ViewerHandle> ViewUrl(ViewRequestDelegate* delegate, |
65 const GURL& url); | 66 const GURL& url) = 0; |
66 | 67 |
67 void AddObserver(DomDistillerObserver* observer); | 68 virtual void AddObserver(DomDistillerObserver* observer) = 0; |
68 void RemoveObserver(DomDistillerObserver* observer); | 69 virtual void RemoveObserver(DomDistillerObserver* observer) = 0; |
| 70 |
| 71 protected: |
| 72 DomDistillerServiceInterface() {} |
| 73 |
| 74 private: |
| 75 DISALLOW_COPY_AND_ASSIGN(DomDistillerServiceInterface); |
| 76 }; |
| 77 |
| 78 // Provide a view of the article list and ways of interacting with it. |
| 79 class DomDistillerService : public DomDistillerServiceInterface { |
| 80 public: |
| 81 DomDistillerService(scoped_ptr<DomDistillerStoreInterface> store, |
| 82 scoped_ptr<DistillerFactory> distiller_factory); |
| 83 virtual ~DomDistillerService(); |
| 84 |
| 85 // DomDistillerServiceInterface implementation. |
| 86 virtual syncer::SyncableService* GetSyncableService() const OVERRIDE; |
| 87 virtual const std::string AddToList( |
| 88 const GURL& url, |
| 89 const ArticleAvailableCallback& article_cb) OVERRIDE; |
| 90 virtual std::vector<ArticleEntry> GetEntries() const OVERRIDE; |
| 91 virtual scoped_ptr<ArticleEntry> RemoveEntry(const std::string& entry_id) |
| 92 OVERRIDE; |
| 93 virtual scoped_ptr<ViewerHandle> ViewEntry(ViewRequestDelegate* delegate, |
| 94 const std::string& entry_id) |
| 95 OVERRIDE; |
| 96 virtual scoped_ptr<ViewerHandle> ViewUrl(ViewRequestDelegate* delegate, |
| 97 const GURL& url) OVERRIDE; |
| 98 virtual void AddObserver(DomDistillerObserver* observer) OVERRIDE; |
| 99 virtual void RemoveObserver(DomDistillerObserver* observer) OVERRIDE; |
69 | 100 |
70 private: | 101 private: |
71 void CancelTask(TaskTracker* task); | 102 void CancelTask(TaskTracker* task); |
72 void AddDistilledPageToList(const ArticleEntry& entry, | 103 void AddDistilledPageToList(const ArticleEntry& entry, |
73 const DistilledArticleProto* article_proto, | 104 const DistilledArticleProto* article_proto, |
74 bool distillation_succeeded); | 105 bool distillation_succeeded); |
75 | 106 |
76 TaskTracker* CreateTaskTracker(const ArticleEntry& entry); | 107 TaskTracker* CreateTaskTracker(const ArticleEntry& entry); |
77 | 108 |
78 TaskTracker* GetTaskTrackerForEntry(const ArticleEntry& entry) const; | 109 TaskTracker* GetTaskTrackerForEntry(const ArticleEntry& entry) const; |
79 | 110 |
80 // Gets the task tracker for the given |url| or |entry|. If no appropriate | 111 // Gets the task tracker for the given |url| or |entry|. If no appropriate |
81 // tracker exists, this will create one, initialize it, and add it to | 112 // tracker exists, this will create one, initialize it, and add it to |
82 // |tasks_|. | 113 // |tasks_|. |
83 TaskTracker* GetOrCreateTaskTrackerForUrl(const GURL& url); | 114 TaskTracker* GetOrCreateTaskTrackerForUrl(const GURL& url); |
84 TaskTracker* GetOrCreateTaskTrackerForEntry(const ArticleEntry& entry); | 115 TaskTracker* GetOrCreateTaskTrackerForEntry(const ArticleEntry& entry); |
85 | 116 |
86 scoped_ptr<DomDistillerStoreInterface> store_; | 117 scoped_ptr<DomDistillerStoreInterface> store_; |
87 scoped_ptr<DistillerFactory> distiller_factory_; | 118 scoped_ptr<DistillerFactory> distiller_factory_; |
88 | 119 |
89 typedef ScopedVector<TaskTracker> TaskList; | 120 typedef ScopedVector<TaskTracker> TaskList; |
90 TaskList tasks_; | 121 TaskList tasks_; |
91 | 122 |
92 DISALLOW_COPY_AND_ASSIGN(DomDistillerService); | 123 DISALLOW_COPY_AND_ASSIGN(DomDistillerService); |
93 }; | 124 }; |
94 | 125 |
95 } // namespace dom_distiller | 126 } // namespace dom_distiller |
96 | 127 |
97 #endif // COMPONENTS_DOM_DISTILLER_CORE_DOM_DISTILLER_SERVICE_H_ | 128 #endif // COMPONENTS_DOM_DISTILLER_CORE_DOM_DISTILLER_SERVICE_H_ |
OLD | NEW |