Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(192)

Side by Side Diff: chrome/browser/extensions/api/dns/dns_api.cc

Issue 10537017: Allow hostnames in socket.connect(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: mihaip's comments + clang fix. Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 #include "chrome/browser/extensions/api/dns/dns_api.h" 5 #include "chrome/browser/extensions/api/dns/dns_api.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/values.h" 8 #include "base/values.h"
9 #include "chrome/browser/browser_process.h" 9 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/extensions/api/dns/host_resolver_wrapper.h"
10 #include "chrome/browser/io_thread.h" 11 #include "chrome/browser/io_thread.h"
11 #include "chrome/common/extensions/api/experimental_dns.h" 12 #include "chrome/common/extensions/api/experimental_dns.h"
12 #include "content/public/browser/browser_thread.h" 13 #include "content/public/browser/browser_thread.h"
13 #include "net/base/host_port_pair.h" 14 #include "net/base/host_port_pair.h"
14 #include "net/base/net_errors.h" 15 #include "net/base/net_errors.h"
15 #include "net/base/net_log.h" 16 #include "net/base/net_log.h"
16 17
17 using content::BrowserThread; 18 using content::BrowserThread;
18 using extensions::api::experimental_dns::ResolveCallbackResolveInfo; 19 using extensions::api::experimental_dns::ResolveCallbackResolveInfo;
19 20
20 namespace Resolve = extensions::api::experimental_dns::Resolve; 21 namespace Resolve = extensions::api::experimental_dns::Resolve;
21 22
22 namespace extensions { 23 namespace extensions {
23 24
24 namespace {
25
26 // If null, then we'll use io_thread_ to obtain the real HostResolver. We use
27 // a plain pointer for to be consistent with the ownership model of the real
28 // one.
29 net::HostResolver* g_host_resolver_for_testing = NULL;
30
31 } // namespace
32
33 DnsResolveFunction::DnsResolveFunction() 25 DnsResolveFunction::DnsResolveFunction()
34 : response_(false), 26 : response_(false),
35 io_thread_(g_browser_process->io_thread()), 27 io_thread_(g_browser_process->io_thread()),
36 request_handle_(new net::HostResolver::RequestHandle()), 28 request_handle_(new net::HostResolver::RequestHandle()),
37 addresses_(new net::AddressList) { 29 addresses_(new net::AddressList) {
38 } 30 }
39 31
40 // static
41 void DnsResolveFunction::set_host_resolver_for_testing(
42 net::HostResolver* host_resolver_for_testing_param) {
43 g_host_resolver_for_testing = host_resolver_for_testing_param;
44 }
45
46 DnsResolveFunction::~DnsResolveFunction() {} 32 DnsResolveFunction::~DnsResolveFunction() {}
47 33
48 bool DnsResolveFunction::RunImpl() { 34 bool DnsResolveFunction::RunImpl() {
49 scoped_ptr<Resolve::Params> params(Resolve::Params::Create(*args_)); 35 scoped_ptr<Resolve::Params> params(Resolve::Params::Create(*args_));
50 EXTENSION_FUNCTION_VALIDATE(params.get()); 36 EXTENSION_FUNCTION_VALIDATE(params.get());
51 37
52 hostname_ = params->hostname; 38 hostname_ = params->hostname;
53 39
54 bool result = BrowserThread::PostTask( 40 bool result = BrowserThread::PostTask(
55 BrowserThread::IO, FROM_HERE, 41 BrowserThread::IO, FROM_HERE,
56 base::Bind(&DnsResolveFunction::WorkOnIOThread, this)); 42 base::Bind(&DnsResolveFunction::WorkOnIOThread, this));
57 DCHECK(result); 43 DCHECK(result);
58 return true; 44 return true;
59 } 45 }
60 46
61 void DnsResolveFunction::WorkOnIOThread() { 47 void DnsResolveFunction::WorkOnIOThread() {
62 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 48 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
63 49
64 net::HostResolver* host_resolver = g_host_resolver_for_testing ? 50 net::HostResolver* host_resolver =
65 g_host_resolver_for_testing : io_thread_->globals()->host_resolver.get(); 51 HostResolverWrapper::GetInstance()->GetHostResolver(
52 io_thread_->globals()->host_resolver.get());
66 DCHECK(host_resolver); 53 DCHECK(host_resolver);
67 54
68 // Yes, we are passing zero as the port. There are some interesting but not 55 // Yes, we are passing zero as the port. There are some interesting but not
69 // presently relevant reasons why HostResolver asks for the port of the 56 // presently relevant reasons why HostResolver asks for the port of the
70 // hostname you'd like to resolve, even though it doesn't use that value in 57 // hostname you'd like to resolve, even though it doesn't use that value in
71 // determining its answer. 58 // determining its answer.
72 net::HostPortPair host_port_pair(hostname_, 0); 59 net::HostPortPair host_port_pair(hostname_, 0);
73 60
74 net::HostResolver::RequestInfo request_info(host_port_pair); 61 net::HostResolver::RequestInfo request_info(host_port_pair);
75 int resolve_result = host_resolver->Resolve( 62 int resolve_result = host_resolver->Resolve(
(...skipping 27 matching lines...) Expand all
103 90
104 bool post_task_result = BrowserThread::PostTask( 91 bool post_task_result = BrowserThread::PostTask(
105 BrowserThread::UI, FROM_HERE, 92 BrowserThread::UI, FROM_HERE,
106 base::Bind(&DnsResolveFunction::RespondOnUIThread, this)); 93 base::Bind(&DnsResolveFunction::RespondOnUIThread, this));
107 DCHECK(post_task_result); 94 DCHECK(post_task_result);
108 95
109 Release(); // Added in WorkOnIOThread(). 96 Release(); // Added in WorkOnIOThread().
110 } 97 }
111 98
112 } // namespace extensions 99 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/dns/dns_api.h ('k') | chrome/browser/extensions/api/dns/dns_apitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698