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/task_tracker.h" | 5 #include "components/dom_distiller/core/task_tracker.h" |
6 | 6 |
7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
8 #include "components/dom_distiller/core/proto/distilled_article.pb.h" | 8 #include "components/dom_distiller/core/proto/distilled_article.pb.h" |
9 #include "components/dom_distiller/core/proto/distilled_page.pb.h" | 9 #include "components/dom_distiller/core/proto/distilled_page.pb.h" |
10 | 10 |
(...skipping 23 matching lines...) Expand all Loading... |
34 } | 34 } |
35 if (entry_.pages_size() == 0) { | 35 if (entry_.pages_size() == 0) { |
36 return; | 36 return; |
37 } | 37 } |
38 | 38 |
39 GURL url(entry_.pages(0).url()); | 39 GURL url(entry_.pages(0).url()); |
40 DCHECK(url.is_valid()); | 40 DCHECK(url.is_valid()); |
41 | 41 |
42 distiller_ = factory->CreateDistiller(); | 42 distiller_ = factory->CreateDistiller(); |
43 distiller_->DistillPage(url, | 43 distiller_->DistillPage(url, |
44 base::Bind(&TaskTracker::OnDistilledDataReady, | 44 base::Bind(&TaskTracker::OnDistilledArticleReady, |
| 45 weak_ptr_factory_.GetWeakPtr()), |
| 46 base::Bind(&TaskTracker::OnArticleDistillationUpdated, |
45 weak_ptr_factory_.GetWeakPtr())); | 47 weak_ptr_factory_.GetWeakPtr())); |
46 } | 48 } |
47 | 49 |
48 void TaskTracker::StartBlobFetcher() { | 50 void TaskTracker::StartBlobFetcher() { |
49 // TODO(cjhopman): There needs to be some local storage for the distilled | 51 // TODO(cjhopman): There needs to be some local storage for the distilled |
50 // blob. When that happens, this should start some task to fetch the blob for | 52 // blob. When that happens, this should start some task to fetch the blob for |
51 // |entry_| and asynchronously notify |this| when it is done. | 53 // |entry_| and asynchronously notify |this| when it is done. |
52 } | 54 } |
53 | 55 |
54 void TaskTracker::AddSaveCallback(const SaveCallback& callback) { | 56 void TaskTracker::AddSaveCallback(const SaveCallback& callback) { |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 save_callbacks_.clear(); | 134 save_callbacks_.clear(); |
133 MaybeCancel(); | 135 MaybeCancel(); |
134 } | 136 } |
135 } | 137 } |
136 | 138 |
137 void TaskTracker::NotifyViewer(ViewRequestDelegate* delegate) { | 139 void TaskTracker::NotifyViewer(ViewRequestDelegate* delegate) { |
138 DCHECK(distillation_complete_); | 140 DCHECK(distillation_complete_); |
139 delegate->OnArticleReady(distilled_article_.get()); | 141 delegate->OnArticleReady(distilled_article_.get()); |
140 } | 142 } |
141 | 143 |
142 void TaskTracker::OnDistilledDataReady( | 144 void TaskTracker::OnDistilledArticleReady( |
143 scoped_ptr<DistilledArticleProto> distilled_article) { | 145 scoped_ptr<DistilledArticleProto> distilled_article) { |
144 distilled_article_ = distilled_article.Pass(); | 146 distilled_article_ = distilled_article.Pass(); |
145 bool distillation_successful = false; | 147 bool distillation_successful = false; |
146 if (distilled_article_->pages_size() > 0) { | 148 if (distilled_article_->pages_size() > 0) { |
147 distillation_successful = true; | 149 distillation_successful = true; |
148 entry_.set_title(distilled_article_->title()); | 150 entry_.set_title(distilled_article_->title()); |
149 // Reset the pages. | 151 // Reset the pages. |
150 entry_.clear_pages(); | 152 entry_.clear_pages(); |
151 for (int i = 0; i < distilled_article_->pages_size(); ++i) { | 153 for (int i = 0; i < distilled_article_->pages_size(); ++i) { |
152 sync_pb::ArticlePage* page = entry_.add_pages(); | 154 sync_pb::ArticlePage* page = entry_.add_pages(); |
153 page->set_url(distilled_article_->pages(i).url()); | 155 page->set_url(distilled_article_->pages(i).url()); |
154 } | 156 } |
155 } | 157 } |
156 | 158 |
157 distillation_complete_ = true; | 159 distillation_complete_ = true; |
158 | 160 |
159 for (size_t i = 0; i < viewers_.size(); ++i) { | 161 for (size_t i = 0; i < viewers_.size(); ++i) { |
160 NotifyViewer(viewers_[i]); | 162 NotifyViewer(viewers_[i]); |
161 } | 163 } |
162 | 164 |
163 // Already inside a callback run SaveCallbacks directly. | 165 // Already inside a callback run SaveCallbacks directly. |
164 DoSaveCallbacks(distillation_successful); | 166 DoSaveCallbacks(distillation_successful); |
165 } | 167 } |
166 | 168 |
| 169 void TaskTracker::OnArticleDistillationUpdated( |
| 170 const ArticleDistillationUpdate& article_update) { |
| 171 for (size_t i = 0; i < viewers_.size(); ++i) { |
| 172 viewers_[i]->OnArticleUpdated(article_update); |
| 173 } |
| 174 } |
| 175 |
167 } // namespace dom_distiller | 176 } // namespace dom_distiller |
OLD | NEW |