#include "content/child/child_histogram_fetcher_impl.h"
#include <ctype.h>
#include <memory>
#include "base/functional/bind.h"
#include "base/location.h"
#include "base/metrics/histogram_delta_serialization.h"
#include "base/metrics/histogram_macros.h"
#include "base/metrics/persistent_histogram_allocator.h"
#include "content/child/child_process.h"
#include "ipc/ipc_sender.h"
#include "mojo/public/cpp/bindings/self_owned_receiver.h"
#include "mojo/public/cpp/system/platform_handle.h"
namespace content {
ChildHistogramFetcherFactoryImpl::ChildHistogramFetcherFactoryImpl() {}
ChildHistogramFetcherFactoryImpl::~ChildHistogramFetcherFactoryImpl() {}
void ChildHistogramFetcherFactoryImpl::Create(
mojo::PendingReceiver<content::mojom::ChildHistogramFetcherFactory>
receiver) {
mojo::MakeSelfOwnedReceiver(
std::make_unique<ChildHistogramFetcherFactoryImpl>(),
std::move(receiver));
}
void ChildHistogramFetcherFactoryImpl::CreateFetcher(
base::WritableSharedMemoryRegion shared_memory,
mojo::PendingReceiver<content::mojom::ChildHistogramFetcher> receiver) {
if (shared_memory.IsValid()) {
base::GlobalHistogramAllocator::CreateWithSharedMemoryRegion(shared_memory);
}
base::PersistentHistogramAllocator* global_allocator =
base::GlobalHistogramAllocator::Get();
if (global_allocator)
global_allocator->CreateTrackingHistograms(global_allocator->Name());
mojo::MakeSelfOwnedReceiver(std::make_unique<ChildHistogramFetcherImpl>(),
std::move(receiver));
}
ChildHistogramFetcherImpl::ChildHistogramFetcherImpl() {}
ChildHistogramFetcherImpl::~ChildHistogramFetcherImpl() {}
void ChildHistogramFetcherImpl::GetChildNonPersistentHistogramData(
HistogramDataCallback callback) {
base::PersistentHistogramAllocator* global_allocator =
base::GlobalHistogramAllocator::Get();
if (global_allocator)
global_allocator->UpdateTrackingHistograms();
if (!histogram_delta_serialization_) {
histogram_delta_serialization_ =
std::make_unique<base::HistogramDeltaSerialization>("ChildProcess");
}
std::vector<std::string> deltas;
histogram_delta_serialization_->PrepareAndSerializeDeltas(&deltas, false);
std::move(callback).Run(deltas);
#ifndef NDEBUG
static int count = 0;
count++;
LOCAL_HISTOGRAM_COUNTS("Histogram.ChildProcessHistogramSentCount", count);
#endif
}
}