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

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: Indent fixes (full git cl format) Created 6 years, 7 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.
49 // Use CreateDefaultDistillerPage() to create a default |distiller_page|.
50 // The provided |distiller_page| is only used if there is not already a
51 // distillation task in progress for the given |url|.
47 virtual const std::string AddToList( 52 virtual const std::string AddToList(
48 const GURL& url, 53 const GURL& url,
54 scoped_ptr<DistillerPage> distiller_page,
49 const ArticleAvailableCallback& article_cb) = 0; 55 const ArticleAvailableCallback& article_cb) = 0;
50 56
51 // Gets the full list of entries. 57 // Gets the full list of entries.
52 virtual std::vector<ArticleEntry> GetEntries() const = 0; 58 virtual std::vector<ArticleEntry> GetEntries() const = 0;
53 59
54 // Removes the specified entry from the dom distiller store. 60 // Removes the specified entry from the dom distiller store.
55 virtual scoped_ptr<ArticleEntry> RemoveEntry(const std::string& entry_id) = 0; 61 virtual scoped_ptr<ArticleEntry> RemoveEntry(const std::string& entry_id) = 0;
56 62
57 // Request to view an article by entry id. Returns a null pointer if no entry 63 // 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 64 // with |entry_id| exists. The ViewerHandle should be destroyed before the
59 // ViewRequestDelegate. The request will be cancelled when the handle is 65 // ViewRequestDelegate. The request will be cancelled when the handle is
60 // destroyed (or when this service is destroyed), which also ensures that 66 // destroyed (or when this service is destroyed), which also ensures that
61 // the |delegate| is not called after that. 67 // the |delegate| is not called after that.
62 virtual scoped_ptr<ViewerHandle> ViewEntry(ViewRequestDelegate* delegate, 68 // Use CreateDefaultDistillerPage() to create a default |distiller_page|.
63 const std::string& entry_id) = 0; 69 // The provided |distiller_page| is only used if there is not already a
70 // distillation task in progress for the given |entry_id|.
71 virtual scoped_ptr<ViewerHandle> ViewEntry(
72 ViewRequestDelegate* delegate,
73 scoped_ptr<DistillerPage> distiller_page,
74 const std::string& entry_id) = 0;
64 75
65 // Request to view an article by url. 76 // Request to view an article by url.
66 virtual scoped_ptr<ViewerHandle> ViewUrl(ViewRequestDelegate* delegate, 77 // Use CreateDefaultDistillerPage() to create a default |distiller_page|.
67 const GURL& url) = 0; 78 // The provided |distiller_page| is only used if there is not already a
79 // distillation task in progress for the given |url|.
80 virtual scoped_ptr<ViewerHandle> ViewUrl(
81 ViewRequestDelegate* delegate,
82 scoped_ptr<DistillerPage> distiller_page,
83 const GURL& url) = 0;
84
85 // Creates a default DistillerPage.
86 virtual scoped_ptr<DistillerPage> CreateDefaultDistillerPage() = 0;
68 87
69 virtual void AddObserver(DomDistillerObserver* observer) = 0; 88 virtual void AddObserver(DomDistillerObserver* observer) = 0;
70 virtual void RemoveObserver(DomDistillerObserver* observer) = 0; 89 virtual void RemoveObserver(DomDistillerObserver* observer) = 0;
71 90
72 protected: 91 protected:
73 DomDistillerServiceInterface() {} 92 DomDistillerServiceInterface() {}
74 93
75 private: 94 private:
76 DISALLOW_COPY_AND_ASSIGN(DomDistillerServiceInterface); 95 DISALLOW_COPY_AND_ASSIGN(DomDistillerServiceInterface);
77 }; 96 };
78 97
79 // Provide a view of the article list and ways of interacting with it. 98 // Provide a view of the article list and ways of interacting with it.
80 class DomDistillerService : public DomDistillerServiceInterface { 99 class DomDistillerService : public DomDistillerServiceInterface {
81 public: 100 public:
82 DomDistillerService(scoped_ptr<DomDistillerStoreInterface> store, 101 DomDistillerService(scoped_ptr<DomDistillerStoreInterface> store,
83 scoped_ptr<DistillerFactory> distiller_factory); 102 scoped_ptr<DistillerFactory> distiller_factory,
103 scoped_ptr<DistillerPageFactory> distiller_page_factory);
84 virtual ~DomDistillerService(); 104 virtual ~DomDistillerService();
85 105
86 // DomDistillerServiceInterface implementation. 106 // DomDistillerServiceInterface implementation.
87 virtual syncer::SyncableService* GetSyncableService() const OVERRIDE; 107 virtual syncer::SyncableService* GetSyncableService() const OVERRIDE;
88 virtual const std::string AddToList( 108 virtual const std::string AddToList(
89 const GURL& url, 109 const GURL& url,
110 scoped_ptr<DistillerPage> distiller_page,
90 const ArticleAvailableCallback& article_cb) OVERRIDE; 111 const ArticleAvailableCallback& article_cb) OVERRIDE;
91 virtual std::vector<ArticleEntry> GetEntries() const OVERRIDE; 112 virtual std::vector<ArticleEntry> GetEntries() const OVERRIDE;
92 virtual scoped_ptr<ArticleEntry> RemoveEntry(const std::string& entry_id) 113 virtual scoped_ptr<ArticleEntry> RemoveEntry(
93 OVERRIDE; 114 const std::string& entry_id) OVERRIDE;
94 virtual scoped_ptr<ViewerHandle> ViewEntry(ViewRequestDelegate* delegate, 115 virtual scoped_ptr<ViewerHandle> ViewEntry(
95 const std::string& entry_id) 116 ViewRequestDelegate* delegate,
96 OVERRIDE; 117 scoped_ptr<DistillerPage> distiller_page,
97 virtual scoped_ptr<ViewerHandle> ViewUrl(ViewRequestDelegate* delegate, 118 const std::string& entry_id) OVERRIDE;
98 const GURL& url) OVERRIDE; 119 virtual scoped_ptr<ViewerHandle> ViewUrl(
120 ViewRequestDelegate* delegate,
121 scoped_ptr<DistillerPage> distiller_page,
122 const GURL& url) OVERRIDE;
123 virtual scoped_ptr<DistillerPage> CreateDefaultDistillerPage() OVERRIDE;
99 virtual void AddObserver(DomDistillerObserver* observer) OVERRIDE; 124 virtual void AddObserver(DomDistillerObserver* observer) OVERRIDE;
100 virtual void RemoveObserver(DomDistillerObserver* observer) OVERRIDE; 125 virtual void RemoveObserver(DomDistillerObserver* observer) OVERRIDE;
101 126
102 private: 127 private:
103 void CancelTask(TaskTracker* task); 128 void CancelTask(TaskTracker* task);
104 void AddDistilledPageToList(const ArticleEntry& entry, 129 void AddDistilledPageToList(const ArticleEntry& entry,
105 const DistilledArticleProto* article_proto, 130 const DistilledArticleProto* article_proto,
106 bool distillation_succeeded); 131 bool distillation_succeeded);
107 132
108 TaskTracker* CreateTaskTracker(const ArticleEntry& entry); 133 TaskTracker* CreateTaskTracker(const ArticleEntry& entry);
109 134
110 TaskTracker* GetTaskTrackerForEntry(const ArticleEntry& entry) const; 135 TaskTracker* GetTaskTrackerForEntry(const ArticleEntry& entry) const;
111 136
112 // Gets the task tracker for the given |url| or |entry|. If no appropriate 137 // 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 138 // tracker exists, this will create one, initialize it, and add it to
114 // |tasks_|. 139 // |tasks_|.
115 TaskTracker* GetOrCreateTaskTrackerForUrl(const GURL& url); 140 TaskTracker* GetOrCreateTaskTrackerForUrl(const GURL& url);
116 TaskTracker* GetOrCreateTaskTrackerForEntry(const ArticleEntry& entry); 141 TaskTracker* GetOrCreateTaskTrackerForEntry(const ArticleEntry& entry);
117 142
118 scoped_ptr<DomDistillerStoreInterface> store_; 143 scoped_ptr<DomDistillerStoreInterface> store_;
119 scoped_ptr<DistilledContentStore> content_store_; 144 scoped_ptr<DistilledContentStore> content_store_;
120 scoped_ptr<DistillerFactory> distiller_factory_; 145 scoped_ptr<DistillerFactory> distiller_factory_;
146 scoped_ptr<DistillerPageFactory> distiller_page_factory_;
121 147
122 typedef ScopedVector<TaskTracker> TaskList; 148 typedef ScopedVector<TaskTracker> TaskList;
123 TaskList tasks_; 149 TaskList tasks_;
124 150
125 DISALLOW_COPY_AND_ASSIGN(DomDistillerService); 151 DISALLOW_COPY_AND_ASSIGN(DomDistillerService);
126 }; 152 };
127 153
128 } // namespace dom_distiller 154 } // namespace dom_distiller
129 155
130 #endif // COMPONENTS_DOM_DISTILLER_CORE_DOM_DISTILLER_SERVICE_H_ 156 #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