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

Side by Side Diff: base/deferred_sequenced_task_runner_unittest.cc

Issue 1815363002: Add RetainedRef uses where needed. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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
« no previous file with comments | « no previous file | base/synchronization/waitable_event_watcher_posix.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 "base/deferred_sequenced_task_runner.h" 5 #include "base/deferred_sequenced_task_runner.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 base::Thread thread("DeferredSequencedTaskRunnerTestThread"); 149 base::Thread thread("DeferredSequencedTaskRunnerTestThread");
150 thread.Start(); 150 thread.Start();
151 runner_ = new base::DeferredSequencedTaskRunner(thread.task_runner()); 151 runner_ = new base::DeferredSequencedTaskRunner(thread.task_runner());
152 for (int i = 0; i < 5; ++i) { 152 for (int i = 0; i < 5; ++i) {
153 { 153 {
154 // Use a block to ensure that no reference to |short_lived_object| 154 // Use a block to ensure that no reference to |short_lived_object|
155 // is kept on the main thread after it is posted to |runner_|. 155 // is kept on the main thread after it is posted to |runner_|.
156 scoped_refptr<ExecuteTaskOnDestructor> short_lived_object = 156 scoped_refptr<ExecuteTaskOnDestructor> short_lived_object =
157 new ExecuteTaskOnDestructor(this, 2 * i); 157 new ExecuteTaskOnDestructor(this, 2 * i);
158 runner_->PostTask( 158 runner_->PostTask(
159 FROM_HERE, 159 FROM_HERE, base::Bind(&DeferredSequencedTaskRunnerTest::DoNothing,
160 base::Bind(&DeferredSequencedTaskRunnerTest::DoNothing, 160 base::Unretained(this),
161 base::Unretained(this), 161 base::RetainedRef(short_lived_object)));
162 short_lived_object));
163 } 162 }
164 // |short_lived_object| with id |2 * i| should be destroyed before the 163 // |short_lived_object| with id |2 * i| should be destroyed before the
165 // task |2 * i + 1| is executed. 164 // task |2 * i + 1| is executed.
166 PostExecuteTask(2 * i + 1); 165 PostExecuteTask(2 * i + 1);
167 } 166 }
168 StartRunner(); 167 StartRunner();
169 } 168 }
170 169
171 // All |short_lived_object| with id |2 * i| are destroyed before the task 170 // All |short_lived_object| with id |2 * i| are destroyed before the task
172 // |2 * i + 1| is executed. 171 // |2 * i + 1| is executed.
173 EXPECT_THAT(executed_task_ids_, 172 EXPECT_THAT(executed_task_ids_,
174 testing::ElementsAre(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)); 173 testing::ElementsAre(0, 1, 2, 3, 4, 5, 6, 7, 8, 9));
175 } 174 }
176 175
177 } // namespace 176 } // namespace
OLDNEW
« no previous file with comments | « no previous file | base/synchronization/waitable_event_watcher_posix.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698