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 
RequestGlobalDumpForInProcessTesting(base::trace_event::MemoryDumpType dump_type,base::trace_event::MemoryDumpLevelOfDetail level_of_detail)15 void RequestGlobalDumpForInProcessTesting(
16     base::trace_event::MemoryDumpType dump_type,
17     base::trace_event::MemoryDumpLevelOfDetail level_of_detail) {
18   MemoryDumpRequestArgs local_args = {0 /* dump_guid */, dump_type,
19                                       level_of_detail};
20   MemoryDumpManager::GetInstance()->CreateProcessDump(
21       local_args, ProcessMemoryDumpCallback());
22 }
23 
24 // Short circuits the RequestGlobalDumpFunction() to CreateProcessDump(),
25 // effectively allowing to use both in unittests with the same behavior.
26 // Unittests are in-process only and don't require all the multi-process
27 // dump handshaking (which would require bits outside of base).
InitializeMemoryDumpManagerForInProcessTesting(bool is_coordinator)28 void InitializeMemoryDumpManagerForInProcessTesting(bool is_coordinator) {
29   MemoryDumpManager* instance = MemoryDumpManager::GetInstance();
30   instance->set_dumper_registrations_ignored_for_testing(true);
31   instance->Initialize(BindRepeating(&RequestGlobalDumpForInProcessTesting),
32                        is_coordinator);
33 }
34 
35 }  // namespace trace_event
36 }  // namespace base
37 
38 #endif  // BASE_TRACE_EVENT_MEMORY_DUMP_MANAGER_TEST_UTILS_H_
39