pepper_util.h revision 5821806d5e7f356e8fa4b058a389a808ea183019
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
5#ifndef REMOTING_CLIENT_PLUGIN_PLUGIN_UTIL_H_
6#define REMOTING_CLIENT_PLUGIN_PLUGIN_UTIL_H_
7
8#include "base/basictypes.h"
9#include "base/callback_forward.h"
10
11#include "ppapi/cpp/completion_callback.h"
12
13struct PP_NetAddress_Private;
14
15namespace talk_base {
16class SocketAddress;
17}  // namespace talk_base
18
19namespace remoting {
20
21// Adapts a base::Callback to a pp::CompletionCallback, which may be passed to
22// exactly one Pepper API. If the adapted callback is not used then a copy of
23// |callback| will be leaked, including references & passed values bound to it.
24// Pepper guarantees that each completion callback is called once and only once
25// (aborted callbacks are called with PP_ABOIRTED), so there should be no leaks
26// as long as the result of this function is passed to Pepper.
27pp::CompletionCallback PpCompletionCallback(base::Callback<void(int)> callback);
28
29// Helpers to convert between different socket address representations.
30bool SocketAddressToPpAddressWithPort(const talk_base::SocketAddress& address,
31                                      PP_NetAddress_Private* pp_address,
32                                      uint16_t port);
33bool SocketAddressToPpAddress(const talk_base::SocketAddress& address,
34                              PP_NetAddress_Private* pp_address);
35bool PpAddressToSocketAddress(const PP_NetAddress_Private& pp_address,
36                              talk_base::SocketAddress* address);
37
38}  // namespace remoting
39
40#endif  // REMOTING_CLIENT_PLUGIN_PLUGIN_UTIL_H_
41