OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #ifndef CHROMECAST_BROWSER_METRICS_EXTERNAL_METRICS_H_ |
| 6 #define CHROMECAST_BROWSER_METRICS_EXTERNAL_METRICS_H_ |
| 7 |
| 8 #include <string> |
| 9 |
| 10 #include "base/macros.h" |
| 11 #include "base/memory/weak_ptr.h" |
| 12 |
| 13 namespace metrics { |
| 14 class MetricSample; |
| 15 } // namespace metrics |
| 16 |
| 17 namespace chromecast { |
| 18 namespace metrics { |
| 19 |
| 20 class CastStabilityMetricsProvider; |
| 21 |
| 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); |
| 27 ~ExternalMetrics(); |
| 28 |
| 29 // Begins external data collection. Calls to RecordAction originate in the |
| 30 // File thread but are executed in the UI thread. |
| 31 void Start(); |
| 32 |
| 33 private: |
| 34 // The max length of a message (name-value pair, plus header) |
| 35 static const int kMetricsMessageMaxLength = 1024; // be generous |
| 36 |
| 37 // Passes an action event to the UMA service. |
| 38 void RecordAction(const std::string& action_name); |
| 39 |
| 40 // Records an external crash of the given string description. |
| 41 void RecordCrash(const std::string& crash_kind); |
| 42 |
| 43 // Records a sparse histogram. |sample| is expected to be a sparse histogram. |
| 44 void RecordSparseHistogram(const ::metrics::MetricSample& sample); |
| 45 |
| 46 // Collects external events from metrics log file. This is run at periodic |
| 47 // intervals. |
| 48 // |
| 49 // Returns the number of events collected. |
| 50 int CollectEvents(); |
| 51 |
| 52 // Calls CollectEvents and reschedules a future collection. |
| 53 void CollectEventsAndReschedule(); |
| 54 |
| 55 // Schedules a metrics event collection in the future. |
| 56 void ScheduleCollector(); |
| 57 |
| 58 // Reference to stability metrics provider, for reporting external crashes. |
| 59 CastStabilityMetricsProvider* stability_provider_; |
| 60 |
| 61 // File used by libmetrics to send metrics to the browser process. |
| 62 std::string uma_events_file_; |
| 63 |
| 64 base::WeakPtrFactory<ExternalMetrics> weak_factory_; |
| 65 |
| 66 DISALLOW_COPY_AND_ASSIGN(ExternalMetrics); |
| 67 }; |
| 68 |
| 69 } // namespace metrics |
| 70 } // namespace chromecast |
| 71 |
| 72 #endif // CHROMECAST_BROWSER_METRICS_EXTERNAL_METRICS_H_ |
OLD | NEW |