[email protected] | 88269e47 | 2011-06-24 06:32:59 | [diff] [blame] | 1 | // Copyright (c) 2011 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 | |||||
timvolodine | 0eec9ec | 2016-08-17 16:18:48 | [diff] [blame] | 5 | #ifndef COMPONENTS_SPELLCHECK_BROWSER_SPELLCHECK_HOST_METRICS_H_ |
6 | #define COMPONENTS_SPELLCHECK_BROWSER_SPELLCHECK_HOST_METRICS_H_ | ||||
[email protected] | 88269e47 | 2011-06-24 06:32:59 | [diff] [blame] | 7 | |
avi | 664c07b | 2015-12-26 02:18:31 | [diff] [blame] | 8 | #include <stddef.h> |
9 | |||||
[email protected] | 88269e47 | 2011-06-24 06:32:59 | [diff] [blame] | 10 | #include <string> |
Takuto Ikuta | 8332bf9d | 2019-01-05 03:58:00 | [diff] [blame] | 11 | #include <unordered_set> |
[email protected] | 88269e47 | 2011-06-24 06:32:59 | [diff] [blame] | 12 | #include <vector> |
13 | |||||
davidben | 411d3f7 | 2016-01-22 01:41:41 | [diff] [blame] | 14 | #include "base/strings/string16.h" |
[email protected] | cc86ccfe | 2013-06-28 00:10:50 | [diff] [blame] | 15 | #include "base/time/time.h" |
16 | #include "base/timer/timer.h" | ||||
Guillaume Jenkins | b0da3d99 | 2019-07-22 15:25:03 | [diff] [blame] | 17 | #include "build/build_config.h" |
[email protected] | 88269e47 | 2011-06-24 06:32:59 | [diff] [blame] | 18 | |
Guillaume Jenkins | 70ad4bc | 2019-12-12 20:22:49 | [diff] [blame] | 19 | #if defined(OS_WIN) |
20 | // Simple struct to keep track of how many languages are supported by which | ||||
21 | // spell checker. | ||||
22 | struct LocalesSupportInfo { | ||||
23 | size_t locales_supported_by_hunspell_and_native; | ||||
24 | size_t locales_supported_by_hunspell_only; | ||||
25 | size_t locales_supported_by_native_only; | ||||
26 | size_t unsupported_locales; | ||||
27 | }; | ||||
28 | #endif // defined(OS_WIN) | ||||
29 | |||||
[email protected] | 88269e47 | 2011-06-24 06:32:59 | [diff] [blame] | 30 | // A helper object for recording spell-check related histograms. |
31 | // This class encapsulates histogram names and metrics API. | ||||
32 | // This also carries a set of counters for collecting histograms | ||||
33 | // and a timer for making a periodical summary. | ||||
34 | // | ||||
35 | // We expect a user of SpellCheckHost class to instantiate this object, | ||||
36 | // and pass the metrics object to SpellCheckHost's factory method. | ||||
37 | // | ||||
38 | // metrics.reset(new SpellCheckHostMetrics()); | ||||
39 | // spell_check_host = SpellChecHost::Create(...., metrics.get()); | ||||
40 | // | ||||
41 | // The lifetime of the object should be managed by a caller, | ||||
42 | // and the lifetime should be longer than SpellCheckHost instance | ||||
43 | // because SpellCheckHost will use the object. | ||||
44 | class SpellCheckHostMetrics { | ||||
45 | public: | ||||
46 | SpellCheckHostMetrics(); | ||||
47 | ~SpellCheckHostMetrics(); | ||||
48 | |||||
49 | // Collects the number of words in the custom dictionary, which is | ||||
50 | // to be uploaded via UMA. | ||||
[email protected] | 1c2b985 | 2013-04-06 01:16:42 | [diff] [blame] | 51 | static void RecordCustomWordCountStats(size_t count); |
[email protected] | 88269e47 | 2011-06-24 06:32:59 | [diff] [blame] | 52 | |
53 | // Collects status of spellchecking enabling state, which is | ||||
54 | // to be uploaded via UMA | ||||
55 | void RecordEnabledStats(bool enabled); | ||||
56 | |||||
57 | // Collects a histogram for dictionary corruption rate | ||||
58 | // to be uploaded via UMA | ||||
59 | void RecordDictionaryCorruptionStats(bool corrupted); | ||||
60 | |||||
61 | // Collects status of spellchecking enabling state, which is | ||||
62 | // to be uploaded via UMA | ||||
[email protected] | a04db82 | 2013-12-11 19:14:40 | [diff] [blame] | 63 | void RecordCheckedWordStats(const base::string16& word, bool misspell); |
[email protected] | 88269e47 | 2011-06-24 06:32:59 | [diff] [blame] | 64 | |
65 | // Collects a histogram for misspelled word replacement | ||||
66 | // to be uploaded via UMA | ||||
67 | void RecordReplacedWordStats(int delta); | ||||
68 | |||||
69 | // Collects a histogram for context menu showing as a spell correction | ||||
70 | // attempt to be uploaded via UMA | ||||
71 | void RecordSuggestionStats(int delta); | ||||
72 | |||||
[email protected] | 8e6ca16 | 2013-02-22 11:37:30 | [diff] [blame] | 73 | // Records if spelling service is enabled or disabled. |
74 | void RecordSpellingServiceStats(bool enabled); | ||||
75 | |||||
Guillaume Jenkins | b0da3d99 | 2019-07-22 15:25:03 | [diff] [blame] | 76 | #if defined(OS_WIN) |
Guillaume Jenkins | 70ad4bc | 2019-12-12 20:22:49 | [diff] [blame] | 77 | // Records spell check support for user-added Chrome languages that are not |
78 | // eligible for spell checking (due to the hard-coded spell check locales | ||||
79 | // list). | ||||
80 | void RecordAcceptLanguageStats(const LocalesSupportInfo& locales_info); | ||||
Guillaume Jenkins | b0da3d99 | 2019-07-22 15:25:03 | [diff] [blame] | 81 | |
Guillaume Jenkins | 70ad4bc | 2019-12-12 20:22:49 | [diff] [blame] | 82 | // Records which spell checker can handle which enabled spell check locales. |
83 | void RecordSpellcheckLanguageStats(const LocalesSupportInfo& locales_info); | ||||
Guillaume Jenkins | b0da3d99 | 2019-07-22 15:25:03 | [diff] [blame] | 84 | #endif // defined(OS_WIN) |
85 | |||||
[email protected] | 253f137 | 2011-09-29 17:36:55 | [diff] [blame] | 86 | private: |
[email protected] | 80131930 | 2012-11-28 00:54:19 | [diff] [blame] | 87 | friend class SpellcheckHostMetricsTest; |
[email protected] | 88269e47 | 2011-06-24 06:32:59 | [diff] [blame] | 88 | void OnHistogramTimerExpired(); |
89 | |||||
[email protected] | 7e1f665 | 2011-06-27 07:10:43 | [diff] [blame] | 90 | // Records various counters without changing their values. |
91 | void RecordWordCounts(); | ||||
92 | |||||
[email protected] | 88269e47 | 2011-06-24 06:32:59 | [diff] [blame] | 93 | // Number of corrected words of checked words. |
94 | int misspelled_word_count_; | ||||
[email protected] | 80131930 | 2012-11-28 00:54:19 | [diff] [blame] | 95 | int last_misspelled_word_count_; |
96 | |||||
[email protected] | 88269e47 | 2011-06-24 06:32:59 | [diff] [blame] | 97 | // Number of checked words. |
98 | int spellchecked_word_count_; | ||||
[email protected] | 80131930 | 2012-11-28 00:54:19 | [diff] [blame] | 99 | int last_spellchecked_word_count_; |
100 | |||||
[email protected] | 88269e47 | 2011-06-24 06:32:59 | [diff] [blame] | 101 | // Number of suggestion list showings. |
102 | int suggestion_show_count_; | ||||
[email protected] | 80131930 | 2012-11-28 00:54:19 | [diff] [blame] | 103 | int last_suggestion_show_count_; |
104 | |||||
[email protected] | 88269e47 | 2011-06-24 06:32:59 | [diff] [blame] | 105 | // Number of misspelled words replaced by a user. |
106 | int replaced_word_count_; | ||||
[email protected] | 80131930 | 2012-11-28 00:54:19 | [diff] [blame] | 107 | int last_replaced_word_count_; |
108 | |||||
109 | // Last recorded number of unique words. | ||||
Raul Tambre | 80937cd4 | 2019-02-11 12:07:34 | [diff] [blame] | 110 | size_t last_unique_word_count_; |
[email protected] | 80131930 | 2012-11-28 00:54:19 | [diff] [blame] | 111 | |
[email protected] | 88269e47 | 2011-06-24 06:32:59 | [diff] [blame] | 112 | // Time when first spellcheck happened. |
[email protected] | 253f137 | 2011-09-29 17:36:55 | [diff] [blame] | 113 | base::TimeTicks start_time_; |
[email protected] | 88269e47 | 2011-06-24 06:32:59 | [diff] [blame] | 114 | // Set of checked words in the hashed form. |
Takuto Ikuta | 8332bf9d | 2019-01-05 03:58:00 | [diff] [blame] | 115 | std::unordered_set<std::string> checked_word_hashes_; |
danakj | 8c3eb80 | 2015-09-24 07:53:00 | [diff] [blame] | 116 | base::RepeatingTimer recording_timer_; |
[email protected] | 88269e47 | 2011-06-24 06:32:59 | [diff] [blame] | 117 | }; |
118 | |||||
timvolodine | 0eec9ec | 2016-08-17 16:18:48 | [diff] [blame] | 119 | #endif // COMPONENTS_SPELLCHECK_BROWSER_SPELLCHECK_HOST_METRICS_H_ |