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