blob: dc2be738107a621efaee451196bdc732bb753788 [file] [log] [blame]
[email protected]88269e472011-06-24 06:32:591// 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
timvolodine0eec9ec2016-08-17 16:18:485#ifndef COMPONENTS_SPELLCHECK_BROWSER_SPELLCHECK_HOST_METRICS_H_
6#define COMPONENTS_SPELLCHECK_BROWSER_SPELLCHECK_HOST_METRICS_H_
[email protected]88269e472011-06-24 06:32:597
avi664c07b2015-12-26 02:18:318#include <stddef.h>
9
[email protected]88269e472011-06-24 06:32:5910#include <string>
Takuto Ikuta8332bf9d2019-01-05 03:58:0011#include <unordered_set>
[email protected]88269e472011-06-24 06:32:5912#include <vector>
13
davidben411d3f72016-01-22 01:41:4114#include "base/strings/string16.h"
[email protected]cc86ccfe2013-06-28 00:10:5015#include "base/time/time.h"
16#include "base/timer/timer.h"
Guillaume Jenkinsb0da3d992019-07-22 15:25:0317#include "build/build_config.h"
[email protected]88269e472011-06-24 06:32:5918
Guillaume Jenkins70ad4bc2019-12-12 20:22:4919#if defined(OS_WIN)
20// Simple struct to keep track of how many languages are supported by which
21// spell checker.
22struct 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]88269e472011-06-24 06:32:5930// 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.
44class 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]1c2b9852013-04-06 01:16:4251 static void RecordCustomWordCountStats(size_t count);
[email protected]88269e472011-06-24 06:32:5952
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]a04db822013-12-11 19:14:4063 void RecordCheckedWordStats(const base::string16& word, bool misspell);
[email protected]88269e472011-06-24 06:32:5964
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]8e6ca162013-02-22 11:37:3073 // Records if spelling service is enabled or disabled.
74 void RecordSpellingServiceStats(bool enabled);
75
Guillaume Jenkinsb0da3d992019-07-22 15:25:0376#if defined(OS_WIN)
Guillaume Jenkins70ad4bc2019-12-12 20:22:4977 // 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 Jenkinsb0da3d992019-07-22 15:25:0381
Guillaume Jenkins70ad4bc2019-12-12 20:22:4982 // Records which spell checker can handle which enabled spell check locales.
83 void RecordSpellcheckLanguageStats(const LocalesSupportInfo& locales_info);
Guillaume Jenkinsb0da3d992019-07-22 15:25:0384#endif // defined(OS_WIN)
85
[email protected]253f1372011-09-29 17:36:5586 private:
[email protected]801319302012-11-28 00:54:1987 friend class SpellcheckHostMetricsTest;
[email protected]88269e472011-06-24 06:32:5988 void OnHistogramTimerExpired();
89
[email protected]7e1f6652011-06-27 07:10:4390 // Records various counters without changing their values.
91 void RecordWordCounts();
92
[email protected]88269e472011-06-24 06:32:5993 // Number of corrected words of checked words.
94 int misspelled_word_count_;
[email protected]801319302012-11-28 00:54:1995 int last_misspelled_word_count_;
96
[email protected]88269e472011-06-24 06:32:5997 // Number of checked words.
98 int spellchecked_word_count_;
[email protected]801319302012-11-28 00:54:1999 int last_spellchecked_word_count_;
100
[email protected]88269e472011-06-24 06:32:59101 // Number of suggestion list showings.
102 int suggestion_show_count_;
[email protected]801319302012-11-28 00:54:19103 int last_suggestion_show_count_;
104
[email protected]88269e472011-06-24 06:32:59105 // Number of misspelled words replaced by a user.
106 int replaced_word_count_;
[email protected]801319302012-11-28 00:54:19107 int last_replaced_word_count_;
108
109 // Last recorded number of unique words.
Raul Tambre80937cd42019-02-11 12:07:34110 size_t last_unique_word_count_;
[email protected]801319302012-11-28 00:54:19111
[email protected]88269e472011-06-24 06:32:59112 // Time when first spellcheck happened.
[email protected]253f1372011-09-29 17:36:55113 base::TimeTicks start_time_;
[email protected]88269e472011-06-24 06:32:59114 // Set of checked words in the hashed form.
Takuto Ikuta8332bf9d2019-01-05 03:58:00115 std::unordered_set<std::string> checked_word_hashes_;
danakj8c3eb802015-09-24 07:53:00116 base::RepeatingTimer recording_timer_;
[email protected]88269e472011-06-24 06:32:59117};
118
timvolodine0eec9ec2016-08-17 16:18:48119#endif // COMPONENTS_SPELLCHECK_BROWSER_SPELLCHECK_HOST_METRICS_H_