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

Side by Side Diff: chrome/browser/sync_file_system/drive_backend/sync_task_manager.cc

Issue 1873683002: Convert //chrome/browser/sync_file_system from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "chrome/browser/sync_file_system/drive_backend/sync_task_manager.h" 5 #include "chrome/browser/sync_file_system/drive_backend/sync_task_manager.h"
6 6
7 #include <memory>
7 #include <utility> 8 #include <utility>
8 9
9 #include "base/bind.h" 10 #include "base/bind.h"
10 #include "base/location.h" 11 #include "base/location.h"
11 #include "base/macros.h" 12 #include "base/macros.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/sequenced_task_runner.h" 13 #include "base/sequenced_task_runner.h"
14 #include "chrome/browser/sync_file_system/drive_backend/sync_task.h" 14 #include "chrome/browser/sync_file_system/drive_backend/sync_task.h"
15 #include "chrome/browser/sync_file_system/drive_backend/sync_task_token.h" 15 #include "chrome/browser/sync_file_system/drive_backend/sync_task_token.h"
16 #include "chrome/browser/sync_file_system/sync_file_metadata.h" 16 #include "chrome/browser/sync_file_system/sync_file_metadata.h"
17 17
18 using storage::FileSystemURL; 18 using storage::FileSystemURL;
19 19
20 namespace sync_file_system { 20 namespace sync_file_system {
21 namespace drive_backend { 21 namespace drive_backend {
22 22
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 } 88 }
89 89
90 void SyncTaskManager::ScheduleTask( 90 void SyncTaskManager::ScheduleTask(
91 const tracked_objects::Location& from_here, 91 const tracked_objects::Location& from_here,
92 const Task& task, 92 const Task& task,
93 Priority priority, 93 Priority priority,
94 const SyncStatusCallback& callback) { 94 const SyncStatusCallback& callback) {
95 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); 95 DCHECK(sequence_checker_.CalledOnValidSequencedThread());
96 96
97 ScheduleSyncTask(from_here, 97 ScheduleSyncTask(from_here,
98 scoped_ptr<SyncTask>(new SyncTaskAdapter(task)), 98 std::unique_ptr<SyncTask>(new SyncTaskAdapter(task)),
99 priority, 99 priority, callback);
100 callback);
101 } 100 }
102 101
103 void SyncTaskManager::ScheduleSyncTask( 102 void SyncTaskManager::ScheduleSyncTask(
104 const tracked_objects::Location& from_here, 103 const tracked_objects::Location& from_here,
105 scoped_ptr<SyncTask> task, 104 std::unique_ptr<SyncTask> task,
106 Priority priority, 105 Priority priority,
107 const SyncStatusCallback& callback) { 106 const SyncStatusCallback& callback) {
108 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); 107 DCHECK(sequence_checker_.CalledOnValidSequencedThread());
109 108
110 scoped_ptr<SyncTaskToken> token(GetToken(from_here, callback)); 109 std::unique_ptr<SyncTaskToken> token(GetToken(from_here, callback));
111 if (!token) { 110 if (!token) {
112 PushPendingTask( 111 PushPendingTask(
113 base::Bind(&SyncTaskManager::ScheduleSyncTask, 112 base::Bind(&SyncTaskManager::ScheduleSyncTask,
114 weak_ptr_factory_.GetWeakPtr(), from_here, 113 weak_ptr_factory_.GetWeakPtr(), from_here,
115 base::Passed(&task), priority, callback), 114 base::Passed(&task), priority, callback),
116 priority); 115 priority);
117 return; 116 return;
118 } 117 }
119 RunTask(std::move(token), std::move(task)); 118 RunTask(std::move(token), std::move(task));
120 } 119 }
121 120
122 bool SyncTaskManager::ScheduleTaskIfIdle( 121 bool SyncTaskManager::ScheduleTaskIfIdle(
123 const tracked_objects::Location& from_here, 122 const tracked_objects::Location& from_here,
124 const Task& task, 123 const Task& task,
125 const SyncStatusCallback& callback) { 124 const SyncStatusCallback& callback) {
126 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); 125 DCHECK(sequence_checker_.CalledOnValidSequencedThread());
127 126
128 return ScheduleSyncTaskIfIdle( 127 return ScheduleSyncTaskIfIdle(
129 from_here, 128 from_here, std::unique_ptr<SyncTask>(new SyncTaskAdapter(task)),
130 scoped_ptr<SyncTask>(new SyncTaskAdapter(task)),
131 callback); 129 callback);
132 } 130 }
133 131
134 bool SyncTaskManager::ScheduleSyncTaskIfIdle( 132 bool SyncTaskManager::ScheduleSyncTaskIfIdle(
135 const tracked_objects::Location& from_here, 133 const tracked_objects::Location& from_here,
136 scoped_ptr<SyncTask> task, 134 std::unique_ptr<SyncTask> task,
137 const SyncStatusCallback& callback) { 135 const SyncStatusCallback& callback) {
138 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); 136 DCHECK(sequence_checker_.CalledOnValidSequencedThread());
139 137
140 scoped_ptr<SyncTaskToken> token(GetToken(from_here, callback)); 138 std::unique_ptr<SyncTaskToken> token(GetToken(from_here, callback));
141 if (!token) 139 if (!token)
142 return false; 140 return false;
143 RunTask(std::move(token), std::move(task)); 141 RunTask(std::move(token), std::move(task));
144 return true; 142 return true;
145 } 143 }
146 144
147 // static 145 // static
148 void SyncTaskManager::NotifyTaskDone(scoped_ptr<SyncTaskToken> token, 146 void SyncTaskManager::NotifyTaskDone(std::unique_ptr<SyncTaskToken> token,
149 SyncStatusCode status) { 147 SyncStatusCode status) {
150 DCHECK(token); 148 DCHECK(token);
151 149
152 SyncTaskManager* manager = token->manager(); 150 SyncTaskManager* manager = token->manager();
153 if (token->token_id() == SyncTaskToken::kTestingTaskTokenID) { 151 if (token->token_id() == SyncTaskToken::kTestingTaskTokenID) {
154 DCHECK(!manager); 152 DCHECK(!manager);
155 SyncStatusCallback callback = token->callback(); 153 SyncStatusCallback callback = token->callback();
156 token->clear_callback(); 154 token->clear_callback();
157 callback.Run(status); 155 callback.Run(status);
158 return; 156 return;
159 } 157 }
160 158
161 if (manager) 159 if (manager)
162 manager->NotifyTaskDoneBody(std::move(token), status); 160 manager->NotifyTaskDoneBody(std::move(token), status);
163 } 161 }
164 162
165 // static 163 // static
166 void SyncTaskManager::UpdateTaskBlocker( 164 void SyncTaskManager::UpdateTaskBlocker(
167 scoped_ptr<SyncTaskToken> current_task_token, 165 std::unique_ptr<SyncTaskToken> current_task_token,
168 scoped_ptr<TaskBlocker> task_blocker, 166 std::unique_ptr<TaskBlocker> task_blocker,
169 const Continuation& continuation) { 167 const Continuation& continuation) {
170 DCHECK(current_task_token); 168 DCHECK(current_task_token);
171 169
172 SyncTaskManager* manager = current_task_token->manager(); 170 SyncTaskManager* manager = current_task_token->manager();
173 if (current_task_token->token_id() == SyncTaskToken::kTestingTaskTokenID) { 171 if (current_task_token->token_id() == SyncTaskToken::kTestingTaskTokenID) {
174 DCHECK(!manager); 172 DCHECK(!manager);
175 continuation.Run(std::move(current_task_token)); 173 continuation.Run(std::move(current_task_token));
176 return; 174 return;
177 } 175 }
178 176
179 if (!manager) 177 if (!manager)
180 return; 178 return;
181 179
182 scoped_ptr<SyncTaskToken> foreground_task_token; 180 std::unique_ptr<SyncTaskToken> foreground_task_token;
183 scoped_ptr<SyncTaskToken> background_task_token; 181 std::unique_ptr<SyncTaskToken> background_task_token;
184 scoped_ptr<TaskLogger::TaskLog> task_log = current_task_token->PassTaskLog(); 182 std::unique_ptr<TaskLogger::TaskLog> task_log =
183 current_task_token->PassTaskLog();
185 if (current_task_token->token_id() == SyncTaskToken::kForegroundTaskTokenID) 184 if (current_task_token->token_id() == SyncTaskToken::kForegroundTaskTokenID)
186 foreground_task_token = std::move(current_task_token); 185 foreground_task_token = std::move(current_task_token);
187 else 186 else
188 background_task_token = std::move(current_task_token); 187 background_task_token = std::move(current_task_token);
189 188
190 manager->UpdateTaskBlockerBody( 189 manager->UpdateTaskBlockerBody(
191 std::move(foreground_task_token), std::move(background_task_token), 190 std::move(foreground_task_token), std::move(background_task_token),
192 std::move(task_log), std::move(task_blocker), continuation); 191 std::move(task_log), std::move(task_blocker), continuation);
193 } 192 }
194 193
(...skipping 11 matching lines...) Expand all
206 } 205 }
207 206
208 void SyncTaskManager::DetachFromSequence() { 207 void SyncTaskManager::DetachFromSequence() {
209 sequence_checker_.DetachFromSequence(); 208 sequence_checker_.DetachFromSequence();
210 } 209 }
211 210
212 bool SyncTaskManager::ShouldTrackTaskToken() const { 211 bool SyncTaskManager::ShouldTrackTaskToken() const {
213 return !worker_pool_ || !worker_pool_->IsShutdownInProgress(); 212 return !worker_pool_ || !worker_pool_->IsShutdownInProgress();
214 } 213 }
215 214
216 void SyncTaskManager::NotifyTaskDoneBody(scoped_ptr<SyncTaskToken> token, 215 void SyncTaskManager::NotifyTaskDoneBody(std::unique_ptr<SyncTaskToken> token,
217 SyncStatusCode status) { 216 SyncStatusCode status) {
218 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); 217 DCHECK(sequence_checker_.CalledOnValidSequencedThread());
219 DCHECK(token); 218 DCHECK(token);
220 219
221 DVLOG(3) << "NotifyTaskDone: " << "finished with status=" << status 220 DVLOG(3) << "NotifyTaskDone: " << "finished with status=" << status
222 << " (" << SyncStatusCodeToString(status) << ")" 221 << " (" << SyncStatusCodeToString(status) << ")"
223 << " " << token->location().ToString(); 222 << " " << token->location().ToString();
224 223
225 if (token->task_blocker()) { 224 if (token->task_blocker()) {
226 dependency_manager_.Erase(token->task_blocker()); 225 dependency_manager_.Erase(token->task_blocker());
227 token->clear_task_blocker(); 226 token->clear_task_blocker();
228 } 227 }
229 228
230 if (client_) { 229 if (client_) {
231 if (token->has_task_log()) { 230 if (token->has_task_log()) {
232 token->FinalizeTaskLog(SyncStatusCodeToString(status)); 231 token->FinalizeTaskLog(SyncStatusCodeToString(status));
233 client_->RecordTaskLog(token->PassTaskLog()); 232 client_->RecordTaskLog(token->PassTaskLog());
234 } 233 }
235 } 234 }
236 235
237 scoped_ptr<SyncTask> task; 236 std::unique_ptr<SyncTask> task;
238 SyncStatusCallback callback = token->callback(); 237 SyncStatusCallback callback = token->callback();
239 token->clear_callback(); 238 token->clear_callback();
240 if (token->token_id() == SyncTaskToken::kForegroundTaskTokenID) { 239 if (token->token_id() == SyncTaskToken::kForegroundTaskTokenID) {
241 token_ = std::move(token); 240 token_ = std::move(token);
242 task = std::move(running_foreground_task_); 241 task = std::move(running_foreground_task_);
243 } else { 242 } else {
244 task = running_background_tasks_.take_and_erase(token->token_id()); 243 task = running_background_tasks_.take_and_erase(token->token_id());
245 } 244 }
246 245
247 // Acquire the token to prevent a new task to jump into the queue. 246 // Acquire the token to prevent a new task to jump into the queue.
(...skipping 11 matching lines...) Expand all
259 258
260 // Post MaybeStartNextForegroundTask rather than calling it directly to avoid 259 // Post MaybeStartNextForegroundTask rather than calling it directly to avoid
261 // making the call-chaing longer. 260 // making the call-chaing longer.
262 task_runner_->PostTask( 261 task_runner_->PostTask(
263 FROM_HERE, 262 FROM_HERE,
264 base::Bind(&SyncTaskManager::MaybeStartNextForegroundTask, 263 base::Bind(&SyncTaskManager::MaybeStartNextForegroundTask,
265 weak_ptr_factory_.GetWeakPtr(), base::Passed(&token))); 264 weak_ptr_factory_.GetWeakPtr(), base::Passed(&token)));
266 } 265 }
267 266
268 void SyncTaskManager::UpdateTaskBlockerBody( 267 void SyncTaskManager::UpdateTaskBlockerBody(
269 scoped_ptr<SyncTaskToken> foreground_task_token, 268 std::unique_ptr<SyncTaskToken> foreground_task_token,
270 scoped_ptr<SyncTaskToken> background_task_token, 269 std::unique_ptr<SyncTaskToken> background_task_token,
271 scoped_ptr<TaskLogger::TaskLog> task_log, 270 std::unique_ptr<TaskLogger::TaskLog> task_log,
272 scoped_ptr<TaskBlocker> task_blocker, 271 std::unique_ptr<TaskBlocker> task_blocker,
273 const Continuation& continuation) { 272 const Continuation& continuation) {
274 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); 273 DCHECK(sequence_checker_.CalledOnValidSequencedThread());
275 274
276 // Run the task directly if the parallelization is disabled. 275 // Run the task directly if the parallelization is disabled.
277 if (!maximum_background_task_) { 276 if (!maximum_background_task_) {
278 DCHECK(foreground_task_token); 277 DCHECK(foreground_task_token);
279 DCHECK(!background_task_token); 278 DCHECK(!background_task_token);
280 foreground_task_token->SetTaskLog(std::move(task_log)); 279 foreground_task_token->SetTaskLog(std::move(task_log));
281 continuation.Run(std::move(foreground_task_token)); 280 continuation.Run(std::move(foreground_task_token));
282 return; 281 return;
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 running_background_tasks_.set(background_task_token->token_id(), 346 running_background_tasks_.set(background_task_token->token_id(),
348 std::move(running_foreground_task_)); 347 std::move(running_foreground_task_));
349 } 348 }
350 349
351 token_ = std::move(foreground_task_token); 350 token_ = std::move(foreground_task_token);
352 MaybeStartNextForegroundTask(nullptr); 351 MaybeStartNextForegroundTask(nullptr);
353 background_task_token->SetTaskLog(std::move(task_log)); 352 background_task_token->SetTaskLog(std::move(task_log));
354 continuation.Run(std::move(background_task_token)); 353 continuation.Run(std::move(background_task_token));
355 } 354 }
356 355
357 scoped_ptr<SyncTaskToken> SyncTaskManager::GetToken( 356 std::unique_ptr<SyncTaskToken> SyncTaskManager::GetToken(
358 const tracked_objects::Location& from_here, 357 const tracked_objects::Location& from_here,
359 const SyncStatusCallback& callback) { 358 const SyncStatusCallback& callback) {
360 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); 359 DCHECK(sequence_checker_.CalledOnValidSequencedThread());
361 360
362 if (!token_) 361 if (!token_)
363 return nullptr; 362 return nullptr;
364 token_->UpdateTask(from_here, callback); 363 token_->UpdateTask(from_here, callback);
365 return std::move(token_); 364 return std::move(token_);
366 } 365 }
367 366
368 void SyncTaskManager::PushPendingTask( 367 void SyncTaskManager::PushPendingTask(
369 const base::Closure& closure, Priority priority) { 368 const base::Closure& closure, Priority priority) {
370 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); 369 DCHECK(sequence_checker_.CalledOnValidSequencedThread());
371 370
372 pending_tasks_.push(PendingTask(closure, priority, pending_task_seq_++)); 371 pending_tasks_.push(PendingTask(closure, priority, pending_task_seq_++));
373 } 372 }
374 373
375 void SyncTaskManager::RunTask(scoped_ptr<SyncTaskToken> token, 374 void SyncTaskManager::RunTask(std::unique_ptr<SyncTaskToken> token,
376 scoped_ptr<SyncTask> task) { 375 std::unique_ptr<SyncTask> task) {
377 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); 376 DCHECK(sequence_checker_.CalledOnValidSequencedThread());
378 DCHECK(!running_foreground_task_); 377 DCHECK(!running_foreground_task_);
379 378
380 running_foreground_task_ = std::move(task); 379 running_foreground_task_ = std::move(task);
381 running_foreground_task_->RunPreflight(std::move(token)); 380 running_foreground_task_->RunPreflight(std::move(token));
382 } 381 }
383 382
384 void SyncTaskManager::MaybeStartNextForegroundTask( 383 void SyncTaskManager::MaybeStartNextForegroundTask(
385 scoped_ptr<SyncTaskToken> token) { 384 std::unique_ptr<SyncTaskToken> token) {
386 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); 385 DCHECK(sequence_checker_.CalledOnValidSequencedThread());
387 386
388 if (token) { 387 if (token) {
389 DCHECK(!token_); 388 DCHECK(!token_);
390 token_ = std::move(token); 389 token_ = std::move(token);
391 } 390 }
392 391
393 if (!pending_backgrounding_task_.is_null()) { 392 if (!pending_backgrounding_task_.is_null()) {
394 base::Closure closure = pending_backgrounding_task_; 393 base::Closure closure = pending_backgrounding_task_;
395 pending_backgrounding_task_.Reset(); 394 pending_backgrounding_task_.Reset();
(...skipping 10 matching lines...) Expand all
406 closure.Run(); 405 closure.Run();
407 return; 406 return;
408 } 407 }
409 408
410 if (client_) 409 if (client_)
411 client_->MaybeScheduleNextTask(); 410 client_->MaybeScheduleNextTask();
412 } 411 }
413 412
414 } // namespace drive_backend 413 } // namespace drive_backend
415 } // namespace sync_file_system 414 } // namespace sync_file_system
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698