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

Unified Diff: components/sync/model_impl/attachments/task_queue.h

Issue 2915453002: Deprecate NonThreadSafe in components/sync in favor of SequenceChecker. (Closed)
Patch Set: fix comment Created 3 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: components/sync/model_impl/attachments/task_queue.h
diff --git a/components/sync/model_impl/attachments/task_queue.h b/components/sync/model_impl/attachments/task_queue.h
index afd602b654e60db0afe22b24dc06e00896c3eaae..cfdfe24dd76fb43f39f196b6ee887a97ae12f0cd 100644
--- a/components/sync/model_impl/attachments/task_queue.h
+++ b/components/sync/model_impl/attachments/task_queue.h
@@ -17,7 +17,7 @@
#include "base/macros.h"
#include "base/memory/ptr_util.h"
#include "base/memory/weak_ptr.h"
-#include "base/threading/non_thread_safe.h"
+#include "base/sequence_checker.h"
#include "base/threading/thread_task_runner_handle.h"
#include "base/time/time.h"
#include "base/timer/timer.h"
@@ -69,7 +69,7 @@ namespace syncer {
// }
//
template <typename T>
-class TaskQueue : base::NonThreadSafe {
+class TaskQueue {
public:
// A callback provided by users of the TaskQueue to handle tasks.
//
@@ -94,6 +94,8 @@ class TaskQueue : base::NonThreadSafe {
const base::TimeDelta& initial_backoff_delay,
const base::TimeDelta& max_backoff_delay);
+ ~TaskQueue();
+
// Add |task| to the end of the queue.
//
// If |task| is already present (as determined by operator==) it is not added.
@@ -157,6 +159,8 @@ class TaskQueue : base::NonThreadSafe {
std::unique_ptr<base::Timer> backoff_timer_;
base::TimeDelta delay_;
+ SEQUENCE_CHECKER(sequence_checker_);
+
// Must be last data member.
base::WeakPtrFactory<TaskQueue> weak_ptr_factory_;
@@ -191,8 +195,13 @@ TaskQueue<T>::TaskQueue(const HandleTaskCallback& callback,
}
template <typename T>
+TaskQueue<T>::~TaskQueue() {
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
+}
+
+template <typename T>
void TaskQueue<T>::AddToQueue(const T& task) {
- DCHECK(CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
// Ignore duplicates.
if (tasks_.find(task) == tasks_.end()) {
queue_.push_back(task);
@@ -203,7 +212,7 @@ void TaskQueue<T>::AddToQueue(const T& task) {
template <typename T>
void TaskQueue<T>::MarkAsSucceeded(const T& task) {
- DCHECK(CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
FinishTask(task);
// The task succeeded. Stop any pending timer, reset (clear) the backoff, and
// reschedule a dispatch.
@@ -214,7 +223,7 @@ void TaskQueue<T>::MarkAsSucceeded(const T& task) {
template <typename T>
void TaskQueue<T>::MarkAsFailed(const T& task) {
- DCHECK(CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
FinishTask(task);
backoff_entry_->InformOfRequest(false);
ScheduleDispatch();
@@ -222,7 +231,7 @@ void TaskQueue<T>::MarkAsFailed(const T& task) {
template <typename T>
void TaskQueue<T>::Cancel(const T& task) {
- DCHECK(CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
FinishTask(task);
ScheduleDispatch();
}
@@ -236,14 +245,14 @@ void TaskQueue<T>::ResetBackoff() {
template <typename T>
void TaskQueue<T>::SetTimerForTest(std::unique_ptr<base::Timer> timer) {
- DCHECK(CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(timer.get());
backoff_timer_ = std::move(timer);
}
template <typename T>
void TaskQueue<T>::FinishTask(const T& task) {
- DCHECK(CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK_GE(num_in_progress_, 1);
--num_in_progress_;
const size_t num_erased = tasks_.erase(task);
@@ -252,7 +261,7 @@ void TaskQueue<T>::FinishTask(const T& task) {
template <typename T>
void TaskQueue<T>::ScheduleDispatch() {
- DCHECK(CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (backoff_timer_->IsRunning() || !ShouldDispatch()) {
return;
}
@@ -263,7 +272,7 @@ void TaskQueue<T>::ScheduleDispatch() {
template <typename T>
void TaskQueue<T>::Dispatch() {
- DCHECK(CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (!ShouldDispatch()) {
return;
}
« no previous file with comments | « components/sync/model_impl/attachments/attachment_service_impl.cc ('k') | components/sync/model_impl/model_type_store_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698