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

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

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 #include "services/resource_coordinator/public/cpp/memory/memory_dump_manager_de legate_impl.h" 5 #include "services/resource_coordinator/public/cpp/memory/memory_dump_manager_de legate_impl.h"
6 6
7 #include "base/bind.h"
8 #include "base/bind_helpers.h"
9 #include "base/lazy_instance.h"
10 #include "base/single_thread_task_runner.h"
11 #include "base/synchronization/lock.h"
7 #include "base/trace_event/memory_dump_request_args.h" 12 #include "base/trace_event/memory_dump_request_args.h"
8 #include "mojo/public/cpp/bindings/interface_request.h" 13 #include "mojo/public/cpp/bindings/interface_request.h"
9 #include "services/resource_coordinator/public/cpp/memory/coordinator.h" 14 #include "services/resource_coordinator/public/cpp/memory/coordinator.h"
10 #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"
11 #include "services/service_manager/public/cpp/interface_provider.h" 16 #include "services/service_manager/public/cpp/interface_provider.h"
12 17
13 namespace memory_instrumentation { 18 namespace memory_instrumentation {
14 19
15 MemoryDumpManagerDelegateImpl::MemoryDumpManagerDelegateImpl( 20 namespace {
16 service_manager::InterfaceProvider* interface_provider) 21
17 : is_coordinator_(false), binding_(this) { 22 base::LazyInstance<MemoryDumpManagerDelegateImpl>::Leaky
23 g_memory_dump_manager_delegate = LAZY_INSTANCE_INITIALIZER;
24
25 } // namespace
26
27 // static
28 MemoryDumpManagerDelegateImpl* MemoryDumpManagerDelegateImpl::GetInstance() {
29 return g_memory_dump_manager_delegate.Pointer();
30 }
31
32 MemoryDumpManagerDelegateImpl::MemoryDumpManagerDelegateImpl()
33 : initialized_(false),
34 binding_(this),
35 task_runner_(nullptr),
36 pending_memory_dump_guid_(0) {}
37
38 MemoryDumpManagerDelegateImpl::~MemoryDumpManagerDelegateImpl() {}
39
40 void MemoryDumpManagerDelegateImpl::InitializeWithInterfaceProvider(
41 service_manager::InterfaceProvider* interface_provider) {
42 {
43 base::AutoLock lock(initialized_lock_);
44 DCHECK(!initialized_);
45 initialized_ = true;
46 }
47
18 interface_provider->GetInterface(mojo::MakeRequest(&coordinator_)); 48 interface_provider->GetInterface(mojo::MakeRequest(&coordinator_));
19 coordinator_->RegisterProcessLocalDumpManager( 49 coordinator_->RegisterProcessLocalDumpManager(
20 binding_.CreateInterfacePtrAndBind()); 50 binding_.CreateInterfacePtrAndBind());
51 base::trace_event::MemoryDumpManager::GetInstance()->Initialize(this);
21 } 52 }
22 53
23 MemoryDumpManagerDelegateImpl::MemoryDumpManagerDelegateImpl( 54 void MemoryDumpManagerDelegateImpl::InitializeWithCoordinator(
24 Coordinator* coordinator) 55 Coordinator* coordinator,
25 : is_coordinator_(true), binding_(this) { 56 scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
57 DCHECK(task_runner);
58 if (!task_runner->RunsTasksOnCurrentThread()) {
59 task_runner->PostTask(
60 FROM_HERE,
61 base::Bind(&MemoryDumpManagerDelegateImpl::InitializeWithCoordinator,
62 base::Unretained(this), base::Unretained(coordinator),
63 task_runner));
64 return;
65 }
66
67 {
68 base::AutoLock lock(initialized_lock_);
69 DCHECK(!initialized_);
70 initialized_ = true;
71 }
72
73 task_runner_ = task_runner;
26 coordinator->BindCoordinatorRequest(mojo::MakeRequest(&coordinator_)); 74 coordinator->BindCoordinatorRequest(mojo::MakeRequest(&coordinator_));
27 coordinator_->RegisterProcessLocalDumpManager( 75 coordinator_->RegisterProcessLocalDumpManager(
28 binding_.CreateInterfacePtrAndBind()); 76 binding_.CreateInterfacePtrAndBind());
77 base::trace_event::MemoryDumpManager::GetInstance()->Initialize(this);
29 } 78 }
30 79
31 MemoryDumpManagerDelegateImpl::~MemoryDumpManagerDelegateImpl() {}
32
33 bool MemoryDumpManagerDelegateImpl::IsCoordinator() const { 80 bool MemoryDumpManagerDelegateImpl::IsCoordinator() const {
34 return is_coordinator_; 81 return task_runner_ != nullptr;
35 } 82 }
36 83
37 void MemoryDumpManagerDelegateImpl::RequestProcessMemoryDump( 84 void MemoryDumpManagerDelegateImpl::RequestProcessMemoryDump(
38 const base::trace_event::MemoryDumpRequestArgs& args, 85 const base::trace_event::MemoryDumpRequestArgs& args,
39 const RequestProcessMemoryDumpCallback& callback) { 86 const RequestProcessMemoryDumpCallback& callback) {
40 MemoryDumpManagerDelegate::CreateProcessDump(args, callback); 87 MemoryDumpManagerDelegate::CreateProcessDump(args, callback);
41 } 88 }
42 89
43 void MemoryDumpManagerDelegateImpl::RequestGlobalMemoryDump( 90 void MemoryDumpManagerDelegateImpl::RequestGlobalMemoryDump(
44 const base::trace_event::MemoryDumpRequestArgs& args, 91 const base::trace_event::MemoryDumpRequestArgs& args,
45 const base::trace_event::MemoryDumpCallback& callback) { 92 const base::trace_event::MemoryDumpCallback& callback) {
46 coordinator_->RequestGlobalMemoryDump(args, callback); 93 // Note: This condition is here to match the old behavior. If the delegate is
94 // in the browser process, we do not drop parallel requests in the delegate
95 // and so they will be queued by the Coordinator service (see
96 // CoordinatorImpl::RequestGlobalMemoryDump). If the delegate is in a child
97 // process, parallel requests will be cancelled.
98 //
99 // TODO(chiniforooshan): After transitioning to the mojo-based service is
100 // completed, we should enable queueing parallel global memory dump requests
101 // by delegates on all processes.
102 if (task_runner_) {
103 DCHECK(task_runner_);
104 task_runner_->PostTask(
105 FROM_HERE,
106 base::Bind(&mojom::Coordinator::RequestGlobalMemoryDump,
107 base::Unretained(coordinator_.get()), args, callback));
108 return;
109 }
110
111 {
112 base::AutoLock lock(pending_memory_dump_guid_lock_);
113 if (pending_memory_dump_guid_) {
114 callback.Run(args.dump_guid, false);
115 return;
116 }
117 pending_memory_dump_guid_ = args.dump_guid;
118 }
119 DCHECK(!task_runner_);
120 auto callback_proxy =
121 base::Bind(&MemoryDumpManagerDelegateImpl::MemoryDumpCallbackProxy,
122 base::Unretained(this), callback);
123 coordinator_->RequestGlobalMemoryDump(args, callback_proxy);
124 }
125
126 void MemoryDumpManagerDelegateImpl::MemoryDumpCallbackProxy(
127 const base::trace_event::MemoryDumpCallback& callback,
128 uint64_t dump_guid,
129 bool success) {
130 DCHECK_NE(0U, pending_memory_dump_guid_);
131 pending_memory_dump_guid_ = 0;
132 callback.Run(dump_guid, success);
133 }
134
135 void MemoryDumpManagerDelegateImpl::SetAsNonCoordinatorForTesting() {
136 task_runner_ = nullptr;
47 } 137 }
48 138
49 } // namespace memory_instrumentation 139 } // namespace memory_instrumentation
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698