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

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

Issue 151003006: Add support for distilling arbitrary URLs in DOM Distiller Viewer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comments. added unit tests Created 6 years, 10 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
(...skipping 12 matching lines...) Expand all
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 // Calls to, construction and destruction of this service must happen on the
cjhopman 2014/02/25 22:25:14 This comma reads like a typo; i.e. that you meant
nyquist 2014/02/27 00:07:37 Done.
35 // same thread. All callbacks will also be called on the caller's thread.
cjhopman 2014/02/25 22:25:14 I'd say: Callbacks will be called on that same thr
nyquist 2014/02/27 00:07:37 Done.
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 invoked with true if article is
46 // available offline. 45 // available offline.
cjhopman 2014/02/25 22:25:14 Clarify the callback part of this: is it always ca
nyquist 2014/02/27 00:07:37 Done.
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).
cjhopman 2014/02/25 22:25:14 We should be clear about how we will handle the Vi
nyquist 2014/02/27 00:07:37 Done.
60 scoped_ptr<ViewerHandle> ViewEntry(ViewRequestDelegate* delegate, 60 virtual scoped_ptr<ViewerHandle> ViewEntry(ViewRequestDelegate* delegate,
61 const std::string& entry_id); 61 const std::string& entry_id) = 0;
62 62
63 // Request to view an article by url. 63 // Request to view an article by url.
64 scoped_ptr<ViewerHandle> ViewUrl(ViewRequestDelegate* delegate, 64 virtual scoped_ptr<ViewerHandle> ViewUrl(ViewRequestDelegate* delegate,
65 const GURL& url); 65 const GURL& url) = 0;
66 66
67 void AddObserver(DomDistillerObserver* observer); 67 virtual void AddObserver(DomDistillerObserver* observer) = 0;
68 void RemoveObserver(DomDistillerObserver* observer); 68 virtual void RemoveObserver(DomDistillerObserver* observer) = 0;
shashi 2014/02/25 21:48:08 Should the interface also have DISALLOW_COPY_AND_A
nyquist 2014/02/27 00:07:37 Done.
69 };
70
71 // Provide a view of the article list and ways of interacting with it.
72 class DomDistillerService : public DomDistillerServiceInterface {
73 public:
74 DomDistillerService(scoped_ptr<DomDistillerStoreInterface> store,
75 scoped_ptr<DistillerFactory> distiller_factory);
76 virtual ~DomDistillerService();
77
78 // DomDistillerServiceInterface implementation.
79 virtual syncer::SyncableService* GetSyncableService() const OVERRIDE;
80 virtual const std::string AddToList(
81 const GURL& url,
82 const ArticleAvailableCallback& article_cb) OVERRIDE;
83 virtual std::vector<ArticleEntry> GetEntries() const OVERRIDE;
84 virtual scoped_ptr<ArticleEntry> RemoveEntry(const std::string& entry_id)
85 OVERRIDE;
86 virtual scoped_ptr<ViewerHandle> ViewEntry(ViewRequestDelegate* delegate,
87 const std::string& entry_id)
88 OVERRIDE;
89 virtual scoped_ptr<ViewerHandle> ViewUrl(ViewRequestDelegate* delegate,
90 const GURL& url) OVERRIDE;
91 virtual void AddObserver(DomDistillerObserver* observer) OVERRIDE;
92 virtual void RemoveObserver(DomDistillerObserver* observer) OVERRIDE;
69 93
70 private: 94 private:
71 void CancelTask(TaskTracker* task); 95 void CancelTask(TaskTracker* task);
72 void AddDistilledPageToList(const ArticleEntry& entry, 96 void AddDistilledPageToList(const ArticleEntry& entry,
73 const DistilledArticleProto* article_proto, 97 const DistilledArticleProto* article_proto,
74 bool distillation_succeeded); 98 bool distillation_succeeded);
75 99
76 TaskTracker* CreateTaskTracker(const ArticleEntry& entry); 100 TaskTracker* CreateTaskTracker(const ArticleEntry& entry);
77 101
78 TaskTracker* GetTaskTrackerForEntry(const ArticleEntry& entry) const; 102 TaskTracker* GetTaskTrackerForEntry(const ArticleEntry& entry) const;
79 103
80 // Gets the task tracker for the given |url| or |entry|. If no appropriate 104 // 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 105 // tracker exists, this will create one, initialize it, and add it to
82 // |tasks_|. 106 // |tasks_|.
83 TaskTracker* GetOrCreateTaskTrackerForUrl(const GURL& url); 107 TaskTracker* GetOrCreateTaskTrackerForUrl(const GURL& url);
84 TaskTracker* GetOrCreateTaskTrackerForEntry(const ArticleEntry& entry); 108 TaskTracker* GetOrCreateTaskTrackerForEntry(const ArticleEntry& entry);
85 109
86 scoped_ptr<DomDistillerStoreInterface> store_; 110 scoped_ptr<DomDistillerStoreInterface> store_;
87 scoped_ptr<DistillerFactory> distiller_factory_; 111 scoped_ptr<DistillerFactory> distiller_factory_;
88 112
89 typedef ScopedVector<TaskTracker> TaskList; 113 typedef ScopedVector<TaskTracker> TaskList;
90 TaskList tasks_; 114 TaskList tasks_;
91 115
92 DISALLOW_COPY_AND_ASSIGN(DomDistillerService); 116 DISALLOW_COPY_AND_ASSIGN(DomDistillerService);
93 }; 117 };
94 118
95 } // namespace dom_distiller 119 } // namespace dom_distiller
96 120
97 #endif // COMPONENTS_DOM_DISTILLER_CORE_DOM_DISTILLER_SERVICE_H_ 121 #endif // COMPONENTS_DOM_DISTILLER_CORE_DOM_DISTILLER_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698