blob: 3a9f3b8491ec576b9a793e67b770537683021fc9 [file] [log] [blame]
// Copyright 2013 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.
#if defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-private-field"
#elif defined(_MSC_VER)
#pragma warning(push)
#pragma warning(disable:4056)
#pragma warning(disable:4065)
#pragma warning(disable:4756)
#endif
#include "content/common/histogram_fetcher.mojom.h"
#include <math.h>
#include <stdint.h>
#include <utility>
#include "base/hash/md5_constexpr.h"
#include "base/logging.h"
#include "base/run_loop.h"
#include "base/task/common/task_annotator.h"
#include "mojo/public/cpp/bindings/lib/message_internal.h"
#include "mojo/public/cpp/bindings/lib/serialization_util.h"
#include "mojo/public/cpp/bindings/lib/unserialized_message_context.h"
#include "mojo/public/cpp/bindings/lib/validate_params.h"
#include "mojo/public/cpp/bindings/lib/validation_context.h"
#include "mojo/public/cpp/bindings/lib/validation_errors.h"
#include "mojo/public/interfaces/bindings/interface_control_messages.mojom.h"
#include "content/common/histogram_fetcher.mojom-params-data.h"
#include "content/common/histogram_fetcher.mojom-shared-message-ids.h"
#include "content/common/histogram_fetcher.mojom-import-headers.h"
#ifndef CONTENT_COMMON_HISTOGRAM_FETCHER_MOJOM_JUMBO_H_
#define CONTENT_COMMON_HISTOGRAM_FETCHER_MOJOM_JUMBO_H_
#include "mojo/public/cpp/base/shared_memory_mojom_traits.h"
#endif
namespace content {
namespace mojom {
const char ChildHistogramFetcherFactory::Name_[] = "content.mojom.ChildHistogramFetcherFactory";
ChildHistogramFetcherFactoryProxy::ChildHistogramFetcherFactoryProxy(mojo::MessageReceiverWithResponder* receiver)
: receiver_(receiver) {
}
void ChildHistogramFetcherFactoryProxy::CreateFetcher(
base::WritableSharedMemoryRegion in_shared_memory, ChildHistogramFetcherRequest in_child_histogram_fetcher) {
#if BUILDFLAG(MOJO_TRACE_ENABLED)
TRACE_EVENT0("mojom", "<class 'jinja2::utils::Namespace'>::ChildHistogramFetcherFactory::CreateFetcher");
#endif
const bool kExpectsResponse = false;
const bool kIsSync = false;
const uint32_t kFlags =
((kExpectsResponse) ? mojo::Message::kFlagExpectsResponse : 0) |
((kIsSync) ? mojo::Message::kFlagIsSync : 0);
mojo::Message message(
internal::kChildHistogramFetcherFactory_CreateFetcher_Name, kFlags, 0, 0, nullptr);
auto* buffer = message.payload_buffer();
::content::mojom::internal::ChildHistogramFetcherFactory_CreateFetcher_Params_Data::BufferWriter
params;
mojo::internal::SerializationContext serialization_context;
params.Allocate(buffer);
typename decltype(params->shared_memory)::BaseType::BufferWriter
shared_memory_writer;
mojo::internal::Serialize<::mojo_base::mojom::WritableSharedMemoryRegionDataView>(
in_shared_memory, buffer, &shared_memory_writer, &serialization_context);
params->shared_memory.Set(
shared_memory_writer.is_null() ? nullptr : shared_memory_writer.data());
mojo::internal::Serialize<::content::mojom::ChildHistogramFetcherRequestDataView>(
in_child_histogram_fetcher, &params->child_histogram_fetcher, &serialization_context);
MOJO_INTERNAL_DLOG_SERIALIZATION_WARNING(
!mojo::internal::IsHandleOrInterfaceValid(params->child_histogram_fetcher),
mojo::internal::VALIDATION_ERROR_UNEXPECTED_INVALID_HANDLE,
"invalid child_histogram_fetcher in ChildHistogramFetcherFactory.CreateFetcher request");
message.AttachHandlesFromSerializationContext(
&serialization_context);
#if defined(ENABLE_IPC_FUZZER)
message.set_interface_name(ChildHistogramFetcherFactory::Name_);
message.set_method_name("CreateFetcher");
#endif
// This return value may be ignored as false implies the Connector has
// encountered an error, which will be visible through other means.
ignore_result(receiver_->Accept(&message));
}
// static
bool ChildHistogramFetcherFactoryStubDispatch::Accept(
ChildHistogramFetcherFactory* impl,
mojo::Message* message) {
switch (message->header()->name) {
case internal::kChildHistogramFetcherFactory_CreateFetcher_Name: {
#if BUILDFLAG(MOJO_TRACE_ENABLED)
TRACE_EVENT1(
"mojom",
"(Impl)<class 'jinja2::utils::Namespace'>::ChildHistogramFetcherFactory::CreateFetcher",
"message", message->name());
#endif
static constexpr uint32_t kMessageHash = base::MD5Hash32Constexpr(
"(Impl)<class 'jinja2::utils::Namespace'>::ChildHistogramFetcherFactory::CreateFetcher");
base::TaskAnnotator::ScopedSetIpcHash scoped_ipc_hash(kMessageHash);
mojo::internal::MessageDispatchContext context(message);
DCHECK(message->is_serialized());
internal::ChildHistogramFetcherFactory_CreateFetcher_Params_Data* params =
reinterpret_cast<internal::ChildHistogramFetcherFactory_CreateFetcher_Params_Data*>(
message->mutable_payload());
mojo::internal::SerializationContext serialization_context;
serialization_context.TakeHandlesFromMessage(message);
bool success = true;
base::WritableSharedMemoryRegion p_shared_memory{};
ChildHistogramFetcherRequest p_child_histogram_fetcher{};
ChildHistogramFetcherFactory_CreateFetcher_ParamsDataView input_data_view(params, &serialization_context);
if (!input_data_view.ReadSharedMemory(&p_shared_memory))
success = false;
p_child_histogram_fetcher =
input_data_view.TakeChildHistogramFetcher<decltype(p_child_histogram_fetcher)>();
if (!success) {
ReportValidationErrorForMessage(
message,
mojo::internal::VALIDATION_ERROR_DESERIALIZATION_FAILED,
ChildHistogramFetcherFactory::Name_, 0, false);
return false;
}
// A null |impl| means no implementation was bound.
DCHECK(impl);
impl->CreateFetcher(
std::move(p_shared_memory),
std::move(p_child_histogram_fetcher));
return true;
}
}
return false;
}
// static
bool ChildHistogramFetcherFactoryStubDispatch::AcceptWithResponder(
ChildHistogramFetcherFactory* impl,
mojo::Message* message,
std::unique_ptr<mojo::MessageReceiverWithStatus> responder) {
switch (message->header()->name) {
case internal::kChildHistogramFetcherFactory_CreateFetcher_Name: {
break;
}
}
return false;
}
bool ChildHistogramFetcherFactoryRequestValidator::Accept(mojo::Message* message) {
if (!message->is_serialized() ||
mojo::internal::ControlMessageHandler::IsControlMessage(message)) {
return true;
}
mojo::internal::ValidationContext validation_context(
message->payload(), message->payload_num_bytes(),
message->handles()->size(), message->payload_num_interface_ids(), message,
"ChildHistogramFetcherFactory RequestValidator");
switch (message->header()->name) {
case internal::kChildHistogramFetcherFactory_CreateFetcher_Name: {
if (!mojo::internal::ValidateMessageIsRequestWithoutResponse(
message, &validation_context)) {
return false;
}
if (!mojo::internal::ValidateMessagePayload<
internal::ChildHistogramFetcherFactory_CreateFetcher_Params_Data>(
message, &validation_context)) {
return false;
}
return true;
}
default:
break;
}
// Unrecognized message.
ReportValidationError(
&validation_context,
mojo::internal::VALIDATION_ERROR_MESSAGE_HEADER_UNKNOWN_METHOD);
return false;
}
const char ChildHistogramFetcher::Name_[] = "content.mojom.ChildHistogramFetcher";
class ChildHistogramFetcher_GetChildNonPersistentHistogramData_ForwardToCallback
: public mojo::MessageReceiver {
public:
ChildHistogramFetcher_GetChildNonPersistentHistogramData_ForwardToCallback(
ChildHistogramFetcher::GetChildNonPersistentHistogramDataCallback callback
) : callback_(std::move(callback)) {
}
bool Accept(mojo::Message* message) override;
private:
ChildHistogramFetcher::GetChildNonPersistentHistogramDataCallback callback_;
DISALLOW_COPY_AND_ASSIGN(ChildHistogramFetcher_GetChildNonPersistentHistogramData_ForwardToCallback);
};
ChildHistogramFetcherProxy::ChildHistogramFetcherProxy(mojo::MessageReceiverWithResponder* receiver)
: receiver_(receiver) {
}
void ChildHistogramFetcherProxy::GetChildNonPersistentHistogramData(
GetChildNonPersistentHistogramDataCallback callback) {
#if BUILDFLAG(MOJO_TRACE_ENABLED)
TRACE_EVENT0("mojom", "<class 'jinja2::utils::Namespace'>::ChildHistogramFetcher::GetChildNonPersistentHistogramData");
#endif
const bool kExpectsResponse = true;
const bool kIsSync = false;
const uint32_t kFlags =
((kExpectsResponse) ? mojo::Message::kFlagExpectsResponse : 0) |
((kIsSync) ? mojo::Message::kFlagIsSync : 0);
mojo::Message message(
internal::kChildHistogramFetcher_GetChildNonPersistentHistogramData_Name, kFlags, 0, 0, nullptr);
auto* buffer = message.payload_buffer();
::content::mojom::internal::ChildHistogramFetcher_GetChildNonPersistentHistogramData_Params_Data::BufferWriter
params;
mojo::internal::SerializationContext serialization_context;
params.Allocate(buffer);
message.AttachHandlesFromSerializationContext(
&serialization_context);
#if defined(ENABLE_IPC_FUZZER)
message.set_interface_name(ChildHistogramFetcher::Name_);
message.set_method_name("GetChildNonPersistentHistogramData");
#endif
std::unique_ptr<mojo::MessageReceiver> responder(
new ChildHistogramFetcher_GetChildNonPersistentHistogramData_ForwardToCallback(
std::move(callback)));
ignore_result(receiver_->AcceptWithResponder(&message, std::move(responder)));
}
class ChildHistogramFetcher_GetChildNonPersistentHistogramData_ProxyToResponder {
public:
static ChildHistogramFetcher::GetChildNonPersistentHistogramDataCallback CreateCallback(
uint64_t request_id,
bool is_sync,
std::unique_ptr<mojo::MessageReceiverWithStatus> responder) {
std::unique_ptr<ChildHistogramFetcher_GetChildNonPersistentHistogramData_ProxyToResponder> proxy(
new ChildHistogramFetcher_GetChildNonPersistentHistogramData_ProxyToResponder(
request_id, is_sync, std::move(responder)));
return base::BindOnce(&ChildHistogramFetcher_GetChildNonPersistentHistogramData_ProxyToResponder::Run,
std::move(proxy));
}
~ChildHistogramFetcher_GetChildNonPersistentHistogramData_ProxyToResponder() {
#if DCHECK_IS_ON()
if (responder_) {
// If we're being destroyed without being run, we want to ensure the
// binding endpoint has been closed. This checks for that asynchronously.
// We pass a bound generated callback to handle the response so that any
// resulting DCHECK stack will have useful interface type information.
responder_->IsConnectedAsync(base::BindOnce(&OnIsConnectedComplete));
}
#endif
// If the Callback was dropped then deleting the responder will close
// the pipe so the calling application knows to stop waiting for a reply.
responder_ = nullptr;
}
private:
ChildHistogramFetcher_GetChildNonPersistentHistogramData_ProxyToResponder(
uint64_t request_id,
bool is_sync,
std::unique_ptr<mojo::MessageReceiverWithStatus> responder)
: request_id_(request_id),
is_sync_(is_sync),
responder_(std::move(responder)) {
}
#if DCHECK_IS_ON()
static void OnIsConnectedComplete(bool connected) {
DCHECK(!connected)
<< "ChildHistogramFetcher::GetChildNonPersistentHistogramDataCallback was destroyed without "
<< "first either being run or its corresponding binding being closed. "
<< "It is an error to drop response callbacks which still correspond "
<< "to an open interface pipe.";
}
#endif
void Run(
const std::vector<std::string>& in_deltas);
uint64_t request_id_;
bool is_sync_;
std::unique_ptr<mojo::MessageReceiverWithStatus> responder_;
DISALLOW_COPY_AND_ASSIGN(ChildHistogramFetcher_GetChildNonPersistentHistogramData_ProxyToResponder);
};
bool ChildHistogramFetcher_GetChildNonPersistentHistogramData_ForwardToCallback::Accept(
mojo::Message* message) {
#if BUILDFLAG(MOJO_TRACE_ENABLED)
TRACE_EVENT1("mojom", "<class 'jinja2::utils::Namespace'>::ChildHistogramFetcher::GetChildNonPersistentHistogramDataCallback",
"message", message->name());
#endif
mojo::internal::MessageDispatchContext dispatch_context(message);
DCHECK(message->is_serialized());
internal::ChildHistogramFetcher_GetChildNonPersistentHistogramData_ResponseParams_Data* params =
reinterpret_cast<
internal::ChildHistogramFetcher_GetChildNonPersistentHistogramData_ResponseParams_Data*>(
message->mutable_payload());
mojo::internal::SerializationContext serialization_context;
serialization_context.TakeHandlesFromMessage(message);
bool success = true;
std::vector<std::string> p_deltas{};
ChildHistogramFetcher_GetChildNonPersistentHistogramData_ResponseParamsDataView input_data_view(params, &serialization_context);
if (!input_data_view.ReadDeltas(&p_deltas))
success = false;
if (!success) {
ReportValidationErrorForMessage(
message,
mojo::internal::VALIDATION_ERROR_DESERIALIZATION_FAILED,
ChildHistogramFetcher::Name_, 0, true);
return false;
}
if (!callback_.is_null())
std::move(callback_).Run(
std::move(p_deltas));
return true;
}
void ChildHistogramFetcher_GetChildNonPersistentHistogramData_ProxyToResponder::Run(
const std::vector<std::string>& in_deltas) {
const uint32_t kFlags = mojo::Message::kFlagIsResponse |
((is_sync_) ? mojo::Message::kFlagIsSync : 0);
mojo::Message message(
internal::kChildHistogramFetcher_GetChildNonPersistentHistogramData_Name, kFlags, 0, 0, nullptr);
auto* buffer = message.payload_buffer();
::content::mojom::internal::ChildHistogramFetcher_GetChildNonPersistentHistogramData_ResponseParams_Data::BufferWriter
params;
mojo::internal::SerializationContext serialization_context;
params.Allocate(buffer);
typename decltype(params->deltas)::BaseType::BufferWriter
deltas_writer;
const mojo::internal::ContainerValidateParams deltas_validate_params(
0, false, new mojo::internal::ContainerValidateParams(0, false, nullptr));
mojo::internal::Serialize<mojo::ArrayDataView<mojo::StringDataView>>(
in_deltas, buffer, &deltas_writer, &deltas_validate_params,
&serialization_context);
params->deltas.Set(
deltas_writer.is_null() ? nullptr : deltas_writer.data());
MOJO_INTERNAL_DLOG_SERIALIZATION_WARNING(
params->deltas.is_null(),
mojo::internal::VALIDATION_ERROR_UNEXPECTED_NULL_POINTER,
"null deltas in ");
message.AttachHandlesFromSerializationContext(
&serialization_context);
#if BUILDFLAG(MOJO_TRACE_ENABLED)
TRACE_EVENT1("mojom", "(Impl)<class 'jinja2::utils::Namespace'>::ChildHistogramFetcher::GetChildNonPersistentHistogramDataCallback",
"message", message.name());
#endif
#if defined(ENABLE_IPC_FUZZER)
message.set_interface_name(ChildHistogramFetcher::Name_);
message.set_method_name("GetChildNonPersistentHistogramData");
#endif
message.set_request_id(request_id_);
ignore_result(responder_->Accept(&message));
// TODO(darin): Accept() returning false indicates a malformed message, and
// that may be good reason to close the connection. However, we don't have a
// way to do that from here. We should add a way.
responder_ = nullptr;
}
// static
bool ChildHistogramFetcherStubDispatch::Accept(
ChildHistogramFetcher* impl,
mojo::Message* message) {
switch (message->header()->name) {
case internal::kChildHistogramFetcher_GetChildNonPersistentHistogramData_Name: {
break;
}
}
return false;
}
// static
bool ChildHistogramFetcherStubDispatch::AcceptWithResponder(
ChildHistogramFetcher* impl,
mojo::Message* message,
std::unique_ptr<mojo::MessageReceiverWithStatus> responder) {
switch (message->header()->name) {
case internal::kChildHistogramFetcher_GetChildNonPersistentHistogramData_Name: {
#if BUILDFLAG(MOJO_TRACE_ENABLED)
TRACE_EVENT1(
"mojom",
"(Impl)<class 'jinja2::utils::Namespace'>::ChildHistogramFetcher::GetChildNonPersistentHistogramData",
"message", message->name());
#endif
static constexpr uint32_t kMessageHash = base::MD5Hash32Constexpr(
"(Impl)<class 'jinja2::utils::Namespace'>::ChildHistogramFetcher::GetChildNonPersistentHistogramData");
base::TaskAnnotator::ScopedSetIpcHash scoped_ipc_hash(kMessageHash);
mojo::internal::MessageDispatchContext context(message);
internal::ChildHistogramFetcher_GetChildNonPersistentHistogramData_Params_Data* params =
reinterpret_cast<
internal::ChildHistogramFetcher_GetChildNonPersistentHistogramData_Params_Data*>(
message->mutable_payload());
mojo::internal::SerializationContext serialization_context;
serialization_context.TakeHandlesFromMessage(message);
bool success = true;
ChildHistogramFetcher_GetChildNonPersistentHistogramData_ParamsDataView input_data_view(params, &serialization_context);
if (!success) {
ReportValidationErrorForMessage(
message,
mojo::internal::VALIDATION_ERROR_DESERIALIZATION_FAILED,
ChildHistogramFetcher::Name_, 0, false);
return false;
}
ChildHistogramFetcher::GetChildNonPersistentHistogramDataCallback callback =
ChildHistogramFetcher_GetChildNonPersistentHistogramData_ProxyToResponder::CreateCallback(
message->request_id(),
message->has_flag(mojo::Message::kFlagIsSync),
std::move(responder));
// A null |impl| means no implementation was bound.
DCHECK(impl);
impl->GetChildNonPersistentHistogramData(std::move(callback));
return true;
}
}
return false;
}
bool ChildHistogramFetcherRequestValidator::Accept(mojo::Message* message) {
if (!message->is_serialized() ||
mojo::internal::ControlMessageHandler::IsControlMessage(message)) {
return true;
}
mojo::internal::ValidationContext validation_context(
message->payload(), message->payload_num_bytes(),
message->handles()->size(), message->payload_num_interface_ids(), message,
"ChildHistogramFetcher RequestValidator");
switch (message->header()->name) {
case internal::kChildHistogramFetcher_GetChildNonPersistentHistogramData_Name: {
if (!mojo::internal::ValidateMessageIsRequestExpectingResponse(
message, &validation_context)) {
return false;
}
if (!mojo::internal::ValidateMessagePayload<
internal::ChildHistogramFetcher_GetChildNonPersistentHistogramData_Params_Data>(
message, &validation_context)) {
return false;
}
return true;
}
default:
break;
}
// Unrecognized message.
ReportValidationError(
&validation_context,
mojo::internal::VALIDATION_ERROR_MESSAGE_HEADER_UNKNOWN_METHOD);
return false;
}
bool ChildHistogramFetcherResponseValidator::Accept(mojo::Message* message) {
if (!message->is_serialized() ||
mojo::internal::ControlMessageHandler::IsControlMessage(message)) {
return true;
}
mojo::internal::ValidationContext validation_context(
message->payload(), message->payload_num_bytes(),
message->handles()->size(), message->payload_num_interface_ids(), message,
"ChildHistogramFetcher ResponseValidator");
if (!mojo::internal::ValidateMessageIsResponse(message, &validation_context))
return false;
switch (message->header()->name) {
case internal::kChildHistogramFetcher_GetChildNonPersistentHistogramData_Name: {
if (!mojo::internal::ValidateMessagePayload<
internal::ChildHistogramFetcher_GetChildNonPersistentHistogramData_ResponseParams_Data>(
message, &validation_context)) {
return false;
}
return true;
}
default:
break;
}
// Unrecognized message.
ReportValidationError(
&validation_context,
mojo::internal::VALIDATION_ERROR_MESSAGE_HEADER_UNKNOWN_METHOD);
return false;
}
} // namespace mojom
} // namespace content
namespace mojo {
} // namespace mojo
#if defined(__clang__)
#pragma clang diagnostic pop
#elif defined(_MSC_VER)
#pragma warning(pop)
#endif