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

Side by Side Diff: ppapi/proxy/host_resolver_resource_base.cc

Issue 16933003: Implement PPB_HostResolver_Dev: part 2 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 6 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ppapi/proxy/host_resolver_resource_base.h ('k') | ppapi/proxy/ppapi_messages.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 behavior, we convert those to
21 // PP_ERROR_FAILED.
22 // TODO(yzshen): Consider defining ranges for different kinds of PP_Error
23 // codes, so that we can detect network-specific error codes in a better way.
24 if (private_api &&
25 (pp_error <= PP_ERROR_CONNECTION_CLOSED ||
26 pp_error == PP_ERROR_NOACCESS)) {
27 return PP_ERROR_FAILED;
28 }
29
30 return pp_error;
31 }
32
33 } // namespace
34
16 HostResolverResourceBase::HostResolverResourceBase(Connection connection, 35 HostResolverResourceBase::HostResolverResourceBase(Connection connection,
17 PP_Instance instance) 36 PP_Instance instance,
37 bool private_api)
18 : PluginResource(connection, instance), 38 : PluginResource(connection, instance),
39 private_api_(private_api),
19 allow_get_results_(false) { 40 allow_get_results_(false) {
20 SendCreate(BROWSER, PpapiHostMsg_HostResolverPrivate_Create()); 41 if (private_api)
42 SendCreate(BROWSER, PpapiHostMsg_HostResolver_CreatePrivate());
43 else
44 SendCreate(BROWSER, PpapiHostMsg_HostResolver_Create());
21 } 45 }
22 46
23 HostResolverResourceBase::~HostResolverResourceBase() { 47 HostResolverResourceBase::~HostResolverResourceBase() {
24 } 48 }
25 49
26 int32_t HostResolverResourceBase::ResolveImpl( 50 int32_t HostResolverResourceBase::ResolveImpl(
27 const char* host, 51 const char* host,
28 uint16_t port, 52 uint16_t port,
29 const PP_HostResolver_Private_Hint* hint, 53 const PP_HostResolver_Private_Hint* hint,
30 scoped_refptr<TrackedCallback> callback) { 54 scoped_refptr<TrackedCallback> callback) {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 net_address_list.begin(); 102 net_address_list.begin();
79 iter != net_address_list.end(); 103 iter != net_address_list.end();
80 ++iter) { 104 ++iter) {
81 net_address_list_.push_back( 105 net_address_list_.push_back(
82 new NetAddressResource(connection(), pp_instance(), *iter)); 106 new NetAddressResource(connection(), pp_instance(), *iter));
83 } 107 }
84 } else { 108 } else {
85 canonical_name_.clear(); 109 canonical_name_.clear();
86 net_address_list_.clear(); 110 net_address_list_.clear();
87 } 111 }
88 resolve_callback_->Run(params.result()); 112 resolve_callback_->Run(ConvertPPError(params.result(), private_api_));
89 } 113 }
90 114
91 void HostResolverResourceBase::SendResolve( 115 void HostResolverResourceBase::SendResolve(
92 const HostPortPair& host_port, 116 const HostPortPair& host_port,
93 const PP_HostResolver_Private_Hint* hint) { 117 const PP_HostResolver_Private_Hint* hint) {
94 PpapiHostMsg_HostResolverPrivate_Resolve msg(host_port, *hint); 118 PpapiHostMsg_HostResolver_Resolve msg(host_port, *hint);
95 Call<PpapiPluginMsg_HostResolverPrivate_ResolveReply>( 119 Call<PpapiPluginMsg_HostResolver_ResolveReply>(
96 BROWSER, 120 BROWSER,
97 msg, 121 msg,
98 base::Bind(&HostResolverResourceBase::OnPluginMsgResolveReply, 122 base::Bind(&HostResolverResourceBase::OnPluginMsgResolveReply,
99 base::Unretained(this))); 123 base::Unretained(this)));
100 } 124 }
101 125
102 bool HostResolverResourceBase::ResolveInProgress() const { 126 bool HostResolverResourceBase::ResolveInProgress() const {
103 return TrackedCallback::IsPending(resolve_callback_); 127 return TrackedCallback::IsPending(resolve_callback_);
104 } 128 }
105 129
106 } // namespace proxy 130 } // namespace proxy
107 } // namespace ppapi 131 } // namespace ppapi
OLDNEW
« no previous file with comments | « ppapi/proxy/host_resolver_resource_base.h ('k') | ppapi/proxy/ppapi_messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698