Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(182)

Side by Side Diff: components/dom_distiller/core/dom_distiller_service.h

Issue 254483003: Start requiring DistillerPage for calls to DomDistillerService. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
11 #include "base/callback.h" 11 #include "base/callback.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/scoped_vector.h" 13 #include "base/memory/scoped_vector.h"
14 #include "base/memory/weak_ptr.h" 14 #include "base/memory/weak_ptr.h"
15 #include "components/dom_distiller/core/article_entry.h" 15 #include "components/dom_distiller/core/article_entry.h"
16 #include "components/dom_distiller/core/distiller_page.h"
16 17
17 class GURL; 18 class GURL;
18 19
19 namespace syncer { 20 namespace syncer {
20 class SyncableService; 21 class SyncableService;
21 } 22 }
22 23
23 namespace dom_distiller { 24 namespace dom_distiller {
24 25
25 class DistilledArticleProto; 26 class DistilledArticleProto;
26 class DistilledContentStore; 27 class DistilledContentStore;
27 class DistillerFactory; 28 class DistillerFactory;
29 class DistillerPageFactory;
28 class DomDistillerObserver; 30 class DomDistillerObserver;
29 class DomDistillerStoreInterface; 31 class DomDistillerStoreInterface;
30 class TaskTracker; 32 class TaskTracker;
31 class ViewerHandle; 33 class ViewerHandle;
32 class ViewRequestDelegate; 34 class ViewRequestDelegate;
33 35
34 // Service for interacting with the Dom Distiller. 36 // Service for interacting with the Dom Distiller.
35 // Construction, destruction, and usage of this service must happen on the same 37 // Construction, destruction, and usage of this service must happen on the same
36 // thread. Callbacks will be called on that same thread. 38 // thread. Callbacks will be called on that same thread.
37 class DomDistillerServiceInterface { 39 class DomDistillerServiceInterface {
38 public: 40 public:
39 typedef base::Callback<void(bool)> ArticleAvailableCallback; 41 typedef base::Callback<void(bool)> ArticleAvailableCallback;
40 virtual ~DomDistillerServiceInterface() {} 42 virtual ~DomDistillerServiceInterface() {}
41 43
42 virtual syncer::SyncableService* GetSyncableService() const = 0; 44 virtual syncer::SyncableService* GetSyncableService() const = 0;
43 45
44 // Distill the article at |url| and add the resulting entry to the DOM 46 // Distill the article at |url| and add the resulting entry to the DOM
45 // distiller list. |article_cb| is always invoked, and the bool argument to it 47 // distiller list. |article_cb| is always invoked, and the bool argument to it
46 // represents whether the article is available offline. 48 // represents whether the article is available offline.
cjhopman 2014/04/24 23:03:05 One important point here, the provided distiller_p
nyquist 2014/04/25 15:41:13 I have now tried to clarify this in the documentat
49 // Use CreateDefaultDistillerPage() to create a default |distiller_page|.
47 virtual const std::string AddToList( 50 virtual const std::string AddToList(
48 const GURL& url, 51 const GURL& url,
52 scoped_ptr<DistillerPage> distiller_page,
49 const ArticleAvailableCallback& article_cb) = 0; 53 const ArticleAvailableCallback& article_cb) = 0;
50 54
51 // Gets the full list of entries. 55 // Gets the full list of entries.
52 virtual std::vector<ArticleEntry> GetEntries() const = 0; 56 virtual std::vector<ArticleEntry> GetEntries() const = 0;
53 57
54 // Removes the specified entry from the dom distiller store. 58 // Removes the specified entry from the dom distiller store.
55 virtual scoped_ptr<ArticleEntry> RemoveEntry(const std::string& entry_id) = 0; 59 virtual scoped_ptr<ArticleEntry> RemoveEntry(const std::string& entry_id) = 0;
56 60
57 // Request to view an article by entry id. Returns a null pointer if no entry 61 // Request to view an article by entry id. Returns a null pointer if no entry
58 // with |entry_id| exists. The ViewerHandle should be destroyed before the 62 // with |entry_id| exists. The ViewerHandle should be destroyed before the
59 // ViewRequestDelegate. The request will be cancelled when the handle is 63 // ViewRequestDelegate. The request will be cancelled when the handle is
60 // destroyed (or when this service is destroyed), which also ensures that 64 // destroyed (or when this service is destroyed), which also ensures that
61 // the |delegate| is not called after that. 65 // the |delegate| is not called after that.
62 virtual scoped_ptr<ViewerHandle> ViewEntry(ViewRequestDelegate* delegate, 66 // Use CreateDefaultDistillerPage() to create a default |distiller_page|.
63 const std::string& entry_id) = 0; 67 virtual scoped_ptr<ViewerHandle> ViewEntry(
68 ViewRequestDelegate* delegate,
69 scoped_ptr<DistillerPage> distiller_page,
70 const std::string& entry_id) = 0;
64 71
65 // Request to view an article by url. 72 // Request to view an article by url.
66 virtual scoped_ptr<ViewerHandle> ViewUrl(ViewRequestDelegate* delegate, 73 // Use CreateDefaultDistillerPage() to create a default |distiller_page|.
67 const GURL& url) = 0; 74 virtual scoped_ptr<ViewerHandle> ViewUrl(
75 ViewRequestDelegate* delegate,
76 scoped_ptr<DistillerPage> distiller_page,
77 const GURL& url) = 0;
78
79 // Creates a default DistillerPage.
80 virtual scoped_ptr<DistillerPage> CreateDefaultDistillerPage() = 0;
68 81
69 virtual void AddObserver(DomDistillerObserver* observer) = 0; 82 virtual void AddObserver(DomDistillerObserver* observer) = 0;
70 virtual void RemoveObserver(DomDistillerObserver* observer) = 0; 83 virtual void RemoveObserver(DomDistillerObserver* observer) = 0;
71 84
72 protected: 85 protected:
73 DomDistillerServiceInterface() {} 86 DomDistillerServiceInterface() {}
74 87
75 private: 88 private:
76 DISALLOW_COPY_AND_ASSIGN(DomDistillerServiceInterface); 89 DISALLOW_COPY_AND_ASSIGN(DomDistillerServiceInterface);
77 }; 90 };
78 91
79 // Provide a view of the article list and ways of interacting with it. 92 // Provide a view of the article list and ways of interacting with it.
80 class DomDistillerService : public DomDistillerServiceInterface { 93 class DomDistillerService : public DomDistillerServiceInterface {
81 public: 94 public:
82 DomDistillerService(scoped_ptr<DomDistillerStoreInterface> store, 95 DomDistillerService(scoped_ptr<DomDistillerStoreInterface> store,
83 scoped_ptr<DistillerFactory> distiller_factory); 96 scoped_ptr<DistillerFactory> distiller_factory,
97 scoped_ptr<DistillerPageFactory> distiller_page_factory);
84 virtual ~DomDistillerService(); 98 virtual ~DomDistillerService();
85 99
86 // DomDistillerServiceInterface implementation. 100 // DomDistillerServiceInterface implementation.
87 virtual syncer::SyncableService* GetSyncableService() const OVERRIDE; 101 virtual syncer::SyncableService* GetSyncableService() const OVERRIDE;
88 virtual const std::string AddToList( 102 virtual const std::string AddToList(
89 const GURL& url, 103 const GURL& url,
104 scoped_ptr<DistillerPage> distiller_page,
90 const ArticleAvailableCallback& article_cb) OVERRIDE; 105 const ArticleAvailableCallback& article_cb) OVERRIDE;
91 virtual std::vector<ArticleEntry> GetEntries() const OVERRIDE; 106 virtual std::vector<ArticleEntry> GetEntries() const OVERRIDE;
92 virtual scoped_ptr<ArticleEntry> RemoveEntry(const std::string& entry_id) 107 virtual scoped_ptr<ArticleEntry> RemoveEntry(
93 OVERRIDE; 108 const std::string& entry_id) OVERRIDE;
94 virtual scoped_ptr<ViewerHandle> ViewEntry(ViewRequestDelegate* delegate, 109 virtual scoped_ptr<ViewerHandle> ViewEntry(
95 const std::string& entry_id) 110 ViewRequestDelegate* delegate,
96 OVERRIDE; 111 scoped_ptr<DistillerPage> distiller_page,
97 virtual scoped_ptr<ViewerHandle> ViewUrl(ViewRequestDelegate* delegate, 112 const std::string& entry_id) OVERRIDE;
98 const GURL& url) OVERRIDE; 113 virtual scoped_ptr<ViewerHandle> ViewUrl(
114 ViewRequestDelegate* delegate,
115 scoped_ptr<DistillerPage> distiller_page,
116 const GURL& url) OVERRIDE;
117 virtual scoped_ptr<DistillerPage> CreateDefaultDistillerPage() OVERRIDE;
99 virtual void AddObserver(DomDistillerObserver* observer) OVERRIDE; 118 virtual void AddObserver(DomDistillerObserver* observer) OVERRIDE;
100 virtual void RemoveObserver(DomDistillerObserver* observer) OVERRIDE; 119 virtual void RemoveObserver(DomDistillerObserver* observer) OVERRIDE;
101 120
102 private: 121 private:
103 void CancelTask(TaskTracker* task); 122 void CancelTask(TaskTracker* task);
104 void AddDistilledPageToList(const ArticleEntry& entry, 123 void AddDistilledPageToList(const ArticleEntry& entry,
105 const DistilledArticleProto* article_proto, 124 const DistilledArticleProto* article_proto,
106 bool distillation_succeeded); 125 bool distillation_succeeded);
107 126
108 TaskTracker* CreateTaskTracker(const ArticleEntry& entry); 127 TaskTracker* CreateTaskTracker(const ArticleEntry& entry);
109 128
110 TaskTracker* GetTaskTrackerForEntry(const ArticleEntry& entry) const; 129 TaskTracker* GetTaskTrackerForEntry(const ArticleEntry& entry) const;
111 130
112 // Gets the task tracker for the given |url| or |entry|. If no appropriate 131 // Gets the task tracker for the given |url| or |entry|. If no appropriate
113 // tracker exists, this will create one, initialize it, and add it to 132 // tracker exists, this will create one, initialize it, and add it to
114 // |tasks_|. 133 // |tasks_|.
115 TaskTracker* GetOrCreateTaskTrackerForUrl(const GURL& url); 134 TaskTracker* GetOrCreateTaskTrackerForUrl(const GURL& url);
116 TaskTracker* GetOrCreateTaskTrackerForEntry(const ArticleEntry& entry); 135 TaskTracker* GetOrCreateTaskTrackerForEntry(const ArticleEntry& entry);
117 136
118 scoped_ptr<DomDistillerStoreInterface> store_; 137 scoped_ptr<DomDistillerStoreInterface> store_;
119 scoped_ptr<DistilledContentStore> content_store_; 138 scoped_ptr<DistilledContentStore> content_store_;
120 scoped_ptr<DistillerFactory> distiller_factory_; 139 scoped_ptr<DistillerFactory> distiller_factory_;
140 scoped_ptr<DistillerPageFactory> distiller_page_factory_;
121 141
122 typedef ScopedVector<TaskTracker> TaskList; 142 typedef ScopedVector<TaskTracker> TaskList;
123 TaskList tasks_; 143 TaskList tasks_;
124 144
125 DISALLOW_COPY_AND_ASSIGN(DomDistillerService); 145 DISALLOW_COPY_AND_ASSIGN(DomDistillerService);
126 }; 146 };
127 147
128 } // namespace dom_distiller 148 } // namespace dom_distiller
129 149
130 #endif // COMPONENTS_DOM_DISTILLER_CORE_DOM_DISTILLER_SERVICE_H_ 150 #endif // COMPONENTS_DOM_DISTILLER_CORE_DOM_DISTILLER_SERVICE_H_
OLDNEW
« no previous file with comments | « components/dom_distiller/core/distiller_unittest.cc ('k') | components/dom_distiller/core/dom_distiller_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698