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 #ifndef CHROME_BROWSER_EXTENSIONS_API_DNS_DNS_API_H_ 6 #define CHROME_BROWSER_EXTENSIONS_API_DNS_DNS_API_H_ 7 8 #include <string> 9 10 #include "chrome/browser/extensions/extension_function.h" 11 #include "chrome/browser/io_thread.h" 12 #include "net/base/address_list.h" 13 #include "net/base/completion_callback.h" 14 #include "net/dns/host_resolver.h" 15 16 class IOThread; 17 18 namespace extensions { 19 20 class DnsResolveFunction : public AsyncExtensionFunction { 21 public: 22 DECLARE_EXTENSION_FUNCTION("experimental.dns.resolve", 23 EXPERIMENTAL_DNS_RESOLVE) 24 25 DnsResolveFunction(); 26 27 protected: 28 virtual ~DnsResolveFunction(); 29 30 // ExtensionFunction: 31 virtual bool RunImpl() OVERRIDE; 32 33 void WorkOnIOThread(); 34 void RespondOnUIThread(); 35 36 private: 37 void OnLookupFinished(int result); 38 39 std::string hostname_; 40 41 bool response_; // The value sent in SendResponse(). 42 43 // This instance is widely available through BrowserProcess, but we need to 44 // acquire it on the UI thread and then use it on the IO thread, so we keep a 45 // plain pointer to it here as we move from thread to thread. 46 IOThread* io_thread_; 47 48 scoped_ptr<net::HostResolver::RequestHandle> request_handle_; 49 scoped_ptr<net::AddressList> addresses_; 50 }; 51 52 } // namespace extensions 53 54 #endif // CHROME_BROWSER_EXTENSIONS_API_DNS_DNS_API_H_ 55