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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: services/resource_coordinator/public/cpp/memory/memory_dump_manager_delegate_impl.cc
diff --git a/services/resource_coordinator/public/cpp/memory/memory_dump_manager_delegate_impl.cc b/services/resource_coordinator/public/cpp/memory/memory_dump_manager_delegate_impl.cc
index 7072b6775487065afc73b76e77c2a5084d60d0d0..85fce7568c9ad6c0668897c98357f4bf58ac4daf 100644
--- a/services/resource_coordinator/public/cpp/memory/memory_dump_manager_delegate_impl.cc
+++ b/services/resource_coordinator/public/cpp/memory/memory_dump_manager_delegate_impl.cc
@@ -4,6 +4,10 @@
#include "services/resource_coordinator/public/cpp/memory/memory_dump_manager_delegate_impl.h"
+#include "base/bind.h"
+#include "base/bind_helpers.h"
+#include "base/single_thread_task_runner.h"
+#include "base/synchronization/lock.h"
#include "base/trace_event/memory_dump_request_args.h"
#include "mojo/public/cpp/bindings/interface_request.h"
#include "services/resource_coordinator/public/cpp/memory/coordinator.h"
@@ -12,18 +16,21 @@
namespace memory_instrumentation {
-MemoryDumpManagerDelegateImpl::MemoryDumpManagerDelegateImpl(
- service_manager::InterfaceProvider* interface_provider)
- : is_coordinator_(false), binding_(this) {
- interface_provider->GetInterface(mojo::MakeRequest(&coordinator_));
- coordinator_->RegisterProcessLocalDumpManager(
- binding_.CreateInterfacePtrAndBind());
-}
+MemoryDumpManagerDelegateImpl::Config::~Config() {}
MemoryDumpManagerDelegateImpl::MemoryDumpManagerDelegateImpl(
- Coordinator* coordinator)
- : is_coordinator_(true), binding_(this) {
- coordinator->BindCoordinatorRequest(mojo::MakeRequest(&coordinator_));
+ const MemoryDumpManagerDelegateImpl::Config& config)
+ : binding_(this),
+ config_(config),
+ task_runner_(nullptr),
+ pending_memory_dump_guid_(0) {
+ if (config.interface_provider() != nullptr) {
+ config.interface_provider()->GetInterface(mojo::MakeRequest(&coordinator_));
+ } else {
+ task_runner_ = base::ThreadTaskRunnerHandle::Get();
+ config.coordinator()->BindCoordinatorRequest(
+ mojo::MakeRequest(&coordinator_));
+ }
coordinator_->RegisterProcessLocalDumpManager(
binding_.CreateInterfacePtrAndBind());
}
@@ -31,7 +38,7 @@ MemoryDumpManagerDelegateImpl::MemoryDumpManagerDelegateImpl(
MemoryDumpManagerDelegateImpl::~MemoryDumpManagerDelegateImpl() {}
bool MemoryDumpManagerDelegateImpl::IsCoordinator() const {
- return is_coordinator_;
+ return task_runner_ != nullptr;
}
void MemoryDumpManagerDelegateImpl::RequestProcessMemoryDump(
@@ -43,7 +50,46 @@ void MemoryDumpManagerDelegateImpl::RequestProcessMemoryDump(
void MemoryDumpManagerDelegateImpl::RequestGlobalMemoryDump(
const base::trace_event::MemoryDumpRequestArgs& args,
const base::trace_event::MemoryDumpCallback& callback) {
- coordinator_->RequestGlobalMemoryDump(args, callback);
+ // Note: This condition is here to match the old behavior. If the delegate is
+ // in the browser process, we do not drop parallel requests in the delegate
+ // and so they will be queued by the Coordinator service (see
+ // CoordinatorImpl::RequestGlobalMemoryDump). If the delegate is in a child
+ // process, parallel requests will be cancelled.
+ //
+ // TODO(chiniforooshan): Unify the child and browser behavior.
+ if (IsCoordinator()) {
+ task_runner_->PostTask(
+ FROM_HERE,
+ base::Bind(&mojom::Coordinator::RequestGlobalMemoryDump,
+ base::Unretained(coordinator_.get()), args, callback));
+ return;
+ }
+
+ {
+ base::AutoLock lock(pending_memory_dump_guid_lock_);
+ if (pending_memory_dump_guid_) {
+ callback.Run(args.dump_guid, false);
+ return;
+ }
+ pending_memory_dump_guid_ = args.dump_guid;
+ }
+ auto callback_proxy =
+ base::Bind(&MemoryDumpManagerDelegateImpl::MemoryDumpCallbackProxy,
+ base::Unretained(this), callback);
+ coordinator_->RequestGlobalMemoryDump(args, callback_proxy);
+}
+
+void MemoryDumpManagerDelegateImpl::MemoryDumpCallbackProxy(
+ const base::trace_event::MemoryDumpCallback& callback,
+ uint64_t dump_guid,
+ bool success) {
+ DCHECK_NE(0U, pending_memory_dump_guid_);
+ pending_memory_dump_guid_ = 0;
+ callback.Run(dump_guid, success);
+}
+
+void MemoryDumpManagerDelegateImpl::SetAsNonCoordinatorForTesting() {
+ task_runner_ = nullptr;
}
} // namespace memory_instrumentation

Powered by Google App Engine
This is Rietveld 408576698