Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef BASE_TRACE_EVENT_MEMORY_DUMP_PROVIDER_H_ | 5 #ifndef BASE_TRACE_EVENT_MEMORY_DUMP_PROVIDER_H_ |
| 6 #define BASE_TRACE_EVENT_MEMORY_DUMP_PROVIDER_H_ | 6 #define BASE_TRACE_EVENT_MEMORY_DUMP_PROVIDER_H_ |
| 7 | 7 |
| 8 #include "base/base_export.h" | 8 #include "base/base_export.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/memory/ref_counted.h" | |
| 10 #include "base/trace_event/memory_dump_request_args.h" | 11 #include "base/trace_event/memory_dump_request_args.h" |
| 11 | 12 |
| 12 namespace base { | 13 namespace base { |
| 14 | |
| 15 class SingleThreadTaskRunner; | |
| 16 | |
| 13 namespace trace_event { | 17 namespace trace_event { |
| 14 | 18 |
| 15 class ProcessMemoryDump; | 19 class ProcessMemoryDump; |
| 16 | 20 |
| 17 // Args passed to OnMemoryDump(). This is to avoid rewriting all the subclasses | 21 // Args passed to OnMemoryDump(). This is to avoid rewriting all the subclasses |
| 18 // in the codebase when extending the MemoryDumpProvider API. | 22 // in the codebase when extending the MemoryDumpProvider API. |
| 19 struct MemoryDumpArgs { | 23 struct MemoryDumpArgs { |
| 20 MemoryDumpLevelOfDetail level_of_detail; | 24 MemoryDumpLevelOfDetail level_of_detail; |
| 21 }; | 25 }; |
| 22 | 26 |
| 23 // The contract interface that memory dump providers must implement. | 27 // The contract interface that memory dump providers must implement. |
| 24 class BASE_EXPORT MemoryDumpProvider { | 28 class BASE_EXPORT MemoryDumpProvider { |
| 25 public: | 29 public: |
| 30 // Helper methods to register/unregister a memory dump provider. | |
| 31 // The MemoryDumpManager does NOT take memory ownership of |dump_provider|, | |
| 32 // which is expected to either be a singleton or unregister itself. | |
| 33 // If the optional |task_runner| argument is non-null, all the calls to the | |
| 34 // |dump_provider| will be issued on the given thread. Otherwise, the |mdp| | |
| 35 // should be able to handle calls on arbitrary threads. | |
| 36 static void Register( | |
|
Ruud van Asseldonk
2015/10/08 18:40:54
Does this introduce two ways of doing the same thi
| |
| 37 MemoryDumpProvider* dump_provider, | |
| 38 const scoped_refptr<SingleThreadTaskRunner>& task_runner); | |
| 39 | |
| 40 // Similar to Register, but all the calls are guaranteed to happen on the | |
| 41 // current thread's task runner. | |
| 42 static void RegisterOnCurrentThread(MemoryDumpProvider* dump_provider); | |
| 43 | |
| 44 static void Unregister(MemoryDumpProvider* dump_provider); | |
| 45 | |
| 26 // Called by the MemoryDumpManager when generating memory dumps. | 46 // Called by the MemoryDumpManager when generating memory dumps. |
| 27 // The |args| specify if the embedder should generate light/heavy dumps on | 47 // The |args| specify if the embedder should generate light/heavy dumps on |
| 28 // dump requests. The embedder should return true if the |pmd| was | 48 // dump requests. The embedder should return true if the |pmd| was |
| 29 // successfully populated, false if something went wrong and the dump should | 49 // successfully populated, false if something went wrong and the dump should |
| 30 // be considered invalid. | 50 // be considered invalid. |
| 31 // (Note, the MemoryDumpManager has a fail-safe logic which will disable the | 51 // (Note, the MemoryDumpManager has a fail-safe logic which will disable the |
| 32 // MemoryDumpProvider for the entire trace session if it fails consistently). | 52 // MemoryDumpProvider for the entire trace session if it fails consistently). |
| 33 virtual bool OnMemoryDump(const MemoryDumpArgs& args, | 53 virtual bool OnMemoryDump(const MemoryDumpArgs& args, |
| 34 ProcessMemoryDump* pmd) = 0; | 54 ProcessMemoryDump* pmd) = 0; |
| 35 | 55 |
| 36 protected: | 56 protected: |
| 37 MemoryDumpProvider() {} | 57 MemoryDumpProvider() {} |
| 38 virtual ~MemoryDumpProvider() {} | 58 virtual ~MemoryDumpProvider() {} |
| 39 | 59 |
| 40 DISALLOW_COPY_AND_ASSIGN(MemoryDumpProvider); | 60 DISALLOW_COPY_AND_ASSIGN(MemoryDumpProvider); |
| 41 }; | 61 }; |
| 42 | 62 |
| 43 } // namespace trace_event | 63 } // namespace trace_event |
| 44 } // namespace base | 64 } // namespace base |
| 45 | 65 |
| 46 #endif // BASE_TRACE_EVENT_MEMORY_DUMP_PROVIDER_H_ | 66 #endif // BASE_TRACE_EVENT_MEMORY_DUMP_PROVIDER_H_ |
| OLD | NEW |