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 void SampleString(RapporService
* rappor_service
,
15 const std::string
& metric
,
17 const std::string
& sample
) {
20 rappor_service
->RecordSample(metric
, type
, sample
);
23 std::string
GetDomainAndRegistrySampleFromGURL(const GURL
& gurl
) {
24 if (gurl
.SchemeIsHTTPOrHTTPS()) {
25 if (net::IsLocalhost(gurl
.host()))
27 if (gurl
.HostIsIPAddress())
29 return net::registry_controlled_domains::GetDomainAndRegistry(
30 gurl
, net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES
);
32 if (gurl
.SchemeIsFile())
33 return gurl
.scheme() + "://";
34 return gurl
.scheme() + "://" + gurl
.host();
37 void SampleDomainAndRegistryFromGURL(RapporService
* rappor_service
,
38 const std::string
& metric
,
42 rappor_service
->RecordSample(
44 rappor::ETLD_PLUS_ONE_RAPPOR_TYPE
,
45 GetDomainAndRegistrySampleFromGURL(gurl
));