This source file includes following definitions.
- callback_factory_
- HandleMessage
- DelayedPost
- CreateInstance
- CreateModule
#include <string>
#include "ppapi/cpp/instance.h"
#include "ppapi/cpp/module.h"
#include "ppapi/cpp/var.h"
#include "ppapi/utility/completion_callback_factory.h"
#ifdef WIN32
#undef PostMessage
#pragma warning(disable : 4355)
#endif
class CoreInstance : public pp::Instance {
public:
explicit CoreInstance(PP_Instance instance)
: pp::Instance(instance), callback_factory_(this) {}
private:
virtual void HandleMessage(const pp::Var& var_message) {
int32_t delay = var_message.AsInt();
if (delay) {
last_receive_time_ = pp::Module::Get()->core()->GetTimeTicks();
pp::Module::Get()->core()->CallOnMainThread(
delay, callback_factory_.NewCallback(&CoreInstance::DelayedPost), 0);
} else {
pp::Var msg(0);
PostMessage(msg);
}
}
void DelayedPost(int32_t) {
pp::Var msg(pp::Module::Get()->core()->GetTimeTicks() - last_receive_time_);
PostMessage(msg);
}
private:
pp::CompletionCallbackFactory<CoreInstance> callback_factory_;
PP_TimeTicks last_receive_time_;
};
class CoreModule : public pp::Module {
public:
CoreModule() : pp::Module() {}
virtual ~CoreModule() {}
virtual pp::Instance* CreateInstance(PP_Instance instance) {
return new CoreInstance(instance);
}
};
namespace pp {
Module* CreateModule() { return new CoreModule(); }
}