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

Side by Side Diff: cc/tiles/image_controller_unittest.cc

Issue 2637843002: Migrate base::TaskRunner from Closure to OnceClosure (Closed)
Patch Set: rebase without dcheck_in_ref_count Created 3 years, 8 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
OLDNEW
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 "cc/tiles/image_controller.h" 5 #include "cc/tiles/image_controller.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/optional.h" 10 #include "base/optional.h"
11 #include "base/run_loop.h" 11 #include "base/run_loop.h"
12 #include "base/test/test_simple_task_runner.h" 12 #include "base/test/test_simple_task_runner.h"
13 #include "base/threading/sequenced_task_runner_handle.h" 13 #include "base/threading/sequenced_task_runner_handle.h"
14 #include "base/threading/thread_checker_impl.h" 14 #include "base/threading/thread_checker_impl.h"
15 #include "cc/test/skia_common.h" 15 #include "cc/test/skia_common.h"
16 #include "cc/tiles/image_decode_cache.h" 16 #include "cc/tiles/image_decode_cache.h"
17 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
18 18
19 namespace cc { 19 namespace cc {
20 namespace { 20 namespace {
21 21
22 class TestWorkerThread : public base::SimpleThread { 22 class TestWorkerThread : public base::SimpleThread {
23 public: 23 public:
24 TestWorkerThread() 24 TestWorkerThread()
25 : base::SimpleThread("test_worker_thread"), condition_(&lock_) {} 25 : base::SimpleThread("test_worker_thread"), condition_(&lock_) {}
26 26
27 void Run() override { 27 void Run() override {
28 for (;;) { 28 for (;;) {
29 base::Closure task; 29 base::OnceClosure task;
30 { 30 {
31 base::AutoLock hold(lock_); 31 base::AutoLock hold(lock_);
32 if (shutdown_) 32 if (shutdown_)
33 break; 33 break;
34 34
35 if (queue_.empty()) { 35 if (queue_.empty()) {
36 condition_.Wait(); 36 condition_.Wait();
37 continue; 37 continue;
38 } 38 }
39 39
40 task = std::move(queue_.front()); 40 task = std::move(queue_.front());
41 queue_.erase(queue_.begin()); 41 queue_.erase(queue_.begin());
42 } 42 }
43 std::move(task).Run(); 43 std::move(task).Run();
44 } 44 }
45 } 45 }
46 46
47 void Shutdown() { 47 void Shutdown() {
48 base::AutoLock hold(lock_); 48 base::AutoLock hold(lock_);
49 shutdown_ = true; 49 shutdown_ = true;
50 condition_.Signal(); 50 condition_.Signal();
51 } 51 }
52 52
53 void PostTask(base::Closure task) { 53 void PostTask(base::OnceClosure task) {
54 base::AutoLock hold(lock_); 54 base::AutoLock hold(lock_);
55 queue_.push_back(std::move(task)); 55 queue_.push_back(std::move(task));
56 condition_.Signal(); 56 condition_.Signal();
57 } 57 }
58 58
59 private: 59 private:
60 base::Lock lock_; 60 base::Lock lock_;
61 base::ConditionVariable condition_; 61 base::ConditionVariable condition_;
62 std::vector<base::Closure> queue_; 62 std::vector<base::OnceClosure> queue_;
63 bool shutdown_ = false; 63 bool shutdown_ = false;
64 }; 64 };
65 65
66 class WorkerTaskRunner : public base::SequencedTaskRunner { 66 class WorkerTaskRunner : public base::SequencedTaskRunner {
67 public: 67 public:
68 WorkerTaskRunner() { thread_.Start(); } 68 WorkerTaskRunner() { thread_.Start(); }
69 69
70 bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here, 70 bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here,
71 base::Closure task, 71 base::OnceClosure task,
72 base::TimeDelta delay) override { 72 base::TimeDelta delay) override {
73 return PostDelayedTask(from_here, std::move(task), delay); 73 return PostDelayedTask(from_here, std::move(task), delay);
74 } 74 }
75 75
76 bool PostDelayedTask(const tracked_objects::Location& from_here, 76 bool PostDelayedTask(const tracked_objects::Location& from_here,
77 base::Closure task, 77 base::OnceClosure task,
78 base::TimeDelta delay) override { 78 base::TimeDelta delay) override {
79 thread_.PostTask(std::move(task)); 79 thread_.PostTask(std::move(task));
80 return true; 80 return true;
81 } 81 }
82 82
83 bool RunsTasksOnCurrentThread() const override { return false; } 83 bool RunsTasksOnCurrentThread() const override { return false; }
84 84
85 protected: 85 protected:
86 ~WorkerTaskRunner() override { 86 ~WorkerTaskRunner() override {
87 thread_.Shutdown(); 87 thread_.Shutdown();
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 134
135 private: 135 private:
136 int number_of_refs_ = 0; 136 int number_of_refs_ = 0;
137 scoped_refptr<TileTask> task_to_use_; 137 scoped_refptr<TileTask> task_to_use_;
138 }; 138 };
139 139
140 // A simple class that can receive decode callbacks. 140 // A simple class that can receive decode callbacks.
141 class DecodeClient { 141 class DecodeClient {
142 public: 142 public:
143 DecodeClient() {} 143 DecodeClient() {}
144 void Callback(base::Closure quit_closure, 144 void Callback(base::OnceClosure quit_closure,
145 ImageController::ImageDecodeRequestId id, 145 ImageController::ImageDecodeRequestId id,
146 ImageController::ImageDecodeResult result) { 146 ImageController::ImageDecodeResult result) {
147 id_ = id; 147 id_ = id;
148 result_ = result; 148 result_ = result;
149 std::move(quit_closure).Run(); 149 std::move(quit_closure).Run();
150 } 150 }
151 151
152 ImageController::ImageDecodeRequestId id() { return id_; } 152 ImageController::ImageDecodeRequestId id() { return id_; }
153 ImageController::ImageDecodeResult result() { return result_; } 153 ImageController::ImageDecodeResult result() { return result_; }
154 154
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after
586 decode_client2.result()); 586 decode_client2.result());
587 587
588 // Reset the controller since the order of destruction is wrong in this test 588 // Reset the controller since the order of destruction is wrong in this test
589 // (|other_cache| should outlive the controller. This is normally done via 589 // (|other_cache| should outlive the controller. This is normally done via
590 // SetImageDecodeCache(nullptr) or it can be done in the dtor of the cache.) 590 // SetImageDecodeCache(nullptr) or it can be done in the dtor of the cache.)
591 ResetController(); 591 ResetController();
592 } 592 }
593 593
594 } // namespace 594 } // namespace
595 } // namespace cc 595 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698