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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 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 "components/tracing/child_memory_dump_manager_delegate_impl.h"
6
7 #include "base/single_thread_task_runner.h"
8 #include "components/tracing/child_trace_message_filter.h"
9
10 namespace tracing {
11
12 // static
13 ChildMemoryDumpManagerDelegateImpl*
14 ChildMemoryDumpManagerDelegateImpl::GetInstance() {
15 return Singleton<
16 ChildMemoryDumpManagerDelegateImpl,
17 LeakySingletonTraits<ChildMemoryDumpManagerDelegateImpl>>::get();
18 }
19
20 ChildMemoryDumpManagerDelegateImpl::ChildMemoryDumpManagerDelegateImpl()
21 : ctmf_(nullptr) {
22 base::trace_event::MemoryDumpManager::GetInstance()->SetDelegate(this);
23 }
24
25 ChildMemoryDumpManagerDelegateImpl::~ChildMemoryDumpManagerDelegateImpl() {
26 }
27
28 void ChildMemoryDumpManagerDelegateImpl::SetChildTraceMessageFilter(
29 ChildTraceMessageFilter* ctmf) {
30 // Check that we are either registering the CTMF or tearing it down, but not
31 // replacing a valid instance with another one (should never happen).
32 DCHECK(ctmf_ == nullptr || (ctmf == nullptr && ctmf_task_runner_ != nullptr));
33 ctmf_ = ctmf;
34 ctmf_task_runner_ = ctmf ? (ctmf->ipc_message_loop()) : nullptr;
35 }
36
37 // Invoked in child processes by the MemoryDumpManager.
38 void ChildMemoryDumpManagerDelegateImpl::RequestGlobalMemoryDump(
39 const base::trace_event::MemoryDumpRequestArgs& args,
40 const base::trace_event::MemoryDumpCallback& callback) {
41 // Bail out if we receive a dump request from the manager before the
42 // ChildTraceMessageFilter has been initialized.
43 if (!ctmf_task_runner_) {
44 if (!callback.is_null())
45 callback.Run(args.dump_guid, false /* success */);
46 return;
47 }
48
49 // Make sure we access |ctmf_| only on the thread where it lives to avoid
50 // races on shutdown.
51 if (!ctmf_task_runner_->BelongsToCurrentThread()) {
52 ctmf_task_runner_->PostTask(
53 FROM_HERE,
54 base::Bind(&ChildMemoryDumpManagerDelegateImpl::RequestGlobalMemoryDump,
55 base::Unretained(this), args, callback));
56 return;
57 }
58
59 // The ChildTraceMessageFilter could have been destroyed while hopping on the
60 // right thread. If this is the case, bail out.
61 if (!ctmf_) {
62 if (!callback.is_null())
63 callback.Run(args.dump_guid, false /* success */);
64 return;
65 }
66
67 // Send the request up to the browser process' MessageDumpmanager.
68 ctmf_->SendGlobalMemoryDumpRequest(args, callback);
69 }
70
71 } // namespace tracing
OLDNEW
« 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