OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef BASE_TRACE_EVENT_MEMORY_DUMP_MANAGER_TEST_UTILS_H_ |
| 6 #define BASE_TRACE_EVENT_MEMORY_DUMP_MANAGER_TEST_UTILS_H_ |
| 7 |
| 8 #include "base/bind.h" |
| 9 #include "base/trace_event/memory_dump_manager.h" |
| 10 #include "base/trace_event/memory_dump_request_args.h" |
| 11 |
| 12 namespace base { |
| 13 namespace trace_event { |
| 14 |
| 15 // Short-circuit the RequestGlobalDump() calls to CreateProcessDump(). |
| 16 // Rationale: only the in-process logic is required for unittests. |
| 17 void RequestGlobalDumpForInProcessTesting( |
| 18 const MemoryDumpRequestArgs& args, |
| 19 const GlobalMemoryDumpCallback& global_callback) { |
| 20 // Turns a ProcessMemoryDumpCallback into a GlobalMemoryDumpCallback. |
| 21 auto callback_adapter = [](const GlobalMemoryDumpCallback& global_callback, |
| 22 uint64_t dump_guid, bool success, |
| 23 const Optional<MemoryDumpCallbackResult>& result) { |
| 24 if (!global_callback.is_null()) |
| 25 global_callback.Run(dump_guid, success); |
| 26 }; |
| 27 MemoryDumpManager::GetInstance()->CreateProcessDump( |
| 28 args, Bind(callback_adapter, global_callback)); |
| 29 }; |
| 30 |
| 31 // Short circuits the RequestGlobalDumpFunction() to CreateProcessDump(), |
| 32 // effectively allowing to use both in unittests with the same behavior. |
| 33 // Unittests are in-process only and don't require all the multi-process |
| 34 // dump handshaking (which would require bits outside of base). |
| 35 void InitializeMemoryDumpManagerForInProcessTesting(bool is_coordinator) { |
| 36 MemoryDumpManager* instance = MemoryDumpManager::GetInstance(); |
| 37 instance->set_dumper_registrations_ignored_for_testing(true); |
| 38 instance->Initialize(BindRepeating(&RequestGlobalDumpForInProcessTesting), |
| 39 is_coordinator); |
| 40 instance->set_dumper_registrations_ignored_for_testing(false); |
| 41 } |
| 42 |
| 43 } // namespace trace_event |
| 44 } // namespace base |
| 45 |
| 46 #endif // BASE_TRACE_EVENT_MEMORY_DUMP_MANAGER_TEST_UTILS_H_ |
OLD | NEW |