-
-
Save Eterna1/019418c4046c38a394e4702b21256b72 to your computer and use it in GitHub Desktop.
person_interface_impl.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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