OLD | NEW |
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/dom_distiller_store.h" | 9 #include "components/dom_distiller/core/dom_distiller_store.h" |
| 10 #include "components/dom_distiller/core/proto/distilled_article.pb.h" |
10 #include "components/dom_distiller/core/task_tracker.h" | 11 #include "components/dom_distiller/core/task_tracker.h" |
11 #include "url/gurl.h" | 12 #include "url/gurl.h" |
12 | 13 |
13 namespace dom_distiller { | 14 namespace dom_distiller { |
14 | 15 |
15 namespace { | 16 namespace { |
16 | 17 |
17 ArticleEntry CreateSkeletonEntryForUrl(const GURL& url) { | 18 ArticleEntry CreateSkeletonEntryForUrl(const GURL& url) { |
18 ArticleEntry skeleton; | 19 ArticleEntry skeleton; |
19 skeleton.set_entry_id(base::GenerateGUID()); | 20 skeleton.set_entry_id(base::GenerateGUID()); |
20 ArticleEntryPage* page = skeleton.add_pages(); | 21 ArticleEntryPage* page = skeleton.add_pages(); |
21 page->set_url(url.spec()); | 22 page->set_url(url.spec()); |
22 | 23 |
23 DCHECK(IsEntryValid(skeleton)); | 24 DCHECK(IsEntryValid(skeleton)); |
24 return skeleton; | 25 return skeleton; |
25 } | 26 } |
26 | 27 |
27 void RunArticleAvailableCallback( | 28 void RunArticleAvailableCallback( |
28 const DomDistillerService::ArticleAvailableCallback& article_cb, | 29 const DomDistillerService::ArticleAvailableCallback& article_cb, |
29 const ArticleEntry& entry, | 30 const ArticleEntry& entry, |
30 DistilledPageProto* proto, | 31 const DistilledArticleProto* article_proto, |
31 bool distillation_succeeded) { | 32 bool distillation_succeeded) { |
32 article_cb.Run(distillation_succeeded); | 33 article_cb.Run(distillation_succeeded); |
33 } | 34 } |
34 | 35 |
35 } // namespace | 36 } // namespace |
36 | 37 |
37 DomDistillerService::DomDistillerService( | 38 DomDistillerService::DomDistillerService( |
38 scoped_ptr<DomDistillerStoreInterface> store, | 39 scoped_ptr<DomDistillerStoreInterface> store, |
39 scoped_ptr<DistillerFactory> distiller_factory) | 40 scoped_ptr<DistillerFactory> distiller_factory) |
40 : store_(store.Pass()), distiller_factory_(distiller_factory.Pass()) {} | 41 : store_(store.Pass()), distiller_factory_(distiller_factory.Pass()) {} |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 } | 183 } |
183 | 184 |
184 void DomDistillerService::CancelTask(TaskTracker* task) { | 185 void DomDistillerService::CancelTask(TaskTracker* task) { |
185 TaskList::iterator it = std::find(tasks_.begin(), tasks_.end(), task); | 186 TaskList::iterator it = std::find(tasks_.begin(), tasks_.end(), task); |
186 if (it != tasks_.end()) { | 187 if (it != tasks_.end()) { |
187 tasks_.weak_erase(it); | 188 tasks_.weak_erase(it); |
188 base::MessageLoop::current()->DeleteSoon(FROM_HERE, task); | 189 base::MessageLoop::current()->DeleteSoon(FROM_HERE, task); |
189 } | 190 } |
190 } | 191 } |
191 | 192 |
192 void DomDistillerService::AddDistilledPageToList(const ArticleEntry& entry, | 193 void DomDistillerService::AddDistilledPageToList( |
193 DistilledPageProto* proto, | 194 const ArticleEntry& entry, |
194 bool distillation_succeeded) { | 195 const DistilledArticleProto* article_proto, |
| 196 bool distillation_succeeded) { |
195 DCHECK(IsEntryValid(entry)); | 197 DCHECK(IsEntryValid(entry)); |
196 if (distillation_succeeded) { | 198 if (distillation_succeeded) { |
197 DCHECK(proto); | 199 DCHECK(article_proto); |
| 200 DCHECK_GT(article_proto->pages_size(), 0); |
198 store_->UpdateEntry(entry); | 201 store_->UpdateEntry(entry); |
| 202 DCHECK_EQ(article_proto->pages_size(), entry.pages_size()); |
199 } | 203 } |
200 } | 204 } |
201 | 205 |
202 void DomDistillerService::AddObserver(DomDistillerObserver* observer) { | 206 void DomDistillerService::AddObserver(DomDistillerObserver* observer) { |
203 DCHECK(observer); | 207 DCHECK(observer); |
204 store_->AddObserver(observer); | 208 store_->AddObserver(observer); |
205 } | 209 } |
206 | 210 |
207 void DomDistillerService::RemoveObserver(DomDistillerObserver* observer) { | 211 void DomDistillerService::RemoveObserver(DomDistillerObserver* observer) { |
208 DCHECK(observer); | 212 DCHECK(observer); |
209 store_->RemoveObserver(observer); | 213 store_->RemoveObserver(observer); |
210 } | 214 } |
211 | 215 |
212 } // namespace dom_distiller | 216 } // namespace dom_distiller |
OLD | NEW |