OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/bind.h" | 5 #include "base/bind.h" |
6 #include "base/optional.h" | 6 #include "base/optional.h" |
7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
8 #include "base/test/test_simple_task_runner.h" | 8 #include "base/test/test_simple_task_runner.h" |
9 #include "base/threading/sequenced_task_runner_handle.h" | 9 #include "base/threading/sequenced_task_runner_handle.h" |
10 #include "cc/tiles/image_controller.h" | 10 #include "cc/tiles/image_controller.h" |
11 #include "cc/tiles/image_decode_cache.h" | 11 #include "cc/tiles/image_decode_cache.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
13 | 13 |
14 namespace cc { | 14 namespace cc { |
15 namespace { | 15 namespace { |
16 | 16 |
17 class TestWorkerThread : public base::SimpleThread { | 17 class TestWorkerThread : public base::SimpleThread { |
18 public: | 18 public: |
19 TestWorkerThread() | 19 TestWorkerThread() |
20 : base::SimpleThread("test_worker_thread"), condition_(&lock_) {} | 20 : base::SimpleThread("test_worker_thread"), condition_(&lock_) {} |
21 | 21 |
22 void Run() override { | 22 void Run() override { |
23 for (;;) { | 23 for (;;) { |
24 base::AutoLock hold(lock_); | 24 base::Closure task; |
25 if (shutdown_) | 25 { |
26 break; | 26 base::AutoLock hold(lock_); |
| 27 if (shutdown_) |
| 28 break; |
27 | 29 |
28 if (queue_.empty()) { | 30 if (queue_.empty()) { |
29 condition_.Wait(); | 31 condition_.Wait(); |
30 continue; | 32 continue; |
| 33 } |
| 34 |
| 35 task = queue_.front(); |
| 36 queue_.erase(queue_.begin()); |
31 } | 37 } |
32 | 38 task.Run(); |
33 queue_.front().Run(); | |
34 queue_.erase(queue_.begin()); | |
35 } | 39 } |
36 } | 40 } |
37 | 41 |
38 void Shutdown() { | 42 void Shutdown() { |
39 base::AutoLock hold(lock_); | 43 base::AutoLock hold(lock_); |
40 shutdown_ = true; | 44 shutdown_ = true; |
41 condition_.Signal(); | 45 condition_.Signal(); |
42 } | 46 } |
43 | 47 |
44 void PostTask(const base::Closure& task) { | 48 void PostTask(const base::Closure& task) { |
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
438 EXPECT_EQ(expected_id1, decode_client1.id()); | 442 EXPECT_EQ(expected_id1, decode_client1.id()); |
439 EXPECT_TRUE(task->has_run()); | 443 EXPECT_TRUE(task->has_run()); |
440 EXPECT_EQ(1, cache()->number_of_refs()); | 444 EXPECT_EQ(1, cache()->number_of_refs()); |
441 | 445 |
442 controller()->SetImageDecodeCache(nullptr); | 446 controller()->SetImageDecodeCache(nullptr); |
443 EXPECT_EQ(0, cache()->number_of_refs()); | 447 EXPECT_EQ(0, cache()->number_of_refs()); |
444 } | 448 } |
445 | 449 |
446 } // namespace | 450 } // namespace |
447 } // namespace cc | 451 } // namespace cc |
OLD | NEW |