Home | History | Annotate | Download | only in rappor
      1 // Copyright 2014 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 "chrome/browser/metrics/rappor/sampling.h"
      6 
      7 #include "chrome/browser/browser_process.h"
      8 #include "components/rappor/rappor_service.h"
      9 #include "net/base/registry_controlled_domains/registry_controlled_domain.h"
     10 #include "url/gurl.h"
     11 
     12 namespace rappor {
     13 
     14 std::string GetDomainAndRegistrySampleFromGURL(const GURL& gurl) {
     15   if (gurl.SchemeIsHTTPOrHTTPS()) {
     16     return net::registry_controlled_domains::GetDomainAndRegistry(
     17         gurl, net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES);
     18   }
     19   if (gurl.SchemeIsFile())
     20     return gurl.scheme() + "://";
     21   return gurl.scheme() + "://" + gurl.host();
     22 }
     23 
     24 void SampleDomainAndRegistryFromGURL(const std::string& metric,
     25                                      const GURL& gurl) {
     26   if (!g_browser_process->rappor_service())
     27     return;
     28   g_browser_process->rappor_service()->RecordSample(
     29       metric,
     30       rappor::ETLD_PLUS_ONE_RAPPOR_TYPE,
     31       GetDomainAndRegistrySampleFromGURL(gurl));
     32 }
     33 
     34 void SampleDomainAndRegistryFromHost(const std::string& metric,
     35                                      const std::string& host) {
     36   if (!g_browser_process->rappor_service())
     37     return;
     38   g_browser_process->rappor_service()->RecordSample(
     39       metric,
     40       rappor::ETLD_PLUS_ONE_RAPPOR_TYPE,
     41       net::registry_controlled_domains::GetDomainAndRegistry(
     42           host, net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES));
     43 }
     44 
     45 }  // namespace rappor
     46