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

Side by Side Diff: components/rappor/rappor_utils.cc

Issue 1070863002: Add rappor::SampleString for consisntecy with domain+registry case (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rename to SampleString Created 5 years, 8 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
« no previous file with comments | « components/rappor/rappor_utils.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/rappor/rappor_utils.h" 5 #include "components/rappor/rappor_utils.h"
6 6
7 #include "components/rappor/rappor_service.h" 7 #include "components/rappor/rappor_service.h"
8 #include "net/base/net_util.h" 8 #include "net/base/net_util.h"
9 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" 9 #include "net/base/registry_controlled_domains/registry_controlled_domain.h"
10 #include "url/gurl.h" 10 #include "url/gurl.h"
11 11
12 namespace rappor { 12 namespace rappor {
13 13
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);
21 }
22
14 std::string GetDomainAndRegistrySampleFromGURL(const GURL& gurl) { 23 std::string GetDomainAndRegistrySampleFromGURL(const GURL& gurl) {
15 if (gurl.SchemeIsHTTPOrHTTPS()) { 24 if (gurl.SchemeIsHTTPOrHTTPS()) {
16 if (net::IsLocalhost(gurl.host())) 25 if (net::IsLocalhost(gurl.host()))
17 return "localhost"; 26 return "localhost";
18 if (gurl.HostIsIPAddress()) 27 if (gurl.HostIsIPAddress())
19 return "ip_address"; 28 return "ip_address";
20 return net::registry_controlled_domains::GetDomainAndRegistry( 29 return net::registry_controlled_domains::GetDomainAndRegistry(
21 gurl, net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES); 30 gurl, net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES);
22 } 31 }
23 if (gurl.SchemeIsFile()) 32 if (gurl.SchemeIsFile())
24 return gurl.scheme() + "://"; 33 return gurl.scheme() + "://";
25 return gurl.scheme() + "://" + gurl.host(); 34 return gurl.scheme() + "://" + gurl.host();
26 } 35 }
27 36
28 void SampleDomainAndRegistryFromGURL(RapporService* rappor_service, 37 void SampleDomainAndRegistryFromGURL(RapporService* rappor_service,
29 const std::string& metric, 38 const std::string& metric,
30 const GURL& gurl) { 39 const GURL& gurl) {
31 if (!rappor_service) 40 if (!rappor_service)
32 return; 41 return;
33 rappor_service->RecordSample( 42 rappor_service->RecordSample(
34 metric, 43 metric,
35 rappor::ETLD_PLUS_ONE_RAPPOR_TYPE, 44 rappor::ETLD_PLUS_ONE_RAPPOR_TYPE,
36 GetDomainAndRegistrySampleFromGURL(gurl)); 45 GetDomainAndRegistrySampleFromGURL(gurl));
37 } 46 }
38 47
39 } // namespace rappor 48 } // namespace rappor
OLDNEW
« no previous file with comments | « components/rappor/rappor_utils.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698