Pepper_47_C++_interfaces
message_loop.cc
Go to the documentation of this file.
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 
6 
7 #include "ppapi/c/pp_errors.h"
8 #include "ppapi/c/ppb_message_loop.h"
11 #include "ppapi/cpp/module_impl.h"
12 
13 namespace pp {
14 
15 namespace {
16 
17 template <> const char* interface_name<PPB_MessageLoop>() {
18  return PPB_MESSAGELOOP_INTERFACE_1_0;
19 }
20 
21 } // namespace
22 
24 }
25 
27  if (has_interface<PPB_MessageLoop>()) {
28  PassRefFromConstructor(get_interface<PPB_MessageLoop>()->Create(
29  instance.pp_instance()));
30  }
31 }
32 
34  : Resource(other) {
35 }
36 
38  : Resource(pp_message_loop) {
39 }
40 
41 // static
43  if (!has_interface<PPB_MessageLoop>())
44  return MessageLoop();
45  return MessageLoop(
46  get_interface<PPB_MessageLoop>()->GetForMainThread());
47 }
48 
49 // static
51  if (!has_interface<PPB_MessageLoop>())
52  return MessageLoop();
53  return MessageLoop(
54  get_interface<PPB_MessageLoop>()->GetCurrent());
55 }
56 
58  if (!has_interface<PPB_MessageLoop>())
59  return PP_ERROR_NOINTERFACE;
60  return get_interface<PPB_MessageLoop>()->AttachToCurrentThread(
61  pp_resource());
62 }
63 
65  if (!has_interface<PPB_MessageLoop>())
66  return PP_ERROR_NOINTERFACE;
67  return get_interface<PPB_MessageLoop>()->Run(pp_resource());
68 }
69 
71  int64_t delay_ms) {
72  if (!has_interface<PPB_MessageLoop>())
73  return PP_ERROR_NOINTERFACE;
74  return get_interface<PPB_MessageLoop>()->PostWork(
75  pp_resource(),
76  callback.pp_completion_callback(),
77  delay_ms);
78 }
79 
80 int32_t MessageLoop::PostQuit(bool should_destroy) {
81  if (!has_interface<PPB_MessageLoop>())
82  return PP_ERROR_NOINTERFACE;
83  return get_interface<PPB_MessageLoop>()->PostQuit(
84  pp_resource(), PP_FromBool(should_destroy));
85 }
86 
87 } // namespace pp
void PassRefFromConstructor(PP_Resource resource)
Definition: resource.cc:50
int32_t PostWork(const CompletionCallback &callback, int64_t delay_ms=0)
Definition: message_loop.cc:70
static MessageLoop GetForMainThread()
Definition: message_loop.cc:42
MessageLoop()
Creates an is_null() MessageLoop resource.
Definition: message_loop.cc:23
const PP_CompletionCallback & pp_completion_callback() const
int32_t AttachToCurrentThread()
Definition: message_loop.cc:57
static MessageLoop GetCurrent()
Definition: message_loop.cc:50
PP_Resource pp_resource() const
Definition: resource.h:47
int32_t PostQuit(bool should_destroy)
Definition: message_loop.cc:80
PP_Instance pp_instance() const
A reference counted module resource.
Definition: resource.h:20