Skip to content

Commit

Permalink
base: Remove some unnecessary const scoped_refptr<>&.
Browse files Browse the repository at this point in the history
This patch removes some unnecessary const scoped_refptr<>&. It replaces
some instances with a copy of scoped_refptr, followed by a move. Other
instances, it passes a raw non-owning pointer.

R=danakj
BUG=589044

Review URL: https://codereview.chromium.org/1800743003

Cr-Commit-Position: refs/heads/master@{#382043}
  • Loading branch information
vmpstr authored and Commit bot committed Mar 18, 2016
1 parent 7d6d85c commit 82b0c16
Show file tree
Hide file tree
Showing 18 changed files with 108 additions and 139 deletions.
6 changes: 2 additions & 4 deletions base/deferred_sequenced_task_runner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@ DeferredSequencedTaskRunner::DeferredTask::~DeferredTask() {
}

DeferredSequencedTaskRunner::DeferredSequencedTaskRunner(
const scoped_refptr<SequencedTaskRunner>& target_task_runner)
: started_(false),
target_task_runner_(target_task_runner) {
}
scoped_refptr<SequencedTaskRunner> target_task_runner)
: started_(false), target_task_runner_(std::move(target_task_runner)) {}

DeferredSequencedTaskRunner::~DeferredSequencedTaskRunner() {
}
Expand Down
2 changes: 1 addition & 1 deletion base/deferred_sequenced_task_runner.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace base {
class BASE_EXPORT DeferredSequencedTaskRunner : public SequencedTaskRunner {
public:
explicit DeferredSequencedTaskRunner(
const scoped_refptr<SequencedTaskRunner>& target_runner);
scoped_refptr<SequencedTaskRunner> target_runner);

// TaskRunner implementation
bool PostDelayedTask(const tracked_objects::Location& from_here,
Expand Down
13 changes: 6 additions & 7 deletions base/files/important_file_writer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -126,19 +126,18 @@ bool ImportantFileWriter::WriteFileAtomically(const FilePath& path,

ImportantFileWriter::ImportantFileWriter(
const FilePath& path,
const scoped_refptr<SequencedTaskRunner>& task_runner)
scoped_refptr<SequencedTaskRunner> task_runner)
: ImportantFileWriter(
path,
task_runner,
TimeDelta::FromMilliseconds(kDefaultCommitIntervalMs)) {
}
path,
std::move(task_runner),
TimeDelta::FromMilliseconds(kDefaultCommitIntervalMs)) {}

ImportantFileWriter::ImportantFileWriter(
const FilePath& path,
const scoped_refptr<SequencedTaskRunner>& task_runner,
scoped_refptr<SequencedTaskRunner> task_runner,
TimeDelta interval)
: path_(path),
task_runner_(task_runner),
task_runner_(std::move(task_runner)),
serializer_(nullptr),
commit_interval_(interval),
weak_factory_(this) {
Expand Down
4 changes: 2 additions & 2 deletions base/files/important_file_writer.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ class BASE_EXPORT ImportantFileWriter : public NonThreadSafe {
// execute file I/O operations.
// All non-const methods, ctor and dtor must be called on the same thread.
ImportantFileWriter(const FilePath& path,
const scoped_refptr<SequencedTaskRunner>& task_runner);
scoped_refptr<SequencedTaskRunner> task_runner);

// Same as above, but with a custom commit interval.
ImportantFileWriter(const FilePath& path,
const scoped_refptr<SequencedTaskRunner>& task_runner,
scoped_refptr<SequencedTaskRunner> task_runner,
TimeDelta interval);

// You have to ensure that there are no pending writes at the moment
Expand Down
10 changes: 4 additions & 6 deletions base/memory/ref_counted_delete_on_message_loop.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@ namespace base {
// Sample usage:
// class Foo : public RefCountedDeleteOnMessageLoop<Foo> {
//
// Foo(const scoped_refptr<SingleThreadTaskRunner>& loop)
// : RefCountedDeleteOnMessageLoop<Foo>(loop) {
// ...
// }
// Foo(scoped_refptr<SingleThreadTaskRunner> loop)
// : RefCountedDeleteOnMessageLoop<Foo>(std::move(loop)) {}
// ...
// private:
// friend class RefCountedDeleteOnMessageLoop<Foo>;
Expand All @@ -40,8 +38,8 @@ class RefCountedDeleteOnMessageLoop : public subtle::RefCountedThreadSafeBase {
// MessageLoop on the current thread can be acquired by calling
// MessageLoop::current()->task_runner().
RefCountedDeleteOnMessageLoop(
const scoped_refptr<SingleThreadTaskRunner>& task_runner)
: task_runner_(task_runner) {
scoped_refptr<SingleThreadTaskRunner> task_runner)
: task_runner_(std::move(task_runner)) {
DCHECK(task_runner_);
}

Expand Down
8 changes: 4 additions & 4 deletions base/test/sequenced_task_runner_test_template.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ SequencedTaskTracker::SequencedTaskTracker()
}

void SequencedTaskTracker::PostWrappedNonNestableTask(
const scoped_refptr<SequencedTaskRunner>& task_runner,
SequencedTaskRunner* task_runner,
const Closure& task) {
AutoLock event_lock(lock_);
const int post_i = next_post_i_++;
Expand All @@ -34,7 +34,7 @@ void SequencedTaskTracker::PostWrappedNonNestableTask(
}

void SequencedTaskTracker::PostWrappedNestableTask(
const scoped_refptr<SequencedTaskRunner>& task_runner,
SequencedTaskRunner* task_runner,
const Closure& task) {
AutoLock event_lock(lock_);
const int post_i = next_post_i_++;
Expand All @@ -45,7 +45,7 @@ void SequencedTaskTracker::PostWrappedNestableTask(
}

void SequencedTaskTracker::PostWrappedDelayedNonNestableTask(
const scoped_refptr<SequencedTaskRunner>& task_runner,
SequencedTaskRunner* task_runner,
const Closure& task,
TimeDelta delay) {
AutoLock event_lock(lock_);
Expand All @@ -57,7 +57,7 @@ void SequencedTaskTracker::PostWrappedDelayedNonNestableTask(
}

void SequencedTaskTracker::PostNonNestableTasks(
const scoped_refptr<SequencedTaskRunner>& task_runner,
SequencedTaskRunner* task_runner,
int task_count) {
for (int i = 0; i < task_count; ++i) {
PostWrappedNonNestableTask(task_runner, Closure());
Expand Down
60 changes: 28 additions & 32 deletions base/test/sequenced_task_runner_test_template.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,25 +41,20 @@ class SequencedTaskTracker : public RefCountedThreadSafe<SequencedTaskTracker> {
SequencedTaskTracker();

// Posts the non-nestable task |task|, and records its post event.
void PostWrappedNonNestableTask(
const scoped_refptr<SequencedTaskRunner>& task_runner,
const Closure& task);
void PostWrappedNonNestableTask(SequencedTaskRunner* task_runner,
const Closure& task);

// Posts the nestable task |task|, and records its post event.
void PostWrappedNestableTask(
const scoped_refptr<SequencedTaskRunner>& task_runner,
const Closure& task);
void PostWrappedNestableTask(SequencedTaskRunner* task_runner,
const Closure& task);

// Posts the delayed non-nestable task |task|, and records its post event.
void PostWrappedDelayedNonNestableTask(
const scoped_refptr<SequencedTaskRunner>& task_runner,
const Closure& task,
TimeDelta delay);
void PostWrappedDelayedNonNestableTask(SequencedTaskRunner* task_runner,
const Closure& task,
TimeDelta delay);

// Posts |task_count| non-nestable tasks.
void PostNonNestableTasks(
const scoped_refptr<SequencedTaskRunner>& task_runner,
int task_count);
void PostNonNestableTasks(SequencedTaskRunner* task_runner, int task_count);

const std::vector<TaskEvent>& GetTaskEvents() const;

Expand Down Expand Up @@ -141,9 +136,11 @@ TYPED_TEST_P(SequencedTaskRunnerTest, SequentialNonNestable) {
this->delegate_.GetTaskRunner();

this->task_tracker_->PostWrappedNonNestableTask(
task_runner, Bind(&PlatformThread::Sleep, TimeDelta::FromSeconds(1)));
task_runner.get(),
Bind(&PlatformThread::Sleep, TimeDelta::FromSeconds(1)));
for (int i = 1; i < kTaskCount; ++i) {
this->task_tracker_->PostWrappedNonNestableTask(task_runner, Closure());
this->task_tracker_->PostWrappedNonNestableTask(task_runner.get(),
Closure());
}

this->delegate_.StopTaskRunner();
Expand All @@ -163,10 +160,10 @@ TYPED_TEST_P(SequencedTaskRunnerTest, SequentialNestable) {
this->delegate_.GetTaskRunner();

this->task_tracker_->PostWrappedNestableTask(
task_runner,
task_runner.get(),
Bind(&PlatformThread::Sleep, TimeDelta::FromSeconds(1)));
for (int i = 1; i < kTaskCount; ++i) {
this->task_tracker_->PostWrappedNestableTask(task_runner, Closure());
this->task_tracker_->PostWrappedNestableTask(task_runner.get(), Closure());
}

this->delegate_.StopTaskRunner();
Expand All @@ -188,8 +185,7 @@ TYPED_TEST_P(SequencedTaskRunnerTest, SequentialDelayedNonNestable) {

for (int i = 0; i < kTaskCount; ++i) {
this->task_tracker_->PostWrappedDelayedNonNestableTask(
task_runner,
Closure(),
task_runner.get(), Closure(),
TimeDelta::FromMilliseconds(kDelayIncrementMs * i));
}

Expand Down Expand Up @@ -217,7 +213,7 @@ TYPED_TEST_P(SequencedTaskRunnerTest, NonNestablePostFromNonNestableTask) {
this->task_tracker_,
task_runner,
kChildrenPerParent);
this->task_tracker_->PostWrappedNonNestableTask(task_runner, task);
this->task_tracker_->PostWrappedNonNestableTask(task_runner.get(), task);
}

this->delegate_.StopTaskRunner();
Expand All @@ -242,10 +238,10 @@ TYPED_TEST_P(SequencedTaskRunnerTest, DelayedTasksSameDelay) {
const scoped_refptr<SequencedTaskRunner> task_runner =
this->delegate_.GetTaskRunner();

this->task_tracker_->PostWrappedDelayedNonNestableTask(
task_runner, Closure(), kDelay);
this->task_tracker_->PostWrappedDelayedNonNestableTask(
task_runner, Closure(), kDelay);
this->task_tracker_->PostWrappedDelayedNonNestableTask(task_runner.get(),
Closure(), kDelay);
this->task_tracker_->PostWrappedDelayedNonNestableTask(task_runner.get(),
Closure(), kDelay);
this->task_tracker_->WaitForCompletedTasks(kTaskCount);
this->delegate_.StopTaskRunner();

Expand All @@ -264,10 +260,10 @@ TYPED_TEST_P(SequencedTaskRunnerTest, DelayedTaskAfterLongTask) {
this->delegate_.GetTaskRunner();

this->task_tracker_->PostWrappedNonNestableTask(
task_runner, base::Bind(&PlatformThread::Sleep,
TimeDelta::FromMilliseconds(50)));
task_runner.get(),
base::Bind(&PlatformThread::Sleep, TimeDelta::FromMilliseconds(50)));
this->task_tracker_->PostWrappedDelayedNonNestableTask(
task_runner, Closure(), TimeDelta::FromMilliseconds(10));
task_runner.get(), Closure(), TimeDelta::FromMilliseconds(10));
this->task_tracker_->WaitForCompletedTasks(kTaskCount);
this->delegate_.StopTaskRunner();

Expand All @@ -286,11 +282,11 @@ TYPED_TEST_P(SequencedTaskRunnerTest, DelayedTaskAfterManyLongTasks) {

for (int i = 0; i < kTaskCount - 1; i++) {
this->task_tracker_->PostWrappedNonNestableTask(
task_runner, base::Bind(&PlatformThread::Sleep,
TimeDelta::FromMilliseconds(50)));
task_runner.get(),
base::Bind(&PlatformThread::Sleep, TimeDelta::FromMilliseconds(50)));
}
this->task_tracker_->PostWrappedDelayedNonNestableTask(
task_runner, Closure(), TimeDelta::FromMilliseconds(10));
task_runner.get(), Closure(), TimeDelta::FromMilliseconds(10));
this->task_tracker_->WaitForCompletedTasks(kTaskCount);
this->delegate_.StopTaskRunner();

Expand Down Expand Up @@ -333,8 +329,8 @@ TYPED_TEST_P(SequencedTaskRunnerDelayedTest, DelayedTaskBasic) {
this->delegate_.GetTaskRunner();

Time time_before_run = Time::Now();
this->task_tracker_->PostWrappedDelayedNonNestableTask(task_runner, Closure(),
kDelay);
this->task_tracker_->PostWrappedDelayedNonNestableTask(task_runner.get(),
Closure(), kDelay);
this->task_tracker_->WaitForCompletedTasks(kTaskCount);
this->delegate_.StopTaskRunner();
Time time_after_run = Time::Now();
Expand Down
5 changes: 2 additions & 3 deletions base/test/task_runner_test_template.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@ void TaskTracker::WaitForCompletedTasks(int count) {
task_runs_cv_.Wait();
}

void ExpectRunsTasksOnCurrentThread(
bool expected_value,
const scoped_refptr<TaskRunner>& task_runner) {
void ExpectRunsTasksOnCurrentThread(bool expected_value,
TaskRunner* task_runner) {
EXPECT_EQ(expected_value, task_runner->RunsTasksOnCurrentThread());
}

Expand Down
5 changes: 2 additions & 3 deletions base/test/task_runner_test_template.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,8 @@ namespace test {

// Calls RunsTasksOnCurrentThread() on |task_runner| and expects it to
// equal |expected_value|.
void ExpectRunsTasksOnCurrentThread(
bool expected_value,
const scoped_refptr<TaskRunner>& task_runner);
void ExpectRunsTasksOnCurrentThread(bool expected_value,
TaskRunner* task_runner);

} // namespace test

Expand Down
4 changes: 2 additions & 2 deletions base/thread_task_runner_handle.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ bool ThreadTaskRunnerHandle::IsSet() {
}

ThreadTaskRunnerHandle::ThreadTaskRunnerHandle(
const scoped_refptr<SingleThreadTaskRunner>& task_runner)
: task_runner_(task_runner) {
scoped_refptr<SingleThreadTaskRunner> task_runner)
: task_runner_(std::move(task_runner)) {
DCHECK(task_runner_->BelongsToCurrentThread());
DCHECK(!lazy_tls_ptr.Pointer()->Get());
lazy_tls_ptr.Pointer()->Set(this);
Expand Down
2 changes: 1 addition & 1 deletion base/thread_task_runner_handle.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class BASE_EXPORT ThreadTaskRunnerHandle {
// Binds |task_runner| to the current thread. |task_runner| must belong
// to the current thread for this to succeed.
explicit ThreadTaskRunnerHandle(
const scoped_refptr<SingleThreadTaskRunner>& task_runner);
scoped_refptr<SingleThreadTaskRunner> task_runner);
~ThreadTaskRunnerHandle();

private:
Expand Down
23 changes: 10 additions & 13 deletions base/threading/sequenced_worker_pool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ struct SequencedTaskLessThan {
class SequencedWorkerPoolTaskRunner : public TaskRunner {
public:
SequencedWorkerPoolTaskRunner(
const scoped_refptr<SequencedWorkerPool>& pool,
scoped_refptr<SequencedWorkerPool> pool,
SequencedWorkerPool::WorkerShutdown shutdown_behavior);

// TaskRunner implementation
Expand All @@ -118,11 +118,9 @@ class SequencedWorkerPoolTaskRunner : public TaskRunner {
};

SequencedWorkerPoolTaskRunner::SequencedWorkerPoolTaskRunner(
const scoped_refptr<SequencedWorkerPool>& pool,
scoped_refptr<SequencedWorkerPool> pool,
SequencedWorkerPool::WorkerShutdown shutdown_behavior)
: pool_(pool),
shutdown_behavior_(shutdown_behavior) {
}
: pool_(std::move(pool)), shutdown_behavior_(shutdown_behavior) {}

SequencedWorkerPoolTaskRunner::~SequencedWorkerPoolTaskRunner() {
}
Expand Down Expand Up @@ -150,7 +148,7 @@ bool SequencedWorkerPoolTaskRunner::RunsTasksOnCurrentThread() const {
class SequencedWorkerPoolSequencedTaskRunner : public SequencedTaskRunner {
public:
SequencedWorkerPoolSequencedTaskRunner(
const scoped_refptr<SequencedWorkerPool>& pool,
scoped_refptr<SequencedWorkerPool> pool,
SequencedWorkerPool::SequenceToken token,
SequencedWorkerPool::WorkerShutdown shutdown_behavior);

Expand Down Expand Up @@ -178,13 +176,12 @@ class SequencedWorkerPoolSequencedTaskRunner : public SequencedTaskRunner {
};

SequencedWorkerPoolSequencedTaskRunner::SequencedWorkerPoolSequencedTaskRunner(
const scoped_refptr<SequencedWorkerPool>& pool,
scoped_refptr<SequencedWorkerPool> pool,
SequencedWorkerPool::SequenceToken token,
SequencedWorkerPool::WorkerShutdown shutdown_behavior)
: pool_(pool),
: pool_(std::move(pool)),
token_(token),
shutdown_behavior_(shutdown_behavior) {
}
shutdown_behavior_(shutdown_behavior) {}

SequencedWorkerPoolSequencedTaskRunner::
~SequencedWorkerPoolSequencedTaskRunner() {
Expand Down Expand Up @@ -230,7 +227,7 @@ class SequencedWorkerPool::Worker : public SimpleThread {
public:
// Hold a (cyclic) ref to |worker_pool|, since we want to keep it
// around as long as we are running.
Worker(const scoped_refptr<SequencedWorkerPool>& worker_pool,
Worker(scoped_refptr<SequencedWorkerPool> worker_pool,
int thread_number,
const std::string& thread_name_prefix);
~Worker() override;
Expand Down Expand Up @@ -504,11 +501,11 @@ class SequencedWorkerPool::Inner {
// Worker definitions ---------------------------------------------------------

SequencedWorkerPool::Worker::Worker(
const scoped_refptr<SequencedWorkerPool>& worker_pool,
scoped_refptr<SequencedWorkerPool> worker_pool,
int thread_number,
const std::string& prefix)
: SimpleThread(prefix + StringPrintf("Worker%d", thread_number)),
worker_pool_(worker_pool),
worker_pool_(std::move(worker_pool)),
task_shutdown_behavior_(BLOCK_SHUTDOWN),
is_processing_task_(false) {
Start();
Expand Down
5 changes: 2 additions & 3 deletions base/threading/sequenced_worker_pool_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,8 @@ class ThreadBlocker {
class DestructionDeadlockChecker
: public base::RefCountedThreadSafe<DestructionDeadlockChecker> {
public:
explicit DestructionDeadlockChecker(
const scoped_refptr<SequencedWorkerPool>& pool)
: pool_(pool) {}
explicit DestructionDeadlockChecker(scoped_refptr<SequencedWorkerPool> pool)
: pool_(std::move(pool)) {}

protected:
virtual ~DestructionDeadlockChecker() {
Expand Down
Loading

0 comments on commit 82b0c16

Please sign in to comment.