Chromium Code Reviews| Index: ppapi/shared_impl/private/ppb_host_resolver_shared.cc |
| diff --git a/ppapi/shared_impl/private/ppb_host_resolver_shared.cc b/ppapi/shared_impl/private/ppb_host_resolver_shared.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..b717d32659bc5150d8afd9fc8dec73435f4ab7be |
| --- /dev/null |
| +++ b/ppapi/shared_impl/private/ppb_host_resolver_shared.cc |
| @@ -0,0 +1,99 @@ |
| +// 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/ppb_host_resolver_shared.h" |
| + |
| +#include <cstddef> |
| +#include <cstring> |
| + |
| +#include "ppapi/c/pp_errors.h" |
| +#include "ppapi/shared_impl/private/network_list.h" |
| +#include "ppapi/shared_impl/var.h" |
| +#include "ppapi/thunk/thunk.h" |
| + |
| +namespace ppapi { |
| + |
| +PPB_HostResolver_Shared::PPB_HostResolver_Shared(PP_Instance instance) |
| + : Resource(OBJECT_IS_IMPL, instance), |
| + host_resolver_id_(GenerateHostResolverID()), |
| + resolve_in_progress_(false) { |
| +} |
| + |
| +PPB_HostResolver_Shared::PPB_HostResolver_Shared( |
| + const HostResource& resource) |
| + : Resource(OBJECT_IS_PROXY, resource), |
| + host_resolver_id_(GenerateHostResolverID()), |
| + resolve_in_progress_(false) { |
| +} |
| + |
| +PPB_HostResolver_Shared::~PPB_HostResolver_Shared() { |
| +} |
| + |
| +thunk::PPB_HostResolver_Private_API* |
| +PPB_HostResolver_Shared::AsPPB_HostResolver_Private_API() { |
| + return this; |
| +} |
| + |
| +int32_t PPB_HostResolver_Shared::Resolve( |
| + const char* host, |
| + uint16_t port, |
| + const PP_HostResolver_Private_Hint* hint, |
| + PP_CompletionCallback callback) { |
| + if (!host) |
| + return PP_ERROR_BADARGUMENT; |
| + if (!callback.func) |
| + return PP_ERROR_BLOCKS_MAIN_THREAD; |
| + if (resolve_in_progress_) |
| + return PP_ERROR_FAILED; |
| + if (TrackedCallback::IsPending(resolve_callback_)) |
| + return PP_ERROR_INPROGRESS; |
| + |
| + resolve_in_progress_ = true; |
| + resolve_callback_ = new TrackedCallback(this, callback); |
| + SendResolve(host, port, hint); |
| + return PP_OK_COMPLETIONPENDING; |
| +} |
| + |
| +uint32_t PPB_HostResolver_Shared::GetSize() { |
| + return static_cast<uint32_t>(network_list_.GetSize()); |
| +} |
| + |
| +bool PPB_HostResolver_Shared::GetItem(uint32 index, |
| + PP_Var* canonical_name, |
| + PP_NetAddress_Private* address) { |
| + if (resolve_in_progress_) |
|
yzshen1
2012/02/28 08:29:00
If GetItem() is not allowed while resolving, shall
ygorshenin1
2012/02/28 12:09:47
Done.
|
| + return false; |
| + |
| + if (index >= network_list_.GetSize()) |
| + return false; |
| + |
| + std::string name; |
| + if (!network_list_.GetItem(index, &name, address)) |
| + return false; |
| + |
| + if (canonical_name != NULL) |
|
yzshen1
2012/02/28 08:29:00
nit: please be consistent. You could use if (!cano
ygorshenin1
2012/02/28 12:09:47
Done.
|
| + *canonical_name = StringVar::StringToPPVar(name); |
| + return true; |
| +} |
| + |
| +void PPB_HostResolver_Shared::OnResolveCompleted( |
| + bool succeeded, |
| + const NetworkList& network_list) { |
| + resolve_in_progress_ = false; |
| + |
| + if (succeeded) |
| + network_list_ = network_list; |
| + else |
| + network_list_.Clear(); |
| + |
| + TrackedCallback::ClearAndRun(&resolve_callback_, |
| + succeeded ? PP_OK : PP_ERROR_FAILED); |
| +} |
| + |
| +uint32 PPB_HostResolver_Shared::GenerateHostResolverID() { |
| + static uint32 host_resolver_id = 0; |
| + return host_resolver_id++; |
| +} |
| + |
| +} // namespace ppapi |