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

Side by Side Diff: components/rappor/rappor_service.h

Issue 1058333002: Multi-dimension rappor metrics (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 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 #ifndef COMPONENTS_RAPPOR_RAPPOR_SERVICE_H_ 5 #ifndef COMPONENTS_RAPPOR_RAPPOR_SERVICE_H_
6 #define COMPONENTS_RAPPOR_RAPPOR_SERVICE_H_ 6 #define COMPONENTS_RAPPOR_RAPPOR_SERVICE_H_
7 7
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/callback.h" 12 #include "base/callback.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
15 #include "base/timer/timer.h" 15 #include "base/timer/timer.h"
16 #include "components/metrics/daily_event.h" 16 #include "components/metrics/daily_event.h"
17 #include "components/rappor/rappor_metric.h"
17 #include "components/rappor/rappor_parameters.h" 18 #include "components/rappor/rappor_parameters.h"
18 19
19 class PrefRegistrySimple; 20 class PrefRegistrySimple;
20 class PrefService; 21 class PrefService;
21 22
22 namespace net { 23 namespace net {
23 class URLRequestContextGetter; 24 class URLRequestContextGetter;
24 } 25 }
25 26
26 namespace rappor { 27 namespace rappor {
27 28
28 class LogUploaderInterface; 29 class LogUploaderInterface;
29 class RapporMetric; 30 class RapporMetric;
30 class RapporReports; 31 class RapporReports;
31 32
32 // The type of data stored in a metric. 33 // The type of data stored in a metric.
33 enum RapporType { 34 enum RapporType {
34 // For sampling the eTLD+1 of a URL. 35 // For sampling the eTLD+1 of a URL.
35 ETLD_PLUS_ONE_RAPPOR_TYPE = 0, 36 ETLD_PLUS_ONE_RAPPOR_TYPE = 0,
36 COARSE_RAPPOR_TYPE, 37 COARSE_RAPPOR_TYPE,
38 SB_STRING_W_FLAGS_TYPE,
Alexei Svitkine (slow) 2015/04/09 21:25:03 Please comment these - also I don't understand thi
Steven Holte 2015/04/14 20:07:38 Renamed, this and the other metrics, to be more co
37 NUM_RAPPOR_TYPES 39 NUM_RAPPOR_TYPES
38 }; 40 };
39 41
40 // This class provides an interface for recording samples for rappor metrics, 42 // This class provides an interface for recording samples for rappor metrics,
41 // and periodically generates and uploads reports based on the collected data. 43 // and periodically generates and uploads reports based on the collected data.
42 class RapporService { 44 class RapporService {
43 public: 45 public:
44 // Constructs a RapporService. 46 // Constructs a RapporService.
45 // Calling code is responsible for ensuring that the lifetime of 47 // Calling code is responsible for ensuring that the lifetime of
46 // |pref_service| is longer than the lifetime of RapporService. 48 // |pref_service| is longer than the lifetime of RapporService.
(...skipping 15 matching lines...) Expand all
62 // generated and queued for upload. 64 // generated and queued for upload.
63 // If |may_upload| is true, reports will be uploaded from the queue. 65 // If |may_upload| is true, reports will be uploaded from the queue.
64 void Update(RecordingLevel recording_level, bool may_upload); 66 void Update(RecordingLevel recording_level, bool may_upload);
65 67
66 // Records a sample of the rappor metric specified by |metric_name|. 68 // Records a sample of the rappor metric specified by |metric_name|.
67 // Creates and initializes the metric, if it doesn't yet exist. 69 // Creates and initializes the metric, if it doesn't yet exist.
68 virtual void RecordSample(const std::string& metric_name, 70 virtual void RecordSample(const std::string& metric_name,
69 RapporType type, 71 RapporType type,
70 const std::string& sample); 72 const std::string& sample);
71 73
74 void RecordStringAndFlags(const std::string& metric_name,
75 RapporType type,
Alexei Svitkine (slow) 2015/04/09 21:25:03 Nit: Align and add a comment.
Steven Holte 2015/04/14 20:07:38 Done.
76 const std::string& str,
77 uint64_t flags);
Alexei Svitkine (slow) 2015/04/09 21:25:03 Are you planning to add rappor.xml mechanism for s
Steven Holte 2015/04/14 20:07:38 Done.
78
72 // Registers the names of all of the preferences used by RapporService in the 79 // Registers the names of all of the preferences used by RapporService in the
73 // provided PrefRegistry. This should be called before calling Start(). 80 // provided PrefRegistry. This should be called before calling Start().
74 static void RegisterPrefs(PrefRegistrySimple* registry); 81 static void RegisterPrefs(PrefRegistrySimple* registry);
75 82
76 protected: 83 protected:
77 // Initializes the state of the RapporService. 84 // Initializes the state of the RapporService.
78 void InitializeInternal(scoped_ptr<LogUploaderInterface> uploader, 85 void InitializeInternal(scoped_ptr<LogUploaderInterface> uploader,
79 int32_t cohort, 86 int32_t cohort,
80 const std::string& secret); 87 const std::string& secret);
81 88
(...skipping 10 matching lines...) Expand all
92 // the internal map. Exposed for tests. Returns true if any metrics were 99 // the internal map. Exposed for tests. Returns true if any metrics were
93 // recorded. 100 // recorded.
94 bool ExportMetrics(RapporReports* reports); 101 bool ExportMetrics(RapporReports* reports);
95 102
96 private: 103 private:
97 // Records a sample of the rappor metric specified by |parameters|. 104 // Records a sample of the rappor metric specified by |parameters|.
98 // Creates and initializes the metric, if it doesn't yet exist. 105 // Creates and initializes the metric, if it doesn't yet exist.
99 // Exposed for tests. 106 // Exposed for tests.
100 void RecordSampleInternal(const std::string& metric_name, 107 void RecordSampleInternal(const std::string& metric_name,
101 const RapporParameters& parameters, 108 const RapporParameters& parameters,
102 const std::string& sample); 109 const Sample& sample);
103 110
104 // Checks if the service has been started successfully. 111 // Checks if the service has been started successfully.
105 bool IsInitialized() const; 112 bool IsInitialized() const;
106 113
107 // Called whenever the logging interval elapses to generate a new log of 114 // Called whenever the logging interval elapses to generate a new log of
108 // reports and pass it to the uploader. 115 // reports and pass it to the uploader.
109 void OnLogInterval(); 116 void OnLogInterval();
110 117
111 // Finds a metric in the metrics_map_, creating it if it doesn't already 118 // Finds a metric in the metrics_map_, creating it if it doesn't already
112 // exist. 119 // exist.
(...skipping 27 matching lines...) Expand all
140 // We keep all registered metrics in a map, from name to metric. 147 // We keep all registered metrics in a map, from name to metric.
141 // The map owns the metrics it contains. 148 // The map owns the metrics it contains.
142 std::map<std::string, RapporMetric*> metrics_map_; 149 std::map<std::string, RapporMetric*> metrics_map_;
143 150
144 DISALLOW_COPY_AND_ASSIGN(RapporService); 151 DISALLOW_COPY_AND_ASSIGN(RapporService);
145 }; 152 };
146 153
147 } // namespace rappor 154 } // namespace rappor
148 155
149 #endif // COMPONENTS_RAPPOR_RAPPOR_SERVICE_H_ 156 #endif // COMPONENTS_RAPPOR_RAPPOR_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698