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> | |
yzshen1
2013/12/14 01:07:01
empty line between two sections, please.
scheib
2013/12/14 05:43:50
Done.
| |
7 #include "ppapi/cpp/instance.h" | |
8 #include "ppapi/cpp/message_loop.h" | |
9 #include "ppapi/cpp/module.h" | |
10 #include "ppapi/cpp/var.h" | |
11 #include "ppapi/utility/completion_callback_factory.h" | |
12 | |
13 class Instance : public pp::Instance { | |
14 public: | |
15 explicit Instance(PP_Instance instance) : | |
16 pp::Instance(instance), | |
17 callback_factory_(this), | |
18 delay_(10), | |
19 active_(true) { | |
20 DoSomething(PP_OK); | |
21 } | |
22 virtual ~Instance() {} | |
23 | |
24 virtual void HandleMessage(const pp::Var& message_var) { | |
25 std::string message_string = message_var.AsString(); | |
26 if (message_string == "be idle") { | |
27 active_ = false; | |
28 } else { | |
29 PostMessage("Unhandled control message."); | |
30 return; | |
31 } | |
32 } | |
33 | |
34 void DoSomething(int32_t result) { | |
35 if (active_) { | |
36 pp::MessageLoop loop = pp::MessageLoop::GetCurrent(); | |
37 pp::CompletionCallback c = callback_factory_.NewCallback( | |
38 &Instance::DoSomething); | |
39 loop.PostWork(c, delay_); | |
40 } | |
41 } | |
42 | |
43 pp::CompletionCallbackFactory<Instance> callback_factory_; | |
44 int delay_; | |
yzshen1
2013/12/14 01:07:01
Please comment about the unit or rename the variab
scheib
2013/12/14 05:43:50
Done.
| |
45 bool active_; | |
46 }; | |
47 | |
48 class Module : public pp::Module { | |
49 public: | |
50 Module() : pp::Module() {} | |
51 virtual ~Module() {} | |
52 | |
53 virtual pp::Instance* CreateInstance(PP_Instance instance) { | |
54 return new Instance(instance); | |
55 } | |
56 }; | |
57 | |
58 namespace pp { | |
59 Module* CreateModule() { | |
60 return new ::Module(); | |
61 } | |
62 } // namespace pp | |
63 | |
OLD | NEW |