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

Side by Side Diff: net/dns/host_resolver_impl_fuzzer.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: changed implementation of attach/detach of request Created 4 years, 5 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 7
8 #include <memory> 8 #include <memory>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 20 matching lines...) Expand all
31 }; 31 };
32 32
33 class DnsRequest { 33 class DnsRequest {
34 public: 34 public:
35 DnsRequest(net::HostResolver* host_resolver, 35 DnsRequest(net::HostResolver* host_resolver,
36 net::FuzzedDataProvider* data_provider, 36 net::FuzzedDataProvider* data_provider,
37 std::vector<std::unique_ptr<DnsRequest>>* dns_requests) 37 std::vector<std::unique_ptr<DnsRequest>>* dns_requests)
38 : host_resolver_(host_resolver), 38 : host_resolver_(host_resolver),
39 data_provider_(data_provider), 39 data_provider_(data_provider),
40 dns_requests_(dns_requests), 40 dns_requests_(dns_requests),
41 handle_(nullptr), 41 request_(),
mmenke 2016/07/19 19:03:56 this isn't needed.
maksims (do not use this acc) 2016/07/21 07:12:45 Done.
42 is_running_(false) {} 42 is_running_(false) {}
43 43
44 ~DnsRequest() { 44 ~DnsRequest() {
45 if (is_running_) 45 if (is_running_)
46 Cancel(); 46 Cancel();
mmenke 2016/07/19 19:03:56 This is no longer needed - deleting this DnsReques
maksims (do not use this acc) 2016/07/21 07:12:45 Done.
47 } 47 }
48 48
49 // Creates and starts a DNS request using fuzzed parameters. If the request 49 // Creates and starts a DNS request using fuzzed parameters. If the request
50 // doesn't complete synchronously, adds it to |dns_requests|. 50 // doesn't complete synchronously, adds it to |dns_requests|.
51 static void CreateRequest( 51 static void CreateRequest(
52 net::HostResolver* host_resolver, 52 net::HostResolver* host_resolver,
53 net::FuzzedDataProvider* data_provider, 53 net::FuzzedDataProvider* data_provider,
54 std::vector<std::unique_ptr<DnsRequest>>* dns_requests) { 54 std::vector<std::unique_ptr<DnsRequest>>* dns_requests) {
55 std::unique_ptr<DnsRequest> dns_request( 55 std::unique_ptr<DnsRequest> dns_request(
56 new DnsRequest(host_resolver, data_provider, dns_requests)); 56 new DnsRequest(host_resolver, data_provider, dns_requests));
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 148
149 // Decide if should be a cache-only resolution. 149 // Decide if should be a cache-only resolution.
150 if (data_provider_->ConsumeBool()) { 150 if (data_provider_->ConsumeBool()) {
151 return host_resolver_->ResolveFromCache(info, &address_list_, 151 return host_resolver_->ResolveFromCache(info, &address_list_,
152 net::BoundNetLog()); 152 net::BoundNetLog());
153 } 153 }
154 154
155 info.set_allow_cached_response(data_provider_->ConsumeBool()); 155 info.set_allow_cached_response(data_provider_->ConsumeBool());
156 return host_resolver_->Resolve( 156 return host_resolver_->Resolve(
157 info, priority, &address_list_, 157 info, priority, &address_list_,
158 base::Bind(&DnsRequest::OnCallback, base::Unretained(this)), &handle_, 158 base::Bind(&DnsRequest::OnCallback, base::Unretained(this)), &request_,
159 net::BoundNetLog()); 159 net::BoundNetLog());
160 } 160 }
161 161
162 // Waits until the request is done, if it isn't done already. 162 // Waits until the request is done, if it isn't done already.
163 void WaitUntilDone() { 163 void WaitUntilDone() {
164 CHECK(!run_loop_); 164 CHECK(!run_loop_);
165 if (is_running_) { 165 if (is_running_) {
166 run_loop_.reset(new base::RunLoop()); 166 run_loop_.reset(new base::RunLoop());
167 run_loop_->Run(); 167 run_loop_->Run();
168 run_loop_.reset(); 168 run_loop_.reset();
169 CHECK(!is_running_); 169 CHECK(!is_running_);
mmenke 2016/07/19 19:03:56 I'd suggest getting rid of is_running_, and DCHECK
maksims (do not use this acc) 2016/07/21 07:12:45 Done.
170 } 170 }
171 } 171 }
172 172
173 // Cancel the request, if not already completed. Otherwise, does nothing. 173 // Cancel the request, if not already completed. Otherwise, does nothing.
174 void Cancel() { 174 void Cancel() {
175 if (is_running_) 175 if (is_running_)
176 host_resolver_->CancelRequest(handle_); 176 request_.reset();
mmenke 2016/07/19 19:03:56 nit: Can unconditionally reset the request here.
maksims (do not use this acc) 2016/07/21 07:12:45 Done.
177 is_running_ = false; 177 is_running_ = false;
178 } 178 }
179 179
180 net::HostResolver* host_resolver_; 180 net::HostResolver* host_resolver_;
181 net::FuzzedDataProvider* data_provider_; 181 net::FuzzedDataProvider* data_provider_;
182 std::vector<std::unique_ptr<DnsRequest>>* dns_requests_; 182 std::vector<std::unique_ptr<DnsRequest>>* dns_requests_;
183 183
184 net::HostResolver::RequestHandle handle_; 184 std::unique_ptr<net::HostResolver::Request> request_;
185 net::AddressList address_list_; 185 net::AddressList address_list_;
186 186
187 bool is_running_; 187 bool is_running_;
188 188
189 std::unique_ptr<base::RunLoop> run_loop_; 189 std::unique_ptr<base::RunLoop> run_loop_;
190 190
191 DISALLOW_COPY_AND_ASSIGN(DnsRequest); 191 DISALLOW_COPY_AND_ASSIGN(DnsRequest);
192 }; 192 };
193 193
194 } // namespace 194 } // namespace
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 break; 230 break;
231 } 231 }
232 } 232 }
233 } 233 }
234 234
235 // Clean up any pending tasks, after deleting everything. 235 // Clean up any pending tasks, after deleting everything.
236 base::RunLoop().RunUntilIdle(); 236 base::RunLoop().RunUntilIdle();
237 237
238 return 0; 238 return 0;
239 } 239 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698