summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions/api/dns/dns_api.h
blob: 1c646f6e679013f4a75117fa12178570511d2992 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_EXTENSIONS_API_DNS_DNS_API_H_
#define CHROME_BROWSER_EXTENSIONS_API_DNS_DNS_API_H_

#include <string>

#include "chrome/browser/extensions/extension_function.h"
#include "chrome/browser/io_thread.h"
#include "net/base/address_list.h"
#include "net/base/completion_callback.h"
#include "net/base/host_resolver.h"

class IOThread;

namespace extensions {

class DnsResolveFunction : public AsyncExtensionFunction {
 public:
  DECLARE_EXTENSION_FUNCTION("experimental.dns.resolve",
                             EXPERIMENTAL_DNS_RESOLVE)

  DnsResolveFunction();

 protected:
  virtual ~DnsResolveFunction();

  // ExtensionFunction:
  virtual bool RunImpl() OVERRIDE;

  void WorkOnIOThread();
  void RespondOnUIThread();

 private:
  void OnLookupFinished(int result);

  std::string hostname_;

  bool response_;  // The value sent in SendResponse().

  // This instance is widely available through BrowserProcess, but we need to
  // acquire it on the UI thread and then use it on the IO thread, so we keep a
  // plain pointer to it here as we move from thread to thread.
  IOThread* io_thread_;

  scoped_ptr<net::HostResolver::RequestHandle> request_handle_;
  scoped_ptr<net::AddressList> addresses_;
};

}  // namespace extensions

#endif  // CHROME_BROWSER_EXTENSIONS_API_DNS_DNS_API_H_