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

Side by Side Diff: base/trace_event/memory_dump_manager_unittest.cc

Issue 2726523002: Pass Callback to TaskRunner by value and consume it on invocation (1) (Closed)
Patch Set: s/base::ResetAndReturn/std::move/ Created 3 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/trace_event/memory_dump_manager.h" 5 #include "base/trace_event/memory_dump_manager.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <utility>
10 #include <vector> 11 #include <vector>
11 12
12 #include "base/bind_helpers.h" 13 #include "base/bind_helpers.h"
14 #include "base/callback.h"
13 #include "base/memory/ptr_util.h" 15 #include "base/memory/ptr_util.h"
14 #include "base/memory/ref_counted_memory.h" 16 #include "base/memory/ref_counted_memory.h"
15 #include "base/message_loop/message_loop.h" 17 #include "base/message_loop/message_loop.h"
16 #include "base/run_loop.h" 18 #include "base/run_loop.h"
17 #include "base/strings/stringprintf.h" 19 #include "base/strings/stringprintf.h"
18 #include "base/synchronization/waitable_event.h" 20 #include "base/synchronization/waitable_event.h"
19 #include "base/test/sequenced_worker_pool_owner.h" 21 #include "base/test/sequenced_worker_pool_owner.h"
20 #include "base/test/test_io_thread.h" 22 #include "base/test/test_io_thread.h"
21 #include "base/test/trace_event_analyzer.h" 23 #include "base/test/trace_event_analyzer.h"
22 #include "base/threading/platform_thread.h" 24 #include "base/threading/platform_thread.h"
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 const scoped_refptr<RefCountedString>& json, 97 const scoped_refptr<RefCountedString>& json,
96 bool has_more_events) { 98 bool has_more_events) {
97 buffer->AddFragment(json->data()); 99 buffer->AddFragment(json->data());
98 if (!has_more_events) 100 if (!has_more_events)
99 quit_closure.Run(); 101 quit_closure.Run();
100 } 102 }
101 103
102 // Posts |task| to |task_runner| and blocks until it is executed. 104 // Posts |task| to |task_runner| and blocks until it is executed.
103 void PostTaskAndWait(const tracked_objects::Location& from_here, 105 void PostTaskAndWait(const tracked_objects::Location& from_here,
104 SequencedTaskRunner* task_runner, 106 SequencedTaskRunner* task_runner,
105 const base::Closure& task) { 107 base::Closure task) {
106 base::WaitableEvent event(WaitableEvent::ResetPolicy::MANUAL, 108 base::WaitableEvent event(WaitableEvent::ResetPolicy::MANUAL,
107 WaitableEvent::InitialState::NOT_SIGNALED); 109 WaitableEvent::InitialState::NOT_SIGNALED);
108 task_runner->PostTask(from_here, task); 110 task_runner->PostTask(from_here, std::move(task));
109 task_runner->PostTask( 111 task_runner->PostTask(
110 FROM_HERE, base::Bind(&WaitableEvent::Signal, base::Unretained(&event))); 112 FROM_HERE, base::Bind(&WaitableEvent::Signal, base::Unretained(&event)));
111 // The SequencedTaskRunner guarantees that |event| will only be signaled after 113 // The SequencedTaskRunner guarantees that |event| will only be signaled after
112 // |task| is executed. 114 // |task| is executed.
113 event.Wait(); 115 event.Wait();
114 } 116 }
115 117
116 } // namespace 118 } // namespace
117 119
118 // Testing MemoryDumpManagerDelegate which, by default, short-circuits dump 120 // Testing MemoryDumpManagerDelegate which, by default, short-circuits dump
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 public: 176 public:
175 TestSequencedTaskRunner() 177 TestSequencedTaskRunner()
176 : worker_pool_(2 /* max_threads */, "Test Task Runner"), 178 : worker_pool_(2 /* max_threads */, "Test Task Runner"),
177 enabled_(true), 179 enabled_(true),
178 num_of_post_tasks_(0) {} 180 num_of_post_tasks_(0) {}
179 181
180 void set_enabled(bool value) { enabled_ = value; } 182 void set_enabled(bool value) { enabled_ = value; }
181 unsigned no_of_post_tasks() const { return num_of_post_tasks_; } 183 unsigned no_of_post_tasks() const { return num_of_post_tasks_; }
182 184
183 bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here, 185 bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here,
184 const Closure& task, 186 Closure task,
185 TimeDelta delay) override { 187 TimeDelta delay) override {
186 NOTREACHED(); 188 NOTREACHED();
187 return false; 189 return false;
188 } 190 }
189 191
190 bool PostDelayedTask(const tracked_objects::Location& from_here, 192 bool PostDelayedTask(const tracked_objects::Location& from_here,
191 const Closure& task, 193 Closure task,
192 TimeDelta delay) override { 194 TimeDelta delay) override {
193 num_of_post_tasks_++; 195 num_of_post_tasks_++;
194 if (enabled_) { 196 if (enabled_) {
195 return worker_pool_.pool()->PostSequencedWorkerTask(token_, from_here, 197 return worker_pool_.pool()->PostSequencedWorkerTask(token_, from_here,
196 task); 198 std::move(task));
197 } 199 }
198 return false; 200 return false;
199 } 201 }
200 202
201 bool RunsTasksOnCurrentThread() const override { 203 bool RunsTasksOnCurrentThread() const override {
202 return worker_pool_.pool()->RunsTasksOnCurrentThread(); 204 return worker_pool_.pool()->RunsTasksOnCurrentThread();
203 } 205 }
204 206
205 private: 207 private:
206 ~TestSequencedTaskRunner() override {} 208 ~TestSequencedTaskRunner() override {}
(...skipping 1079 matching lines...) Expand 10 before | Expand all | Expand 10 after
1286 thread.Start(); 1288 thread.Start();
1287 RegisterDumpProvider(&mdp1, thread.task_runner(), kDefaultOptions, 1289 RegisterDumpProvider(&mdp1, thread.task_runner(), kDefaultOptions,
1288 "BlacklistTestDumpProvider"); 1290 "BlacklistTestDumpProvider");
1289 // Unregistering on wrong thread should not crash. 1291 // Unregistering on wrong thread should not crash.
1290 mdm_->UnregisterDumpProvider(&mdp1); 1292 mdm_->UnregisterDumpProvider(&mdp1);
1291 thread.Stop(); 1293 thread.Stop();
1292 } 1294 }
1293 1295
1294 } // namespace trace_event 1296 } // namespace trace_event
1295 } // namespace base 1297 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698