Chromium Code Reviews| Index: components/rappor/rappor_service.h |
| diff --git a/components/rappor/rappor_service.h b/components/rappor/rappor_service.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..92562f5efbbf0e81e5e9b6c21a3d78b80d574ab6 |
| --- /dev/null |
| +++ b/components/rappor/rappor_service.h |
| @@ -0,0 +1,86 @@ |
| +// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef COMPONENTS_RAPPOR_RAPPOR_SERVICE_H_ |
| +#define COMPONENTS_RAPPOR_RAPPOR_SERVICE_H_ |
| + |
| +#include <string> |
| +#include <vector> |
| + |
| +#include "base/basictypes.h" |
| +#include "base/lazy_instance.h" |
| +#include "base/memory/weak_ptr.h" |
| +#include "base/prefs/pref_service.h" |
| +#include "base/time/time.h" |
| +#include "base/timer/timer.h" |
| +#include "components/rappor/log_uploader.h" |
| +#include "components/rappor/proto/rappor_metric.pb.h" |
| +#include "components/rappor/rappor_metric.h" |
| + |
| +class PrefRegistrySimple; |
| + |
| +namespace rappor { |
| + |
| +class RapporReporter; |
| + |
| +// This class provides base functionality for logging rappor data. |
| +class RapporService { |
| + public: |
| + RapporService(); |
| + virtual ~RapporService(); |
| + |
| + // Starts the rappord system. Should be called when starting up. |
| + void Start(PrefService* pref_service, net::URLRequestContextGetter* context); |
| + |
| + // At startup, prefs needs to be called with a list of all the pref names and |
|
Alexei Svitkine (slow)
2013/12/24 16:59:30
Nit: reword. Mention that this should be called be
Steven Holte
2014/01/04 00:12:54
Done.
|
| + // types we'll be using. |
| + static void RegisterPrefs(PrefRegistrySimple* registry); |
| + |
| + // Find a rappor by name, and create it if it doesn't already exist, and adds |
|
Alexei Svitkine (slow)
2013/12/24 16:59:30
Nit: How about: "Records a set of samples on the r
Steven Holte
2014/01/04 00:12:54
Done.
|
| + // samples to it. This method is thread safe. |
| + void RecordSamples(const RapporParameters* parameters, |
|
Alexei Svitkine (slow)
2013/12/24 16:59:30
Nit: pass by const ref (unless passing NULL is a s
Steven Holte
2014/01/04 00:12:54
Done.
|
| + const std::vector<std::string>& samples); |
| + |
| + private: |
| + friend class RapporServiceTest; |
| + |
| + // Generates a rappor_secret and stores it in preferences. If already stored, |
| + // just retreives the stored value. |
| + void GenerateRapporSecret(PrefService* pref_service); |
| + |
| + // Logs a single RapporMetric value to the rappor_metrics_proto_. |
| + void LogRappor(const RapporMetric& rappor); |
| + |
| + // Logs all of the collected RapporMetric metrics to the rappor_metric_proto_. |
| + void LogRapporMetrics(); |
| + |
| + // Called whenever the logging interval elapses. |
| + void OnLogInterval(); |
| + |
| + // Find a rappor by name, and create it if it doesn't already exist. |
|
Alexei Svitkine (slow)
2013/12/24 16:59:30
Nit: "rappor" -> "rappor metric".
Steven Holte
2014/01/04 00:12:54
Done.
|
| + RapporMetric* GetRapporMetric(const RapporParameters* parameters); |
| + |
| + // Client side secret used to generate fake bits. |
| + std::string rappor_secret_; |
| + |
| + RapporMetricsProto rappor_metrics_proto_; |
| + |
| + // Timer which schedules calls OnLogInterval() |
| + base::OneShotTimer<RapporService> log_rotation_timer_; |
| + |
| + LogUploader uploader_; |
| + |
| + // We keep all registered histograms in a map, from name to histogram. |
| + typedef std::map<std::string, RapporMetric*> RapporMap; |
| + RapporMap rappors_; |
| + |
| + // Lock protects access to above map. |
| + base::Lock lock_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(RapporService); |
| +}; |
| + |
| +} // namespace rappor |
| + |
| +#endif // COMPONENTS_RAPPOR_RAPPOR_SERVICE_H_ |