Cast: Stop logging kVideoFrameSentToEncoder and rename a couple events.
[chromium-blink-merge.git] / chrome / browser / chromeos / external_metrics.h
blob5be9fc2490bc8c3ff486fde128afa90506d245b5
1 // Copyright (c) 2010 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 CHROME_BROWSER_CHROMEOS_EXTERNAL_METRICS_H_
6 #define CHROME_BROWSER_CHROMEOS_EXTERNAL_METRICS_H_
8 #include <string>
10 #include "base/basictypes.h"
11 #include "base/compiler_specific.h"
12 #include "base/containers/hash_tables.h"
13 #include "base/files/file_path.h"
14 #include "base/gtest_prod_util.h"
15 #include "base/memory/ref_counted.h"
17 namespace chromeos {
19 // ExternalMetrics is a service that Chrome offers to Chrome OS to upload
20 // metrics to the UMA server on its behalf. Chrome periodically reads the
21 // content of a well-know file, and parses it into name-value pairs, each
22 // representing a Chrome OS metrics event. The events are logged using the
23 // normal UMA mechanism. The file is then truncated to zero size. Chrome uses
24 // flock() to synchronize accesses to the file.
25 class ExternalMetrics : public base::RefCountedThreadSafe<ExternalMetrics> {
26 public:
27 ExternalMetrics();
29 // Begins the external data collection. This service is started and stopped
30 // by the chrome metrics service. Calls to RecordAction originate in the
31 // File thread but are executed in the UI thread.
32 void Start();
34 private:
35 friend class base::RefCountedThreadSafe<ExternalMetrics>;
36 FRIEND_TEST_ALL_PREFIXES(ExternalMetricsTest, ParseExternalMetricsFile);
38 // There is one function with this type for each action.
39 typedef void (*RecordFunctionType)();
41 typedef void (*RecorderType)(const char*, const char*); // For testing only.
43 // The max length of a message (name-value pair, plus header)
44 static const int kMetricsMessageMaxLength = 1024; // be generous
46 ~ExternalMetrics();
48 // Passes an action event to the UMA service on the UI thread.
49 void RecordActionUI(std::string action_string);
51 // Passes an action event to the UMA service.
52 void RecordAction(const char* action_name);
54 // Records an external crash of the given string description to
55 // UMA service on the UI thread.
56 void RecordCrashUI(const std::string& crash_kind);
58 // Records an external crash of the given string description.
59 void RecordCrash(const std::string& crash_kind);
61 // Passes an histogram event to the UMA service. |histogram_data| is in the
62 // form <histogram-name> <sample> <min> <max> <buckets_count>.
63 void RecordHistogram(const char* histogram_data);
65 // Passes a linear histogram event to the UMA service. |histogram_data| is
66 // in the form <histogram-name> <sample> <max>.
67 void RecordLinearHistogram(const char* histogram_data);
69 // Passes a sparse histogram event to the UMA service. |histogram_data| is
70 // in the form <histogram-name> <sample>.
71 void RecordSparseHistogram(const char* histogram_data);
73 // Collects external events from metrics log file. This is run at periodic
74 // intervals.
75 void CollectEvents();
77 // Calls CollectEvents and reschedules a future collection.
78 void CollectEventsAndReschedule();
80 // Schedules a metrics event collection in the future.
81 void ScheduleCollector();
83 // Calls setup methods for Chrome OS field trials that need to be initialized
84 // based on data from the file system. They are setup here so that we can
85 // make absolutely sure that they are setup before we gather UMA statistics
86 // from ChromeOS.
87 void SetupFieldTrialsOnFileThread();
89 // Maps histogram or action names to recorder structs.
90 base::hash_map<std::string, RecordFunctionType> action_recorders_;
92 // Set containing known user actions.
93 base::hash_set<std::string> valid_user_actions_;
95 // Used for testing only.
96 RecorderType test_recorder_;
97 base::FilePath test_path_;
99 DISALLOW_COPY_AND_ASSIGN(ExternalMetrics);
102 } // namespace chromeos
104 #endif // CHROME_BROWSER_CHROMEOS_EXTERNAL_METRICS_H_