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 protected: | |
71 DomDistillerServiceInterface() {} | |
72 | |
73 private: | |
74 DISALLOW_COPY_AND_ASSIGN(DomDistillerServiceInterface); | |
75 }; | |
76 | |
77 // Provide a view of the article list and ways of interacting with it. | |
78 class DomDistillerService : public DomDistillerServiceInterface { | |
79 public: | |
80 DomDistillerService(scoped_ptr<DomDistillerStoreInterface> store, | |
81 scoped_ptr<DistillerFactory> distiller_factory); | |
82 virtual ~DomDistillerService(); | |
83 | |
84 // DomDistillerServiceInterface implementation. | |
85 virtual syncer::SyncableService* GetSyncableService() const OVERRIDE; | |
86 virtual const std::string AddToList( | |
87 const GURL& url, | |
88 const ArticleAvailableCallback& article_cb) OVERRIDE; | |
89 virtual std::vector<ArticleEntry> GetEntries() const OVERRIDE; | |
90 virtual scoped_ptr<ArticleEntry> RemoveEntry(const std::string& entry_id) | |
91 OVERRIDE; | |
92 virtual scoped_ptr<ViewerHandle> ViewEntry(ViewRequestDelegate* delegate, | |
93 const std::string& entry_id) | |
94 OVERRIDE; | |
95 virtual scoped_ptr<ViewerHandle> ViewUrl(ViewRequestDelegate* delegate, | |
96 const GURL& url) OVERRIDE; | |
97 virtual void AddObserver(DomDistillerObserver* observer) OVERRIDE; | |
98 virtual void RemoveObserver(DomDistillerObserver* observer) OVERRIDE; | |
69 | 99 |
70 private: | 100 private: |
71 void CancelTask(TaskTracker* task); | 101 void CancelTask(TaskTracker* task); |
72 void AddDistilledPageToList(const ArticleEntry& entry, | 102 void AddDistilledPageToList(const ArticleEntry& entry, |
73 const DistilledArticleProto* article_proto, | 103 const DistilledArticleProto* article_proto, |
74 bool distillation_succeeded); | 104 bool distillation_succeeded); |
75 | 105 |
76 TaskTracker* CreateTaskTracker(const ArticleEntry& entry); | 106 TaskTracker* CreateTaskTracker(const ArticleEntry& entry); |
77 | 107 |
78 TaskTracker* GetTaskTrackerForEntry(const ArticleEntry& entry) const; | 108 TaskTracker* GetTaskTrackerForEntry(const ArticleEntry& entry) const; |
79 | 109 |
80 // Gets the task tracker for the given |url| or |entry|. If no appropriate | 110 // 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 | 111 // tracker exists, this will create one, initialize it, and add it to |
82 // |tasks_|. | 112 // |tasks_|. |
83 TaskTracker* GetOrCreateTaskTrackerForUrl(const GURL& url); | 113 TaskTracker* GetOrCreateTaskTrackerForUrl(const GURL& url); |
84 TaskTracker* GetOrCreateTaskTrackerForEntry(const ArticleEntry& entry); | 114 TaskTracker* GetOrCreateTaskTrackerForEntry(const ArticleEntry& entry); |
85 | 115 |
86 scoped_ptr<DomDistillerStoreInterface> store_; | 116 scoped_ptr<DomDistillerStoreInterface> store_; |
87 scoped_ptr<DistillerFactory> distiller_factory_; | 117 scoped_ptr<DistillerFactory> distiller_factory_; |
88 | 118 |
89 typedef ScopedVector<TaskTracker> TaskList; | 119 typedef ScopedVector<TaskTracker> TaskList; |
90 TaskList tasks_; | 120 TaskList tasks_; |
91 | |
92 DISALLOW_COPY_AND_ASSIGN(DomDistillerService); | |
nasko
2014/02/27 22:40:44
Why is this no longer needed?
nyquist
2014/02/28 16:46:51
Done. Kept this in addition to the one in the pure
| |
93 }; | 121 }; |
94 | 122 |
95 } // namespace dom_distiller | 123 } // namespace dom_distiller |
96 | 124 |
97 #endif // COMPONENTS_DOM_DISTILLER_CORE_DOM_DISTILLER_SERVICE_H_ | 125 #endif // COMPONENTS_DOM_DISTILLER_CORE_DOM_DISTILLER_SERVICE_H_ |
OLD | NEW |