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

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

Issue 1545283002: Convert Pass()→std::move() in //chrome/browser/ui (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 12 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 <utility>
8
7 #include "base/bind.h" 9 #include "base/bind.h"
8 #include "base/location.h" 10 #include "base/location.h"
9 #include "base/macros.h" 11 #include "base/macros.h"
10 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
11 #include "base/sequenced_task_runner.h" 13 #include "base/sequenced_task_runner.h"
12 #include "chrome/browser/sync_file_system/drive_backend/sync_task.h" 14 #include "chrome/browser/sync_file_system/drive_backend/sync_task.h"
13 #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"
14 #include "chrome/browser/sync_file_system/sync_file_metadata.h" 16 #include "chrome/browser/sync_file_system/sync_file_metadata.h"
15 17
16 using storage::FileSystemURL; 18 using storage::FileSystemURL;
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 107
106 scoped_ptr<SyncTaskToken> token(GetToken(from_here, callback)); 108 scoped_ptr<SyncTaskToken> token(GetToken(from_here, callback));
107 if (!token) { 109 if (!token) {
108 PushPendingTask( 110 PushPendingTask(
109 base::Bind(&SyncTaskManager::ScheduleSyncTask, 111 base::Bind(&SyncTaskManager::ScheduleSyncTask,
110 weak_ptr_factory_.GetWeakPtr(), from_here, 112 weak_ptr_factory_.GetWeakPtr(), from_here,
111 base::Passed(&task), priority, callback), 113 base::Passed(&task), priority, callback),
112 priority); 114 priority);
113 return; 115 return;
114 } 116 }
115 RunTask(token.Pass(), task.Pass()); 117 RunTask(std::move(token), std::move(task));
116 } 118 }
117 119
118 bool SyncTaskManager::ScheduleTaskIfIdle( 120 bool SyncTaskManager::ScheduleTaskIfIdle(
119 const tracked_objects::Location& from_here, 121 const tracked_objects::Location& from_here,
120 const Task& task, 122 const Task& task,
121 const SyncStatusCallback& callback) { 123 const SyncStatusCallback& callback) {
122 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); 124 DCHECK(sequence_checker_.CalledOnValidSequencedThread());
123 125
124 return ScheduleSyncTaskIfIdle( 126 return ScheduleSyncTaskIfIdle(
125 from_here, 127 from_here,
126 scoped_ptr<SyncTask>(new SyncTaskAdapter(task)), 128 scoped_ptr<SyncTask>(new SyncTaskAdapter(task)),
127 callback); 129 callback);
128 } 130 }
129 131
130 bool SyncTaskManager::ScheduleSyncTaskIfIdle( 132 bool SyncTaskManager::ScheduleSyncTaskIfIdle(
131 const tracked_objects::Location& from_here, 133 const tracked_objects::Location& from_here,
132 scoped_ptr<SyncTask> task, 134 scoped_ptr<SyncTask> task,
133 const SyncStatusCallback& callback) { 135 const SyncStatusCallback& callback) {
134 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); 136 DCHECK(sequence_checker_.CalledOnValidSequencedThread());
135 137
136 scoped_ptr<SyncTaskToken> token(GetToken(from_here, callback)); 138 scoped_ptr<SyncTaskToken> token(GetToken(from_here, callback));
137 if (!token) 139 if (!token)
138 return false; 140 return false;
139 RunTask(token.Pass(), task.Pass()); 141 RunTask(std::move(token), std::move(task));
140 return true; 142 return true;
141 } 143 }
142 144
143 // static 145 // static
144 void SyncTaskManager::NotifyTaskDone(scoped_ptr<SyncTaskToken> token, 146 void SyncTaskManager::NotifyTaskDone(scoped_ptr<SyncTaskToken> token,
145 SyncStatusCode status) { 147 SyncStatusCode status) {
146 DCHECK(token); 148 DCHECK(token);
147 149
148 SyncTaskManager* manager = token->manager(); 150 SyncTaskManager* manager = token->manager();
149 if (token->token_id() == SyncTaskToken::kTestingTaskTokenID) { 151 if (token->token_id() == SyncTaskToken::kTestingTaskTokenID) {
150 DCHECK(!manager); 152 DCHECK(!manager);
151 SyncStatusCallback callback = token->callback(); 153 SyncStatusCallback callback = token->callback();
152 token->clear_callback(); 154 token->clear_callback();
153 callback.Run(status); 155 callback.Run(status);
154 return; 156 return;
155 } 157 }
156 158
157 if (manager) 159 if (manager)
158 manager->NotifyTaskDoneBody(token.Pass(), status); 160 manager->NotifyTaskDoneBody(std::move(token), status);
159 } 161 }
160 162
161 // static 163 // static
162 void SyncTaskManager::UpdateTaskBlocker( 164 void SyncTaskManager::UpdateTaskBlocker(
163 scoped_ptr<SyncTaskToken> current_task_token, 165 scoped_ptr<SyncTaskToken> current_task_token,
164 scoped_ptr<TaskBlocker> task_blocker, 166 scoped_ptr<TaskBlocker> task_blocker,
165 const Continuation& continuation) { 167 const Continuation& continuation) {
166 DCHECK(current_task_token); 168 DCHECK(current_task_token);
167 169
168 SyncTaskManager* manager = current_task_token->manager(); 170 SyncTaskManager* manager = current_task_token->manager();
169 if (current_task_token->token_id() == SyncTaskToken::kTestingTaskTokenID) { 171 if (current_task_token->token_id() == SyncTaskToken::kTestingTaskTokenID) {
170 DCHECK(!manager); 172 DCHECK(!manager);
171 continuation.Run(current_task_token.Pass()); 173 continuation.Run(std::move(current_task_token));
172 return; 174 return;
173 } 175 }
174 176
175 if (!manager) 177 if (!manager)
176 return; 178 return;
177 179
178 scoped_ptr<SyncTaskToken> foreground_task_token; 180 scoped_ptr<SyncTaskToken> foreground_task_token;
179 scoped_ptr<SyncTaskToken> background_task_token; 181 scoped_ptr<SyncTaskToken> background_task_token;
180 scoped_ptr<TaskLogger::TaskLog> task_log = current_task_token->PassTaskLog(); 182 scoped_ptr<TaskLogger::TaskLog> task_log = current_task_token->PassTaskLog();
181 if (current_task_token->token_id() == SyncTaskToken::kForegroundTaskTokenID) 183 if (current_task_token->token_id() == SyncTaskToken::kForegroundTaskTokenID)
182 foreground_task_token = current_task_token.Pass(); 184 foreground_task_token = std::move(current_task_token);
183 else 185 else
184 background_task_token = current_task_token.Pass(); 186 background_task_token = std::move(current_task_token);
185 187
186 manager->UpdateTaskBlockerBody(foreground_task_token.Pass(), 188 manager->UpdateTaskBlockerBody(
187 background_task_token.Pass(), 189 std::move(foreground_task_token), std::move(background_task_token),
188 task_log.Pass(), 190 std::move(task_log), std::move(task_blocker), continuation);
189 task_blocker.Pass(),
190 continuation);
191 } 191 }
192 192
193 bool SyncTaskManager::IsRunningTask(int64_t token_id) const { 193 bool SyncTaskManager::IsRunningTask(int64_t token_id) const {
194 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); 194 DCHECK(sequence_checker_.CalledOnValidSequencedThread());
195 195
196 // If the client is gone, all task should be aborted. 196 // If the client is gone, all task should be aborted.
197 if (!client_) 197 if (!client_)
198 return false; 198 return false;
199 199
200 if (token_id == SyncTaskToken::kForegroundTaskTokenID) 200 if (token_id == SyncTaskToken::kForegroundTaskTokenID)
(...skipping 28 matching lines...) Expand all
229 if (token->has_task_log()) { 229 if (token->has_task_log()) {
230 token->FinalizeTaskLog(SyncStatusCodeToString(status)); 230 token->FinalizeTaskLog(SyncStatusCodeToString(status));
231 client_->RecordTaskLog(token->PassTaskLog()); 231 client_->RecordTaskLog(token->PassTaskLog());
232 } 232 }
233 } 233 }
234 234
235 scoped_ptr<SyncTask> task; 235 scoped_ptr<SyncTask> task;
236 SyncStatusCallback callback = token->callback(); 236 SyncStatusCallback callback = token->callback();
237 token->clear_callback(); 237 token->clear_callback();
238 if (token->token_id() == SyncTaskToken::kForegroundTaskTokenID) { 238 if (token->token_id() == SyncTaskToken::kForegroundTaskTokenID) {
239 token_ = token.Pass(); 239 token_ = std::move(token);
240 task = running_foreground_task_.Pass(); 240 task = std::move(running_foreground_task_);
241 } else { 241 } else {
242 task = running_background_tasks_.take_and_erase(token->token_id()); 242 task = running_background_tasks_.take_and_erase(token->token_id());
243 } 243 }
244 244
245 // Acquire the token to prevent a new task to jump into the queue. 245 // Acquire the token to prevent a new task to jump into the queue.
246 token = token_.Pass(); 246 token = std::move(token_);
247 247
248 bool task_used_network = false; 248 bool task_used_network = false;
249 if (task) 249 if (task)
250 task_used_network = task->used_network(); 250 task_used_network = task->used_network();
251 251
252 if (client_) 252 if (client_)
253 client_->NotifyLastOperationStatus(status, task_used_network); 253 client_->NotifyLastOperationStatus(status, task_used_network);
254 254
255 if (!callback.is_null()) 255 if (!callback.is_null())
256 callback.Run(status); 256 callback.Run(status);
(...skipping 11 matching lines...) Expand all
268 scoped_ptr<SyncTaskToken> background_task_token, 268 scoped_ptr<SyncTaskToken> background_task_token,
269 scoped_ptr<TaskLogger::TaskLog> task_log, 269 scoped_ptr<TaskLogger::TaskLog> task_log,
270 scoped_ptr<TaskBlocker> task_blocker, 270 scoped_ptr<TaskBlocker> task_blocker,
271 const Continuation& continuation) { 271 const Continuation& continuation) {
272 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); 272 DCHECK(sequence_checker_.CalledOnValidSequencedThread());
273 273
274 // Run the task directly if the parallelization is disabled. 274 // Run the task directly if the parallelization is disabled.
275 if (!maximum_background_task_) { 275 if (!maximum_background_task_) {
276 DCHECK(foreground_task_token); 276 DCHECK(foreground_task_token);
277 DCHECK(!background_task_token); 277 DCHECK(!background_task_token);
278 foreground_task_token->SetTaskLog(task_log.Pass()); 278 foreground_task_token->SetTaskLog(std::move(task_log));
279 continuation.Run(foreground_task_token.Pass()); 279 continuation.Run(std::move(foreground_task_token));
280 return; 280 return;
281 } 281 }
282 282
283 // Clear existing |task_blocker| from |dependency_manager_| before 283 // Clear existing |task_blocker| from |dependency_manager_| before
284 // getting |foreground_task_token|, so that we can avoid dead lock. 284 // getting |foreground_task_token|, so that we can avoid dead lock.
285 if (background_task_token && background_task_token->task_blocker()) { 285 if (background_task_token && background_task_token->task_blocker()) {
286 dependency_manager_.Erase(background_task_token->task_blocker()); 286 dependency_manager_.Erase(background_task_token->task_blocker());
287 background_task_token->clear_task_blocker(); 287 background_task_token->clear_task_blocker();
288 } 288 }
289 289
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 weak_ptr_factory_.GetWeakPtr(), 325 weak_ptr_factory_.GetWeakPtr(),
326 base::Passed(&foreground_task_token), 326 base::Passed(&foreground_task_token),
327 base::Passed(&background_task_token), 327 base::Passed(&background_task_token),
328 base::Passed(&task_log), 328 base::Passed(&task_log),
329 base::Passed(&task_blocker), 329 base::Passed(&task_blocker),
330 continuation); 330 continuation);
331 return; 331 return;
332 } 332 }
333 333
334 if (background_task_token) { 334 if (background_task_token) {
335 background_task_token->set_task_blocker(task_blocker.Pass()); 335 background_task_token->set_task_blocker(std::move(task_blocker));
336 } else { 336 } else {
337 tracked_objects::Location from_here = foreground_task_token->location(); 337 tracked_objects::Location from_here = foreground_task_token->location();
338 SyncStatusCallback callback = foreground_task_token->callback(); 338 SyncStatusCallback callback = foreground_task_token->callback();
339 foreground_task_token->clear_callback(); 339 foreground_task_token->clear_callback();
340 340
341 background_task_token = 341 background_task_token = SyncTaskToken::CreateForBackgroundTask(
342 SyncTaskToken::CreateForBackgroundTask(weak_ptr_factory_.GetWeakPtr(), 342 weak_ptr_factory_.GetWeakPtr(), task_runner_.get(), task_token_seq_++,
343 task_runner_.get(), 343 std::move(task_blocker));
344 task_token_seq_++,
345 task_blocker.Pass());
346 background_task_token->UpdateTask(from_here, callback); 344 background_task_token->UpdateTask(from_here, callback);
347 running_background_tasks_.set(background_task_token->token_id(), 345 running_background_tasks_.set(background_task_token->token_id(),
348 running_foreground_task_.Pass()); 346 std::move(running_foreground_task_));
349 } 347 }
350 348
351 token_ = foreground_task_token.Pass(); 349 token_ = std::move(foreground_task_token);
352 MaybeStartNextForegroundTask(nullptr); 350 MaybeStartNextForegroundTask(nullptr);
353 background_task_token->SetTaskLog(task_log.Pass()); 351 background_task_token->SetTaskLog(std::move(task_log));
354 continuation.Run(background_task_token.Pass()); 352 continuation.Run(std::move(background_task_token));
355 } 353 }
356 354
357 scoped_ptr<SyncTaskToken> SyncTaskManager::GetToken( 355 scoped_ptr<SyncTaskToken> SyncTaskManager::GetToken(
358 const tracked_objects::Location& from_here, 356 const tracked_objects::Location& from_here,
359 const SyncStatusCallback& callback) { 357 const SyncStatusCallback& callback) {
360 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); 358 DCHECK(sequence_checker_.CalledOnValidSequencedThread());
361 359
362 if (!token_) 360 if (!token_)
363 return nullptr; 361 return nullptr;
364 token_->UpdateTask(from_here, callback); 362 token_->UpdateTask(from_here, callback);
365 return token_.Pass(); 363 return std::move(token_);
366 } 364 }
367 365
368 void SyncTaskManager::PushPendingTask( 366 void SyncTaskManager::PushPendingTask(
369 const base::Closure& closure, Priority priority) { 367 const base::Closure& closure, Priority priority) {
370 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); 368 DCHECK(sequence_checker_.CalledOnValidSequencedThread());
371 369
372 pending_tasks_.push(PendingTask(closure, priority, pending_task_seq_++)); 370 pending_tasks_.push(PendingTask(closure, priority, pending_task_seq_++));
373 } 371 }
374 372
375 void SyncTaskManager::RunTask(scoped_ptr<SyncTaskToken> token, 373 void SyncTaskManager::RunTask(scoped_ptr<SyncTaskToken> token,
376 scoped_ptr<SyncTask> task) { 374 scoped_ptr<SyncTask> task) {
377 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); 375 DCHECK(sequence_checker_.CalledOnValidSequencedThread());
378 DCHECK(!running_foreground_task_); 376 DCHECK(!running_foreground_task_);
379 377
380 running_foreground_task_ = task.Pass(); 378 running_foreground_task_ = std::move(task);
381 running_foreground_task_->RunPreflight(token.Pass()); 379 running_foreground_task_->RunPreflight(std::move(token));
382 } 380 }
383 381
384 void SyncTaskManager::MaybeStartNextForegroundTask( 382 void SyncTaskManager::MaybeStartNextForegroundTask(
385 scoped_ptr<SyncTaskToken> token) { 383 scoped_ptr<SyncTaskToken> token) {
386 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); 384 DCHECK(sequence_checker_.CalledOnValidSequencedThread());
387 385
388 if (token) { 386 if (token) {
389 DCHECK(!token_); 387 DCHECK(!token_);
390 token_ = token.Pass(); 388 token_ = std::move(token);
391 } 389 }
392 390
393 if (!pending_backgrounding_task_.is_null()) { 391 if (!pending_backgrounding_task_.is_null()) {
394 base::Closure closure = pending_backgrounding_task_; 392 base::Closure closure = pending_backgrounding_task_;
395 pending_backgrounding_task_.Reset(); 393 pending_backgrounding_task_.Reset();
396 closure.Run(); 394 closure.Run();
397 return; 395 return;
398 } 396 }
399 397
400 if (!token_) 398 if (!token_)
401 return; 399 return;
402 400
403 if (!pending_tasks_.empty()) { 401 if (!pending_tasks_.empty()) {
404 base::Closure closure = pending_tasks_.top().task; 402 base::Closure closure = pending_tasks_.top().task;
405 pending_tasks_.pop(); 403 pending_tasks_.pop();
406 closure.Run(); 404 closure.Run();
407 return; 405 return;
408 } 406 }
409 407
410 if (client_) 408 if (client_)
411 client_->MaybeScheduleNextTask(); 409 client_->MaybeScheduleNextTask();
412 } 410 }
413 411
414 } // namespace drive_backend 412 } // namespace drive_backend
415 } // namespace sync_file_system 413 } // namespace sync_file_system
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698