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 |
| 21 class PrefRegistrySimple; |
| 22 |
| 23 namespace rappor { |
| 24 |
| 25 class RapporReporter; |
| 26 |
| 27 // This class provides base functionality for logging rappor data. |
| 28 class RapporService { |
| 29 public: |
| 30 RapporService(); |
| 31 virtual ~RapporService(); |
| 32 |
| 33 // Starts the rappord system. Should be called when starting up. |
| 34 void Start(PrefService* pref_service, net::URLRequestContextGetter* context); |
| 35 |
| 36 // Registers the names of all of the Preferences used by RapporService in the |
| 37 // provided PrefRegistry. This should be called before calling Start(). |
| 38 static void RegisterPrefs(PrefRegistrySimple* registry); |
| 39 |
| 40 // Records a set of samples on the rappor metric specified by |parameters|. |
| 41 // Creates and initializes the metric, if it doesn't yet exist. |
| 42 void RecordSamples(const RapporParameters& parameters, |
| 43 const std::vector<std::string>& samples); |
| 44 |
| 45 private: |
| 46 friend class RapporServiceTest; |
| 47 |
| 48 // Generates a rappor_secret and stores it in preferences. If already stored, |
| 49 // just retreives the stored value. |
| 50 void GenerateRapporSecret(PrefService* pref_service); |
| 51 |
| 52 // Logs a single RapporMetric value to the rappor_metrics_proto_. |
| 53 void LogRappor(const RapporMetric& rappor); |
| 54 |
| 55 // Logs all of the collected RapporMetric metrics to the rappor_metric_proto_. |
| 56 void LogRapporMetrics(); |
| 57 |
| 58 // Called whenever the logging interval elapses. |
| 59 void OnLogInterval(); |
| 60 |
| 61 // Find a rappor metric by name, and create it if it doesn't already exist. |
| 62 RapporMetric* GetRapporMetric(const RapporParameters& parameters); |
| 63 |
| 64 // Client side secret used to generate fake bits. |
| 65 std::string rappor_secret_; |
| 66 |
| 67 RapporMetricsProto rappor_metrics_proto_; |
| 68 |
| 69 // Timer which schedules calls OnLogInterval() |
| 70 base::OneShotTimer<RapporService> log_rotation_timer_; |
| 71 |
| 72 LogUploader uploader_; |
| 73 |
| 74 // We keep all registered histograms in a map, from name to histogram. |
| 75 typedef std::map<std::string, RapporMetric*> RapporMap; |
| 76 RapporMap rappors_; |
| 77 |
| 78 // Lock protects access to above map. |
| 79 base::Lock lock_; |
| 80 |
| 81 DISALLOW_COPY_AND_ASSIGN(RapporService); |
| 82 }; |
| 83 |
| 84 } // namespace rappor |
| 85 |
| 86 #endif // COMPONENTS_RAPPOR_RAPPOR_SERVICE_H_ |
OLD | NEW |