OLD | NEW |
---|---|
(Empty) | |
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. | |
4 | |
5 #include <cstdio> | |
6 #include <string> | |
7 | |
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" | |
13 | |
14 class Instance : public pp::Instance { | |
15 public: | |
16 explicit Instance(PP_Instance instance) : | |
17 pp::Instance(instance), | |
18 callback_factory_(this), | |
19 delay_milliseconds_(10), | |
20 active_(true) { | |
21 DoSomething(PP_OK); | |
22 } | |
23 virtual ~Instance() {} | |
24 | |
25 virtual void HandleMessage(const pp::Var& message_var) { | |
26 std::string message_string = message_var.AsString(); | |
27 if (message_string == "be idle") { | |
28 active_ = false; | |
29 } else { | |
30 PostMessage("Unhandled control message."); | |
31 return; | |
Mark Seaborn
2013/12/18 21:07:57
This is superfluous in this context
scheib
2013/12/19 01:31:37
Done.
| |
32 } | |
33 } | |
34 | |
35 void DoSomething(int32_t result) { | |
36 if (active_) { | |
37 pp::MessageLoop loop = pp::MessageLoop::GetCurrent(); | |
38 pp::CompletionCallback c = callback_factory_.NewCallback( | |
39 &Instance::DoSomething); | |
40 loop.PostWork(c, delay_milliseconds_); | |
41 } | |
42 } | |
43 | |
44 pp::CompletionCallbackFactory<Instance> callback_factory_; | |
45 int delay_milliseconds_; | |
46 bool active_; | |
47 }; | |
48 | |
49 class Module : public pp::Module { | |
50 public: | |
51 Module() : pp::Module() {} | |
52 virtual ~Module() {} | |
53 | |
54 virtual pp::Instance* CreateInstance(PP_Instance instance) { | |
55 return new Instance(instance); | |
56 } | |
57 }; | |
58 | |
59 namespace pp { | |
60 Module* CreateModule() { | |
61 return new ::Module(); | |
62 } | |
63 } // namespace pp | |
64 | |
OLD | NEW |