Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 "components/tracing/child_memory_dump_manager_delegate_impl.h" | 5 #include "components/tracing/child_memory_dump_manager_delegate_impl.h" |
| 6 | 6 |
| 7 #include "base/single_thread_task_runner.h" | 7 #include "base/single_thread_task_runner.h" |
| 8 #include "components/tracing/child_trace_message_filter.h" | 8 #include "components/tracing/child_trace_message_filter.h" |
| 9 | 9 |
| 10 namespace tracing { | 10 namespace tracing { |
| 11 | 11 |
| 12 namespace { | |
| 13 void AbortDumpRequest(const base::trace_event::MemoryDumpRequestArgs& args, | |
| 14 const base::trace_event::MemoryDumpCallback& callback) { | |
| 15 if (!callback.is_null()) | |
| 16 callback.Run(args.dump_guid, false /* success */); | |
| 17 } | |
| 18 } // namespace | |
| 19 | |
| 12 // static | 20 // static |
| 13 ChildMemoryDumpManagerDelegateImpl* | 21 ChildMemoryDumpManagerDelegateImpl* |
| 14 ChildMemoryDumpManagerDelegateImpl::GetInstance() { | 22 ChildMemoryDumpManagerDelegateImpl::GetInstance() { |
| 15 return base::Singleton< | 23 return base::Singleton< |
| 16 ChildMemoryDumpManagerDelegateImpl, | 24 ChildMemoryDumpManagerDelegateImpl, |
| 17 base::LeakySingletonTraits<ChildMemoryDumpManagerDelegateImpl>>::get(); | 25 base::LeakySingletonTraits<ChildMemoryDumpManagerDelegateImpl>>::get(); |
| 18 } | 26 } |
| 19 | 27 |
| 20 ChildMemoryDumpManagerDelegateImpl::ChildMemoryDumpManagerDelegateImpl() | 28 ChildMemoryDumpManagerDelegateImpl::ChildMemoryDumpManagerDelegateImpl() |
| 21 : ctmf_(nullptr), | 29 : ctmf_(nullptr), |
| 22 tracing_process_id_( | 30 tracing_process_id_( |
| 23 base::trace_event::MemoryDumpManager::kInvalidTracingProcessId) { | 31 base::trace_event::MemoryDumpManager::kInvalidTracingProcessId) { |
| 24 base::trace_event::MemoryDumpManager::GetInstance()->Initialize( | |
| 25 this /* delegate */, false /* is_coordinator */); | |
| 26 } | 32 } |
| 27 | 33 |
| 28 ChildMemoryDumpManagerDelegateImpl::~ChildMemoryDumpManagerDelegateImpl() {} | 34 ChildMemoryDumpManagerDelegateImpl::~ChildMemoryDumpManagerDelegateImpl() {} |
| 29 | 35 |
| 30 void ChildMemoryDumpManagerDelegateImpl::SetChildTraceMessageFilter( | 36 void ChildMemoryDumpManagerDelegateImpl::SetChildTraceMessageFilter( |
| 31 ChildTraceMessageFilter* ctmf) { | 37 ChildTraceMessageFilter* ctmf) { |
| 38 const auto& task_runner = ctmf ? (ctmf->ipc_task_runner()) : nullptr; | |
| 32 // Check that we are either registering the CTMF or tearing it down, but not | 39 // Check that we are either registering the CTMF or tearing it down, but not |
| 33 // replacing a valid instance with another one (should never happen). | 40 // replacing a valid instance with another one (should never happen). |
| 34 DCHECK(ctmf_ == nullptr || (ctmf == nullptr && ctmf_task_runner_ != nullptr)); | 41 DCHECK(ctmf_ == nullptr || (ctmf == nullptr && ctmf_task_runner_ != nullptr)); |
| 35 ctmf_ = ctmf; | 42 ctmf_ = ctmf; |
| 36 ctmf_task_runner_ = ctmf ? (ctmf->ipc_task_runner()) : nullptr; | 43 |
| 44 { | |
| 45 base::AutoLock lock(lock_); | |
| 46 ctmf_task_runner_ = task_runner; | |
| 47 } | |
| 48 | |
| 49 if (ctmf) { | |
| 50 base::trace_event::MemoryDumpManager::GetInstance()->Initialize( | |
|
dsinclair
2015/09/16 17:14:55
Why does the initialize call move from the constru
Primiano Tucci (use gerrit)
2015/09/16 17:46:20
Uh? this is not the dtor. This is the SetChildTrac
dsinclair
2015/09/16 17:53:03
Doh, skipped line 36 when I scanned up and just sa
| |
| 51 this /* delegate */, false /* is_coordinator */); | |
| 52 } | |
| 37 } | 53 } |
| 38 | 54 |
| 39 // Invoked in child processes by the MemoryDumpManager. | 55 // Invoked in child processes by the MemoryDumpManager. |
| 40 void ChildMemoryDumpManagerDelegateImpl::RequestGlobalMemoryDump( | 56 void ChildMemoryDumpManagerDelegateImpl::RequestGlobalMemoryDump( |
| 41 const base::trace_event::MemoryDumpRequestArgs& args, | 57 const base::trace_event::MemoryDumpRequestArgs& args, |
| 42 const base::trace_event::MemoryDumpCallback& callback) { | 58 const base::trace_event::MemoryDumpCallback& callback) { |
| 59 // RequestGlobalMemoryDump can be called on any thread, cannot access | |
| 60 // ctmf_task_runner_ as it could be racy. | |
| 61 scoped_refptr<base::SingleThreadTaskRunner> ctmf_task_runner; | |
| 62 { | |
| 63 base::AutoLock lock(lock_); | |
| 64 ctmf_task_runner = ctmf_task_runner_; | |
| 65 } | |
| 66 | |
| 43 // Bail out if we receive a dump request from the manager before the | 67 // Bail out if we receive a dump request from the manager before the |
| 44 // ChildTraceMessageFilter has been initialized. | 68 // ChildTraceMessageFilter has been initialized. |
| 45 if (!ctmf_task_runner_) { | 69 if (!ctmf_task_runner) |
| 46 if (!callback.is_null()) | 70 return AbortDumpRequest(args, callback); |
| 47 callback.Run(args.dump_guid, false /* success */); | |
| 48 return; | |
| 49 } | |
| 50 | 71 |
| 51 // Make sure we access |ctmf_| only on the thread where it lives to avoid | 72 // Make sure we access |ctmf_| only on the thread where it lives to avoid |
| 52 // races on shutdown. | 73 // races on shutdown. |
| 53 if (!ctmf_task_runner_->BelongsToCurrentThread()) { | 74 if (!ctmf_task_runner->BelongsToCurrentThread()) { |
| 54 ctmf_task_runner_->PostTask( | 75 const bool did_post_task = ctmf_task_runner->PostTask( |
| 55 FROM_HERE, | 76 FROM_HERE, |
| 56 base::Bind(&ChildMemoryDumpManagerDelegateImpl::RequestGlobalMemoryDump, | 77 base::Bind(&ChildMemoryDumpManagerDelegateImpl::RequestGlobalMemoryDump, |
| 57 base::Unretained(this), args, callback)); | 78 base::Unretained(this), args, callback)); |
| 79 if (!did_post_task) | |
| 80 return AbortDumpRequest(args, callback); | |
| 58 return; | 81 return; |
| 59 } | 82 } |
| 60 | 83 |
| 61 // The ChildTraceMessageFilter could have been destroyed while hopping on the | 84 // The ChildTraceMessageFilter could have been destroyed while hopping on the |
| 62 // right thread. If this is the case, bail out. | 85 // right thread. If this is the case, bail out. |
| 63 if (!ctmf_) { | 86 if (!ctmf_) |
| 64 if (!callback.is_null()) | 87 return AbortDumpRequest(args, callback); |
| 65 callback.Run(args.dump_guid, false /* success */); | |
| 66 return; | |
| 67 } | |
| 68 | 88 |
| 69 // Send the request up to the browser process' MessageDumpmanager. | 89 // Send the request up to the browser process' MessageDumpmanager. |
| 70 ctmf_->SendGlobalMemoryDumpRequest(args, callback); | 90 ctmf_->SendGlobalMemoryDumpRequest(args, callback); |
| 71 } | 91 } |
| 72 | 92 |
| 73 uint64 ChildMemoryDumpManagerDelegateImpl::GetTracingProcessId() const { | 93 uint64 ChildMemoryDumpManagerDelegateImpl::GetTracingProcessId() const { |
| 74 return tracing_process_id_; | 94 return tracing_process_id_; |
| 75 } | 95 } |
| 76 | 96 |
| 77 } // namespace tracing | 97 } // namespace tracing |
| OLD | NEW |