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

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

Issue 1879613003: Convert //components/dom_distiller from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 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
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 <memory>
8 #include <string> 9 #include <string>
9 #include <vector> 10 #include <vector>
10 11
11 #include "base/callback.h" 12 #include "base/callback.h"
12 #include "base/macros.h" 13 #include "base/macros.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/scoped_vector.h" 14 #include "base/memory/scoped_vector.h"
15 #include "base/memory/weak_ptr.h" 15 #include "base/memory/weak_ptr.h"
16 #include "components/dom_distiller/core/article_entry.h" 16 #include "components/dom_distiller/core/article_entry.h"
17 #include "components/dom_distiller/core/distilled_page_prefs.h" 17 #include "components/dom_distiller/core/distilled_page_prefs.h"
18 #include "components/dom_distiller/core/distiller_page.h" 18 #include "components/dom_distiller/core/distiller_page.h"
19 19
20 class GURL; 20 class GURL;
21 21
22 namespace syncer { 22 namespace syncer {
23 class SyncableService; 23 class SyncableService;
(...skipping 22 matching lines...) Expand all
46 virtual syncer::SyncableService* GetSyncableService() const = 0; 46 virtual syncer::SyncableService* GetSyncableService() const = 0;
47 47
48 // Distill the article at |url| and add the resulting entry to the DOM 48 // Distill the article at |url| and add the resulting entry to the DOM
49 // distiller list. |article_cb| is always invoked, and the bool argument to it 49 // distiller list. |article_cb| is always invoked, and the bool argument to it
50 // represents whether the article is available offline. 50 // represents whether the article is available offline.
51 // Use CreateDefaultDistillerPage() to create a default |distiller_page|. 51 // Use CreateDefaultDistillerPage() to create a default |distiller_page|.
52 // The provided |distiller_page| is only used if there is not already a 52 // The provided |distiller_page| is only used if there is not already a
53 // distillation task in progress for the given |url|. 53 // distillation task in progress for the given |url|.
54 virtual const std::string AddToList( 54 virtual const std::string AddToList(
55 const GURL& url, 55 const GURL& url,
56 scoped_ptr<DistillerPage> distiller_page, 56 std::unique_ptr<DistillerPage> distiller_page,
57 const ArticleAvailableCallback& article_cb) = 0; 57 const ArticleAvailableCallback& article_cb) = 0;
58 58
59 // Returns whether an article stored has the given entry id. 59 // Returns whether an article stored has the given entry id.
60 virtual bool HasEntry(const std::string& entry_id) = 0; 60 virtual bool HasEntry(const std::string& entry_id) = 0;
61 61
62 // Returns the source URL given an entry ID. If the entry ID article has 62 // Returns the source URL given an entry ID. If the entry ID article has
63 // multiple pages, this will return the URL of the first page. Returns an 63 // multiple pages, this will return the URL of the first page. Returns an
64 // empty string if there is no entry associated with the given entry ID. 64 // empty string if there is no entry associated with the given entry ID.
65 virtual std::string GetUrlForEntry(const std::string& entry_id) = 0; 65 virtual std::string GetUrlForEntry(const std::string& entry_id) = 0;
66 66
67 // Gets the full list of entries. 67 // Gets the full list of entries.
68 virtual std::vector<ArticleEntry> GetEntries() const = 0; 68 virtual std::vector<ArticleEntry> GetEntries() const = 0;
69 69
70 // Removes the specified entry from the dom distiller store. 70 // Removes the specified entry from the dom distiller store.
71 virtual scoped_ptr<ArticleEntry> RemoveEntry(const std::string& entry_id) = 0; 71 virtual std::unique_ptr<ArticleEntry> RemoveEntry(
72 const std::string& entry_id) = 0;
72 73
73 // Request to view an article by entry id. Returns a null pointer if no entry 74 // Request to view an article by entry id. Returns a null pointer if no entry
74 // with |entry_id| exists. The ViewerHandle should be destroyed before the 75 // with |entry_id| exists. The ViewerHandle should be destroyed before the
75 // ViewRequestDelegate. The request will be cancelled when the handle is 76 // ViewRequestDelegate. The request will be cancelled when the handle is
76 // destroyed (or when this service is destroyed), which also ensures that 77 // destroyed (or when this service is destroyed), which also ensures that
77 // the |delegate| is not called after that. 78 // the |delegate| is not called after that.
78 // Use CreateDefaultDistillerPage() to create a default |distiller_page|. 79 // Use CreateDefaultDistillerPage() to create a default |distiller_page|.
79 // The provided |distiller_page| is only used if there is not already a 80 // The provided |distiller_page| is only used if there is not already a
80 // distillation task in progress for the given |entry_id|. 81 // distillation task in progress for the given |entry_id|.
81 virtual scoped_ptr<ViewerHandle> ViewEntry( 82 virtual std::unique_ptr<ViewerHandle> ViewEntry(
82 ViewRequestDelegate* delegate, 83 ViewRequestDelegate* delegate,
83 scoped_ptr<DistillerPage> distiller_page, 84 std::unique_ptr<DistillerPage> distiller_page,
84 const std::string& entry_id) = 0; 85 const std::string& entry_id) = 0;
85 86
86 // Request to view an article by url. 87 // Request to view an article by url.
87 // Use CreateDefaultDistillerPage() to create a default |distiller_page|. 88 // Use CreateDefaultDistillerPage() to create a default |distiller_page|.
88 // The provided |distiller_page| is only used if there is not already a 89 // The provided |distiller_page| is only used if there is not already a
89 // distillation task in progress for the given |url|. 90 // distillation task in progress for the given |url|.
90 virtual scoped_ptr<ViewerHandle> ViewUrl( 91 virtual std::unique_ptr<ViewerHandle> ViewUrl(
91 ViewRequestDelegate* delegate, 92 ViewRequestDelegate* delegate,
92 scoped_ptr<DistillerPage> distiller_page, 93 std::unique_ptr<DistillerPage> distiller_page,
93 const GURL& url) = 0; 94 const GURL& url) = 0;
94 95
95 // Creates a default DistillerPage. 96 // Creates a default DistillerPage.
96 virtual scoped_ptr<DistillerPage> CreateDefaultDistillerPage( 97 virtual std::unique_ptr<DistillerPage> CreateDefaultDistillerPage(
97 const gfx::Size& render_view_size) = 0; 98 const gfx::Size& render_view_size) = 0;
98 virtual scoped_ptr<DistillerPage> CreateDefaultDistillerPageWithHandle( 99 virtual std::unique_ptr<DistillerPage> CreateDefaultDistillerPageWithHandle(
99 scoped_ptr<SourcePageHandle> handle) = 0; 100 std::unique_ptr<SourcePageHandle> handle) = 0;
100 101
101 virtual void AddObserver(DomDistillerObserver* observer) = 0; 102 virtual void AddObserver(DomDistillerObserver* observer) = 0;
102 virtual void RemoveObserver(DomDistillerObserver* observer) = 0; 103 virtual void RemoveObserver(DomDistillerObserver* observer) = 0;
103 104
104 // Returns the DistilledPagePrefs owned by the instance of 105 // Returns the DistilledPagePrefs owned by the instance of
105 // DomDistillerService. 106 // DomDistillerService.
106 virtual DistilledPagePrefs* GetDistilledPagePrefs() = 0; 107 virtual DistilledPagePrefs* GetDistilledPagePrefs() = 0;
107 108
108 protected: 109 protected:
109 DomDistillerServiceInterface() {} 110 DomDistillerServiceInterface() {}
110 111
111 private: 112 private:
112 DISALLOW_COPY_AND_ASSIGN(DomDistillerServiceInterface); 113 DISALLOW_COPY_AND_ASSIGN(DomDistillerServiceInterface);
113 }; 114 };
114 115
115 // Provide a view of the article list and ways of interacting with it. 116 // Provide a view of the article list and ways of interacting with it.
116 class DomDistillerService : public DomDistillerServiceInterface { 117 class DomDistillerService : public DomDistillerServiceInterface {
117 public: 118 public:
118 DomDistillerService(scoped_ptr<DomDistillerStoreInterface> store, 119 DomDistillerService(
119 scoped_ptr<DistillerFactory> distiller_factory, 120 std::unique_ptr<DomDistillerStoreInterface> store,
120 scoped_ptr<DistillerPageFactory> distiller_page_factory, 121 std::unique_ptr<DistillerFactory> distiller_factory,
121 scoped_ptr<DistilledPagePrefs> distilled_page_prefs); 122 std::unique_ptr<DistillerPageFactory> distiller_page_factory,
123 std::unique_ptr<DistilledPagePrefs> distilled_page_prefs);
122 ~DomDistillerService() override; 124 ~DomDistillerService() override;
123 125
124 // DomDistillerServiceInterface implementation. 126 // DomDistillerServiceInterface implementation.
125 syncer::SyncableService* GetSyncableService() const override; 127 syncer::SyncableService* GetSyncableService() const override;
126 const std::string AddToList( 128 const std::string AddToList(
127 const GURL& url, 129 const GURL& url,
128 scoped_ptr<DistillerPage> distiller_page, 130 std::unique_ptr<DistillerPage> distiller_page,
129 const ArticleAvailableCallback& article_cb) override; 131 const ArticleAvailableCallback& article_cb) override;
130 bool HasEntry(const std::string& entry_id) override; 132 bool HasEntry(const std::string& entry_id) override;
131 std::string GetUrlForEntry(const std::string& entry_id) override; 133 std::string GetUrlForEntry(const std::string& entry_id) override;
132 std::vector<ArticleEntry> GetEntries() const override; 134 std::vector<ArticleEntry> GetEntries() const override;
133 scoped_ptr<ArticleEntry> RemoveEntry(const std::string& entry_id) override; 135 std::unique_ptr<ArticleEntry> RemoveEntry(
134 scoped_ptr<ViewerHandle> ViewEntry(ViewRequestDelegate* delegate, 136 const std::string& entry_id) override;
135 scoped_ptr<DistillerPage> distiller_page, 137 std::unique_ptr<ViewerHandle> ViewEntry(
136 const std::string& entry_id) override; 138 ViewRequestDelegate* delegate,
137 scoped_ptr<ViewerHandle> ViewUrl(ViewRequestDelegate* delegate, 139 std::unique_ptr<DistillerPage> distiller_page,
138 scoped_ptr<DistillerPage> distiller_page, 140 const std::string& entry_id) override;
139 const GURL& url) override; 141 std::unique_ptr<ViewerHandle> ViewUrl(
140 scoped_ptr<DistillerPage> CreateDefaultDistillerPage( 142 ViewRequestDelegate* delegate,
143 std::unique_ptr<DistillerPage> distiller_page,
144 const GURL& url) override;
145 std::unique_ptr<DistillerPage> CreateDefaultDistillerPage(
141 const gfx::Size& render_view_size) override; 146 const gfx::Size& render_view_size) override;
142 scoped_ptr<DistillerPage> CreateDefaultDistillerPageWithHandle( 147 std::unique_ptr<DistillerPage> CreateDefaultDistillerPageWithHandle(
143 scoped_ptr<SourcePageHandle> handle) override; 148 std::unique_ptr<SourcePageHandle> handle) override;
144 void AddObserver(DomDistillerObserver* observer) override; 149 void AddObserver(DomDistillerObserver* observer) override;
145 void RemoveObserver(DomDistillerObserver* observer) override; 150 void RemoveObserver(DomDistillerObserver* observer) override;
146 DistilledPagePrefs* GetDistilledPagePrefs() override; 151 DistilledPagePrefs* GetDistilledPagePrefs() override;
147 152
148 private: 153 private:
149 void CancelTask(TaskTracker* task); 154 void CancelTask(TaskTracker* task);
150 void AddDistilledPageToList(const ArticleEntry& entry, 155 void AddDistilledPageToList(const ArticleEntry& entry,
151 const DistilledArticleProto* article_proto, 156 const DistilledArticleProto* article_proto,
152 bool distillation_succeeded); 157 bool distillation_succeeded);
153 158
154 TaskTracker* CreateTaskTracker(const ArticleEntry& entry); 159 TaskTracker* CreateTaskTracker(const ArticleEntry& entry);
155 160
156 TaskTracker* GetTaskTrackerForEntry(const ArticleEntry& entry) const; 161 TaskTracker* GetTaskTrackerForEntry(const ArticleEntry& entry) const;
157 TaskTracker* GetTaskTrackerForUrl(const GURL& url) const; 162 TaskTracker* GetTaskTrackerForUrl(const GURL& url) const;
158 163
159 // Gets the task tracker for the given |url| or |entry|. If no appropriate 164 // Gets the task tracker for the given |url| or |entry|. If no appropriate
160 // tracker exists, this will create one and put it in the |TaskTracker| 165 // tracker exists, this will create one and put it in the |TaskTracker|
161 // parameter passed into this function, initialize it, and add it to 166 // parameter passed into this function, initialize it, and add it to
162 // |tasks_|. If a |TaskTracker| needed to be created, these functions will 167 // |tasks_|. If a |TaskTracker| needed to be created, these functions will
163 // return true. 168 // return true.
164 bool GetOrCreateTaskTrackerForUrl(const GURL& url, 169 bool GetOrCreateTaskTrackerForUrl(const GURL& url,
165 TaskTracker** task_tracker); 170 TaskTracker** task_tracker);
166 bool GetOrCreateTaskTrackerForEntry(const ArticleEntry& entry, 171 bool GetOrCreateTaskTrackerForEntry(const ArticleEntry& entry,
167 TaskTracker** task_tracker); 172 TaskTracker** task_tracker);
168 173
169 scoped_ptr<DomDistillerStoreInterface> store_; 174 std::unique_ptr<DomDistillerStoreInterface> store_;
170 scoped_ptr<DistilledContentStore> content_store_; 175 std::unique_ptr<DistilledContentStore> content_store_;
171 scoped_ptr<DistillerFactory> distiller_factory_; 176 std::unique_ptr<DistillerFactory> distiller_factory_;
172 scoped_ptr<DistillerPageFactory> distiller_page_factory_; 177 std::unique_ptr<DistillerPageFactory> distiller_page_factory_;
173 scoped_ptr<DistilledPagePrefs> distilled_page_prefs_; 178 std::unique_ptr<DistilledPagePrefs> distilled_page_prefs_;
174 179
175 typedef ScopedVector<TaskTracker> TaskList; 180 typedef ScopedVector<TaskTracker> TaskList;
176 TaskList tasks_; 181 TaskList tasks_;
177 182
178 DISALLOW_COPY_AND_ASSIGN(DomDistillerService); 183 DISALLOW_COPY_AND_ASSIGN(DomDistillerService);
179 }; 184 };
180 185
181 } // namespace dom_distiller 186 } // namespace dom_distiller
182 187
183 #endif // COMPONENTS_DOM_DISTILLER_CORE_DOM_DISTILLER_SERVICE_H_ 188 #endif // COMPONENTS_DOM_DISTILLER_CORE_DOM_DISTILLER_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698