17d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved.
27d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
37d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)// found in the LICENSE file.
47d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
57d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#ifndef PPAPI_PROXY_HOST_RESOLVER_RESOURCE_BASE_H_
67d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#define PPAPI_PROXY_HOST_RESOLVER_RESOURCE_BASE_H_
77d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
87d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include <string>
97d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include <vector>
107d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
117d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "base/basictypes.h"
127d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "base/compiler_specific.h"
137d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "base/memory/ref_counted.h"
147d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "ppapi/c/private/ppb_host_resolver_private.h"
157d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "ppapi/proxy/plugin_resource.h"
167d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "ppapi/proxy/ppapi_proxy_export.h"
177d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
187d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)namespace ppapi {
197d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
207d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)class TrackedCallback;
217d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
227d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)struct HostPortPair {
237d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  std::string host;
247d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  uint16_t port;
257d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)};
267d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
277d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)namespace proxy {
287d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
297d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)class NetAddressResource;
307d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
317d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)class PPAPI_PROXY_EXPORT HostResolverResourceBase: public PluginResource {
327d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) public:
33eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  HostResolverResourceBase(Connection connection,
34eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch                           PP_Instance instance,
35eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch                           bool private_api);
367d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  virtual ~HostResolverResourceBase();
377d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
387d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  int32_t ResolveImpl(const char* host,
397d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)                      uint16_t port,
407d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)                      const PP_HostResolver_Private_Hint* hint,
417d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)                      scoped_refptr<TrackedCallback> callback);
427d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  PP_Var GetCanonicalNameImpl();
437d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  uint32_t GetSizeImpl();
447d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  scoped_refptr<NetAddressResource> GetNetAddressImpl(uint32_t index);
457d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
467d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) private:
477d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // IPC message handlers.
487d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  void OnPluginMsgResolveReply(
497d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)      const ResourceMessageReplyParams& params,
507d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)      const std::string& canonical_name,
517d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)      const std::vector<PP_NetAddress_Private>& net_address_list);
527d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
537d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  void SendResolve(const HostPortPair& host_port,
547d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)                   const PP_HostResolver_Private_Hint* hint);
557d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
567d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  bool ResolveInProgress() const;
577d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
58eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  bool private_api_;
59eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
607d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  scoped_refptr<TrackedCallback> resolve_callback_;
617d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
627d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // Set to false if there is a pending resolve request or the previous request
637d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // failed.
647d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  bool allow_get_results_;
657d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  std::string canonical_name_;
667d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  std::vector<scoped_refptr<NetAddressResource> > net_address_list_;
677d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
687d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(HostResolverResourceBase);
697d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)};
707d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
717d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)}  // namespace proxy
727d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)}  // namespace ppapi
737d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
747d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#endif  // PPAPI_PROXY_HOST_RESOLVER_RESOURCE_BASE_H_
75