diff options
author | sergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-09-05 01:06:46 +0000 |
---|---|---|
committer | sergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-09-05 01:06:46 +0000 |
commit | e6a1b4ee5411faaf44a95204299e9738bffc8a80 (patch) | |
tree | 068d777fdaadeb9f1574b459c4b64fdf4ee51816 /ppapi/cpp | |
parent | 47ebce481df17bd82c0966403fc26a424beea077 (diff) | |
download | chromium_src-e6a1b4ee5411faaf44a95204299e9738bffc8a80.zip chromium_src-e6a1b4ee5411faaf44a95204299e9738bffc8a80.tar.gz chromium_src-e6a1b4ee5411faaf44a95204299e9738bffc8a80.tar.bz2 |
Use PP_ArrayOutput and PPB_NetAddress in PPB_NetworkList_Private..
PPB_NetworkList_Private was implemented before PP_ArrayOutput and PPB_NetAddress
was added. Refactor GetIPAddress() to use these new types.
Also removed in-process support because PPB_NetAddress doesn't support in-process mode.
BUG=281781
TBR=piman@chromium.org (trivial changes in content_renderer.gypi)
Review URL: https://chromiumcodereview.appspot.com/23806003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@221324 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi/cpp')
-rw-r--r-- | ppapi/cpp/private/network_list_private.cc | 74 | ||||
-rw-r--r-- | ppapi/cpp/private/network_list_private.h | 6 |
2 files changed, 33 insertions, 47 deletions
diff --git a/ppapi/cpp/private/network_list_private.cc b/ppapi/cpp/private/network_list_private.cc index 1297aa3..5a3a5be 100644 --- a/ppapi/cpp/private/network_list_private.cc +++ b/ppapi/cpp/private/network_list_private.cc @@ -4,15 +4,19 @@ #include "ppapi/cpp/private/network_list_private.h" +#include "ppapi/c/pp_errors.h" +#include "ppapi/cpp/array_output.h" +#include "ppapi/cpp/logging.h" #include "ppapi/cpp/module_impl.h" +#include "ppapi/cpp/net_address.h" #include "ppapi/cpp/var.h" namespace pp { namespace { -template <> const char* interface_name<PPB_NetworkList_Private>() { - return PPB_NETWORKLIST_PRIVATE_INTERFACE; +template <> const char* interface_name<PPB_NetworkList_Private_0_3>() { + return PPB_NETWORKLIST_PRIVATE_INTERFACE_0_3; } } // namespace @@ -26,84 +30,64 @@ NetworkListPrivate::NetworkListPrivate(PassRef, PP_Resource resource) // static bool NetworkListPrivate::IsAvailable() { - return has_interface<PPB_NetworkList_Private>(); + return has_interface<PPB_NetworkList_Private_0_3>(); } uint32_t NetworkListPrivate::GetCount() const { - if (!has_interface<PPB_NetworkList_Private>()) + if (!has_interface<PPB_NetworkList_Private_0_3>()) return 0; - return get_interface<PPB_NetworkList_Private>()->GetCount(pp_resource()); + return get_interface<PPB_NetworkList_Private_0_3>()->GetCount(pp_resource()); } std::string NetworkListPrivate::GetName(uint32_t index) const { - if (!has_interface<PPB_NetworkList_Private>()) + if (!has_interface<PPB_NetworkList_Private_0_3>()) return std::string(); Var result(PASS_REF, - get_interface<PPB_NetworkList_Private>()->GetName( + get_interface<PPB_NetworkList_Private_0_3>()->GetName( pp_resource(), index)); return result.is_string() ? result.AsString() : std::string(); } PP_NetworkListType_Private NetworkListPrivate::GetType(uint32_t index) const { - if (!has_interface<PPB_NetworkList_Private>()) + if (!has_interface<PPB_NetworkList_Private_0_3>()) return PP_NETWORKLIST_ETHERNET; - return get_interface<PPB_NetworkList_Private>()->GetType( + return get_interface<PPB_NetworkList_Private_0_3>()->GetType( pp_resource(), index); } PP_NetworkListState_Private NetworkListPrivate::GetState(uint32_t index) const { - if (!has_interface<PPB_NetworkList_Private>()) + if (!has_interface<PPB_NetworkList_Private_0_3>()) return PP_NETWORKLIST_DOWN; - return get_interface<PPB_NetworkList_Private>()->GetState( + return get_interface<PPB_NetworkList_Private_0_3>()->GetState( pp_resource(), index); } -void NetworkListPrivate::GetIpAddresses( +int32_t NetworkListPrivate::GetIpAddresses( uint32_t index, - std::vector<PP_NetAddress_Private>* addresses) const { - if (!has_interface<PPB_NetworkList_Private>()) - return; - - // Most network interfaces don't have more than 3 network - // interfaces. - addresses->resize(3); - - int32_t result = get_interface<PPB_NetworkList_Private>()->GetIpAddresses( - pp_resource(), index, &addresses->front(), addresses->size()); - - if (result < 0) { - addresses->resize(0); - return; - } - - if (result <= static_cast<int32_t>(addresses->size())) { - addresses->resize(result); - return; - } - - addresses->resize(result); - result = get_interface<PPB_NetworkList_Private>()->GetIpAddresses( - pp_resource(), index, &addresses->front(), addresses->size()); - if (result < 0) { - addresses->resize(0); - } else if (result < static_cast<int32_t>(addresses->size())) { - addresses->resize(result); - } + std::vector<NetAddress>* addresses) const { + if (!has_interface<PPB_NetworkList_Private_0_3>()) + return PP_ERROR_NOINTERFACE; + if (!addresses) + return PP_ERROR_BADARGUMENT; + + ResourceArrayOutputAdapter<NetAddress> adapter(addresses); + return get_interface<PPB_NetworkList_Private_0_3>()->GetIpAddresses( + pp_resource(), index, adapter.pp_array_output()); } std::string NetworkListPrivate::GetDisplayName(uint32_t index) const { - if (!has_interface<PPB_NetworkList_Private>()) + if (!has_interface<PPB_NetworkList_Private_0_3>()) return std::string(); Var result(PASS_REF, - get_interface<PPB_NetworkList_Private>()->GetDisplayName( + get_interface<PPB_NetworkList_Private_0_3>()->GetDisplayName( pp_resource(), index)); return result.is_string() ? result.AsString() : std::string(); } uint32_t NetworkListPrivate::GetMTU(uint32_t index) const { - if (!has_interface<PPB_NetworkList_Private>()) + if (!has_interface<PPB_NetworkList_Private_0_3>()) return 0; - return get_interface<PPB_NetworkList_Private>()->GetMTU( + return get_interface<PPB_NetworkList_Private_0_3>()->GetMTU( pp_resource(), index); } diff --git a/ppapi/cpp/private/network_list_private.h b/ppapi/cpp/private/network_list_private.h index 31cd9b5..c338aa6 100644 --- a/ppapi/cpp/private/network_list_private.h +++ b/ppapi/cpp/private/network_list_private.h @@ -14,6 +14,8 @@ namespace pp { +class NetAddress; + class NetworkListPrivate : public Resource { public: NetworkListPrivate(); @@ -41,8 +43,8 @@ class NetworkListPrivate : public Resource { /// Gets the list of IP addresses for the network interface with the /// specified <code>index</code> and stores them in /// <code>addresses</code>. - void GetIpAddresses(uint32_t index, - std::vector<PP_NetAddress_Private>* addresses) const; + int32_t GetIpAddresses(uint32_t index, + std::vector<NetAddress>* addresses) const; /// @return Returns the display name for the network interface with /// the specified <code>index</code>. |