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 #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_parameters.h" | 17 #include "components/rappor/rappor_parameters.h" |
18 #include "components/rappor/sample.h" | |
19 #include "components/rappor/sampler.h" | |
18 | 20 |
19 class PrefRegistrySimple; | 21 class PrefRegistrySimple; |
20 class PrefService; | 22 class PrefService; |
21 | 23 |
22 namespace net { | 24 namespace net { |
23 class URLRequestContextGetter; | 25 class URLRequestContextGetter; |
24 } | 26 } |
25 | 27 |
26 namespace rappor { | 28 namespace rappor { |
27 | 29 |
(...skipping 28 matching lines...) Expand all Loading... | |
56 // preferences from disk. | 58 // preferences from disk. |
57 void Initialize(net::URLRequestContextGetter* context); | 59 void Initialize(net::URLRequestContextGetter* context); |
58 | 60 |
59 // Updates the settings for metric recording and uploading. | 61 // Updates the settings for metric recording and uploading. |
60 // The RapporService must be initialized before this method is called. | 62 // The RapporService must be initialized before this method is called. |
61 // If |recording_level| > REPORTING_DISABLED, periodic reports will be | 63 // If |recording_level| > REPORTING_DISABLED, periodic reports will be |
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 |
68 // The constructs and returns a Sample object for the caller to record | |
Alexei Svitkine (slow)
2015/04/24 18:10:01
Nit: Reword ("The constructs").
Steven Holte
2015/04/24 18:39:57
Done.
| |
69 // fields in. | |
70 scoped_ptr<Sample> CreateSample(RapporType); | |
71 | |
72 // Records a Sample of rappor metric specified by |metric_name|. | |
73 // | |
74 // example: | |
75 // scoped_ptr<Sample> sample = rappor_service->CreateSample(MY_METRIC_TYPE); | |
76 // sample->SetStringField("Field1", "some string"); | |
77 // sample->SetFlagsValue("Field2", SOME|FLAGS); | |
78 // rappor_service->RecordSample("MyMetric", sample.Pass()); | |
Nathan Parker
2015/04/24 18:26:25
Can you add comment that this will lead to a repor
Steven Holte
2015/04/24 18:39:57
Done.
| |
79 void RecordSampleObj(const std::string& metric_name, | |
Alexei Svitkine (slow)
2015/04/24 18:10:01
Maybe add a TODO to rename?
Steven Holte
2015/04/24 18:39:57
Done.
| |
80 scoped_ptr<Sample> sample); | |
81 | |
66 // Records a sample of the rappor metric specified by |metric_name|. | 82 // Records a sample of the rappor metric specified by |metric_name|. |
67 // Creates and initializes the metric, if it doesn't yet exist. | 83 // Creates and initializes the metric, if it doesn't yet exist. |
68 virtual void RecordSample(const std::string& metric_name, | 84 virtual void RecordSample(const std::string& metric_name, |
69 RapporType type, | 85 RapporType type, |
70 const std::string& sample); | 86 const std::string& sample); |
71 | 87 |
72 // Registers the names of all of the preferences used by RapporService in the | 88 // Registers the names of all of the preferences used by RapporService in the |
73 // provided PrefRegistry. This should be called before calling Start(). | 89 // provided PrefRegistry. This should be called before calling Start(). |
74 static void RegisterPrefs(PrefRegistrySimple* registry); | 90 static void RegisterPrefs(PrefRegistrySimple* registry); |
75 | 91 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
134 // A private LogUploader instance for sending reports to the server. | 150 // A private LogUploader instance for sending reports to the server. |
135 scoped_ptr<LogUploaderInterface> uploader_; | 151 scoped_ptr<LogUploaderInterface> uploader_; |
136 | 152 |
137 // What reporting level of metrics are being reported. | 153 // What reporting level of metrics are being reported. |
138 RecordingLevel recording_level_; | 154 RecordingLevel recording_level_; |
139 | 155 |
140 // We keep all registered metrics in a map, from name to metric. | 156 // We keep all registered metrics in a map, from name to metric. |
141 // The map owns the metrics it contains. | 157 // The map owns the metrics it contains. |
142 std::map<std::string, RapporMetric*> metrics_map_; | 158 std::map<std::string, RapporMetric*> metrics_map_; |
143 | 159 |
160 internal::Sampler sampler_; | |
161 | |
144 DISALLOW_COPY_AND_ASSIGN(RapporService); | 162 DISALLOW_COPY_AND_ASSIGN(RapporService); |
145 }; | 163 }; |
146 | 164 |
147 } // namespace rappor | 165 } // namespace rappor |
148 | 166 |
149 #endif // COMPONENTS_RAPPOR_RAPPOR_SERVICE_H_ | 167 #endif // COMPONENTS_RAPPOR_RAPPOR_SERVICE_H_ |
OLD | NEW |