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

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: rebase 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 public: 175 public:
174 TestSequencedTaskRunner() 176 TestSequencedTaskRunner()
175 : worker_pool_(2 /* max_threads */, "Test Task Runner"), 177 : worker_pool_(2 /* max_threads */, "Test Task Runner"),
176 enabled_(true), 178 enabled_(true),
177 num_of_post_tasks_(0) {} 179 num_of_post_tasks_(0) {}
178 180
179 void set_enabled(bool value) { enabled_ = value; } 181 void set_enabled(bool value) { enabled_ = value; }
180 unsigned no_of_post_tasks() const { return num_of_post_tasks_; } 182 unsigned no_of_post_tasks() const { return num_of_post_tasks_; }
181 183
182 bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here, 184 bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here,
183 const Closure& task, 185 Closure task,
184 TimeDelta delay) override { 186 TimeDelta delay) override {
185 NOTREACHED(); 187 NOTREACHED();
186 return false; 188 return false;
187 } 189 }
188 190
189 bool PostDelayedTask(const tracked_objects::Location& from_here, 191 bool PostDelayedTask(const tracked_objects::Location& from_here,
190 const Closure& task, 192 Closure task,
191 TimeDelta delay) override { 193 TimeDelta delay) override {
192 num_of_post_tasks_++; 194 num_of_post_tasks_++;
193 if (enabled_) { 195 if (enabled_) {
194 return worker_pool_.pool()->PostSequencedWorkerTask(token_, from_here, 196 return worker_pool_.pool()->PostSequencedWorkerTask(token_, from_here,
195 task); 197 std::move(task));
196 } 198 }
197 return false; 199 return false;
198 } 200 }
199 201
200 bool RunsTasksOnCurrentThread() const override { 202 bool RunsTasksOnCurrentThread() const override {
201 return worker_pool_.pool()->RunsTasksOnCurrentThread(); 203 return worker_pool_.pool()->RunsTasksOnCurrentThread();
202 } 204 }
203 205
204 private: 206 private:
205 ~TestSequencedTaskRunner() override {} 207 ~TestSequencedTaskRunner() override {}
(...skipping 1080 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