blob: fe0df1570b83d920919fef15dea280e1e625e68e [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
[email protected]8ec71262011-07-28 08:12:465#ifndef CHROME_BROWSER_SPELLCHECKER_SPELLCHECK_HOST_METRICS_H_
6#define CHROME_BROWSER_SPELLCHECKER_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>
11#include <vector>
12
[email protected]14c1c232013-06-11 17:52:4413#include "base/containers/hash_tables.h"
[email protected]cc86ccfe2013-06-28 00:10:5014#include "base/time/time.h"
15#include "base/timer/timer.h"
[email protected]88269e472011-06-24 06:32:5916
17// A helper object for recording spell-check related histograms.
18// This class encapsulates histogram names and metrics API.
19// This also carries a set of counters for collecting histograms
20// and a timer for making a periodical summary.
21//
22// We expect a user of SpellCheckHost class to instantiate this object,
23// and pass the metrics object to SpellCheckHost's factory method.
24//
25// metrics.reset(new SpellCheckHostMetrics());
26// spell_check_host = SpellChecHost::Create(...., metrics.get());
27//
28// The lifetime of the object should be managed by a caller,
29// and the lifetime should be longer than SpellCheckHost instance
30// because SpellCheckHost will use the object.
31class SpellCheckHostMetrics {
32 public:
33 SpellCheckHostMetrics();
34 ~SpellCheckHostMetrics();
35
36 // Collects the number of words in the custom dictionary, which is
37 // to be uploaded via UMA.
[email protected]1c2b9852013-04-06 01:16:4238 static void RecordCustomWordCountStats(size_t count);
[email protected]88269e472011-06-24 06:32:5939
40 // Collects status of spellchecking enabling state, which is
41 // to be uploaded via UMA
42 void RecordEnabledStats(bool enabled);
43
44 // Collects a histogram for dictionary corruption rate
45 // to be uploaded via UMA
46 void RecordDictionaryCorruptionStats(bool corrupted);
47
48 // Collects status of spellchecking enabling state, which is
49 // to be uploaded via UMA
[email protected]a04db822013-12-11 19:14:4050 void RecordCheckedWordStats(const base::string16& word, bool misspell);
[email protected]88269e472011-06-24 06:32:5951
52 // Collects a histogram for misspelled word replacement
53 // to be uploaded via UMA
54 void RecordReplacedWordStats(int delta);
55
56 // Collects a histogram for context menu showing as a spell correction
57 // attempt to be uploaded via UMA
58 void RecordSuggestionStats(int delta);
59
[email protected]8e6ca162013-02-22 11:37:3060 // Records if spelling service is enabled or disabled.
61 void RecordSpellingServiceStats(bool enabled);
62
[email protected]253f1372011-09-29 17:36:5563 private:
[email protected]801319302012-11-28 00:54:1964 friend class SpellcheckHostMetricsTest;
[email protected]88269e472011-06-24 06:32:5965 void OnHistogramTimerExpired();
66
[email protected]7e1f6652011-06-27 07:10:4367 // Records various counters without changing their values.
68 void RecordWordCounts();
69
[email protected]88269e472011-06-24 06:32:5970 // Number of corrected words of checked words.
71 int misspelled_word_count_;
[email protected]801319302012-11-28 00:54:1972 int last_misspelled_word_count_;
73
[email protected]88269e472011-06-24 06:32:5974 // Number of checked words.
75 int spellchecked_word_count_;
[email protected]801319302012-11-28 00:54:1976 int last_spellchecked_word_count_;
77
[email protected]88269e472011-06-24 06:32:5978 // Number of suggestion list showings.
79 int suggestion_show_count_;
[email protected]801319302012-11-28 00:54:1980 int last_suggestion_show_count_;
81
[email protected]88269e472011-06-24 06:32:5982 // Number of misspelled words replaced by a user.
83 int replaced_word_count_;
[email protected]801319302012-11-28 00:54:1984 int last_replaced_word_count_;
85
86 // Last recorded number of unique words.
87 int last_unique_word_count_;
88
[email protected]88269e472011-06-24 06:32:5989 // Time when first spellcheck happened.
[email protected]253f1372011-09-29 17:36:5590 base::TimeTicks start_time_;
[email protected]88269e472011-06-24 06:32:5991 // Set of checked words in the hashed form.
92 base::hash_set<std::string> checked_word_hashes_;
danakj8c3eb802015-09-24 07:53:0093 base::RepeatingTimer recording_timer_;
[email protected]88269e472011-06-24 06:32:5994};
95
[email protected]8ec71262011-07-28 08:12:4696#endif // CHROME_BROWSER_SPELLCHECKER_SPELLCHECK_HOST_METRICS_H_