blob: 60e61d96b79aac41fe46493d0c97af8e82b342e1 [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
8#include <string>
9#include <vector>
10
[email protected]14c1c232013-06-11 17:52:4411#include "base/containers/hash_tables.h"
[email protected]cc86ccfe2013-06-28 00:10:5012#include "base/time/time.h"
13#include "base/timer/timer.h"
[email protected]88269e472011-06-24 06:32:5914
15// A helper object for recording spell-check related histograms.
16// This class encapsulates histogram names and metrics API.
17// This also carries a set of counters for collecting histograms
18// and a timer for making a periodical summary.
19//
20// We expect a user of SpellCheckHost class to instantiate this object,
21// and pass the metrics object to SpellCheckHost's factory method.
22//
23// metrics.reset(new SpellCheckHostMetrics());
24// spell_check_host = SpellChecHost::Create(...., metrics.get());
25//
26// The lifetime of the object should be managed by a caller,
27// and the lifetime should be longer than SpellCheckHost instance
28// because SpellCheckHost will use the object.
29class SpellCheckHostMetrics {
30 public:
31 SpellCheckHostMetrics();
32 ~SpellCheckHostMetrics();
33
34 // Collects the number of words in the custom dictionary, which is
35 // to be uploaded via UMA.
[email protected]1c2b9852013-04-06 01:16:4236 static void RecordCustomWordCountStats(size_t count);
[email protected]88269e472011-06-24 06:32:5937
38 // Collects status of spellchecking enabling state, which is
39 // to be uploaded via UMA
40 void RecordEnabledStats(bool enabled);
41
42 // Collects a histogram for dictionary corruption rate
43 // to be uploaded via UMA
44 void RecordDictionaryCorruptionStats(bool corrupted);
45
46 // Collects status of spellchecking enabling state, which is
47 // to be uploaded via UMA
[email protected]a04db822013-12-11 19:14:4048 void RecordCheckedWordStats(const base::string16& word, bool misspell);
[email protected]88269e472011-06-24 06:32:5949
50 // Collects a histogram for misspelled word replacement
51 // to be uploaded via UMA
52 void RecordReplacedWordStats(int delta);
53
54 // Collects a histogram for context menu showing as a spell correction
55 // attempt to be uploaded via UMA
56 void RecordSuggestionStats(int delta);
57
[email protected]8e6ca162013-02-22 11:37:3058 // Records if spelling service is enabled or disabled.
59 void RecordSpellingServiceStats(bool enabled);
60
[email protected]253f1372011-09-29 17:36:5561 private:
[email protected]801319302012-11-28 00:54:1962 friend class SpellcheckHostMetricsTest;
[email protected]88269e472011-06-24 06:32:5963 void OnHistogramTimerExpired();
64
[email protected]7e1f6652011-06-27 07:10:4365 // Records various counters without changing their values.
66 void RecordWordCounts();
67
[email protected]88269e472011-06-24 06:32:5968 // Number of corrected words of checked words.
69 int misspelled_word_count_;
[email protected]801319302012-11-28 00:54:1970 int last_misspelled_word_count_;
71
[email protected]88269e472011-06-24 06:32:5972 // Number of checked words.
73 int spellchecked_word_count_;
[email protected]801319302012-11-28 00:54:1974 int last_spellchecked_word_count_;
75
[email protected]88269e472011-06-24 06:32:5976 // Number of suggestion list showings.
77 int suggestion_show_count_;
[email protected]801319302012-11-28 00:54:1978 int last_suggestion_show_count_;
79
[email protected]88269e472011-06-24 06:32:5980 // Number of misspelled words replaced by a user.
81 int replaced_word_count_;
[email protected]801319302012-11-28 00:54:1982 int last_replaced_word_count_;
83
84 // Last recorded number of unique words.
85 int last_unique_word_count_;
86
[email protected]88269e472011-06-24 06:32:5987 // Time when first spellcheck happened.
[email protected]253f1372011-09-29 17:36:5588 base::TimeTicks start_time_;
[email protected]88269e472011-06-24 06:32:5989 // Set of checked words in the hashed form.
90 base::hash_set<std::string> checked_word_hashes_;
91 base::RepeatingTimer<SpellCheckHostMetrics> recording_timer_;
92};
93
[email protected]8ec71262011-07-28 08:12:4694#endif // CHROME_BROWSER_SPELLCHECKER_SPELLCHECK_HOST_METRICS_H_