OLD | NEW |
---|---|
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 // Change for readability | |
6 | |
5 #ifndef COMPONENTS_RAPPOR_RAPPOR_SERVICE_H_ | 7 #ifndef COMPONENTS_RAPPOR_RAPPOR_SERVICE_H_ |
6 #define COMPONENTS_RAPPOR_RAPPOR_SERVICE_H_ | 8 #define COMPONENTS_RAPPOR_RAPPOR_SERVICE_H_ |
7 | 9 |
8 #include <string> | 10 #include <string> |
9 | 11 |
10 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
11 #include "base/prefs/pref_service.h" | 13 #include "base/prefs/pref_service.h" |
12 #include "base/time/time.h" | 14 #include "base/time/time.h" |
13 #include "base/timer/timer.h" | 15 #include "base/timer/timer.h" |
14 #include "components/rappor/log_uploader.h" | 16 #include "components/rappor/log_uploader.h" |
15 #include "components/rappor/proto/rappor_metric.pb.h" | 17 #include "components/rappor/proto/rappor_metric.pb.h" |
16 #include "components/rappor/rappor_metric.h" | 18 #include "components/rappor/rappor_metric.h" |
17 | 19 |
18 class PrefRegistrySimple; | 20 class PrefRegistrySimple; |
19 | 21 |
20 namespace rappor { | 22 namespace rappor { |
21 | 23 |
22 // The type of data stored in a metric. | 24 // The type of data stored in a metric. |
23 enum RapporType { | 25 enum RapporType { |
24 ETLD_PLUS_ONE_RAPPOR_TYPE = 0, | 26 ETLD_PLUS_ONE_RAPPOR_TYPE = 0, |
ktl
2014/03/17 11:22:25
Comment? Is the zero value significant somewhere?
Steven Holte
2014/03/18 03:13:07
Added comments. The 0 value is used implicitly be
| |
25 NUM_RAPPOR_TYPES | 27 NUM_RAPPOR_TYPES |
26 }; | 28 }; |
27 | 29 |
28 // This class provides an interface for recording samples for rappor metrics, | 30 // This class provides an interface for recording samples for rappor metrics, |
29 // and periodically generates and uploads reports based on the collected data. | 31 // and periodically generates and uploads reports based on the collected data. |
30 class RapporService { | 32 class RapporService { |
31 public: | 33 public: |
32 RapporService(); | 34 RapporService(); |
33 virtual ~RapporService(); | 35 virtual ~RapporService(); |
34 | 36 |
35 // Starts the periodic generation of reports and upload attempts. | 37 // Starts the periodic generation of reports and upload attempts. |
36 void Start(PrefService* pref_service, net::URLRequestContextGetter* context); | 38 void Start(PrefService* pref_service, net::URLRequestContextGetter* context); |
ktl
2014/03/17 11:22:25
Does URLRequestContextGetter come from you direct
Steven Holte
2014/03/18 03:13:07
Done.
| |
37 | 39 |
38 // Records a sample of the rappor metric specified by |metric_name|. | 40 // Records a sample of the rappor metric specified by |metric_name|. |
39 // Creates and initializes the metric, if it doesn't yet exist. | 41 // Creates and initializes the metric, if it doesn't yet exist. |
40 void RecordSample(const std::string& metric_name, | 42 void RecordSample(const std::string& metric_name, |
41 RapporType type, | 43 RapporType type, |
42 const std::string& sample); | 44 const std::string& sample); |
43 | 45 |
44 // Sets the cohort value. For use by tests only. | 46 // Sets the cohort value. For use by tests only. |
45 void SetCohortForTesting(uint32_t cohort) { cohort_ = cohort; } | 47 void SetCohortForTesting(uint32_t cohort) { cohort_ = cohort; } |
46 | 48 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
84 // exist. | 86 // exist. |
85 RapporMetric* LookUpMetric(const std::string& metric_name, | 87 RapporMetric* LookUpMetric(const std::string& metric_name, |
86 const RapporParameters& parameters); | 88 const RapporParameters& parameters); |
87 | 89 |
88 // Client-side secret used to generate fake bits. | 90 // Client-side secret used to generate fake bits. |
89 std::string secret_; | 91 std::string secret_; |
90 | 92 |
91 // The cohort this client is assigned to. -1 is uninitialized. | 93 // The cohort this client is assigned to. -1 is uninitialized. |
92 int32_t cohort_; | 94 int32_t cohort_; |
93 | 95 |
94 // Timer which schedules calls to OnLogInterval() | 96 // Timer which schedules calls to OnLogInterval() |
ktl
2014/03/17 11:22:25
Add period.
Steven Holte
2014/03/18 03:13:07
Done.
| |
95 base::OneShotTimer<RapporService> log_rotation_timer_; | 97 base::OneShotTimer<RapporService> log_rotation_timer_; |
96 | 98 |
97 // A private LogUploader instance for sending reports to the server. | 99 // A private LogUploader instance for sending reports to the server. |
98 scoped_ptr<LogUploader> uploader_; | 100 scoped_ptr<LogUploader> uploader_; |
ktl
2014/03/17 11:22:25
Do you still use scoped_ptr<> instead of more stan
Ilya Sherman
2014/03/17 19:14:36
Chromium code does not yet have unique_ptr support
Steven Holte
2014/03/18 03:13:07
Added include.
| |
99 | 101 |
100 // We keep all registered metrics in a map, from name to metric. | 102 // We keep all registered metrics in a map, from name to metric. |
101 // The map owns the metrics it contains. | 103 // The map owns the metrics it contains. |
102 std::map<std::string, RapporMetric*> metrics_map_; | 104 std::map<std::string, RapporMetric*> metrics_map_; |
ktl
2014/03/17 11:22:25
#include <map>
In modern C++, it would be prefera
Ilya Sherman
2014/03/17 19:14:36
Unfortunately, Chromium code cannot yet use C++11.
| |
103 | 105 |
104 DISALLOW_COPY_AND_ASSIGN(RapporService); | 106 DISALLOW_COPY_AND_ASSIGN(RapporService); |
105 }; | 107 }; |
106 | 108 |
107 } // namespace rappor | 109 } // namespace rappor |
108 | 110 |
109 #endif // COMPONENTS_RAPPOR_RAPPOR_SERVICE_H_ | 111 #endif // COMPONENTS_RAPPOR_RAPPOR_SERVICE_H_ |
OLD | NEW |