Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(61)

Side by Side Diff: remoting/client/plugin/pepper_util.cc

Issue 10384171: Fix PepperPortAllocator to resolve STUN addresses using HostResolverPrivate. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "remoting/client/plugin/pepper_util.h" 5 #include "remoting/client/plugin/pepper_util.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/logging.h"
8 #include "ppapi/c/pp_completion_callback.h" 9 #include "ppapi/c/pp_completion_callback.h"
9 #include "ppapi/cpp/module.h" 10 #include "ppapi/cpp/module.h"
11 #include "ppapi/cpp/private/net_address_private.h"
12 #include "third_party/libjingle/source/talk/base/socketaddress.h"
10 13
11 namespace remoting { 14 namespace remoting {
12 15
13 static void CallbackAdapter(void* user_data, int32_t result) { 16 static void CallbackAdapter(void* user_data, int32_t result) {
14 scoped_ptr<base::Callback<void(int)> > callback( 17 scoped_ptr<base::Callback<void(int)> > callback(
15 reinterpret_cast<base::Callback<void(int)>*>(user_data)); 18 reinterpret_cast<base::Callback<void(int)>*>(user_data));
16 callback->Run(result); 19 callback->Run(result);
17 } 20 }
18 21
19 pp::CompletionCallback PpCompletionCallback( 22 pp::CompletionCallback PpCompletionCallback(
20 base::Callback<void(int)> callback) { 23 base::Callback<void(int)> callback) {
21 return pp::CompletionCallback(&CallbackAdapter, 24 return pp::CompletionCallback(&CallbackAdapter,
22 new base::Callback<void(int)>(callback)); 25 new base::Callback<void(int)>(callback));
23 } 26 }
24 27
28 bool SocketAddressToPpAddressWithPort(const talk_base::SocketAddress& address,
29 PP_NetAddress_Private* pp_address,
30 uint16_t port) {
31 bool result = false;
32 switch (address.ipaddr().family()) {
33 case AF_INET: {
34 in_addr addr = address.ipaddr().ipv4_address();
35 result = pp::NetAddressPrivate::CreateFromIPv4Address(
36 reinterpret_cast<uint8_t*>(&addr), port, pp_address);
37 break;
38 }
39 case AF_INET6: {
40 in6_addr addr = address.ipaddr().ipv6_address();
41 result = pp::NetAddressPrivate::CreateFromIPv6Address(
42 addr.s6_addr, 0, port, pp_address);
43 break;
44 }
45 default: {
46 LOG(WARNING) << "Unknown address family: " << address.ipaddr().family();
47 }
48 }
49 if (!result) {
50 LOG(WARNING) << "Failed to convert address: " << address.ToString();
51 }
52 return result;
53 }
54
55 bool SocketAddressToPpAddress(const talk_base::SocketAddress& address,
56 PP_NetAddress_Private* pp_address) {
57 return SocketAddressToPpAddressWithPort(address, pp_address, address.port());
58 }
59
60 bool PpAddressToSocketAddress(const PP_NetAddress_Private& pp_address,
61 talk_base::SocketAddress* address) {
62 uint8_t addr_storage[16];
63 bool result = pp::NetAddressPrivate::GetAddress(
64 pp_address, &addr_storage, sizeof(addr_storage));
65
66 if (result) {
67 switch (pp::NetAddressPrivate::GetFamily(pp_address)) {
68 case PP_NETADDRESSFAMILY_IPV4:
69 address->SetIP(talk_base::IPAddress(
70 *reinterpret_cast<in_addr*>(addr_storage)));
71 break;
72 case PP_NETADDRESSFAMILY_IPV6:
73 address->SetIP(talk_base::IPAddress(
74 *reinterpret_cast<in6_addr*>(addr_storage)));
75 break;
76 default:
77 result = false;
78 }
79 }
80
81 if (!result) {
82 LOG(WARNING) << "Failed to convert address: "
83 << pp::NetAddressPrivate::Describe(pp_address, true);
84 } else {
85 address->SetPort(pp::NetAddressPrivate::GetPort(pp_address));
86 }
87 return result;
88 }
89
25 } // namespace remoting 90 } // namespace remoting
OLDNEW
« remoting/client/plugin/pepper_util.h ('K') | « remoting/client/plugin/pepper_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698