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 |
10 #include <map> | |
8 #include <string> | 11 #include <string> |
9 | 12 |
10 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
14 #include "base/macros.h" | |
15 #include "base/memory/scoped_ptr.h" | |
11 #include "base/prefs/pref_service.h" | 16 #include "base/prefs/pref_service.h" |
ktl
2014/03/21 13:40:02
Seems like you don't really need to #include this
Steven Holte
2014/03/21 19:52:25
Done.
| |
12 #include "base/time/time.h" | 17 #include "base/time/time.h" |
13 #include "base/timer/timer.h" | 18 #include "base/timer/timer.h" |
14 #include "components/rappor/log_uploader.h" | 19 #include "components/rappor/log_uploader.h" |
15 #include "components/rappor/proto/rappor_metric.pb.h" | 20 #include "components/rappor/proto/rappor_metric.pb.h" |
16 #include "components/rappor/rappor_metric.h" | 21 #include "components/rappor/rappor_metric.h" |
17 | 22 |
18 class PrefRegistrySimple; | 23 class PrefRegistrySimple; |
19 | 24 |
25 namespace net { | |
26 class URLRequestContextGetter; | |
27 } | |
28 | |
20 namespace rappor { | 29 namespace rappor { |
21 | 30 |
22 // The type of data stored in a metric. | 31 // The type of data stored in a metric. |
23 enum RapporType { | 32 enum RapporType { |
33 // For sampling the eTLD+1 of a URL. | |
24 ETLD_PLUS_ONE_RAPPOR_TYPE = 0, | 34 ETLD_PLUS_ONE_RAPPOR_TYPE = 0, |
25 NUM_RAPPOR_TYPES | 35 NUM_RAPPOR_TYPES |
26 }; | 36 }; |
27 | 37 |
28 // This class provides an interface for recording samples for rappor metrics, | 38 // This class provides an interface for recording samples for rappor metrics, |
29 // and periodically generates and uploads reports based on the collected data. | 39 // and periodically generates and uploads reports based on the collected data. |
30 class RapporService { | 40 class RapporService { |
31 public: | 41 public: |
32 RapporService(); | 42 RapporService(); |
33 virtual ~RapporService(); | 43 virtual ~RapporService(); |
(...skipping 11 matching lines...) Expand all Loading... | |
45 void SetCohortForTesting(uint32_t cohort) { cohort_ = cohort; } | 55 void SetCohortForTesting(uint32_t cohort) { cohort_ = cohort; } |
46 | 56 |
47 // Sets the secret value. For use by tests only. | 57 // Sets the secret value. For use by tests only. |
48 void SetSecretForTesting(const std::string& secret) { secret_ = secret; } | 58 void SetSecretForTesting(const std::string& secret) { secret_ = secret; } |
49 | 59 |
50 // Registers the names of all of the preferences used by RapporService in the | 60 // Registers the names of all of the preferences used by RapporService in the |
51 // provided PrefRegistry. This should be called before calling Start(). | 61 // provided PrefRegistry. This should be called before calling Start(). |
52 static void RegisterPrefs(PrefRegistrySimple* registry); | 62 static void RegisterPrefs(PrefRegistrySimple* registry); |
53 | 63 |
54 protected: | 64 protected: |
55 // Logs all of the collected metrics to the reports proto message. Exposed | 65 // Logs all of the collected metrics to the reports proto message and clears |
56 // for tests. Returns true if any metrics were recorded. | 66 // the internal map. Exposed for tests. Returns true if any metrics were |
67 // recorded. | |
57 bool ExportMetrics(RapporReports* reports); | 68 bool ExportMetrics(RapporReports* reports); |
58 | 69 |
59 // Records a sample of the rappor metric specified by |parameters|. | 70 // Records a sample of the rappor metric specified by |parameters|. |
60 // Creates and initializes the metric, if it doesn't yet exist. | 71 // Creates and initializes the metric, if it doesn't yet exist. |
61 // Exposed for tests. | 72 // Exposed for tests. |
62 void RecordSampleInternal(const std::string& metric_name, | 73 void RecordSampleInternal(const std::string& metric_name, |
63 const RapporParameters& parameters, | 74 const RapporParameters& parameters, |
64 const std::string& sample); | 75 const std::string& sample); |
65 | 76 |
66 private: | 77 private: |
(...skipping 17 matching lines...) Expand all Loading... | |
84 // exist. | 95 // exist. |
85 RapporMetric* LookUpMetric(const std::string& metric_name, | 96 RapporMetric* LookUpMetric(const std::string& metric_name, |
86 const RapporParameters& parameters); | 97 const RapporParameters& parameters); |
87 | 98 |
88 // Client-side secret used to generate fake bits. | 99 // Client-side secret used to generate fake bits. |
89 std::string secret_; | 100 std::string secret_; |
90 | 101 |
91 // The cohort this client is assigned to. -1 is uninitialized. | 102 // The cohort this client is assigned to. -1 is uninitialized. |
92 int32_t cohort_; | 103 int32_t cohort_; |
93 | 104 |
94 // Timer which schedules calls to OnLogInterval() | 105 // Timer which schedules calls to OnLogInterval(). |
95 base::OneShotTimer<RapporService> log_rotation_timer_; | 106 base::OneShotTimer<RapporService> log_rotation_timer_; |
96 | 107 |
97 // A private LogUploader instance for sending reports to the server. | 108 // A private LogUploader instance for sending reports to the server. |
98 scoped_ptr<LogUploader> uploader_; | 109 scoped_ptr<LogUploader> uploader_; |
99 | 110 |
100 // We keep all registered metrics in a map, from name to metric. | 111 // We keep all registered metrics in a map, from name to metric. |
101 // The map owns the metrics it contains. | 112 // The map owns the metrics it contains. |
102 std::map<std::string, RapporMetric*> metrics_map_; | 113 std::map<std::string, RapporMetric*> metrics_map_; |
103 | 114 |
104 DISALLOW_COPY_AND_ASSIGN(RapporService); | 115 DISALLOW_COPY_AND_ASSIGN(RapporService); |
105 }; | 116 }; |
106 | 117 |
107 } // namespace rappor | 118 } // namespace rappor |
108 | 119 |
109 #endif // COMPONENTS_RAPPOR_RAPPOR_SERVICE_H_ | 120 #endif // COMPONENTS_RAPPOR_RAPPOR_SERVICE_H_ |
OLD | NEW |