1// Copyright (c) 2012 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 "ppapi/c/pp_errors.h"
6#include "ppapi/cpp/input_event.h"
7#include "ppapi/cpp/instance.h"
8#include "ppapi/cpp/module.h"
9#include "ppapi/utility/completion_callback_factory.h"
10#include "ppapi/utility/threading/simple_thread.h"
11
12class MyInstance : public pp::Instance {
13 public:
14  MyInstance(PP_Instance instance) : pp::Instance(instance) {
15    thread_ = new pp::SimpleThread(this);
16    factory_.Initialize(this);
17  }
18
19  virtual ~MyInstance() {
20    delete thread_;
21  }
22
23  virtual bool Init(uint32_t argc, const char* argn[], const char* argv[]) {
24    thread_->Start();
25    thread_->message_loop().PostWork(
26        factory_.NewCallback(&MyInstance::CallOnBackground));
27    return true;
28  }
29
30  virtual void DidChangeView(const pp::View& view) {
31  }
32
33 private:
34  void CallOnBackground(int32_t result) {
35  }
36
37  pp::CompletionCallbackFactory<MyInstance> factory_;
38
39  pp::SimpleThread* thread_;
40};
41
42
43class MyModule : public pp::Module {
44 public:
45  MyModule() : pp::Module() {}
46  virtual ~MyModule() {}
47
48  virtual pp::Instance* CreateInstance(PP_Instance instance) {
49    return new MyInstance(instance);
50  }
51};
52
53namespace pp {
54
55// Factory function for your specialization of the Module object.
56Module* CreateModule() {
57  return new MyModule();
58}
59
60}  // namespace pp
61