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

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

Issue 2741203002: memory-infra: Finish moving to Mojo (3nd attempt) (Closed)
Patch Set: rebase 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/single_thread_task_runner.h"
9 #include "base/synchronization/lock.h"
8 #include "base/trace_event/memory_dump_manager.h" 10 #include "base/trace_event/memory_dump_manager.h"
9 #include "base/trace_event/memory_dump_request_args.h" 11 #include "base/trace_event/memory_dump_request_args.h"
10 #include "mojo/public/cpp/bindings/binding.h" 12 #include "mojo/public/cpp/bindings/binding.h"
11 #include "services/resource_coordinator/public/cpp/memory/coordinator.h" 13 #include "services/resource_coordinator/public/cpp/memory/coordinator.h"
12 #include "services/resource_coordinator/public/interfaces/memory/memory_instrume ntation.mojom.h" 14 #include "services/resource_coordinator/public/interfaces/memory/memory_instrume ntation.mojom.h"
13 #include "services/service_manager/public/cpp/interface_provider.h" 15 #include "services/service_manager/public/cpp/interface_provider.h"
14 16
15 namespace memory_instrumentation { 17 namespace memory_instrumentation {
16 18
19 // This is the bridge between MemoryDumpManager and the Coordinator service.
20 // This indirection is needed to avoid a dependency from //base, where
21 // MemoryDumpManager lives, to //services, where the Coordinator service lives.
22 //
23 // This cannot just be implemented by the Coordinator service, because there is
24 // no Coordinator service in child processes. So, in a child process, the
25 // delegate remotely connects to the Coordinator service. In the browser
26 // process, the delegate locally connects to the Coordinator service.
17 class MemoryDumpManagerDelegateImpl 27 class MemoryDumpManagerDelegateImpl
18 : public base::trace_event::MemoryDumpManagerDelegate, 28 : public base::trace_event::MemoryDumpManagerDelegate,
19 public mojom::ProcessLocalDumpManager { 29 public mojom::ProcessLocalDumpManager {
20 public: 30 public:
21 // Use to bind to a remote coordinator. 31 class Config {
22 MemoryDumpManagerDelegateImpl( 32 public:
23 service_manager::InterfaceProvider* interface_provider); 33 Config(service_manager::InterfaceProvider* interface_provider)
34 : interface_provider_(interface_provider), coordinator_(nullptr) {}
35 Config(Coordinator* coordinator)
36 : interface_provider_(nullptr), coordinator_(coordinator) {}
37 ~Config();
24 38
25 // Use to bind to a coordinator in the same process. 39 service_manager::InterfaceProvider* interface_provider() const {
26 MemoryDumpManagerDelegateImpl(Coordinator* coordinator); 40 return interface_provider_;
41 }
42
43 Coordinator* coordinator() const { return coordinator_; }
44
45 private:
46 service_manager::InterfaceProvider* interface_provider_;
47 Coordinator* coordinator_;
48 bool is_test_config_;
49 };
50
51 explicit MemoryDumpManagerDelegateImpl(const Config& config);
27 ~MemoryDumpManagerDelegateImpl() override; 52 ~MemoryDumpManagerDelegateImpl() override;
28 53
29 bool IsCoordinator() const; 54 bool IsCoordinator() const override;
30 55
31 // The base::trace_event::MemoryDumpManager calls this. 56 // The base::trace_event::MemoryDumpManager calls this.
32 void RequestGlobalMemoryDump( 57 void RequestGlobalMemoryDump(
33 const base::trace_event::MemoryDumpRequestArgs& args, 58 const base::trace_event::MemoryDumpRequestArgs& args,
34 const base::trace_event::MemoryDumpCallback& callback) override; 59 const base::trace_event::MemoryDumpCallback& callback) override;
35 60
61 Config config() { return config_; }
62 void SetAsNonCoordinatorForTesting();
63
36 private: 64 private:
65 friend std::default_delete<MemoryDumpManagerDelegateImpl>; // For testing
66 friend class MemoryDumpManagerDelegateImplTest; // For testing
67
37 // The ProcessLocalDumpManager interface. The coordinator calls this. 68 // The ProcessLocalDumpManager interface. The coordinator calls this.
38 void RequestProcessMemoryDump( 69 void RequestProcessMemoryDump(
39 const base::trace_event::MemoryDumpRequestArgs& args, 70 const base::trace_event::MemoryDumpRequestArgs& args,
40 const RequestProcessMemoryDumpCallback& callback) override; 71 const RequestProcessMemoryDumpCallback& callback) override;
41 72
42 bool is_coordinator_; 73 // A proxy callback for updating |pending_memory_dump_guid_|.
74 void MemoryDumpCallbackProxy(
75 const base::trace_event::MemoryDumpCallback& callback,
76 uint64_t dump_guid,
77 bool success);
78
43 mojom::CoordinatorPtr coordinator_; 79 mojom::CoordinatorPtr coordinator_;
44 mojo::Binding<mojom::ProcessLocalDumpManager> binding_; 80 mojo::Binding<mojom::ProcessLocalDumpManager> binding_;
81 const Config config_;
82 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
83 uint64_t pending_memory_dump_guid_;
84
85 // Prevents racy access to |pending_memory_dump_guid_|.
86 base::Lock pending_memory_dump_guid_lock_;
87
88 // Prevents racy access to |initialized_|.
89 base::Lock initialized_lock_;
45 90
46 DISALLOW_COPY_AND_ASSIGN(MemoryDumpManagerDelegateImpl); 91 DISALLOW_COPY_AND_ASSIGN(MemoryDumpManagerDelegateImpl);
47 }; 92 };
48 93
49 } // namespace memory_instrumentation 94 } // namespace memory_instrumentation
50 95
51 #endif // SERVICES_RESOURCE_COORDINATOR_PUBLIC_CPP_MEMORY_MEMORY_DUMP_MANAGER_D ELEGATE_IMPL_H_ 96 #endif // SERVICES_RESOURCE_COORDINATOR_PUBLIC_CPP_MEMORY_MEMORY_DUMP_MANAGER_D ELEGATE_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698