• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
3 // found in the LICENSE file.
4 
5 #ifndef PPAPI_PROXY_HOST_RESOLVER_RESOURCE_BASE_H_
6 #define PPAPI_PROXY_HOST_RESOLVER_RESOURCE_BASE_H_
7 
8 #include <string>
9 #include <vector>
10 
11 #include "base/basictypes.h"
12 #include "base/compiler_specific.h"
13 #include "base/memory/ref_counted.h"
14 #include "ppapi/c/private/ppb_host_resolver_private.h"
15 #include "ppapi/proxy/plugin_resource.h"
16 #include "ppapi/proxy/ppapi_proxy_export.h"
17 
18 namespace ppapi {
19 
20 class TrackedCallback;
21 
22 struct HostPortPair {
23   std::string host;
24   uint16_t port;
25 };
26 
27 namespace proxy {
28 
29 class NetAddressResource;
30 
31 class PPAPI_PROXY_EXPORT HostResolverResourceBase: public PluginResource {
32  public:
33   HostResolverResourceBase(Connection connection,
34                            PP_Instance instance,
35                            bool private_api);
36   virtual ~HostResolverResourceBase();
37 
38   int32_t ResolveImpl(const char* host,
39                       uint16_t port,
40                       const PP_HostResolver_Private_Hint* hint,
41                       scoped_refptr<TrackedCallback> callback);
42   PP_Var GetCanonicalNameImpl();
43   uint32_t GetSizeImpl();
44   scoped_refptr<NetAddressResource> GetNetAddressImpl(uint32_t index);
45 
46  private:
47   // IPC message handlers.
48   void OnPluginMsgResolveReply(
49       const ResourceMessageReplyParams& params,
50       const std::string& canonical_name,
51       const std::vector<PP_NetAddress_Private>& net_address_list);
52 
53   void SendResolve(const HostPortPair& host_port,
54                    const PP_HostResolver_Private_Hint* hint);
55 
56   bool ResolveInProgress() const;
57 
58   bool private_api_;
59 
60   scoped_refptr<TrackedCallback> resolve_callback_;
61 
62   // Set to false if there is a pending resolve request or the previous request
63   // failed.
64   bool allow_get_results_;
65   std::string canonical_name_;
66   std::vector<scoped_refptr<NetAddressResource> > net_address_list_;
67 
68   DISALLOW_COPY_AND_ASSIGN(HostResolverResourceBase);
69 };
70 
71 }  // namespace proxy
72 }  // namespace ppapi
73 
74 #endif  // PPAPI_PROXY_HOST_RESOLVER_RESOURCE_BASE_H_
75