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

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

Issue 2116983002: Change HostResolver::Resolve() to take an std::unique_ptr<Request>* rather than a RequestHandle* (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: http_stream_factory_impl_job_controller_unittest RequestHandle* to unique_ptr Created 4 years, 4 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
OLDNEW
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"
11 #include "content/public/browser/resource_context.h" 11 #include "content/public/browser/resource_context.h"
12 #include "extensions/browser/api/dns/host_resolver_wrapper.h" 12 #include "extensions/browser/api/dns/host_resolver_wrapper.h"
13 #include "extensions/common/api/dns.h" 13 #include "extensions/common/api/dns.h"
14 #include "net/base/host_port_pair.h" 14 #include "net/base/host_port_pair.h"
15 #include "net/base/net_errors.h" 15 #include "net/base/net_errors.h"
16 #include "net/log/net_log.h" 16 #include "net/log/net_log.h"
17 17
18 using content::BrowserThread; 18 using content::BrowserThread;
19 using extensions::api::dns::ResolveCallbackResolveInfo; 19 using extensions::api::dns::ResolveCallbackResolveInfo;
20 20
21 namespace Resolve = extensions::api::dns::Resolve; 21 namespace Resolve = extensions::api::dns::Resolve;
22 22
23 namespace extensions { 23 namespace extensions {
24 24
25 DnsResolveFunction::DnsResolveFunction() 25 DnsResolveFunction::DnsResolveFunction()
26 : resource_context_(NULL), 26 : resource_context_(), response_(false), addresses_(new net::AddressList) {}
27 response_(false),
28 request_handle_(new net::HostResolver::RequestHandle()),
29 addresses_(new net::AddressList) {}
30 27
31 DnsResolveFunction::~DnsResolveFunction() {} 28 DnsResolveFunction::~DnsResolveFunction() {}
32 29
33 bool DnsResolveFunction::RunAsync() { 30 bool DnsResolveFunction::RunAsync() {
34 std::unique_ptr<Resolve::Params> params(Resolve::Params::Create(*args_)); 31 std::unique_ptr<Resolve::Params> params(Resolve::Params::Create(*args_));
35 EXTENSION_FUNCTION_VALIDATE(params.get()); 32 EXTENSION_FUNCTION_VALIDATE(params.get());
36 33
37 hostname_ = params->hostname; 34 hostname_ = params->hostname;
38 resource_context_ = browser_context()->GetResourceContext(); 35 resource_context_ = browser_context()->GetResourceContext();
39 36
(...skipping 13 matching lines...) Expand all
53 DCHECK(host_resolver); 50 DCHECK(host_resolver);
54 51
55 // Yes, we are passing zero as the port. There are some interesting but not 52 // Yes, we are passing zero as the port. There are some interesting but not
56 // presently relevant reasons why HostResolver asks for the port of the 53 // presently relevant reasons why HostResolver asks for the port of the
57 // hostname you'd like to resolve, even though it doesn't use that value in 54 // hostname you'd like to resolve, even though it doesn't use that value in
58 // determining its answer. 55 // determining its answer.
59 net::HostPortPair host_port_pair(hostname_, 0); 56 net::HostPortPair host_port_pair(hostname_, 0);
60 57
61 net::HostResolver::RequestInfo request_info(host_port_pair); 58 net::HostResolver::RequestInfo request_info(host_port_pair);
62 int resolve_result = host_resolver->Resolve( 59 int resolve_result = host_resolver->Resolve(
63 request_info, 60 request_info, net::DEFAULT_PRIORITY, addresses_.get(),
64 net::DEFAULT_PRIORITY, 61 base::Bind(&DnsResolveFunction::OnLookupFinished, this), &request_,
65 addresses_.get(),
66 base::Bind(&DnsResolveFunction::OnLookupFinished, this),
67 request_handle_.get(),
68 net::BoundNetLog()); 62 net::BoundNetLog());
69 63
70 // Balanced in OnLookupFinished. 64 // Balanced in OnLookupFinished.
71 AddRef(); 65 AddRef();
72 66
73 if (resolve_result != net::ERR_IO_PENDING) 67 if (resolve_result != net::ERR_IO_PENDING)
74 OnLookupFinished(resolve_result); 68 OnLookupFinished(resolve_result);
75 } 69 }
76 70
77 void DnsResolveFunction::RespondOnUIThread() { 71 void DnsResolveFunction::RespondOnUIThread() {
(...skipping 16 matching lines...) Expand all
94 bool post_task_result = BrowserThread::PostTask( 88 bool post_task_result = BrowserThread::PostTask(
95 BrowserThread::UI, 89 BrowserThread::UI,
96 FROM_HERE, 90 FROM_HERE,
97 base::Bind(&DnsResolveFunction::RespondOnUIThread, this)); 91 base::Bind(&DnsResolveFunction::RespondOnUIThread, this));
98 DCHECK(post_task_result); 92 DCHECK(post_task_result);
99 93
100 Release(); // Added in WorkOnIOThread(). 94 Release(); // Added in WorkOnIOThread().
101 } 95 }
102 96
103 } // namespace extensions 97 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698