OLD | NEW |
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 <utility> |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 base::WaitableEvent event(WaitableEvent::ResetPolicy::MANUAL, | 108 base::WaitableEvent event(WaitableEvent::ResetPolicy::MANUAL, |
109 WaitableEvent::InitialState::NOT_SIGNALED); | 109 WaitableEvent::InitialState::NOT_SIGNALED); |
110 task_runner->PostTask(from_here, std::move(task)); | 110 task_runner->PostTask(from_here, std::move(task)); |
111 task_runner->PostTask( | 111 task_runner->PostTask( |
112 FROM_HERE, base::Bind(&WaitableEvent::Signal, base::Unretained(&event))); | 112 FROM_HERE, base::Bind(&WaitableEvent::Signal, base::Unretained(&event))); |
113 // The SequencedTaskRunner guarantees that |event| will only be signaled after | 113 // The SequencedTaskRunner guarantees that |event| will only be signaled after |
114 // |task| is executed. | 114 // |task| is executed. |
115 event.Wait(); | 115 event.Wait(); |
116 } | 116 } |
117 | 117 |
118 } // namespace | |
119 | |
120 // Testing MemoryDumpManagerDelegate which, by default, short-circuits dump | 118 // Testing MemoryDumpManagerDelegate which, by default, short-circuits dump |
121 // requests locally to the MemoryDumpManager instead of performing IPC dances. | 119 // requests locally to the MemoryDumpManager instead of performing IPC dances. |
122 class MemoryDumpManagerDelegateForTesting : public MemoryDumpManagerDelegate { | 120 class MemoryDumpManagerDelegateForTesting : public MemoryDumpManagerDelegate { |
123 public: | 121 public: |
124 MemoryDumpManagerDelegateForTesting(bool is_coordinator) | 122 MemoryDumpManagerDelegateForTesting(bool is_coordinator) |
125 : is_coordinator_(is_coordinator) { | 123 : is_coordinator_(is_coordinator) { |
126 ON_CALL(*this, RequestGlobalMemoryDump(_, _)) | 124 ON_CALL(*this, RequestGlobalMemoryDump(_, _)) |
127 .WillByDefault(Invoke( | 125 .WillByDefault(Invoke( |
128 this, &MemoryDumpManagerDelegateForTesting::CreateProcessDump)); | 126 this, &MemoryDumpManagerDelegateForTesting::CreateProcessDump)); |
129 } | 127 } |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 | 204 |
207 private: | 205 private: |
208 ~TestSequencedTaskRunner() override {} | 206 ~TestSequencedTaskRunner() override {} |
209 | 207 |
210 SequencedWorkerPoolOwner worker_pool_; | 208 SequencedWorkerPoolOwner worker_pool_; |
211 const SequencedWorkerPool::SequenceToken token_; | 209 const SequencedWorkerPool::SequenceToken token_; |
212 bool enabled_; | 210 bool enabled_; |
213 unsigned num_of_post_tasks_; | 211 unsigned num_of_post_tasks_; |
214 }; | 212 }; |
215 | 213 |
| 214 } // namespace |
| 215 |
216 class MemoryDumpManagerTest : public testing::Test { | 216 class MemoryDumpManagerTest : public testing::Test { |
217 public: | 217 public: |
218 MemoryDumpManagerTest() : testing::Test(), kDefaultOptions() {} | 218 MemoryDumpManagerTest() : testing::Test(), kDefaultOptions() {} |
219 | 219 |
220 void SetUp() override { | 220 void SetUp() override { |
221 last_callback_success_ = false; | 221 last_callback_success_ = false; |
222 message_loop_.reset(new MessageLoop()); | 222 message_loop_.reset(new MessageLoop()); |
223 mdm_.reset(new MemoryDumpManager()); | 223 mdm_.reset(new MemoryDumpManager()); |
224 MemoryDumpManager::SetInstanceForTesting(mdm_.get()); | 224 MemoryDumpManager::SetInstanceForTesting(mdm_.get()); |
225 ASSERT_EQ(mdm_.get(), MemoryDumpManager::GetInstance()); | 225 ASSERT_EQ(mdm_.get(), MemoryDumpManager::GetInstance()); |
(...skipping 1065 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1291 thread.Start(); | 1291 thread.Start(); |
1292 RegisterDumpProvider(&mdp1, thread.task_runner(), kDefaultOptions, | 1292 RegisterDumpProvider(&mdp1, thread.task_runner(), kDefaultOptions, |
1293 "BlacklistTestDumpProvider"); | 1293 "BlacklistTestDumpProvider"); |
1294 // Unregistering on wrong thread should not crash. | 1294 // Unregistering on wrong thread should not crash. |
1295 mdm_->UnregisterDumpProvider(&mdp1); | 1295 mdm_->UnregisterDumpProvider(&mdp1); |
1296 thread.Stop(); | 1296 thread.Stop(); |
1297 } | 1297 } |
1298 | 1298 |
1299 } // namespace trace_event | 1299 } // namespace trace_event |
1300 } // namespace base | 1300 } // namespace base |
OLD | NEW |