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
* getMemoryAllocatorDump(
45 const blink::WebString
& absolute_name
) const;
47 virtual void takeAllDumpsFrom(blink::WebProcessMemoryDump
* other
);
49 const base::trace_event::ProcessMemoryDump
* process_memory_dump() const {
50 return process_memory_dump_
;
54 FRIEND_TEST_ALL_PREFIXES(WebProcessMemoryDumpImplTest
, IntegrationTest
);
56 // Only for the case of ProcessMemoryDump being owned (i.e. the default ctor).
57 scoped_ptr
<base::trace_event::ProcessMemoryDump
> owned_process_memory_dump_
;
59 // The underlying ProcessMemoryDump instance to which the
60 // createMemoryAllocatorDump() calls will be proxied to.
61 base::trace_event::ProcessMemoryDump
* process_memory_dump_
; // Not owned.
63 // Reverse index of MemoryAllocatorDump -> WebMemoryAllocatorDumpImpl wrapper.
64 // By design WebMemoryDumpProvider(s) are not supposed to hold the pointer
65 // to the WebProcessMemoryDump passed as argument of the onMemoryDump() call.
66 // Those pointers are valid only within the scope of the call and can be
67 // safely torn down once the WebProcessMemoryDumpImpl itself is destroyed.
68 base::ScopedPtrHashMap
<base::trace_event::MemoryAllocatorDump
*,
69 scoped_ptr
<WebMemoryAllocatorDumpImpl
>>
70 memory_allocator_dumps_
;
72 DISALLOW_COPY_AND_ASSIGN(WebProcessMemoryDumpImpl
);
75 } // namespace content
77 #endif // CONTENT_CHILD_WEB_PROCESS_MEMORY_DUMP_IMPL_H_