15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "remoting/client/plugin/pepper_plugin_thread_delegate.h"
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ppapi/cpp/completion_callback.h"
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ppapi/cpp/module.h"
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace remoting {
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)PepperPluginThreadDelegate::PepperPluginThreadDelegate()
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    : core_(pp::Module::Get()->core()) {
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)PepperPluginThreadDelegate::~PepperPluginThreadDelegate() { }
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool PepperPluginThreadDelegate::RunOnPluginThread(
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    base::TimeDelta delay, void(CDECL function)(void*), void* data) {
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // It is safe to cast |function| to PP_CompletionCallback_Func,
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // which is defined as void(*)(void*, int). The callee will just
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // ignore the last argument. The only case when it may be unsafe is
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // with VS when default calling convention is set to __stdcall, but
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // this code will not typecheck in that case.
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  core_->CallOnMainThread(
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      delay.InMilliseconds(), pp::CompletionCallback(
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          reinterpret_cast<PP_CompletionCallback_Func>(function), data), 0);
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return true;
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace remoting
32