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
3 // found in the LICENSE file.
5 #ifndef CONTENT_CHILD_WEB_PROCESS_MEMORY_DUMP_IMPL_H_
6 #define CONTENT_CHILD_WEB_PROCESS_MEMORY_DUMP_IMPL_H_
8 #include "base/containers/scoped_ptr_hash_map.h"
9 #include "base/gtest_prod_util.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "content/common/content_export.h"
12 #include "third_party/WebKit/public/platform/WebProcessMemoryDump.h"
15 namespace trace_event
{
16 class MemoryAllocatorDump
;
17 class ProcessMemoryDump
;
19 } // namespace trace_event
23 class WebMemoryAllocatorDumpImpl
;
25 // Implements the blink::WebProcessMemoryDump interface by means of proxying the
26 // calls to createMemoryAllocatorDump() to the underlying
27 // base::trace_event::ProcessMemoryDump instance.
28 class CONTENT_EXPORT WebProcessMemoryDumpImpl final
29 : public NON_EXPORTED_BASE(blink::WebProcessMemoryDump
) {
31 // Creates a standalone WebProcessMemoryDumpImp, which owns the underlying
33 WebProcessMemoryDumpImpl();
35 // Wraps (without owning) an existing ProcessMemoryDump.
36 explicit WebProcessMemoryDumpImpl(
37 base::trace_event::ProcessMemoryDump
* process_memory_dump
);
39 virtual ~WebProcessMemoryDumpImpl();
41 // blink::WebProcessMemoryDump implementation.
42 virtual blink::WebMemoryAllocatorDump
* createMemoryAllocatorDump(
43 const blink::WebString
& absolute_name
);
44 virtual blink::WebMemoryAllocatorDump
* createMemoryAllocatorDump(
45 const blink::WebString
& absolute_name
,
46 blink::WebMemoryAllocatorDumpGuid guid
);
47 virtual blink::WebMemoryAllocatorDump
* getMemoryAllocatorDump(
48 const blink::WebString
& absolute_name
) const;
50 virtual void takeAllDumpsFrom(blink::WebProcessMemoryDump
* other
);
51 virtual void AddOwnershipEdge(blink::WebMemoryAllocatorDumpGuid source
,
52 blink::WebMemoryAllocatorDumpGuid target
,
54 virtual void AddOwnershipEdge(blink::WebMemoryAllocatorDumpGuid source
,
55 blink::WebMemoryAllocatorDumpGuid target
);
57 const base::trace_event::ProcessMemoryDump
* process_memory_dump() const {
58 return process_memory_dump_
;
62 FRIEND_TEST_ALL_PREFIXES(WebProcessMemoryDumpImplTest
, IntegrationTest
);
64 blink::WebMemoryAllocatorDump
* createWebMemoryAllocatorDump(
65 base::trace_event::MemoryAllocatorDump
* memory_allocator_dump
);
67 // Only for the case of ProcessMemoryDump being owned (i.e. the default ctor).
68 scoped_ptr
<base::trace_event::ProcessMemoryDump
> owned_process_memory_dump_
;
70 // The underlying ProcessMemoryDump instance to which the
71 // createMemoryAllocatorDump() calls will be proxied to.
72 base::trace_event::ProcessMemoryDump
* process_memory_dump_
; // Not owned.
74 // Reverse index of MemoryAllocatorDump -> WebMemoryAllocatorDumpImpl wrapper.
75 // By design WebMemoryDumpProvider(s) are not supposed to hold the pointer
76 // to the WebProcessMemoryDump passed as argument of the onMemoryDump() call.
77 // Those pointers are valid only within the scope of the call and can be
78 // safely torn down once the WebProcessMemoryDumpImpl itself is destroyed.
79 base::ScopedPtrHashMap
<base::trace_event::MemoryAllocatorDump
*,
80 scoped_ptr
<WebMemoryAllocatorDumpImpl
>>
81 memory_allocator_dumps_
;
83 DISALLOW_COPY_AND_ASSIGN(WebProcessMemoryDumpImpl
);
86 } // namespace content
88 #endif // CONTENT_CHILD_WEB_PROCESS_MEMORY_DUMP_IMPL_H_