Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
person_interface_impl.cc
#include "content/browser/CTF/person_interface_impl.h"
#include "mojo/public/cpp/bindings/callback_helpers.h"
#include "mojo/public/cpp/bindings/strong_binding.h"
namespace content {
PersonInterfaceImpl::PersonInterfaceImpl() : weak_factory_(this) {}
// static
void PersonInterfaceImpl::Create(blink::mojom::PersonInterfaceRequest request) {
mojo::MakeStrongBinding(
std::make_unique<PersonInterfaceImpl>(),
std::move(request));
}
PersonInterfaceImpl::~PersonInterfaceImpl() {}
base::WeakPtr<PersonInterfaceImpl> PersonInterfaceImpl::AsWeakPtr() {
return weak_factory_.GetWeakPtr();
}
void PersonInterfaceImpl::GetName(GetNameCallback callback) {
std::move(callback).Run(name);
}
void PersonInterfaceImpl::SetName(const std::string &new_name,
SetNameCallback callback) {
name = new_name;
std::move(callback).Run();
}
void PersonInterfaceImpl::GetAge(GetAgeCallback callback) {
std::move(callback).Run(age);
}
void PersonInterfaceImpl::SetAge(uint64_t new_age, SetAgeCallback callback) {
age = new_age;
std::move(callback).Run();
}
void PersonInterfaceImpl::GetWeight(GetWeightCallback callback) {
std::move(callback).Run(weight);
}
void PersonInterfaceImpl::SetWeight(uint64_t new_weight,
SetWeightCallback callback) {
weight = new_weight;
std::move(callback).Run();
}
void PersonInterfaceImpl::AddWeight(
PersonInterfaceImpl::CookAndEatCallback callback,
blink::mojom::FoodInterfacePtr foodPtr, uint64_t weight_) {
weight += weight_;
std::move(callback).Run();
}
void PersonInterfaceImpl::CookAndEat(blink::mojom::FoodInterfacePtr foodPtr,
CookAndEatCallback callback) {
blink::mojom::FoodInterface *raw_food = foodPtr.get();
raw_food->GetWeight(base::BindOnce(&PersonInterfaceImpl::AddWeight,
base::Unretained(this),
std::move(callback), std::move(foodPtr)));
}
} // namespace content
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.