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

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

Issue 11411357: PPB_HostResolver_Private is switched to the new Pepper proxy. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sync. Created 7 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ppapi/proxy/host_resolver_private_resource.h ('k') | ppapi/proxy/interface_list.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ppapi/proxy/host_resolver_private_resource.h"
6
7 #include "ppapi/c/pp_errors.h"
8 #include "ppapi/proxy/ppapi_messages.h"
9 #include "ppapi/shared_impl/var.h"
10
11 namespace ppapi {
12 namespace proxy {
13
14 HostResolverPrivateResource::HostResolverPrivateResource(Connection connection,
15 PP_Instance instance)
16 : PluginResource(connection, instance) {
17 SendCreate(BROWSER, PpapiHostMsg_HostResolverPrivate_Create());
18 }
19
20 HostResolverPrivateResource::~HostResolverPrivateResource() {
21 }
22
23 thunk::PPB_HostResolver_Private_API*
24 HostResolverPrivateResource::AsPPB_HostResolver_Private_API() {
25 return this;
26 }
27
28 int32_t HostResolverPrivateResource::Resolve(
29 const char* host,
30 uint16_t port,
31 const PP_HostResolver_Private_Hint* hint,
32 scoped_refptr<TrackedCallback> callback) {
33 if (!host)
34 return PP_ERROR_BADARGUMENT;
35 if (ResolveInProgress())
36 return PP_ERROR_INPROGRESS;
37
38 resolve_callback_ = callback;
39
40 HostPortPair host_port;
41 host_port.host = host;
42 host_port.port = port;
43
44 SendResolve(host_port, hint);
45 return PP_OK_COMPLETIONPENDING;
46 }
47
48 PP_Var HostResolverPrivateResource::GetCanonicalName() {
49 return StringVar::StringToPPVar(canonical_name_);
50 }
51
52 uint32_t HostResolverPrivateResource::GetSize() {
53 if (ResolveInProgress())
54 return 0;
55 return static_cast<uint32_t>(net_address_list_.size());
56 }
57
58 bool HostResolverPrivateResource::GetNetAddress(
59 uint32 index,
60 PP_NetAddress_Private* address) {
61 if (ResolveInProgress() || index >= GetSize())
62 return false;
63 *address = net_address_list_[index];
64 return true;
65 }
66
67 void HostResolverPrivateResource::OnPluginMsgResolveReply(
68 const ResourceMessageReplyParams& params,
69 const std::string& canonical_name,
70 const std::vector<PP_NetAddress_Private>& net_address_list) {
71 if (params.result() == PP_OK) {
72 canonical_name_ = canonical_name;
73 net_address_list_ = net_address_list;
74 } else {
75 canonical_name_.clear();
76 net_address_list_.clear();
77 }
78 resolve_callback_->Run(params.result());
79 }
80
81 void HostResolverPrivateResource::SendResolve(
82 const HostPortPair& host_port,
83 const PP_HostResolver_Private_Hint* hint) {
84 PpapiHostMsg_HostResolverPrivate_Resolve msg(host_port, *hint);
85 Call<PpapiPluginMsg_HostResolverPrivate_ResolveReply>(
86 BROWSER,
87 msg,
88 base::Bind(&HostResolverPrivateResource::OnPluginMsgResolveReply,
89 base::Unretained(this)));
90 }
91
92 bool HostResolverPrivateResource::ResolveInProgress() const {
93 return TrackedCallback::IsPending(resolve_callback_);
94 }
95
96 } // namespace proxy
97 } // namespace ppapi
OLDNEW
« no previous file with comments | « ppapi/proxy/host_resolver_private_resource.h ('k') | ppapi/proxy/interface_list.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698