1 // Copyright 2015 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.
5 #include "components/rappor/rappor_utils.h"
7 #include "components/rappor/rappor_service.h"
8 #include "net/base/net_util.h"
9 #include "net/base/registry_controlled_domains/registry_controlled_domain.h"
14 std::string
GetDomainAndRegistrySampleFromGURL(const GURL
& gurl
) {
15 if (gurl
.SchemeIsHTTPOrHTTPS()) {
16 if (net::IsLocalhost(gurl
.host()))
18 if (gurl
.HostIsIPAddress())
20 return net::registry_controlled_domains::GetDomainAndRegistry(
21 gurl
, net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES
);
23 if (gurl
.SchemeIsFile())
24 return gurl
.scheme() + "://";
25 return gurl
.scheme() + "://" + gurl
.host();
28 void SampleDomainAndRegistryFromGURL(RapporService
* rappor_service
,
29 const std::string
& metric
,
33 rappor_service
->RecordSample(
35 rappor::ETLD_PLUS_ONE_RAPPOR_TYPE
,
36 GetDomainAndRegistrySampleFromGURL(gurl
));