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

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

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 #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/single_thread_task_runner.h"
10 #include "base/synchronization/lock.h"
7 #include "base/trace_event/memory_dump_request_args.h" 11 #include "base/trace_event/memory_dump_request_args.h"
8 #include "mojo/public/cpp/bindings/interface_request.h" 12 #include "mojo/public/cpp/bindings/interface_request.h"
9 #include "services/resource_coordinator/public/cpp/memory/coordinator.h" 13 #include "services/resource_coordinator/public/cpp/memory/coordinator.h"
10 #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"
11 #include "services/service_manager/public/cpp/interface_provider.h" 15 #include "services/service_manager/public/cpp/interface_provider.h"
12 16
13 namespace memory_instrumentation { 17 namespace memory_instrumentation {
14 18
19 MemoryDumpManagerDelegateImpl::Config::~Config() {}
20
15 MemoryDumpManagerDelegateImpl::MemoryDumpManagerDelegateImpl( 21 MemoryDumpManagerDelegateImpl::MemoryDumpManagerDelegateImpl(
16 service_manager::InterfaceProvider* interface_provider) 22 const MemoryDumpManagerDelegateImpl::Config& config)
17 : is_coordinator_(false), binding_(this) { 23 : binding_(this),
18 interface_provider->GetInterface(mojo::MakeRequest(&coordinator_)); 24 config_(config),
25 task_runner_(nullptr),
26 pending_memory_dump_guid_(0) {
27 if (config.interface_provider() != nullptr) {
28 config.interface_provider()->GetInterface(mojo::MakeRequest(&coordinator_));
29 } else {
30 task_runner_ = base::ThreadTaskRunnerHandle::Get();
31 config.coordinator()->BindCoordinatorRequest(
32 mojo::MakeRequest(&coordinator_));
33 }
19 coordinator_->RegisterProcessLocalDumpManager( 34 coordinator_->RegisterProcessLocalDumpManager(
20 binding_.CreateInterfacePtrAndBind()); 35 binding_.CreateInterfacePtrAndBind());
21 } 36 }
22
23 MemoryDumpManagerDelegateImpl::MemoryDumpManagerDelegateImpl(
24 Coordinator* coordinator)
25 : is_coordinator_(true), binding_(this) {
26 coordinator->BindCoordinatorRequest(mojo::MakeRequest(&coordinator_));
27 coordinator_->RegisterProcessLocalDumpManager(
28 binding_.CreateInterfacePtrAndBind());
29 }
30 37
31 MemoryDumpManagerDelegateImpl::~MemoryDumpManagerDelegateImpl() {} 38 MemoryDumpManagerDelegateImpl::~MemoryDumpManagerDelegateImpl() {}
32 39
33 bool MemoryDumpManagerDelegateImpl::IsCoordinator() const { 40 bool MemoryDumpManagerDelegateImpl::IsCoordinator() const {
34 return is_coordinator_; 41 return task_runner_ != nullptr;
35 } 42 }
36 43
37 void MemoryDumpManagerDelegateImpl::RequestProcessMemoryDump( 44 void MemoryDumpManagerDelegateImpl::RequestProcessMemoryDump(
38 const base::trace_event::MemoryDumpRequestArgs& args, 45 const base::trace_event::MemoryDumpRequestArgs& args,
39 const RequestProcessMemoryDumpCallback& callback) { 46 const RequestProcessMemoryDumpCallback& callback) {
40 MemoryDumpManagerDelegate::CreateProcessDump(args, callback); 47 MemoryDumpManagerDelegate::CreateProcessDump(args, callback);
41 } 48 }
42 49
43 void MemoryDumpManagerDelegateImpl::RequestGlobalMemoryDump( 50 void MemoryDumpManagerDelegateImpl::RequestGlobalMemoryDump(
44 const base::trace_event::MemoryDumpRequestArgs& args, 51 const base::trace_event::MemoryDumpRequestArgs& args,
45 const base::trace_event::MemoryDumpCallback& callback) { 52 const base::trace_event::MemoryDumpCallback& callback) {
46 coordinator_->RequestGlobalMemoryDump(args, callback); 53 // Note: This condition is here to match the old behavior. If the delegate is
54 // in the browser process, we do not drop parallel requests in the delegate
55 // and so they will be queued by the Coordinator service (see
56 // CoordinatorImpl::RequestGlobalMemoryDump). If the delegate is in a child
57 // process, parallel requests will be cancelled.
58 //
59 // TODO(chiniforooshan): Unify the child and browser behavior.
60 if (IsCoordinator()) {
61 task_runner_->PostTask(
62 FROM_HERE,
63 base::Bind(&mojom::Coordinator::RequestGlobalMemoryDump,
64 base::Unretained(coordinator_.get()), args, callback));
65 return;
66 }
67
68 {
69 base::AutoLock lock(pending_memory_dump_guid_lock_);
70 if (pending_memory_dump_guid_) {
71 callback.Run(args.dump_guid, false);
72 return;
73 }
74 pending_memory_dump_guid_ = args.dump_guid;
75 }
76 auto callback_proxy =
77 base::Bind(&MemoryDumpManagerDelegateImpl::MemoryDumpCallbackProxy,
78 base::Unretained(this), callback);
79 coordinator_->RequestGlobalMemoryDump(args, callback_proxy);
80 }
81
82 void MemoryDumpManagerDelegateImpl::MemoryDumpCallbackProxy(
83 const base::trace_event::MemoryDumpCallback& callback,
84 uint64_t dump_guid,
85 bool success) {
86 DCHECK_NE(0U, pending_memory_dump_guid_);
87 pending_memory_dump_guid_ = 0;
88 callback.Run(dump_guid, success);
89 }
90
91 void MemoryDumpManagerDelegateImpl::SetAsNonCoordinatorForTesting() {
92 task_runner_ = nullptr;
47 } 93 }
48 94
49 } // namespace memory_instrumentation 95 } // namespace memory_instrumentation
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698