| 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..3ffa77e54eafee571204390d62c2060189c0da36
|
| --- /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);
|
| +
|
| + // Registers the names of all of the Preferences used by RapporService in the
|
| + // provided PrefRegistry. This should be called before calling Start().
|
| + static void RegisterPrefs(PrefRegistrySimple* registry);
|
| +
|
| + // Records a set of samples on the rappor metric specified by |parameters|.
|
| + // Creates and initializes the metric, if it doesn't yet exist.
|
| + void RecordSamples(const RapporParameters& parameters,
|
| + 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 metric by name, and create it if it doesn't already exist.
|
| + 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_
|
|
|