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

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

Issue 2510803003: Pass RapporService to content/browser/ (Closed)
Patch Set: Fix more compile errors in JNI files Created 4 years 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
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/public/rappor_utils.h"
6 6
7 #include "components/rappor/rappor_service.h"
8 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" 7 #include "net/base/registry_controlled_domains/registry_controlled_domain.h"
9 #include "net/base/url_util.h" 8 #include "net/base/url_util.h"
10 #include "url/gurl.h" 9 #include "url/gurl.h"
11 10
12 namespace rappor { 11 namespace rappor {
13 12
14 void SampleString(RapporService* rappor_service, 13 void SampleString(RapporService* rappor_service,
15 const std::string& metric, 14 const std::string& metric,
16 RapporType type, 15 RapporType type,
17 const std::string& sample) { 16 const std::string& sample) {
18 if (!rappor_service) 17 if (!rappor_service)
19 return; 18 return;
20 rappor_service->RecordSample(metric, type, sample); 19 rappor_service->RecordSampleString(metric, type, sample);
21 } 20 }
22 21
23 std::string GetDomainAndRegistrySampleFromGURL(const GURL& gurl) { 22 std::string GetDomainAndRegistrySampleFromGURL(const GURL& gurl) {
24 if (gurl.SchemeIsHTTPOrHTTPS()) { 23 if (gurl.SchemeIsHTTPOrHTTPS()) {
25 if (net::IsLocalhost(gurl.host())) 24 if (net::IsLocalhost(gurl.host()))
26 return "localhost"; 25 return "localhost";
27 if (gurl.HostIsIPAddress()) 26 if (gurl.HostIsIPAddress())
28 return "ip_address"; 27 return "ip_address";
29 return net::registry_controlled_domains::GetDomainAndRegistry( 28 return net::registry_controlled_domains::GetDomainAndRegistry(
30 gurl, net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES); 29 gurl, net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES);
31 } 30 }
32 if (gurl.SchemeIsFile()) 31 if (gurl.SchemeIsFile())
33 return gurl.scheme() + "://"; 32 return gurl.scheme() + "://";
34 return gurl.scheme() + "://" + gurl.host(); 33 return gurl.scheme() + "://" + gurl.host();
35 } 34 }
36 35
37 void SampleDomainAndRegistryFromGURL(RapporService* rappor_service, 36 void SampleDomainAndRegistryFromGURL(RapporService* rappor_service,
38 const std::string& metric, 37 const std::string& metric,
39 const GURL& gurl) { 38 const GURL& gurl) {
40 if (!rappor_service) 39 if (!rappor_service)
41 return; 40 return;
42 rappor_service->RecordSample( 41 rappor_service->RecordSampleString(metric, rappor::ETLD_PLUS_ONE_RAPPOR_TYPE,
43 metric, 42 GetDomainAndRegistrySampleFromGURL(gurl));
44 rappor::ETLD_PLUS_ONE_RAPPOR_TYPE,
45 GetDomainAndRegistrySampleFromGURL(gurl));
46 } 43 }
47 44
48 RapporService* (*g_GetDefaultService)() = nullptr; 45 RapporService* (*g_GetDefaultService)() = nullptr;
49 46
50 RapporService* GetDefaultService() { 47 RapporService* GetDefaultService() {
51 return (g_GetDefaultService != nullptr) ? g_GetDefaultService() : nullptr; 48 return (g_GetDefaultService != nullptr) ? g_GetDefaultService() : nullptr;
52 } 49 }
53 50
54 void SetDefaultServiceAccessor(RapporService* (*getDefaultService)()) { 51 void SetDefaultServiceAccessor(RapporService* (*getDefaultService)()) {
55 DCHECK(g_GetDefaultService == nullptr); 52 DCHECK(g_GetDefaultService == nullptr);
56 g_GetDefaultService = getDefaultService; 53 g_GetDefaultService = getDefaultService;
57 } 54 }
58 55
59 } // namespace rappor 56 } // namespace rappor
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698