1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
8 #include "ppapi/cpp/instance.h"
9 #include "ppapi/cpp/message_loop.h"
10 #include "ppapi/cpp/module.h"
11 #include "ppapi/cpp/var.h"
12 #include "ppapi/utility/completion_callback_factory.h"
14 class Instance
: public pp::Instance
{
16 explicit Instance(PP_Instance instance
) :
17 pp::Instance(instance
),
18 callback_factory_(this),
19 delay_milliseconds_(10),
23 virtual ~Instance() {}
25 virtual void HandleMessage(const pp::Var
& message_var
) {
26 std::string message_string
= message_var
.AsString();
27 if (message_string
== "be idle") {
30 PostMessage("Unhandled control message.");
34 void DoSomething(int32_t result
) {
36 pp::MessageLoop loop
= pp::MessageLoop::GetCurrent();
37 pp::CompletionCallback c
= callback_factory_
.NewCallback(
38 &Instance::DoSomething
);
39 loop
.PostWork(c
, delay_milliseconds_
);
43 pp::CompletionCallbackFactory
<Instance
> callback_factory_
;
44 int delay_milliseconds_
;
48 class Module
: public pp::Module
{
50 Module() : pp::Module() {}
53 virtual pp::Instance
* CreateInstance(PP_Instance instance
) {
54 return new Instance(instance
);
59 Module
* CreateModule() {
60 return new ::Module();