OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #ifndef CONTENT_CHILD_WEB_PROCESS_MEMORY_DUMP_IMPL_H_ | |
6 #define CONTENT_CHILD_WEB_PROCESS_MEMORY_DUMP_IMPL_H_ | |
7 | |
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 "base/memory/scoped_vector.h" | |
12 #include "base/trace_event/memory_dump_request_args.h" | |
13 #include "content/common/content_export.h" | |
14 #include "third_party/WebKit/public/platform/WebProcessMemoryDump.h" | |
15 | |
16 namespace base { | |
17 namespace trace_event { | |
18 class MemoryAllocatorDump; | |
19 class ProcessMemoryDump; | |
20 } // namespace base | |
21 } // namespace trace_event | |
22 | |
23 namespace skia { | |
24 class SkiaTraceMemoryDumpImpl; | |
25 } // namespace skia | |
26 | |
27 namespace content { | |
28 | |
29 class WebMemoryAllocatorDumpImpl; | |
30 | |
31 // Implements the blink::WebProcessMemoryDump interface by means of proxying the | |
32 // calls to createMemoryAllocatorDump() to the underlying | |
33 // base::trace_event::ProcessMemoryDump instance. | |
34 class CONTENT_EXPORT WebProcessMemoryDumpImpl final | |
35 : public NON_EXPORTED_BASE(blink::WebProcessMemoryDump) { | |
36 public: | |
37 // Creates a standalone WebProcessMemoryDumpImp, which owns the underlying | |
38 // ProcessMemoryDump. | |
39 WebProcessMemoryDumpImpl(); | |
40 | |
41 // Wraps (without owning) an existing ProcessMemoryDump. | |
42 explicit WebProcessMemoryDumpImpl( | |
43 base::trace_event::MemoryDumpLevelOfDetail level_of_detail, | |
44 base::trace_event::ProcessMemoryDump* process_memory_dump); | |
45 | |
46 ~WebProcessMemoryDumpImpl() override; | |
47 | |
48 // blink::WebProcessMemoryDump implementation. | |
49 blink::WebMemoryAllocatorDump* createMemoryAllocatorDump( | |
50 const blink::WebString& absolute_name) override; | |
51 blink::WebMemoryAllocatorDump* createMemoryAllocatorDump( | |
52 const blink::WebString& absolute_name, | |
53 blink::WebMemoryAllocatorDumpGuid guid) override; | |
54 blink::WebMemoryAllocatorDump* getMemoryAllocatorDump( | |
55 const blink::WebString& absolute_name) const override; | |
56 void clear() override; | |
57 void takeAllDumpsFrom(blink::WebProcessMemoryDump* other) override; | |
58 void AddOwnershipEdge(blink::WebMemoryAllocatorDumpGuid source, | |
59 blink::WebMemoryAllocatorDumpGuid target, | |
60 int importance) override; | |
61 void AddOwnershipEdge(blink::WebMemoryAllocatorDumpGuid source, | |
62 blink::WebMemoryAllocatorDumpGuid target) override; | |
63 void AddSuballocation(blink::WebMemoryAllocatorDumpGuid source, | |
64 const blink::WebString& targetNodeName) override; | |
65 SkTraceMemoryDump* CreateDumpAdapterForSkia( | |
66 const blink::WebString& dumpNamePrefix) override; | |
67 | |
68 const base::trace_event::ProcessMemoryDump* process_memory_dump() const { | |
69 return process_memory_dump_; | |
70 } | |
71 | |
72 private: | |
73 FRIEND_TEST_ALL_PREFIXES(WebProcessMemoryDumpImplTest, IntegrationTest); | |
74 | |
75 blink::WebMemoryAllocatorDump* createWebMemoryAllocatorDump( | |
76 base::trace_event::MemoryAllocatorDump* memory_allocator_dump); | |
77 | |
78 // Only for the case of ProcessMemoryDump being owned (i.e. the default ctor). | |
79 scoped_ptr<base::trace_event::ProcessMemoryDump> owned_process_memory_dump_; | |
80 | |
81 // The underlying ProcessMemoryDump instance to which the | |
82 // createMemoryAllocatorDump() calls will be proxied to. | |
83 base::trace_event::ProcessMemoryDump* process_memory_dump_; // Not owned. | |
84 | |
85 // TODO(ssid): Remove it once this information is added to ProcessMemoryDump. | |
86 base::trace_event::MemoryDumpLevelOfDetail level_of_detail_; | |
87 | |
88 // Reverse index of MemoryAllocatorDump -> WebMemoryAllocatorDumpImpl wrapper. | |
89 // By design WebMemoryDumpProvider(s) are not supposed to hold the pointer | |
90 // to the WebProcessMemoryDump passed as argument of the onMemoryDump() call. | |
91 // Those pointers are valid only within the scope of the call and can be | |
92 // safely torn down once the WebProcessMemoryDumpImpl itself is destroyed. | |
93 base::ScopedPtrHashMap<base::trace_event::MemoryAllocatorDump*, | |
94 scoped_ptr<WebMemoryAllocatorDumpImpl>> | |
95 memory_allocator_dumps_; | |
96 | |
97 // Stores SkTraceMemoryDump for the current ProcessMemoryDump. | |
98 ScopedVector<skia::SkiaTraceMemoryDumpImpl> sk_trace_dump_list_; | |
99 | |
100 DISALLOW_COPY_AND_ASSIGN(WebProcessMemoryDumpImpl); | |
101 }; | |
102 | |
103 } // namespace content | |
104 | |
105 #endif // CONTENT_CHILD_WEB_PROCESS_MEMORY_DUMP_IMPL_H_ | |
OLD | NEW |