Drive: Add BatchableRequest subclass.
[chromium-blink-merge.git] / chromecast / browser / metrics / external_metrics.h
blobdd125e211b6609ea227e9415749edd3384c0b22c
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
3 // found in the LICENSE file.
5 #ifndef CHROMECAST_BROWSER_METRICS_EXTERNAL_METRICS_H_
6 #define CHROMECAST_BROWSER_METRICS_EXTERNAL_METRICS_H_
8 #include <string>
10 #include "base/macros.h"
11 #include "base/memory/weak_ptr.h"
13 namespace metrics {
14 class MetricSample;
15 } // namespace metrics
17 namespace chromecast {
18 namespace metrics {
20 class CastStabilityMetricsProvider;
22 // ExternalMetrics service allows processes outside of the Chromecast browser
23 // process to upload metrics via reading/writing to a known shared file.
24 class ExternalMetrics {
25 public:
26 explicit ExternalMetrics(CastStabilityMetricsProvider* stability_provider);
28 // Begins external data collection. Calls to RecordAction originate in the
29 // File thread but are executed in the UI thread.
30 void Start();
32 // Destroys itself in appropriate thread.
33 void StopAndDestroy();
35 private:
36 friend class base::DeleteHelper<ExternalMetrics>;
38 ~ExternalMetrics();
40 // The max length of a message (name-value pair, plus header)
41 static const int kMetricsMessageMaxLength = 1024; // be generous
43 // Records an external crash of the given string description.
44 void RecordCrash(const std::string& crash_kind);
46 // Records a sparse histogram. |sample| is expected to be a sparse histogram.
47 void RecordSparseHistogram(const ::metrics::MetricSample& sample);
49 // Collects external events from metrics log file. This is run at periodic
50 // intervals.
52 // Returns the number of events collected.
53 int CollectEvents();
55 // Calls CollectEvents and reschedules a future collection.
56 void CollectEventsAndReschedule();
58 // Schedules a metrics event collection in the future.
59 void ScheduleCollector();
61 // Reference to stability metrics provider, for reporting external crashes.
62 CastStabilityMetricsProvider* stability_provider_;
64 // File used by libmetrics to send metrics to the browser process.
65 std::string uma_events_file_;
67 base::WeakPtrFactory<ExternalMetrics> weak_factory_;
69 DISALLOW_COPY_AND_ASSIGN(ExternalMetrics);
72 } // namespace metrics
73 } // namespace chromecast
75 #endif // CHROMECAST_BROWSER_METRICS_EXTERNAL_METRICS_H_