| OLD | NEW |
| 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 Loading... |
| 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 |
| OLD | NEW |