| 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 13 matching lines...) Expand all Loading... |
| 24 | 24 |
| 25 DnsResolveFunction::DnsResolveFunction() | 25 DnsResolveFunction::DnsResolveFunction() |
| 26 : resource_context_(NULL), | 26 : resource_context_(NULL), |
| 27 response_(false), | 27 response_(false), |
| 28 request_handle_(new net::HostResolver::RequestHandle()), | 28 request_handle_(new net::HostResolver::RequestHandle()), |
| 29 addresses_(new net::AddressList) {} | 29 addresses_(new net::AddressList) {} |
| 30 | 30 |
| 31 DnsResolveFunction::~DnsResolveFunction() {} | 31 DnsResolveFunction::~DnsResolveFunction() {} |
| 32 | 32 |
| 33 bool DnsResolveFunction::RunAsync() { | 33 bool DnsResolveFunction::RunAsync() { |
| 34 scoped_ptr<Resolve::Params> params(Resolve::Params::Create(*args_)); | 34 std::unique_ptr<Resolve::Params> params(Resolve::Params::Create(*args_)); |
| 35 EXTENSION_FUNCTION_VALIDATE(params.get()); | 35 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 36 | 36 |
| 37 hostname_ = params->hostname; | 37 hostname_ = params->hostname; |
| 38 resource_context_ = browser_context()->GetResourceContext(); | 38 resource_context_ = browser_context()->GetResourceContext(); |
| 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); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 73 if (resolve_result != net::ERR_IO_PENDING) | 73 if (resolve_result != net::ERR_IO_PENDING) |
| 74 OnLookupFinished(resolve_result); | 74 OnLookupFinished(resolve_result); |
| 75 } | 75 } |
| 76 | 76 |
| 77 void DnsResolveFunction::RespondOnUIThread() { | 77 void DnsResolveFunction::RespondOnUIThread() { |
| 78 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 78 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 79 SendResponse(response_); | 79 SendResponse(response_); |
| 80 } | 80 } |
| 81 | 81 |
| 82 void DnsResolveFunction::OnLookupFinished(int resolve_result) { | 82 void DnsResolveFunction::OnLookupFinished(int resolve_result) { |
| 83 scoped_ptr<ResolveCallbackResolveInfo> resolve_info( | 83 std::unique_ptr<ResolveCallbackResolveInfo> resolve_info( |
| 84 new ResolveCallbackResolveInfo()); | 84 new ResolveCallbackResolveInfo()); |
| 85 resolve_info->result_code = resolve_result; | 85 resolve_info->result_code = resolve_result; |
| 86 if (resolve_result == net::OK) { | 86 if (resolve_result == net::OK) { |
| 87 DCHECK(!addresses_->empty()); | 87 DCHECK(!addresses_->empty()); |
| 88 resolve_info->address.reset( | 88 resolve_info->address.reset( |
| 89 new std::string(addresses_->front().ToStringWithoutPort())); | 89 new std::string(addresses_->front().ToStringWithoutPort())); |
| 90 } | 90 } |
| 91 results_ = Resolve::Results::Create(*resolve_info); | 91 results_ = Resolve::Results::Create(*resolve_info); |
| 92 response_ = true; | 92 response_ = true; |
| 93 | 93 |
| 94 bool post_task_result = BrowserThread::PostTask( | 94 bool post_task_result = BrowserThread::PostTask( |
| 95 BrowserThread::UI, | 95 BrowserThread::UI, |
| 96 FROM_HERE, | 96 FROM_HERE, |
| 97 base::Bind(&DnsResolveFunction::RespondOnUIThread, this)); | 97 base::Bind(&DnsResolveFunction::RespondOnUIThread, this)); |
| 98 DCHECK(post_task_result); | 98 DCHECK(post_task_result); |
| 99 | 99 |
| 100 Release(); // Added in WorkOnIOThread(). | 100 Release(); // Added in WorkOnIOThread(). |
| 101 } | 101 } |
| 102 | 102 |
| 103 } // namespace extensions | 103 } // namespace extensions |
| OLD | NEW |