| OLD | NEW |
| 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 "ppapi/shared_impl/private/ppb_host_resolver_shared.h" | 5 #include "ppapi/shared_impl/private/ppb_host_resolver_shared.h" |
| 6 | 6 |
| 7 #include <cstddef> | 7 #include <cstddef> |
| 8 #include <cstring> | 8 #include <cstring> |
| 9 | 9 |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #if !defined(OS_NACL) | |
| 12 #include "net/base/address_list.h" | |
| 13 #endif | |
| 14 #include "ppapi/c/pp_errors.h" | 11 #include "ppapi/c/pp_errors.h" |
| 15 #include "ppapi/shared_impl/private/net_address_private_impl.h" | 12 #include "ppapi/shared_impl/private/net_address_private_impl.h" |
| 16 #include "ppapi/shared_impl/var.h" | 13 #include "ppapi/shared_impl/var.h" |
| 17 #include "ppapi/thunk/thunk.h" | 14 #include "ppapi/thunk/thunk.h" |
| 18 | 15 |
| 19 namespace ppapi { | 16 namespace ppapi { |
| 20 | 17 |
| 21 #if !defined(OS_NACL) && !defined(NACL_WIN64) | |
| 22 NetAddressList* CreateNetAddressListFromAddressList( | |
| 23 const net::AddressList& list) { | |
| 24 scoped_ptr<NetAddressList> net_address_list(new NetAddressList()); | |
| 25 PP_NetAddress_Private address; | |
| 26 | |
| 27 for (size_t i = 0; i < list.size(); ++i) { | |
| 28 if (!NetAddressPrivateImpl::IPEndPointToNetAddress(list[i], &address)) | |
| 29 return NULL; | |
| 30 net_address_list->push_back(address); | |
| 31 } | |
| 32 | |
| 33 return net_address_list.release(); | |
| 34 } | |
| 35 #endif // !defined(OS_NACL) && !defined(NACL_WIN64) | |
| 36 | |
| 37 PPB_HostResolver_Shared::PPB_HostResolver_Shared(PP_Instance instance) | 18 PPB_HostResolver_Shared::PPB_HostResolver_Shared(PP_Instance instance) |
| 38 : Resource(OBJECT_IS_IMPL, instance), | 19 : Resource(OBJECT_IS_IMPL, instance), |
| 39 host_resolver_id_(GenerateHostResolverID()) { | 20 host_resolver_id_(GenerateHostResolverID()) { |
| 40 } | 21 } |
| 41 | 22 |
| 42 PPB_HostResolver_Shared::PPB_HostResolver_Shared( | 23 PPB_HostResolver_Shared::PPB_HostResolver_Shared( |
| 43 const HostResource& resource) | 24 const HostResource& resource) |
| 44 : Resource(OBJECT_IS_PROXY, resource), | 25 : Resource(OBJECT_IS_PROXY, resource), |
| 45 host_resolver_id_(GenerateHostResolverID()) { | 26 host_resolver_id_(GenerateHostResolverID()) { |
| 46 } | 27 } |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 PP_NetAddress_Private* address) { | 68 PP_NetAddress_Private* address) { |
| 88 if (ResolveInProgress() || index >= GetSize()) | 69 if (ResolveInProgress() || index >= GetSize()) |
| 89 return false; | 70 return false; |
| 90 *address = net_address_list_[index]; | 71 *address = net_address_list_[index]; |
| 91 return true; | 72 return true; |
| 92 } | 73 } |
| 93 | 74 |
| 94 void PPB_HostResolver_Shared::OnResolveCompleted( | 75 void PPB_HostResolver_Shared::OnResolveCompleted( |
| 95 bool succeeded, | 76 bool succeeded, |
| 96 const std::string& canonical_name, | 77 const std::string& canonical_name, |
| 97 const NetAddressList& net_address_list) { | 78 const std::vector<PP_NetAddress_Private>& net_address_list) { |
| 98 if (succeeded) { | 79 if (succeeded) { |
| 99 canonical_name_ = canonical_name; | 80 canonical_name_ = canonical_name; |
| 100 net_address_list_ = net_address_list; | 81 net_address_list_ = net_address_list; |
| 101 } else { | 82 } else { |
| 102 canonical_name_.clear(); | 83 canonical_name_.clear(); |
| 103 net_address_list_.clear(); | 84 net_address_list_.clear(); |
| 104 } | 85 } |
| 105 | 86 |
| 106 TrackedCallback::ClearAndRun(&resolve_callback_, | 87 TrackedCallback::ClearAndRun(&resolve_callback_, |
| 107 succeeded ? PP_OK : PP_ERROR_FAILED); | 88 succeeded ? PP_OK : PP_ERROR_FAILED); |
| 108 } | 89 } |
| 109 | 90 |
| 110 uint32 PPB_HostResolver_Shared::GenerateHostResolverID() { | 91 uint32 PPB_HostResolver_Shared::GenerateHostResolverID() { |
| 111 static uint32 host_resolver_id = 0; | 92 static uint32 host_resolver_id = 0; |
| 112 return host_resolver_id++; | 93 return host_resolver_id++; |
| 113 } | 94 } |
| 114 | 95 |
| 115 bool PPB_HostResolver_Shared::ResolveInProgress() const { | 96 bool PPB_HostResolver_Shared::ResolveInProgress() const { |
| 116 return TrackedCallback::IsPending(resolve_callback_); | 97 return TrackedCallback::IsPending(resolve_callback_); |
| 117 } | 98 } |
| 118 | 99 |
| 119 } // namespace ppapi | 100 } // namespace ppapi |
| OLD | NEW |