OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "extensions/browser/api/dns/dns_api.h" | 5 #include "extensions/browser/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 "content/public/browser/browser_context.h" | 9 #include "content/public/browser/browser_context.h" |
10 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
(...skipping 28 matching lines...) Expand all Loading... |
39 | 39 |
40 bool result = BrowserThread::PostTask( | 40 bool result = BrowserThread::PostTask( |
41 BrowserThread::IO, | 41 BrowserThread::IO, |
42 FROM_HERE, | 42 FROM_HERE, |
43 base::Bind(&DnsResolveFunction::WorkOnIOThread, this)); | 43 base::Bind(&DnsResolveFunction::WorkOnIOThread, this)); |
44 DCHECK(result); | 44 DCHECK(result); |
45 return true; | 45 return true; |
46 } | 46 } |
47 | 47 |
48 void DnsResolveFunction::WorkOnIOThread() { | 48 void DnsResolveFunction::WorkOnIOThread() { |
49 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 49 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
50 | 50 |
51 net::HostResolver* host_resolver = | 51 net::HostResolver* host_resolver = |
52 HostResolverWrapper::GetInstance()->GetHostResolver( | 52 HostResolverWrapper::GetInstance()->GetHostResolver( |
53 resource_context_->GetHostResolver()); | 53 resource_context_->GetHostResolver()); |
54 DCHECK(host_resolver); | 54 DCHECK(host_resolver); |
55 | 55 |
56 // Yes, we are passing zero as the port. There are some interesting but not | 56 // Yes, we are passing zero as the port. There are some interesting but not |
57 // presently relevant reasons why HostResolver asks for the port of the | 57 // presently relevant reasons why HostResolver asks for the port of the |
58 // hostname you'd like to resolve, even though it doesn't use that value in | 58 // hostname you'd like to resolve, even though it doesn't use that value in |
59 // determining its answer. | 59 // determining its answer. |
60 net::HostPortPair host_port_pair(hostname_, 0); | 60 net::HostPortPair host_port_pair(hostname_, 0); |
61 | 61 |
62 net::HostResolver::RequestInfo request_info(host_port_pair); | 62 net::HostResolver::RequestInfo request_info(host_port_pair); |
63 int resolve_result = host_resolver->Resolve( | 63 int resolve_result = host_resolver->Resolve( |
64 request_info, | 64 request_info, |
65 net::DEFAULT_PRIORITY, | 65 net::DEFAULT_PRIORITY, |
66 addresses_.get(), | 66 addresses_.get(), |
67 base::Bind(&DnsResolveFunction::OnLookupFinished, this), | 67 base::Bind(&DnsResolveFunction::OnLookupFinished, this), |
68 request_handle_.get(), | 68 request_handle_.get(), |
69 net::BoundNetLog()); | 69 net::BoundNetLog()); |
70 | 70 |
71 // Balanced in OnLookupFinished. | 71 // Balanced in OnLookupFinished. |
72 AddRef(); | 72 AddRef(); |
73 | 73 |
74 if (resolve_result != net::ERR_IO_PENDING) | 74 if (resolve_result != net::ERR_IO_PENDING) |
75 OnLookupFinished(resolve_result); | 75 OnLookupFinished(resolve_result); |
76 } | 76 } |
77 | 77 |
78 void DnsResolveFunction::RespondOnUIThread() { | 78 void DnsResolveFunction::RespondOnUIThread() { |
79 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 79 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
80 SendResponse(response_); | 80 SendResponse(response_); |
81 } | 81 } |
82 | 82 |
83 void DnsResolveFunction::OnLookupFinished(int resolve_result) { | 83 void DnsResolveFunction::OnLookupFinished(int resolve_result) { |
84 scoped_ptr<ResolveCallbackResolveInfo> resolve_info( | 84 scoped_ptr<ResolveCallbackResolveInfo> resolve_info( |
85 new ResolveCallbackResolveInfo()); | 85 new ResolveCallbackResolveInfo()); |
86 resolve_info->result_code = resolve_result; | 86 resolve_info->result_code = resolve_result; |
87 if (resolve_result == net::OK) { | 87 if (resolve_result == net::OK) { |
88 DCHECK(!addresses_->empty()); | 88 DCHECK(!addresses_->empty()); |
89 resolve_info->address.reset( | 89 resolve_info->address.reset( |
90 new std::string(addresses_->front().ToStringWithoutPort())); | 90 new std::string(addresses_->front().ToStringWithoutPort())); |
91 } | 91 } |
92 results_ = Resolve::Results::Create(*resolve_info); | 92 results_ = Resolve::Results::Create(*resolve_info); |
93 response_ = true; | 93 response_ = true; |
94 | 94 |
95 bool post_task_result = BrowserThread::PostTask( | 95 bool post_task_result = BrowserThread::PostTask( |
96 BrowserThread::UI, | 96 BrowserThread::UI, |
97 FROM_HERE, | 97 FROM_HERE, |
98 base::Bind(&DnsResolveFunction::RespondOnUIThread, this)); | 98 base::Bind(&DnsResolveFunction::RespondOnUIThread, this)); |
99 DCHECK(post_task_result); | 99 DCHECK(post_task_result); |
100 | 100 |
101 Release(); // Added in WorkOnIOThread(). | 101 Release(); // Added in WorkOnIOThread(). |
102 } | 102 } |
103 | 103 |
104 } // namespace extensions | 104 } // namespace extensions |
OLD | NEW |