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

Unified Diff: ppapi/shared_impl/private/network_list.cc

Issue 9455092: HostResolver is exposed to plugin. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Added shared declaration of GetPPB_HostResolver_Private_0_1_Thunk. Created 8 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: ppapi/shared_impl/private/network_list.cc
diff --git a/ppapi/shared_impl/private/network_list.cc b/ppapi/shared_impl/private/network_list.cc
new file mode 100644
index 0000000000000000000000000000000000000000..e5c313657a080d0ce7f96a25f4d8948b83459c88
--- /dev/null
+++ b/ppapi/shared_impl/private/network_list.cc
@@ -0,0 +1,73 @@
+// Copyright (c) 2012 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/shared_impl/private/network_list.h"
+
+#include <cstring>
+
+#include "base/memory/scoped_ptr.h"
+#include "net/base/sys_addrinfo.h"
+#include "ppapi/shared_impl/private/net_address_private_impl.h"
+
+namespace ppapi {
+
+NetworkList::NetworkList() {
+}
+
+NetworkList::~NetworkList() {
+}
+
+NetworkList* NetworkList::CreateFromAddrInfo(const addrinfo* ai) {
+ scoped_ptr<NetworkList> network_list(new NetworkList());
+
+ std::string canonical_name;
+ PP_NetAddress_Private address;
+
+ while (ai != NULL) {
+ if (ai->ai_canonname != NULL)
+ canonical_name = ai->ai_canonname;
+ else
+ canonical_name = "";
+
+ if (!NetAddressPrivateImpl::SockaddrToNetAddress(ai->ai_addr,
+ ai->ai_addrlen,
+ &address)) {
+ return NULL;
+ }
+
+ network_list->Append(canonical_name, address);
+ ai = ai->ai_next;
+ }
+ return network_list.release();
+}
+
+void NetworkList::Clear() {
+ canonical_name_list_.clear();
+ address_list_.clear();
+}
+
+void NetworkList::Append(const std::string& canonical_name,
+ const PP_NetAddress_Private& address) {
+ canonical_name_list_.push_back(canonical_name);
+ address_list_.push_back(address);
+}
+
+size_t NetworkList::GetSize() const {
+ return canonical_name_list_.size();
+}
+
+bool NetworkList::GetItem(size_t index,
+ std::string* canonical_name,
+ PP_NetAddress_Private* address) const {
+ if (index >= GetSize())
+ return false;
+
+ if (canonical_name)
+ *canonical_name = canonical_name_list_[index];
+ if (address)
+ memmove(address, &address_list_[index], sizeof(*address));
yzshen1 2012/02/28 08:29:00 You could assign directly.
ygorshenin1 2012/02/28 12:09:47 Done.
+ return true;
+}
+
+} // namespace ppapi

Powered by Google App Engine
This is Rietveld 408576698