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

Unified Diff: components/tracing/child_memory_dump_manager_delegate_impl.cc

Issue 1039963003: [tracing] child-process-side impl for inter-process memory dumps (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ipc_3_messages
Patch Set: Add temporary workaround for crbug.com/474973 Created 5 years, 8 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: components/tracing/child_memory_dump_manager_delegate_impl.cc
diff --git a/components/tracing/child_memory_dump_manager_delegate_impl.cc b/components/tracing/child_memory_dump_manager_delegate_impl.cc
new file mode 100644
index 0000000000000000000000000000000000000000..5595b14072f72c1da8965fa86cb2862728fb267b
--- /dev/null
+++ b/components/tracing/child_memory_dump_manager_delegate_impl.cc
@@ -0,0 +1,71 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "components/tracing/child_memory_dump_manager_delegate_impl.h"
+
+#include "base/single_thread_task_runner.h"
+#include "components/tracing/child_trace_message_filter.h"
+
+namespace tracing {
+
+// static
+ChildMemoryDumpManagerDelegateImpl*
+ChildMemoryDumpManagerDelegateImpl::GetInstance() {
+ return Singleton<
+ ChildMemoryDumpManagerDelegateImpl,
+ LeakySingletonTraits<ChildMemoryDumpManagerDelegateImpl>>::get();
+}
+
+ChildMemoryDumpManagerDelegateImpl::ChildMemoryDumpManagerDelegateImpl()
+ : ctmf_(nullptr) {
+ base::trace_event::MemoryDumpManager::GetInstance()->SetDelegate(this);
+}
+
+ChildMemoryDumpManagerDelegateImpl::~ChildMemoryDumpManagerDelegateImpl() {
+}
+
+void ChildMemoryDumpManagerDelegateImpl::SetChildTraceMessageFilter(
+ ChildTraceMessageFilter* ctmf) {
+ // Check that we are either registering the CTMF or tearing it down, but not
+ // replacing a valid instance with another one (should never happen).
+ DCHECK(ctmf_ == nullptr || (ctmf == nullptr && ctmf_task_runner_ != nullptr));
+ ctmf_ = ctmf;
+ ctmf_task_runner_ = ctmf ? (ctmf->ipc_message_loop()) : nullptr;
+}
+
+// Invoked in child processes by the MemoryDumpManager.
+void ChildMemoryDumpManagerDelegateImpl::RequestGlobalMemoryDump(
+ const base::trace_event::MemoryDumpRequestArgs& args,
+ const base::trace_event::MemoryDumpCallback& callback) {
+ // Bail out if we receive a dump request from the manager before the
+ // ChildTraceMessageFilter has been initialized.
+ if (!ctmf_task_runner_) {
+ if (!callback.is_null())
+ callback.Run(args.dump_guid, false /* success */);
+ return;
+ }
+
+ // Make sure we access |ctmf_| only on the thread where it lives to avoid
+ // races on shutdown.
+ if (!ctmf_task_runner_->BelongsToCurrentThread()) {
+ ctmf_task_runner_->PostTask(
+ FROM_HERE,
+ base::Bind(&ChildMemoryDumpManagerDelegateImpl::RequestGlobalMemoryDump,
+ base::Unretained(this), args, callback));
+ return;
+ }
+
+ // The ChildTraceMessageFilter could have been destroyed while hopping on the
+ // right thread. If this is the case, bail out.
+ if (!ctmf_) {
+ if (!callback.is_null())
+ callback.Run(args.dump_guid, false /* success */);
+ return;
+ }
+
+ // Send the request up to the browser process' MessageDumpmanager.
+ ctmf_->SendGlobalMemoryDumpRequest(args, callback);
+}
+
+} // namespace tracing
« no previous file with comments | « components/tracing/child_memory_dump_manager_delegate_impl.h ('k') | components/tracing/child_trace_message_filter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698