| 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 // Constructs a Sample object for the caller to record fields in. |
| 69 scoped_ptr<Sample> CreateSample(RapporType); |
| 70 |
| 71 // Records a Sample of rappor metric specified by |metric_name|. |
| 72 // |
| 73 // TODO(holte): Rename RecordSample to RecordString and then rename this |
| 74 // to RecordSample. |
| 75 // |
| 76 // example: |
| 77 // scoped_ptr<Sample> sample = rappor_service->CreateSample(MY_METRIC_TYPE); |
| 78 // sample->SetStringField("Field1", "some string"); |
| 79 // sample->SetFlagsValue("Field2", SOME|FLAGS); |
| 80 // rappor_service->RecordSample("MyMetric", sample.Pass()); |
| 81 // |
| 82 // This will result in a report setting two metrics "MyMetric.Field1" and |
| 83 // "MyMetric.Field2", and they will both be generated from the same sample, |
| 84 // to allow for correllations to be computed. |
| 85 void RecordSampleObj(const std::string& metric_name, |
| 86 scoped_ptr<Sample> sample); |
| 87 |
| 66 // Records a sample of the rappor metric specified by |metric_name|. | 88 // Records a sample of the rappor metric specified by |metric_name|. |
| 67 // Creates and initializes the metric, if it doesn't yet exist. | 89 // Creates and initializes the metric, if it doesn't yet exist. |
| 68 virtual void RecordSample(const std::string& metric_name, | 90 virtual void RecordSample(const std::string& metric_name, |
| 69 RapporType type, | 91 RapporType type, |
| 70 const std::string& sample); | 92 const std::string& sample); |
| 71 | 93 |
| 72 // Registers the names of all of the preferences used by RapporService in the | 94 // Registers the names of all of the preferences used by RapporService in the |
| 73 // provided PrefRegistry. This should be called before calling Start(). | 95 // provided PrefRegistry. This should be called before calling Start(). |
| 74 static void RegisterPrefs(PrefRegistrySimple* registry); | 96 static void RegisterPrefs(PrefRegistrySimple* registry); |
| 75 | 97 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 // A private LogUploader instance for sending reports to the server. | 156 // A private LogUploader instance for sending reports to the server. |
| 135 scoped_ptr<LogUploaderInterface> uploader_; | 157 scoped_ptr<LogUploaderInterface> uploader_; |
| 136 | 158 |
| 137 // What reporting level of metrics are being reported. | 159 // What reporting level of metrics are being reported. |
| 138 RecordingLevel recording_level_; | 160 RecordingLevel recording_level_; |
| 139 | 161 |
| 140 // We keep all registered metrics in a map, from name to metric. | 162 // We keep all registered metrics in a map, from name to metric. |
| 141 // The map owns the metrics it contains. | 163 // The map owns the metrics it contains. |
| 142 std::map<std::string, RapporMetric*> metrics_map_; | 164 std::map<std::string, RapporMetric*> metrics_map_; |
| 143 | 165 |
| 166 internal::Sampler sampler_; |
| 167 |
| 144 DISALLOW_COPY_AND_ASSIGN(RapporService); | 168 DISALLOW_COPY_AND_ASSIGN(RapporService); |
| 145 }; | 169 }; |
| 146 | 170 |
| 147 } // namespace rappor | 171 } // namespace rappor |
| 148 | 172 |
| 149 #endif // COMPONENTS_RAPPOR_RAPPOR_SERVICE_H_ | 173 #endif // COMPONENTS_RAPPOR_RAPPOR_SERVICE_H_ |
| OLD | NEW |