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

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

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 #include "components/dom_distiller/core/task_tracker.h" 5 #include "components/dom_distiller/core/task_tracker.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/auto_reset.h" 10 #include "base/auto_reset.h"
(...skipping 26 matching lines...) Expand all
37 distilled_article_(), 37 distilled_article_(),
38 content_ready_(false), 38 content_ready_(false),
39 destruction_allowed_(true), 39 destruction_allowed_(true),
40 weak_ptr_factory_(this) {} 40 weak_ptr_factory_(this) {}
41 41
42 TaskTracker::~TaskTracker() { 42 TaskTracker::~TaskTracker() {
43 DCHECK(destruction_allowed_); 43 DCHECK(destruction_allowed_);
44 DCHECK(viewers_.empty()); 44 DCHECK(viewers_.empty());
45 } 45 }
46 46
47 void TaskTracker::StartDistiller(DistillerFactory* factory, 47 void TaskTracker::StartDistiller(
48 scoped_ptr<DistillerPage> distiller_page) { 48 DistillerFactory* factory,
49 std::unique_ptr<DistillerPage> distiller_page) {
49 if (distiller_) { 50 if (distiller_) {
50 return; 51 return;
51 } 52 }
52 if (entry_.pages_size() == 0) { 53 if (entry_.pages_size() == 0) {
53 return; 54 return;
54 } 55 }
55 GURL url(entry_.pages(0).url()); 56 GURL url(entry_.pages(0).url());
56 DCHECK(url.is_valid()); 57 DCHECK(url.is_valid());
57 58
58 distiller_ = factory->CreateDistillerForUrl(url); 59 distiller_ = factory->CreateDistillerForUrl(url);
(...skipping 16 matching lines...) Expand all
75 void TaskTracker::AddSaveCallback(const SaveCallback& callback) { 76 void TaskTracker::AddSaveCallback(const SaveCallback& callback) {
76 DCHECK(!callback.is_null()); 77 DCHECK(!callback.is_null());
77 save_callbacks_.push_back(callback); 78 save_callbacks_.push_back(callback);
78 if (content_ready_) { 79 if (content_ready_) {
79 // Distillation for this task has already completed, and so it can be 80 // Distillation for this task has already completed, and so it can be
80 // immediately saved. 81 // immediately saved.
81 ScheduleSaveCallbacks(true); 82 ScheduleSaveCallbacks(true);
82 } 83 }
83 } 84 }
84 85
85 scoped_ptr<ViewerHandle> TaskTracker::AddViewer(ViewRequestDelegate* delegate) { 86 std::unique_ptr<ViewerHandle> TaskTracker::AddViewer(
87 ViewRequestDelegate* delegate) {
86 viewers_.push_back(delegate); 88 viewers_.push_back(delegate);
87 if (content_ready_) { 89 if (content_ready_) {
88 // Distillation for this task has already completed, and so the delegate can 90 // Distillation for this task has already completed, and so the delegate can
89 // be immediately told of the result. 91 // be immediately told of the result.
90 base::ThreadTaskRunnerHandle::Get()->PostTask( 92 base::ThreadTaskRunnerHandle::Get()->PostTask(
91 FROM_HERE, base::Bind(&TaskTracker::NotifyViewer, 93 FROM_HERE, base::Bind(&TaskTracker::NotifyViewer,
92 weak_ptr_factory_.GetWeakPtr(), delegate)); 94 weak_ptr_factory_.GetWeakPtr(), delegate));
93 } 95 }
94 return scoped_ptr<ViewerHandle>(new ViewerHandle(base::Bind( 96 return std::unique_ptr<ViewerHandle>(new ViewerHandle(base::Bind(
95 &TaskTracker::RemoveViewer, weak_ptr_factory_.GetWeakPtr(), delegate))); 97 &TaskTracker::RemoveViewer, weak_ptr_factory_.GetWeakPtr(), delegate)));
96 } 98 }
97 99
98 const std::string& TaskTracker::GetEntryId() const { return entry_.entry_id(); } 100 const std::string& TaskTracker::GetEntryId() const { return entry_.entry_id(); }
99 101
100 bool TaskTracker::HasEntryId(const std::string& entry_id) const { 102 bool TaskTracker::HasEntryId(const std::string& entry_id) const {
101 return entry_.entry_id() == entry_id; 103 return entry_.entry_id() == entry_id;
102 } 104 }
103 105
104 bool TaskTracker::HasUrl(const GURL& url) const { 106 bool TaskTracker::HasUrl(const GURL& url) const {
(...skipping 28 matching lines...) Expand all
133 void TaskTracker::CancelSaveCallbacks() { ScheduleSaveCallbacks(false); } 135 void TaskTracker::CancelSaveCallbacks() { ScheduleSaveCallbacks(false); }
134 136
135 void TaskTracker::ScheduleSaveCallbacks(bool distillation_succeeded) { 137 void TaskTracker::ScheduleSaveCallbacks(bool distillation_succeeded) {
136 base::ThreadTaskRunnerHandle::Get()->PostTask( 138 base::ThreadTaskRunnerHandle::Get()->PostTask(
137 FROM_HERE, 139 FROM_HERE,
138 base::Bind(&TaskTracker::DoSaveCallbacks, weak_ptr_factory_.GetWeakPtr(), 140 base::Bind(&TaskTracker::DoSaveCallbacks, weak_ptr_factory_.GetWeakPtr(),
139 distillation_succeeded)); 141 distillation_succeeded));
140 } 142 }
141 143
142 void TaskTracker::OnDistillerFinished( 144 void TaskTracker::OnDistillerFinished(
143 scoped_ptr<DistilledArticleProto> distilled_article) { 145 std::unique_ptr<DistilledArticleProto> distilled_article) {
144 if (content_ready_) { 146 if (content_ready_) {
145 return; 147 return;
146 } 148 }
147 149
148 DistilledArticleReady(std::move(distilled_article)); 150 DistilledArticleReady(std::move(distilled_article));
149 if (content_ready_) { 151 if (content_ready_) {
150 AddDistilledContentToStore(*distilled_article_); 152 AddDistilledContentToStore(*distilled_article_);
151 } 153 }
152 154
153 // 'distiller_ != null' is used as a signal that distillation is in progress, 155 // 'distiller_ != null' is used as a signal that distillation is in progress,
154 // so it needs to be released so that we know distillation is done. 156 // so it needs to be released so that we know distillation is done.
155 base::MessageLoop::current()->DeleteSoon(FROM_HERE, distiller_.release()); 157 base::MessageLoop::current()->DeleteSoon(FROM_HERE, distiller_.release());
156 158
157 ContentSourceFinished(); 159 ContentSourceFinished();
158 } 160 }
159 161
160 void TaskTracker::CancelPendingSources() { 162 void TaskTracker::CancelPendingSources() {
161 if (distiller_) { 163 if (distiller_) {
162 base::MessageLoop::current()->DeleteSoon(FROM_HERE, distiller_.release()); 164 base::MessageLoop::current()->DeleteSoon(FROM_HERE, distiller_.release());
163 } 165 }
164 } 166 }
165 167
166 void TaskTracker::OnBlobFetched( 168 void TaskTracker::OnBlobFetched(
167 bool success, 169 bool success,
168 scoped_ptr<DistilledArticleProto> distilled_article) { 170 std::unique_ptr<DistilledArticleProto> distilled_article) {
169 blob_fetcher_running_ = false; 171 blob_fetcher_running_ = false;
170 172
171 if (content_ready_) { 173 if (content_ready_) {
172 return; 174 return;
173 } 175 }
174 176
175 DistilledArticleReady(std::move(distilled_article)); 177 DistilledArticleReady(std::move(distilled_article));
176 178
177 ContentSourceFinished(); 179 ContentSourceFinished();
178 } 180 }
179 181
180 bool TaskTracker::IsAnySourceRunning() const { 182 bool TaskTracker::IsAnySourceRunning() const {
181 return distiller_ || blob_fetcher_running_; 183 return distiller_ || blob_fetcher_running_;
182 } 184 }
183 185
184 void TaskTracker::ContentSourceFinished() { 186 void TaskTracker::ContentSourceFinished() {
185 if (content_ready_) { 187 if (content_ready_) {
186 CancelPendingSources(); 188 CancelPendingSources();
187 } else if (!IsAnySourceRunning()) { 189 } else if (!IsAnySourceRunning()) {
188 distilled_article_.reset(new DistilledArticleProto()); 190 distilled_article_.reset(new DistilledArticleProto());
189 NotifyViewersAndCallbacks(); 191 NotifyViewersAndCallbacks();
190 } 192 }
191 } 193 }
192 194
193 void TaskTracker::DistilledArticleReady( 195 void TaskTracker::DistilledArticleReady(
194 scoped_ptr<DistilledArticleProto> distilled_article) { 196 std::unique_ptr<DistilledArticleProto> distilled_article) {
195 DCHECK(!content_ready_); 197 DCHECK(!content_ready_);
196 198
197 if (distilled_article->pages_size() == 0) { 199 if (distilled_article->pages_size() == 0) {
198 return; 200 return;
199 } 201 }
200 202
201 content_ready_ = true; 203 content_ready_ = true;
202 204
203 distilled_article_ = std::move(distilled_article); 205 distilled_article_ = std::move(distilled_article);
204 entry_.set_title(distilled_article_->title()); 206 entry_.set_title(distilled_article_->title());
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 void TaskTracker::AddDistilledContentToStore( 249 void TaskTracker::AddDistilledContentToStore(
248 const DistilledArticleProto& content) { 250 const DistilledArticleProto& content) {
249 if (content_store_) { 251 if (content_store_) {
250 content_store_->SaveContent( 252 content_store_->SaveContent(
251 entry_, content, DistilledContentStore::SaveCallback()); 253 entry_, content, DistilledContentStore::SaveCallback());
252 } 254 }
253 } 255 }
254 256
255 257
256 } // namespace dom_distiller 258 } // namespace dom_distiller
OLDNEW
« no previous file with comments | « components/dom_distiller/core/task_tracker.h ('k') | components/dom_distiller/core/task_tracker_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698