Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1709)

Side by Side Diff: services/resource_coordinator/public/cpp/memory/memory_dump_manager_delegate_impl.h

Issue 2694083005: memory-infra: Finish moving memory_infra from TracingController (Closed)
Patch Set: style: auto must not deduce to raw pointer Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 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 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 SERVICES_RESOURCE_COORDINATOR_PUBLIC_CPP_MEMORY_MEMORY_DUMP_MANAGER_DELE GATE_IMPL_H_ 5 #ifndef SERVICES_RESOURCE_COORDINATOR_PUBLIC_CPP_MEMORY_MEMORY_DUMP_MANAGER_DELE GATE_IMPL_H_
6 #define SERVICES_RESOURCE_COORDINATOR_PUBLIC_CPP_MEMORY_MEMORY_DUMP_MANAGER_DELE GATE_IMPL_H_ 6 #define SERVICES_RESOURCE_COORDINATOR_PUBLIC_CPP_MEMORY_MEMORY_DUMP_MANAGER_DELE GATE_IMPL_H_
7 7
8 #include "base/lazy_instance.h"
9 #include "base/single_thread_task_runner.h"
10 #include "base/synchronization/lock.h"
8 #include "base/trace_event/memory_dump_manager.h" 11 #include "base/trace_event/memory_dump_manager.h"
9 #include "base/trace_event/memory_dump_request_args.h" 12 #include "base/trace_event/memory_dump_request_args.h"
10 #include "mojo/public/cpp/bindings/binding.h" 13 #include "mojo/public/cpp/bindings/binding.h"
11 #include "services/resource_coordinator/public/cpp/memory/coordinator.h" 14 #include "services/resource_coordinator/public/cpp/memory/coordinator.h"
12 #include "services/resource_coordinator/public/interfaces/memory/memory_instrume ntation.mojom.h" 15 #include "services/resource_coordinator/public/interfaces/memory/memory_instrume ntation.mojom.h"
13 #include "services/service_manager/public/cpp/interface_provider.h" 16 #include "services/service_manager/public/cpp/interface_provider.h"
14 17
15 namespace memory_instrumentation { 18 namespace memory_instrumentation {
16 19
17 class MemoryDumpManagerDelegateImpl 20 class MemoryDumpManagerDelegateImpl
18 : public base::trace_event::MemoryDumpManagerDelegate, 21 : public base::trace_event::MemoryDumpManagerDelegate,
19 public mojom::ProcessLocalDumpManager { 22 public mojom::ProcessLocalDumpManager {
20 public: 23 public:
24 static MemoryDumpManagerDelegateImpl* GetInstance();
25
21 // Use to bind to a remote coordinator. 26 // Use to bind to a remote coordinator.
22 MemoryDumpManagerDelegateImpl( 27 void InitializeWithInterfaceProvider(
23 service_manager::InterfaceProvider* interface_provider); 28 service_manager::InterfaceProvider* interface_provider);
24 29
25 // Use to bind to a coordinator in the same process. 30 // Use to bind to a coordinator in the same process.
26 MemoryDumpManagerDelegateImpl(Coordinator* coordinator); 31 void InitializeWithCoordinator(
27 ~MemoryDumpManagerDelegateImpl() override; 32 Coordinator* coordinator,
33 scoped_refptr<base::SingleThreadTaskRunner> task_runner);
28 34
29 bool IsCoordinator() const; 35 bool IsCoordinator() const override;
30 36
31 // The base::trace_event::MemoryDumpManager calls this. 37 // The base::trace_event::MemoryDumpManager calls this.
32 void RequestGlobalMemoryDump( 38 void RequestGlobalMemoryDump(
33 const base::trace_event::MemoryDumpRequestArgs& args, 39 const base::trace_event::MemoryDumpRequestArgs& args,
34 const base::trace_event::MemoryDumpCallback& callback) override; 40 const base::trace_event::MemoryDumpCallback& callback) override;
35 41
42 void SetAsNonCoordinatorForTesting();
43
36 private: 44 private:
45 friend std::default_delete<MemoryDumpManagerDelegateImpl>; // For testing
46 friend class MemoryDumpManagerDelegateImplTest; // For testing
47 friend struct base::DefaultLazyInstanceTraits<MemoryDumpManagerDelegateImpl>;
48
49 MemoryDumpManagerDelegateImpl();
50 ~MemoryDumpManagerDelegateImpl() override;
51
37 // The ProcessLocalDumpManager interface. The coordinator calls this. 52 // The ProcessLocalDumpManager interface. The coordinator calls this.
38 void RequestProcessMemoryDump( 53 void RequestProcessMemoryDump(
39 const base::trace_event::MemoryDumpRequestArgs& args, 54 const base::trace_event::MemoryDumpRequestArgs& args,
40 const RequestProcessMemoryDumpCallback& callback) override; 55 const RequestProcessMemoryDumpCallback& callback) override;
41 56
42 bool is_coordinator_; 57 // A proxy callback for updating |pending_memory_dump_guid_|.
58 void MemoryDumpCallbackProxy(
59 const base::trace_event::MemoryDumpCallback& callback,
60 uint64_t dump_guid,
61 bool success);
62
63 bool initialized_;
43 mojom::CoordinatorPtr coordinator_; 64 mojom::CoordinatorPtr coordinator_;
44 mojo::Binding<mojom::ProcessLocalDumpManager> binding_; 65 mojo::Binding<mojom::ProcessLocalDumpManager> binding_;
66 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
67 uint64_t pending_memory_dump_guid_;
68
69 // Prevents racy access to |pending_memory_dump_guid_|.
70 base::Lock pending_memory_dump_guid_lock_;
71
72 // Prevents racy access to |initialized_|.
73 base::Lock initialized_lock_;
45 74
46 DISALLOW_COPY_AND_ASSIGN(MemoryDumpManagerDelegateImpl); 75 DISALLOW_COPY_AND_ASSIGN(MemoryDumpManagerDelegateImpl);
47 }; 76 };
48 77
49 } // namespace memory_instrumentation 78 } // namespace memory_instrumentation
50 79
51 #endif // SERVICES_RESOURCE_COORDINATOR_PUBLIC_CPP_MEMORY_MEMORY_DUMP_MANAGER_D ELEGATE_IMPL_H_ 80 #endif // SERVICES_RESOURCE_COORDINATOR_PUBLIC_CPP_MEMORY_MEMORY_DUMP_MANAGER_D ELEGATE_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698