OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2013 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 #include <vector> | |
10 | |
11 #include "base/basictypes.h" | |
12 #include "base/lazy_instance.h" | |
13 #include "base/memory/weak_ptr.h" | |
14 #include "base/prefs/pref_service.h" | |
15 #include "base/time/time.h" | |
16 #include "base/timer/timer.h" | |
17 #include "components/rappor/log_uploader.h" | |
18 #include "components/rappor/proto/rappor_metric.pb.h" | |
19 #include "components/rappor/rappor_metric.h" | |
20 #include "url/gurl.h" | |
21 | |
22 class PrefRegistrySimple; | |
23 | |
24 namespace rappor { | |
25 | |
26 class RapporReporter; | |
Ilya Sherman
2014/01/10 11:00:32
Hmm, where is this class defined? I don't recall
Steven Holte
2014/01/14 00:47:54
Removed.
| |
27 | |
28 // This class provides base functionality for logging rappor data. | |
Ilya Sherman
2014/01/10 11:00:32
nit: What does the "base" in "base functionality"
Steven Holte
2014/01/14 00:47:54
Rewrote comment.
| |
29 class RapporService { | |
30 public: | |
31 RapporService(); | |
32 virtual ~RapporService(); | |
33 | |
34 // Starts the rappord system. Should be called when starting up. | |
Ilya Sherman
2014/01/10 11:00:32
nit: "rappord" -> "rappor"?
Steven Holte
2014/01/14 00:47:54
Rewrote comment.
| |
35 void Start(PrefService* pref_service, net::URLRequestContextGetter* context); | |
36 | |
37 // Registers the names of all of the Preferences used by RapporService in the | |
Ilya Sherman
2014/01/10 11:00:32
nit: No need to capitalize "Preferences" here, I t
Steven Holte
2014/01/14 00:47:54
Done.
| |
38 // provided PrefRegistry. This should be called before calling Start(). | |
39 static void RegisterPrefs(PrefRegistrySimple* registry); | |
40 | |
41 // Records a set of samples on the rappor metric specified by |parameters|. | |
42 // Creates and initializes the metric, if it doesn't yet exist. | |
43 void RecordSamples(const RapporParameters& parameters, | |
44 const std::vector<std::string>& samples); | |
45 | |
46 // Utility method for recording a URL. Breaks the URL up into parts and | |
47 // records samples for each of them. | |
48 void RecordUrl(const RapporParameters& parameters, const GURL& url); | |
49 | |
50 private: | |
51 friend class RapporServiceTest; | |
Ilya Sherman
2014/01/10 11:00:32
Please don't add friend classes to new code, unles
Steven Holte
2014/01/15 04:53:44
Done.
| |
52 | |
53 // Generates a rappor_secret and stores it in preferences. If already stored, | |
Ilya Sherman
2014/01/10 11:00:32
nit: "rappor_secret" isn't a variable name defined
Steven Holte
2014/01/15 04:53:44
This referenced rappor_secret_, now references sec
| |
54 // just retreives the stored value. | |
Ilya Sherman
2014/01/10 11:00:32
Is it important that a client's rappor secret rema
Steven Holte
2014/01/15 04:53:44
Rewrote this comment a bit.
| |
55 void GenerateRapporSecret(PrefService* pref_service); | |
56 | |
57 // Logs a single RapporMetric value to the rappor_metrics_proto_. | |
58 void LogRappor(const RapporMetric& rappor); | |
Ilya Sherman
2014/01/10 11:00:32
nit: "LogRappor" -> "LogMetric"; "rappor" -> "metr
Steven Holte
2014/01/15 04:53:44
Done.
| |
59 | |
60 // Logs all of the collected RapporMetric metrics to the rappor_metric_proto_. | |
61 void LogRapporMetrics(); | |
62 | |
63 // Called whenever the logging interval elapses. | |
Ilya Sherman
2014/01/10 11:00:32
What does the method do when it's called? Please
Steven Holte
2014/01/15 04:53:44
Done.
| |
64 void OnLogInterval(); | |
65 | |
66 // Find a rappor metric by name, and create it if it doesn't already exist. | |
Ilya Sherman
2014/01/10 11:00:32
nit: "and create it" -> "creating it"
Steven Holte
2014/01/15 04:53:44
Done.
| |
67 RapporMetric* GetRapporMetric(const RapporParameters& parameters); | |
68 | |
69 // Client side secret used to generate fake bits. | |
Ilya Sherman
2014/01/10 11:00:32
nit: "Client side" -> "Client-side"
Steven Holte
2014/01/15 04:53:44
Done.
| |
70 std::string rappor_secret_; | |
Ilya Sherman
2014/01/10 11:00:32
nit: Probably no need for the "rappor_" prefix her
Steven Holte
2014/01/15 04:53:44
Done.
| |
71 | |
72 RapporMetricsProto rappor_metrics_proto_; | |
Ilya Sherman
2014/01/10 11:00:32
nit: Docs, please.
Steven Holte
2014/01/15 04:53:44
Removed
| |
73 | |
74 // Timer which schedules calls OnLogInterval() | |
Ilya Sherman
2014/01/10 11:00:32
nit: "calls" -> "calls to"
Steven Holte
2014/01/15 04:53:44
Done.
| |
75 base::OneShotTimer<RapporService> log_rotation_timer_; | |
76 | |
77 LogUploader* uploader_; | |
Ilya Sherman
2014/01/10 11:00:32
nit: Docs. Also, who owns the memory for this obj
Steven Holte
2014/01/15 04:53:44
Changed to scoped_ptr. Added docstring.
| |
78 | |
79 // We keep all registered histograms in a map, from name to histogram. | |
80 typedef std::map<std::string, RapporMetric*> RapporMap; | |
Ilya Sherman
2014/01/10 11:00:32
Optional nit: This is definitely a personal style
Steven Holte
2014/01/15 04:53:44
Done.
| |
81 RapporMap rappors_; | |
Ilya Sherman
2014/01/10 11:00:32
nit: metrics_;
Steven Holte
2014/01/15 04:53:44
Changed to metrics_map_
| |
82 | |
83 // Lock protects access to above map. | |
84 base::Lock lock_; | |
Ilya Sherman
2014/01/10 11:00:32
Why does the map need a lock? Is this class threa
Steven Holte
2014/01/15 04:53:44
I would expect all of the upload/report generation
| |
85 | |
86 DISALLOW_COPY_AND_ASSIGN(RapporService); | |
87 }; | |
88 | |
89 } // namespace rappor | |
90 | |
91 #endif // COMPONENTS_RAPPOR_RAPPOR_SERVICE_H_ | |
OLD | NEW |