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

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

Issue 189833002: Add a DistilledContentStore (and an in-memory impl) (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 #include "components/dom_distiller/core/dom_distiller_service.h" 5 #include "components/dom_distiller/core/dom_distiller_service.h"
6 6
7 #include "base/guid.h" 7 #include "base/guid.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "components/dom_distiller/core/distilled_content_store.h"
9 #include "components/dom_distiller/core/dom_distiller_store.h" 10 #include "components/dom_distiller/core/dom_distiller_store.h"
10 #include "components/dom_distiller/core/proto/distilled_article.pb.h" 11 #include "components/dom_distiller/core/proto/distilled_article.pb.h"
11 #include "components/dom_distiller/core/task_tracker.h" 12 #include "components/dom_distiller/core/task_tracker.h"
12 #include "url/gurl.h" 13 #include "url/gurl.h"
13 14
14 namespace dom_distiller { 15 namespace dom_distiller {
15 16
16 namespace { 17 namespace {
17 18
18 ArticleEntry CreateSkeletonEntryForUrl(const GURL& url) { 19 ArticleEntry CreateSkeletonEntryForUrl(const GURL& url) {
(...skipping 12 matching lines...) Expand all
31 const DistilledArticleProto* article_proto, 32 const DistilledArticleProto* article_proto,
32 bool distillation_succeeded) { 33 bool distillation_succeeded) {
33 article_cb.Run(distillation_succeeded); 34 article_cb.Run(distillation_succeeded);
34 } 35 }
35 36
36 } // namespace 37 } // namespace
37 38
38 DomDistillerService::DomDistillerService( 39 DomDistillerService::DomDistillerService(
39 scoped_ptr<DomDistillerStoreInterface> store, 40 scoped_ptr<DomDistillerStoreInterface> store,
40 scoped_ptr<DistillerFactory> distiller_factory) 41 scoped_ptr<DistillerFactory> distiller_factory)
41 : store_(store.Pass()), distiller_factory_(distiller_factory.Pass()) {} 42 : store_(store.Pass()),
43 content_store_(new InMemoryContentStore()),
44 distiller_factory_(distiller_factory.Pass()) {}
42 45
43 DomDistillerService::~DomDistillerService() {} 46 DomDistillerService::~DomDistillerService() {}
44 47
45 syncer::SyncableService* DomDistillerService::GetSyncableService() const { 48 syncer::SyncableService* DomDistillerService::GetSyncableService() const {
46 return store_->GetSyncableService(); 49 return store_->GetSyncableService();
47 } 50 }
48 51
49 const std::string DomDistillerService::AddToList( 52 const std::string DomDistillerService::AddToList(
50 const GURL& url, 53 const GURL& url,
51 const ArticleAvailableCallback& article_cb) { 54 const ArticleAvailableCallback& article_cb) {
(...skipping 20 matching lines...) Expand all
72 75
73 if (!article_cb.is_null()) { 76 if (!article_cb.is_null()) {
74 task_tracker->AddSaveCallback( 77 task_tracker->AddSaveCallback(
75 base::Bind(&RunArticleAvailableCallback, article_cb)); 78 base::Bind(&RunArticleAvailableCallback, article_cb));
76 } 79 }
77 80
78 if (!is_already_added) { 81 if (!is_already_added) {
79 task_tracker->AddSaveCallback(base::Bind( 82 task_tracker->AddSaveCallback(base::Bind(
80 &DomDistillerService::AddDistilledPageToList, base::Unretained(this))); 83 &DomDistillerService::AddDistilledPageToList, base::Unretained(this)));
81 task_tracker->StartDistiller(distiller_factory_.get()); 84 task_tracker->StartDistiller(distiller_factory_.get());
85 task_tracker->StartBlobFetcher();
82 } 86 }
83 87
84 return task_tracker->GetEntryId(); 88 return task_tracker->GetEntryId();
85 } 89 }
86 90
87 std::vector<ArticleEntry> DomDistillerService::GetEntries() const { 91 std::vector<ArticleEntry> DomDistillerService::GetEntries() const {
88 return store_->GetEntries(); 92 return store_->GetEntries();
89 } 93 }
90 94
91 scoped_ptr<ArticleEntry> DomDistillerService::RemoveEntry( 95 scoped_ptr<ArticleEntry> DomDistillerService::RemoveEntry(
(...skipping 19 matching lines...) Expand all
111 ViewRequestDelegate* delegate, 115 ViewRequestDelegate* delegate,
112 const std::string& entry_id) { 116 const std::string& entry_id) {
113 ArticleEntry entry; 117 ArticleEntry entry;
114 if (!store_->GetEntryById(entry_id, &entry)) { 118 if (!store_->GetEntryById(entry_id, &entry)) {
115 return scoped_ptr<ViewerHandle>(); 119 return scoped_ptr<ViewerHandle>();
116 } 120 }
117 121
118 TaskTracker* task_tracker = GetOrCreateTaskTrackerForEntry(entry); 122 TaskTracker* task_tracker = GetOrCreateTaskTrackerForEntry(entry);
119 scoped_ptr<ViewerHandle> viewer_handle = task_tracker->AddViewer(delegate); 123 scoped_ptr<ViewerHandle> viewer_handle = task_tracker->AddViewer(delegate);
120 task_tracker->StartDistiller(distiller_factory_.get()); 124 task_tracker->StartDistiller(distiller_factory_.get());
125 task_tracker->StartBlobFetcher();
121 126
122 return viewer_handle.Pass(); 127 return viewer_handle.Pass();
123 } 128 }
124 129
125 scoped_ptr<ViewerHandle> DomDistillerService::ViewUrl( 130 scoped_ptr<ViewerHandle> DomDistillerService::ViewUrl(
126 ViewRequestDelegate* delegate, 131 ViewRequestDelegate* delegate,
127 const GURL& url) { 132 const GURL& url) {
128 if (!url.is_valid()) { 133 if (!url.is_valid()) {
129 return scoped_ptr<ViewerHandle>(); 134 return scoped_ptr<ViewerHandle>();
130 } 135 }
131 136
132 TaskTracker* task_tracker = GetOrCreateTaskTrackerForUrl(url); 137 TaskTracker* task_tracker = GetOrCreateTaskTrackerForUrl(url);
133 scoped_ptr<ViewerHandle> viewer_handle = task_tracker->AddViewer(delegate); 138 scoped_ptr<ViewerHandle> viewer_handle = task_tracker->AddViewer(delegate);
134 task_tracker->StartDistiller(distiller_factory_.get()); 139 task_tracker->StartDistiller(distiller_factory_.get());
140 task_tracker->StartBlobFetcher();
135 141
136 return viewer_handle.Pass(); 142 return viewer_handle.Pass();
137 } 143 }
138 144
139 TaskTracker* DomDistillerService::GetOrCreateTaskTrackerForUrl( 145 TaskTracker* DomDistillerService::GetOrCreateTaskTrackerForUrl(
140 const GURL& url) { 146 const GURL& url) {
141 ArticleEntry entry; 147 ArticleEntry entry;
142 if (store_->GetEntryByUrl(url, &entry)) { 148 if (store_->GetEntryByUrl(url, &entry)) {
143 return GetOrCreateTaskTrackerForEntry(entry); 149 return GetOrCreateTaskTrackerForEntry(entry);
144 } 150 }
(...skipping 25 matching lines...) Expand all
170 TaskTracker* task_tracker = GetTaskTrackerForEntry(entry); 176 TaskTracker* task_tracker = GetTaskTrackerForEntry(entry);
171 if (task_tracker == NULL) { 177 if (task_tracker == NULL) {
172 task_tracker = CreateTaskTracker(entry); 178 task_tracker = CreateTaskTracker(entry);
173 } 179 }
174 return task_tracker; 180 return task_tracker;
175 } 181 }
176 182
177 TaskTracker* DomDistillerService::CreateTaskTracker(const ArticleEntry& entry) { 183 TaskTracker* DomDistillerService::CreateTaskTracker(const ArticleEntry& entry) {
178 TaskTracker::CancelCallback cancel_callback = 184 TaskTracker::CancelCallback cancel_callback =
179 base::Bind(&DomDistillerService::CancelTask, base::Unretained(this)); 185 base::Bind(&DomDistillerService::CancelTask, base::Unretained(this));
180 TaskTracker* tracker = new TaskTracker(entry, cancel_callback); 186 TaskTracker* tracker =
187 new TaskTracker(entry, cancel_callback, content_store_.get());
181 tasks_.push_back(tracker); 188 tasks_.push_back(tracker);
182 return tracker; 189 return tracker;
183 } 190 }
184 191
185 void DomDistillerService::CancelTask(TaskTracker* task) { 192 void DomDistillerService::CancelTask(TaskTracker* task) {
186 TaskList::iterator it = std::find(tasks_.begin(), tasks_.end(), task); 193 TaskList::iterator it = std::find(tasks_.begin(), tasks_.end(), task);
187 if (it != tasks_.end()) { 194 if (it != tasks_.end()) {
188 tasks_.weak_erase(it); 195 tasks_.weak_erase(it);
189 base::MessageLoop::current()->DeleteSoon(FROM_HERE, task); 196 base::MessageLoop::current()->DeleteSoon(FROM_HERE, task);
190 } 197 }
(...skipping 16 matching lines...) Expand all
207 DCHECK(observer); 214 DCHECK(observer);
208 store_->AddObserver(observer); 215 store_->AddObserver(observer);
209 } 216 }
210 217
211 void DomDistillerService::RemoveObserver(DomDistillerObserver* observer) { 218 void DomDistillerService::RemoveObserver(DomDistillerObserver* observer) {
212 DCHECK(observer); 219 DCHECK(observer);
213 store_->RemoveObserver(observer); 220 store_->RemoveObserver(observer);
214 } 221 }
215 222
216 } // namespace dom_distiller 223 } // namespace dom_distiller
OLDNEW
« no previous file with comments | « components/dom_distiller/core/dom_distiller_service.h ('k') | components/dom_distiller/core/task_tracker.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698