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