Mir

Code review comment for lp:~albaguirre/mir/fix-1433330

Revision history for this message
Alberto Aguirre (albaguirre) wrote :

> 20 +class SelfDeletingCallback : public google::protobuf::Closure {
> 21 +public:
> 22 +
> 23 + SelfDeletingCallback(std::function<void()> const& callback)
> 24 + : callback(callback)
> 25 + {
> 26 + }
> 27 +
> 28 + void Run() {
> 29 + callback();
> 30 + delete this;
> 31 + }
> 32 +
> 33 + private:
> 34 + SelfDeletingCallback(SelfDeletingCallback&) = delete;
> 35 + void operator=(const SelfDeletingCallback&) = delete;
> 36 + std::function<void()> callback;
> 37 +};
>
> Why is this needed? google::protobuf::NewCallback<> deletes itself.
> (NewPermanentCallback<> is the version that doesn't).

The code in question used to use google::protobuf::NewCallback<>. I need to be able to promote a weak_ptr within Run() so I can't use it as is. I don't want to change any Protobuf related code hence SelfDeletingCallback.

> And as Alexandros says, callbacks could throw.
OK.

« Back to merge proposal