| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_DNS_DNS_API_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_DNS_DNS_API_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_API_DNS_DNS_API_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_API_DNS_DNS_API_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "chrome/browser/extensions/extension_function.h" | 11 #include "chrome/browser/extensions/extension_function.h" |
| 12 #include "chrome/browser/io_thread.h" | 12 #include "chrome/browser/io_thread.h" |
| 13 #include "net/base/address_list.h" | 13 #include "net/base/address_list.h" |
| 14 #include "net/base/completion_callback.h" | 14 #include "net/base/completion_callback.h" |
| 15 #include "net/base/host_resolver.h" | 15 #include "net/base/host_resolver.h" |
| 16 | 16 |
| 17 class IOThread; | 17 class IOThread; |
| 18 | 18 |
| 19 namespace extensions { | 19 namespace extensions { |
| 20 | 20 |
| 21 class DnsResolveFunction : public AsyncExtensionFunction { | 21 class DnsResolveFunction : public AsyncExtensionFunction { |
| 22 public: | 22 public: |
| 23 DECLARE_EXTENSION_FUNCTION_NAME("experimental.dns.resolve") | 23 DECLARE_EXTENSION_FUNCTION_NAME("experimental.dns.resolve") |
| 24 | 24 |
| 25 DnsResolveFunction(); | 25 DnsResolveFunction(); |
| 26 | 26 |
| 27 // See below. Caller retains ownership. | |
| 28 static void set_host_resolver_for_testing( | |
| 29 net::HostResolver* host_resolver_for_testing); | |
| 30 | |
| 31 protected: | 27 protected: |
| 32 virtual ~DnsResolveFunction(); | 28 virtual ~DnsResolveFunction(); |
| 33 | 29 |
| 34 // ExtensionFunction: | 30 // ExtensionFunction: |
| 35 virtual bool RunImpl() OVERRIDE; | 31 virtual bool RunImpl() OVERRIDE; |
| 36 | 32 |
| 37 void WorkOnIOThread(); | 33 void WorkOnIOThread(); |
| 38 void RespondOnUIThread(); | 34 void RespondOnUIThread(); |
| 39 | 35 |
| 40 private: | 36 private: |
| 41 void OnLookupFinished(int result); | 37 void OnLookupFinished(int result); |
| 42 | 38 |
| 43 std::string hostname_; | 39 std::string hostname_; |
| 44 | 40 |
| 45 bool response_; // The value sent in SendResponse(). | 41 bool response_; // The value sent in SendResponse(). |
| 46 | 42 |
| 47 // This instance is widely available through BrowserProcess, but we need to | 43 // This instance is widely available through BrowserProcess, but we need to |
| 48 // acquire it on the UI thread and then use it on the IO thread, so we keep a | 44 // acquire it on the UI thread and then use it on the IO thread, so we keep a |
| 49 // plain pointer to it here as we move from thread to thread. | 45 // plain pointer to it here as we move from thread to thread. |
| 50 IOThread* io_thread_; | 46 IOThread* io_thread_; |
| 51 | 47 |
| 52 scoped_ptr<net::HostResolver::RequestHandle> request_handle_; | 48 scoped_ptr<net::HostResolver::RequestHandle> request_handle_; |
| 53 scoped_ptr<net::AddressList> addresses_; | 49 scoped_ptr<net::AddressList> addresses_; |
| 54 }; | 50 }; |
| 55 | 51 |
| 56 } // namespace extensions | 52 } // namespace extensions |
| 57 | 53 |
| 58 #endif // CHROME_BROWSER_EXTENSIONS_API_DNS_DNS_API_H_ | 54 #endif // CHROME_BROWSER_EXTENSIONS_API_DNS_DNS_API_H_ |
| OLD | NEW |