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

Side by Side Diff: net/nqe/network_quality_estimator_util.cc

Issue 2936823002: NQE: Exclude network observations from private networks (Closed)
Patch Set: bengr comments, rebased Created 3 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
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "net/nqe/network_quality_estimator_util.h"
6
7 #include "net/base/address_list.h"
8 #include "net/base/host_port_pair.h"
9 #include "net/base/ip_address.h"
10 #include "net/base/ip_endpoint.h"
11 #include "net/base/net_errors.h"
12 #include "net/dns/host_resolver.h"
13
14 namespace net {
15
16 namespace nqe {
17
18 namespace internal {
19
20 bool IsPrivateHost(HostResolver* host_resolver,
21 const HostPortPair& host_port_pair,
22 const NetLogWithSource& net_log) {
23 // Try resolving |host_port_pair.host()| synchronously.
24 HostResolver::RequestInfo resolve_info(host_port_pair);
25 resolve_info.set_allow_cached_response(true);
26 AddressList addresses;
27 // Resolve synchronously using the resolver's cache.
28 int rv = host_resolver->ResolveFromCache(resolve_info, &addresses, net_log);
29
30 DCHECK_NE(rv, ERR_IO_PENDING);
31 if (rv == OK && !addresses.empty()) {
32 // Checking only the first address should be sufficient.
33 IPEndPoint ip_end_point = addresses.front();
34 net::IPAddress ip_address = ip_end_point.address();
35 if (ip_address.IsReserved())
36 return true;
37 }
38
39 return false;
40 }
41
42 } // namespace internal
43
44 } // namespace nqe
45
46 } // namespace net
OLDNEW
« no previous file with comments | « net/nqe/network_quality_estimator_util.h ('k') | net/nqe/network_quality_estimator_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698