Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/proxy/host_resolver_resource_base.h" | 5 #include "ppapi/proxy/host_resolver_resource_base.h" |
| 6 | 6 |
| 7 #include "ppapi/c/pp_errors.h" | 7 #include "ppapi/c/pp_errors.h" |
| 8 #include "ppapi/proxy/net_address_resource.h" | 8 #include "ppapi/proxy/net_address_resource.h" |
| 9 #include "ppapi/proxy/ppapi_messages.h" | 9 #include "ppapi/proxy/ppapi_messages.h" |
| 10 #include "ppapi/shared_impl/tracked_callback.h" | 10 #include "ppapi/shared_impl/tracked_callback.h" |
| 11 #include "ppapi/shared_impl/var.h" | 11 #include "ppapi/shared_impl/var.h" |
| 12 | 12 |
| 13 namespace ppapi { | 13 namespace ppapi { |
| 14 namespace proxy { | 14 namespace proxy { |
| 15 | 15 |
| 16 namespace { | |
| 17 | |
| 18 int32_t ConvertPPError(int32_t pp_error, bool private_api) { | |
| 19 // The private API doesn't return network-specific error codes or | |
| 20 // PP_ERROR_NOACCESS. In order to preserve the havavior, we convert those to | |
| 21 // PP_ERROR_FAILED. | |
| 22 if (private_api && | |
| 23 (pp_error <= PP_ERROR_CONNECTION_CLOSED || | |
|
raymes
2013/06/18 18:21:17
nit: It would sort of be nicer to check whether th
yzshen1
2013/06/18 19:08:43
I agree with you that the current code doesn't loo
| |
| 24 pp_error == PP_ERROR_NOACCESS)) { | |
| 25 return PP_ERROR_FAILED; | |
| 26 } | |
| 27 | |
| 28 return pp_error; | |
| 29 } | |
| 30 | |
| 31 } // namespace | |
| 32 | |
| 16 HostResolverResourceBase::HostResolverResourceBase(Connection connection, | 33 HostResolverResourceBase::HostResolverResourceBase(Connection connection, |
| 17 PP_Instance instance) | 34 PP_Instance instance, |
| 35 bool private_api) | |
| 18 : PluginResource(connection, instance), | 36 : PluginResource(connection, instance), |
| 37 private_api_(private_api), | |
| 19 allow_get_results_(false) { | 38 allow_get_results_(false) { |
| 20 SendCreate(BROWSER, PpapiHostMsg_HostResolverPrivate_Create()); | 39 if (private_api) |
| 40 SendCreate(BROWSER, PpapiHostMsg_HostResolver_CreatePrivate()); | |
| 41 else | |
| 42 SendCreate(BROWSER, PpapiHostMsg_HostResolver_Create()); | |
| 21 } | 43 } |
| 22 | 44 |
| 23 HostResolverResourceBase::~HostResolverResourceBase() { | 45 HostResolverResourceBase::~HostResolverResourceBase() { |
| 24 } | 46 } |
| 25 | 47 |
| 26 int32_t HostResolverResourceBase::ResolveImpl( | 48 int32_t HostResolverResourceBase::ResolveImpl( |
| 27 const char* host, | 49 const char* host, |
| 28 uint16_t port, | 50 uint16_t port, |
| 29 const PP_HostResolver_Private_Hint* hint, | 51 const PP_HostResolver_Private_Hint* hint, |
| 30 scoped_refptr<TrackedCallback> callback) { | 52 scoped_refptr<TrackedCallback> callback) { |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 78 net_address_list.begin(); | 100 net_address_list.begin(); |
| 79 iter != net_address_list.end(); | 101 iter != net_address_list.end(); |
| 80 ++iter) { | 102 ++iter) { |
| 81 net_address_list_.push_back( | 103 net_address_list_.push_back( |
| 82 new NetAddressResource(connection(), pp_instance(), *iter)); | 104 new NetAddressResource(connection(), pp_instance(), *iter)); |
| 83 } | 105 } |
| 84 } else { | 106 } else { |
| 85 canonical_name_.clear(); | 107 canonical_name_.clear(); |
| 86 net_address_list_.clear(); | 108 net_address_list_.clear(); |
| 87 } | 109 } |
| 88 resolve_callback_->Run(params.result()); | 110 resolve_callback_->Run(ConvertPPError(params.result(), private_api_)); |
| 89 } | 111 } |
| 90 | 112 |
| 91 void HostResolverResourceBase::SendResolve( | 113 void HostResolverResourceBase::SendResolve( |
| 92 const HostPortPair& host_port, | 114 const HostPortPair& host_port, |
| 93 const PP_HostResolver_Private_Hint* hint) { | 115 const PP_HostResolver_Private_Hint* hint) { |
| 94 PpapiHostMsg_HostResolverPrivate_Resolve msg(host_port, *hint); | 116 PpapiHostMsg_HostResolver_Resolve msg(host_port, *hint); |
| 95 Call<PpapiPluginMsg_HostResolverPrivate_ResolveReply>( | 117 Call<PpapiPluginMsg_HostResolver_ResolveReply>( |
| 96 BROWSER, | 118 BROWSER, |
| 97 msg, | 119 msg, |
| 98 base::Bind(&HostResolverResourceBase::OnPluginMsgResolveReply, | 120 base::Bind(&HostResolverResourceBase::OnPluginMsgResolveReply, |
| 99 base::Unretained(this))); | 121 base::Unretained(this))); |
| 100 } | 122 } |
| 101 | 123 |
| 102 bool HostResolverResourceBase::ResolveInProgress() const { | 124 bool HostResolverResourceBase::ResolveInProgress() const { |
| 103 return TrackedCallback::IsPending(resolve_callback_); | 125 return TrackedCallback::IsPending(resolve_callback_); |
| 104 } | 126 } |
| 105 | 127 |
| 106 } // namespace proxy | 128 } // namespace proxy |
| 107 } // namespace ppapi | 129 } // namespace ppapi |
| OLD | NEW |