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

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

Issue 49753002: RAPPOR implementation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Split Name/Parameters Created 6 years, 10 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
(Empty)
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 #ifndef COMPONENTS_RAPPOR_RAPPOR_SERVICE_H_
6 #define COMPONENTS_RAPPOR_RAPPOR_SERVICE_H_
7
8 #include <string>
9
10 #include "base/basictypes.h"
11 #include "base/lazy_instance.h"
12 #include "base/memory/weak_ptr.h"
13 #include "base/prefs/pref_service.h"
14 #include "base/time/time.h"
15 #include "base/timer/timer.h"
16 #include "components/rappor/log_uploader.h"
17 #include "components/rappor/proto/rappor_metric.pb.h"
18 #include "components/rappor/rappor_metric.h"
19
20 class PrefRegistrySimple;
21
22 namespace rappor {
23
24 // The type of data stored in a metric.
25 enum RapporType {
26 ETLD_PLUS_ONE_RAPPOR_TYPE = 0,
27 NUM_RAPPOR_TYPES
28 };
29
30 // This class provides an interface for recording samples for rappor metrics,
31 // and periodically generates and uploads reports based on the collected data.
32 class RapporService {
33 public:
34 RapporService();
35 virtual ~RapporService();
36
37 // Starts the periodic generation of reports and upload attempts.
38 void Start(PrefService* pref_service, net::URLRequestContextGetter* context);
39
40 // Registers the names of all of the preferences used by RapporService in the
41 // provided PrefRegistry. This should be called before calling Start().
42 static void RegisterPrefs(PrefRegistrySimple* registry);
Alexei Svitkine (slow) 2014/02/05 18:07:01 Move this below, so the static method is not betwe
Steven Holte 2014/02/05 22:44:37 Done.
43
44 // Records a sample of the rappor metric specified by |metric_name|.
45 // Creates and initializes the metric, if it doesn't yet exist.
46 void RecordSample(const std::string& metric_name,
47 RapporType type,
48 const std::string& sample);
49
50 protected:
51 // Logs all of the collected metrics to the reports proto message. Exposed
52 // for tests. Returns true if any metrics were recorded.
53 bool LogMetrics(RapporReports* reports);
Alexei Svitkine (slow) 2014/02/05 18:07:01 I would call this ExportMetrics() or something sim
Steven Holte 2014/02/05 22:44:37 Done.
54
55 // Records a sample of the rappor metric specified by |parameters|.
56 // Creates and initializes the metric, if it doesn't yet exist.
57 void RecordSampleInternal(const std::string& metric_name,
58 const RapporParameters& parameters,
59 const std::string& sample);
60
61 // The cohort this client is assigned to. -1 is uninitialized.
62 int32_t cohort_;
Alexei Svitkine (slow) 2014/02/05 18:07:01 Add a newline after this. Though, I'd keep this p
Steven Holte 2014/02/05 22:44:37 Moved to private.
63 private:
64 // Retrieves the cohort number this client was assigned to, generating it if
65 // doesn't already exist. The cohort should be persistent.
66 void LoadCohort(PrefService* pref_service);
67
68 // Retrieves the value for secret_ from preferences, generating it if doesn't
69 // already exist. The secret should be persistent, so that additional bits
70 // from the client do not get exposed over time.
71 void LoadSecret(PrefService* pref_service);
72
73 // Logs a single metric's output to the report message.
74 void LogMetric(const RapporMetric& metric, RapporReports::Report* report);
75
76 // Called whenever the logging interval elapses to generate a new log of
77 // reports and pass it to the uploader.
78 void OnLogInterval();
79
80 // Finds a metric in the metrics_map_, creating it if it doesn't already
81 // exist.
82 RapporMetric* LookupMetric(const std::string& metric_name,
83 const RapporParameters& parameters);
84
85 // Client-side secret used to generate fake bits.
86 std::string secret_;
87
88 // Timer which schedules calls to OnLogInterval()
89 base::OneShotTimer<RapporService> log_rotation_timer_;
90
91 // A private LogUploader instance for sending reports to the server.
92 scoped_ptr<LogUploader> uploader_;
93
94 // We keep all registered histograms in a map, from name to histogram.
95 std::map<std::string, RapporMetric*> metrics_map_;
96
97 // Lock protects access to above map.
98 base::Lock lock_;
99
100 DISALLOW_COPY_AND_ASSIGN(RapporService);
101 };
102
103 } // namespace rappor
104
105 #endif // COMPONENTS_RAPPOR_RAPPOR_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698