Allow only one bookmark to be added for multiple fast starring
[chromium-blink-merge.git] / ppapi / examples / threading / threading.cc
blobbfd21a910619bcda70efe77df7f3cfb78244bb22
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.
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"
12 class MyInstance : public pp::Instance {
13 public:
14 MyInstance(PP_Instance instance) : pp::Instance(instance) {
15 thread_ = new pp::SimpleThread(this);
16 factory_.Initialize(this);
19 virtual ~MyInstance() {
20 delete thread_;
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;
30 virtual void DidChangeView(const pp::View& view) {
33 private:
34 void CallOnBackground(int32_t result) {
37 pp::CompletionCallbackFactory<MyInstance> factory_;
39 pp::SimpleThread* thread_;
43 class MyModule : public pp::Module {
44 public:
45 MyModule() : pp::Module() {}
46 virtual ~MyModule() {}
48 virtual pp::Instance* CreateInstance(PP_Instance instance) {
49 return new MyInstance(instance);
53 namespace pp {
55 // Factory function for your specialization of the Module object.
56 Module* CreateModule() {
57 return new MyModule();
60 } // namespace pp