summaryrefslogtreecommitdiffstats
path: root/ppapi/thunk/common.cc
blob: b59f1398b3b6f7120a157c3823b3e2b352590ad7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// Copyright (c) 2011 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/thunk/common.h"

#include "base/message_loop.h"
#include "ppapi/c/pp_errors.h"

namespace ppapi {
namespace thunk {

int32_t MayForceCallback(PP_CompletionCallback callback, int32_t result) {
  if (result == PP_OK_COMPLETIONPENDING)
    return result;

  if (callback.func == NULL ||
      (callback.flags & PP_COMPLETIONCALLBACK_FLAG_OPTIONAL) != 0)
    return result;

  // TODO(polina): make this work off the main thread as well
  // (At this point this should not be an issue because PPAPI is only supported
  // on the main thread).
  MessageLoop::current()->PostTask(FROM_HERE, NewRunnableFunction(
      callback.func, callback.user_data, result));
  return PP_OK_COMPLETIONPENDING;
}

}  // namespace thunk
}  // namespace ppapi