| 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/capturing_net_log.h" | 14 #include "net/base/capturing_net_log.h" |
| 15 #include "net/base/completion_callback.h" | 15 #include "net/base/completion_callback.h" |
| 16 #include "net/base/host_resolver.h" | 16 #include "net/base/host_resolver.h" |
| 17 | 17 |
| 18 class IOThread; | 18 class IOThread; |
| 19 | 19 |
| 20 namespace extensions { | 20 namespace extensions { |
| 21 | 21 |
| 22 class DnsResolveFunction : public AsyncExtensionFunction { | 22 class DnsResolveFunction : public AsyncExtensionFunction { |
| 23 public: | 23 public: |
| 24 DECLARE_EXTENSION_FUNCTION_NAME("experimental.dns.resolve") |
| 25 |
| 24 DnsResolveFunction(); | 26 DnsResolveFunction(); |
| 25 virtual ~DnsResolveFunction(); | |
| 26 | |
| 27 virtual bool RunImpl() OVERRIDE; | |
| 28 | 27 |
| 29 // See below. Caller retains ownership. | 28 // See below. Caller retains ownership. |
| 30 static void set_host_resolver_for_testing( | 29 static void set_host_resolver_for_testing( |
| 31 net::HostResolver* host_resolver_for_testing); | 30 net::HostResolver* host_resolver_for_testing); |
| 32 | 31 |
| 33 protected: | 32 protected: |
| 33 virtual ~DnsResolveFunction(); |
| 34 |
| 35 // ExtensionFunction: |
| 36 virtual bool RunImpl() OVERRIDE; |
| 37 |
| 34 void WorkOnIOThread(); | 38 void WorkOnIOThread(); |
| 35 void RespondOnUIThread(); | 39 void RespondOnUIThread(); |
| 36 | 40 |
| 37 private: | 41 private: |
| 42 void OnLookupFinished(int result); |
| 43 |
| 38 std::string hostname_; | 44 std::string hostname_; |
| 39 | 45 |
| 40 bool response_; // The value sent in SendResponse(). | 46 bool response_; // The value sent in SendResponse(). |
| 41 | 47 |
| 42 // This instance is widely available through BrowserProcess, but we need to | 48 // This instance is widely available through BrowserProcess, but we need to |
| 43 // acquire it on the UI thread and then use it on the IO thread, so we keep a | 49 // acquire it on the UI thread and then use it on the IO thread, so we keep a |
| 44 // plain pointer to it here as we move from thread to thread. | 50 // plain pointer to it here as we move from thread to thread. |
| 45 IOThread* io_thread_; | 51 IOThread* io_thread_; |
| 46 | 52 |
| 47 // If null, then we'll use io_thread_ to obtain the real HostResolver. We use | |
| 48 // a plain pointer for to be consistent with the ownership model of the real | |
| 49 // one. | |
| 50 static net::HostResolver* host_resolver_for_testing; | |
| 51 | |
| 52 scoped_ptr<net::CapturingBoundNetLog> capturing_bound_net_log_; | 53 scoped_ptr<net::CapturingBoundNetLog> capturing_bound_net_log_; |
| 53 scoped_ptr<net::HostResolver::RequestHandle> request_handle_; | 54 scoped_ptr<net::HostResolver::RequestHandle> request_handle_; |
| 54 scoped_ptr<net::AddressList> addresses_; | 55 scoped_ptr<net::AddressList> addresses_; |
| 55 | |
| 56 void OnLookupFinished(int result); | |
| 57 | |
| 58 DECLARE_EXTENSION_FUNCTION_NAME("experimental.dns.resolve") | |
| 59 }; | 56 }; |
| 60 | 57 |
| 61 } // namespace extensions | 58 } // namespace extensions |
| 62 | 59 |
| 63 #endif // CHROME_BROWSER_EXTENSIONS_API_DNS_DNS_API_H_ | 60 #endif // CHROME_BROWSER_EXTENSIONS_API_DNS_DNS_API_H_ |
| OLD | NEW |