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_
10 #include "base/macros.h"
11 #include "base/memory/weak_ptr.h"
15 } // namespace metrics
17 namespace chromecast
{
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
{
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.
32 // Destroys itself in appropriate thread.
33 void StopAndDestroy();
36 friend class base::DeleteHelper
<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
52 // Returns the number of events collected.
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_