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 |
| 20 class PrefRegistrySimple; |
| 21 |
| 22 namespace rappor { |
| 23 |
| 24 // This class provides base functionality for logging rappor data. |
| 25 class RapporService { |
| 26 public: |
| 27 RapporService(); |
| 28 virtual ~RapporService(); |
| 29 |
| 30 // Starts the rappord system. Should be called when starting up. |
| 31 void Start(PrefService* pref_service, net::URLRequestContextGetter* context); |
| 32 |
| 33 // At startup, prefs needs to be called with a list of all the pref names and |
| 34 // types we'll be using. |
| 35 static void RegisterPrefs(PrefRegistrySimple* registry); |
| 36 |
| 37 private: |
| 38 friend class RapporServiceTest; |
| 39 |
| 40 // Client side secret used to generate fake bits. |
| 41 std::string rappor_secret_; |
| 42 |
| 43 RapporMetricsProto rappor_metrics_proto_; |
| 44 |
| 45 // Timer which schedules calls OnLogInterval() |
| 46 base::OneShotTimer<RapporService> log_rotation_timer_; |
| 47 |
| 48 LogUploader uploader_; |
| 49 |
| 50 // Generates a rappor_secret and stores it in preferences. If already stored, |
| 51 // just retreives the stored value. |
| 52 void GenerateRapporSecret(PrefService* pref_service); |
| 53 |
| 54 // Records a single Rappor value to the rappor_metrics_proto_. |
| 55 void RecordRapporMetric(const std::string& metric_name, |
| 56 const std::vector<uint8_t> bytes); |
| 57 |
| 58 // Records all of the collected Rappor metrics to the rappor_metric_proto_. |
| 59 void RecordRapporMetrics(); |
| 60 |
| 61 // Called whenever the logging interval elapses. |
| 62 void OnLogInterval(); |
| 63 |
| 64 DISALLOW_COPY_AND_ASSIGN(RapporService); |
| 65 }; |
| 66 |
| 67 } // namespace rappor |
| 68 |
| 69 #endif // COMPONENTS_RAPPOR_RAPPOR_SERVICE_H_ |
OLD | NEW |