Extension syncing: Introduce a NeedsSync pref
[chromium-blink-merge.git] / components / rappor / rappor_utils.cc
blob9b253c2fa5fa376b0c46099b6599ed6138a1e344
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"
10 #include "url/gurl.h"
12 namespace rappor {
14 void SampleString(RapporService* rappor_service,
15 const std::string& metric,
16 RapporType type,
17 const std::string& sample) {
18 if (!rappor_service)
19 return;
20 rappor_service->RecordSample(metric, type, sample);
23 std::string GetDomainAndRegistrySampleFromGURL(const GURL& gurl) {
24 if (gurl.SchemeIsHTTPOrHTTPS()) {
25 if (net::IsLocalhost(gurl.host()))
26 return "localhost";
27 if (gurl.HostIsIPAddress())
28 return "ip_address";
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,
39 const GURL& gurl) {
40 if (!rappor_service)
41 return;
42 rappor_service->RecordSample(
43 metric,
44 rappor::ETLD_PLUS_ONE_RAPPOR_TYPE,
45 GetDomainAndRegistrySampleFromGURL(gurl));
48 } // namespace rappor