// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ppapi/cpp/message_loop.h" #include "ppapi/c/pp_errors.h" #include "ppapi/c/ppb_message_loop.h" #include "ppapi/cpp/completion_callback.h" #include "ppapi/cpp/instance_handle.h" #include "ppapi/cpp/module_impl.h" namespace pp { namespace { template <> const char* interface_name() { return PPB_MESSAGELOOP_INTERFACE_1_0; } } // namespace MessageLoop::MessageLoop() : Resource() { } MessageLoop::MessageLoop(const InstanceHandle& instance) : Resource() { if (has_interface()) { PassRefFromConstructor(get_interface()->Create( instance.pp_instance())); } } MessageLoop::MessageLoop(const MessageLoop& other) : Resource(other) { } MessageLoop::MessageLoop(PP_Resource pp_message_loop) : Resource(pp_message_loop) { } // static MessageLoop MessageLoop::GetForMainThread() { if (!has_interface()) return MessageLoop(); return MessageLoop( get_interface()->GetForMainThread()); } // static MessageLoop MessageLoop::GetCurrent() { if (!has_interface()) return MessageLoop(); return MessageLoop( get_interface()->GetCurrent()); } int32_t MessageLoop::AttachToCurrentThread() { if (!has_interface()) return PP_ERROR_NOINTERFACE; return get_interface()->AttachToCurrentThread( pp_resource()); } int32_t MessageLoop::Run() { if (!has_interface()) return PP_ERROR_NOINTERFACE; return get_interface()->Run(pp_resource()); } int32_t MessageLoop::PostWork(const CompletionCallback& callback, int64_t delay_ms) { if (!has_interface()) return PP_ERROR_NOINTERFACE; return get_interface()->PostWork( pp_resource(), callback.pp_completion_callback(), delay_ms); } int32_t MessageLoop::PostQuit(bool should_destroy) { if (!has_interface()) return PP_ERROR_NOINTERFACE; return get_interface()->PostQuit( pp_resource(), PP_FromBool(should_destroy)); } } // namespace pp