Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(303)

Unified Diff: chromecast/browser/metrics/external_metrics.h

Issue 701633002: Chromecast: adds handler to log metrics from external processes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: style nit Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chromecast/browser/metrics/external_metrics.h
diff --git a/chromecast/browser/metrics/external_metrics.h b/chromecast/browser/metrics/external_metrics.h
new file mode 100644
index 0000000000000000000000000000000000000000..2b4bc5381a5c81f5a9a64bee3fbc02a297c17b4d
--- /dev/null
+++ b/chromecast/browser/metrics/external_metrics.h
@@ -0,0 +1,72 @@
+// Copyright 2014 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 CHROMECAST_BROWSER_METRICS_EXTERNAL_METRICS_H_
+#define CHROMECAST_BROWSER_METRICS_EXTERNAL_METRICS_H_
+
+#include <string>
+
+#include "base/macros.h"
+#include "base/memory/weak_ptr.h"
+
+namespace metrics {
+class MetricSample;
+} // namespace metrics
+
+namespace chromecast {
+namespace metrics {
+
+class CastStabilityMetricsProvider;
+
+// ExternalMetrics service allows processes outside of the Chromecast browser
+// process to upload metrics via reading/writing to a known shared file.
+class ExternalMetrics {
+ public:
+ explicit ExternalMetrics(CastStabilityMetricsProvider* stability_provider);
+ ~ExternalMetrics();
+
+ // Begins external data collection. Calls to RecordAction originate in the
+ // File thread but are executed in the UI thread.
+ void Start();
+
+ private:
+ // The max length of a message (name-value pair, plus header)
+ static const int kMetricsMessageMaxLength = 1024; // be generous
+
+ // Passes an action event to the UMA service.
+ void RecordAction(const std::string& action_name);
+
+ // Records an external crash of the given string description.
+ void RecordCrash(const std::string& crash_kind);
+
+ // Records a sparse histogram. |sample| is expected to be a sparse histogram.
+ void RecordSparseHistogram(const ::metrics::MetricSample& sample);
+
+ // Collects external events from metrics log file. This is run at periodic
+ // intervals.
+ //
+ // Returns the number of events collected.
+ int CollectEvents();
+
+ // Calls CollectEvents and reschedules a future collection.
+ void CollectEventsAndReschedule();
+
+ // Schedules a metrics event collection in the future.
+ void ScheduleCollector();
+
+ // Reference to stability metrics provider, for reporting external crashes.
+ CastStabilityMetricsProvider* stability_provider_;
+
+ // File used by libmetrics to send metrics to the browser process.
+ std::string uma_events_file_;
+
+ base::WeakPtrFactory<ExternalMetrics> weak_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(ExternalMetrics);
+};
+
+} // namespace metrics
+} // namespace chromecast
+
+#endif // CHROMECAST_BROWSER_METRICS_EXTERNAL_METRICS_H_

Powered by Google App Engine
This is Rietveld 408576698