Index: content/browser/browser_child_process_host_impl.cc |
diff --git a/content/browser/browser_child_process_host_impl.cc b/content/browser/browser_child_process_host_impl.cc |
index afc52015320fecafb9abc463abf4a979e56945f4..c5f61aba6b38953d91fcdbaa7818bf06ea3a8059 100644 |
--- a/content/browser/browser_child_process_host_impl.cc |
+++ b/content/browser/browser_child_process_host_impl.cc |
@@ -15,6 +15,8 @@ |
#include "base/macros.h" |
#include "base/metrics/field_trial.h" |
#include "base/metrics/histogram.h" |
+#include "base/metrics/persistent_histogram_allocator.h" |
+#include "base/metrics/persistent_memory_allocator.h" |
#include "base/stl_util.h" |
#include "base/strings/string_util.h" |
#include "base/synchronization/waitable_event.h" |
@@ -84,15 +86,15 @@ BrowserChildProcessHost* BrowserChildProcessHost::Create( |
content::ProcessType process_type, |
BrowserChildProcessHostDelegate* delegate) { |
return new BrowserChildProcessHostImpl( |
- process_type, delegate, mojo::edk::GenerateRandomToken()); |
+ process_type, delegate, mojo::edk::GenerateRandomToken(), 0, nullptr); |
} |
BrowserChildProcessHost* BrowserChildProcessHost::Create( |
content::ProcessType process_type, |
BrowserChildProcessHostDelegate* delegate, |
const std::string& mojo_child_token) { |
- return new BrowserChildProcessHostImpl( |
- process_type, delegate, mojo_child_token); |
+ return new BrowserChildProcessHostImpl(process_type, delegate, |
+ mojo_child_token, 0, nullptr); |
} |
BrowserChildProcessHost* BrowserChildProcessHost::FromID(int child_process_id) { |
@@ -135,7 +137,9 @@ void BrowserChildProcessHostImpl::RemoveObserver( |
BrowserChildProcessHostImpl::BrowserChildProcessHostImpl( |
content::ProcessType process_type, |
BrowserChildProcessHostDelegate* delegate, |
- const std::string& mojo_child_token) |
+ const std::string& mojo_child_token, |
+ size_t shared_metrics_memory_size, |
+ base::StringPiece shared_metrics_name) |
: data_(process_type), |
delegate_(delegate), |
mojo_child_token_(mojo_child_token), |
@@ -168,6 +172,16 @@ BrowserChildProcessHostImpl::BrowserChildProcessHostImpl( |
GetContentClient()->browser()->BrowserChildProcessHostCreated(this); |
power_monitor_message_broadcaster_.Init(); |
+ |
+ // Create a persistent memory segment for subprocess histograms only if |
+ // they're active in the browser. |
+ if (shared_metrics_memory_size > 0 && base::GlobalHistogramAllocator::Get()) { |
+ std::unique_ptr<base::SharedMemory> shm(new base::SharedMemory()); |
+ shm->CreateAndMapAnonymous(shared_metrics_memory_size); |
+ metrics_allocator_.reset(new base::SharedPersistentMemoryAllocator( |
+ std::move(shm), static_cast<uint64_t>(data_.id), shared_metrics_name, |
+ /*readonly=*/false)); |
Alexei Svitkine (slow)
2016/08/12 23:14:36
I think it would be better to just have the the Br
bcwhite
2016/08/15 19:43:10
I don't think that would be good. That would forc
Alexei Svitkine (slow)
2016/08/18 07:21:19
The callers wouldn't need to know the persistent c
bcwhite
2016/08/18 15:21:55
This class knows about creating shared memory beca
Alexei Svitkine (slow)
2016/08/18 15:57:28
Let me step back a bit. The concrete things I'm no
bcwhite
2016/08/18 17:42:17
It cares about the shared memory details but that'
Alexei Svitkine (slow)
2016/08/19 15:10:51
I see your point. I still don't like that this cla
bcwhite
2016/08/19 15:55:21
Eventually that will be removed, but it's used her
bcwhite
2016/08/19 15:55:21
New separate method for creating the allocator tha
|
+ } |
} |
BrowserChildProcessHostImpl::~BrowserChildProcessHostImpl() { |
@@ -268,6 +282,11 @@ const base::Process& BrowserChildProcessHostImpl::GetProcess() const { |
return child_process_->GetProcess(); |
} |
+std::unique_ptr<base::SharedPersistentMemoryAllocator> |
+BrowserChildProcessHostImpl::TakeMetricsAllocator() { |
+ return std::move(metrics_allocator_); |
+} |
+ |
void BrowserChildProcessHostImpl::SetName(const base::string16& name) { |
DCHECK_CURRENTLY_ON(BrowserThread::IO); |
data_.name = name; |
@@ -335,6 +354,7 @@ void BrowserChildProcessHostImpl::OnChannelConnected(int32_t peer_pid) { |
delegate_->OnChannelConnected(peer_pid); |
if (IsProcessLaunched()) { |
+ ShareMetricsAllocatorToProcess(); |
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
base::Bind(&NotifyProcessLaunchedAndConnected, |
data_)); |
@@ -436,6 +456,16 @@ bool BrowserChildProcessHostImpl::Send(IPC::Message* message) { |
return child_process_host_->Send(message); |
} |
+void BrowserChildProcessHostImpl::ShareMetricsAllocatorToProcess() { |
+ if (metrics_allocator_) { |
+ base::SharedMemoryHandle shm_handle; |
+ metrics_allocator_->shared_memory()->ShareToProcess(data_.handle, |
+ &shm_handle); |
+ Send(new ChildProcessMsg_SetHistogramMemory( |
+ shm_handle, metrics_allocator_->shared_memory()->mapped_size())); |
+ } |
+} |
+ |
void BrowserChildProcessHostImpl::OnProcessLaunchFailed(int error_code) { |
delegate_->OnProcessLaunchFailed(error_code); |
notify_child_disconnected_ = false; |
@@ -462,6 +492,7 @@ void BrowserChildProcessHostImpl::OnProcessLaunched() { |
delegate_->OnProcessLaunched(); |
if (is_channel_connected_) { |
+ ShareMetricsAllocatorToProcess(); |
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
base::Bind(&NotifyProcessLaunchedAndConnected, |
data_)); |