blob: 1ad9ba451c780afaebd1eee018dbf2fa4803fb15 [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#include "chrome/browser/spellchecker/spellcheck_host_metrics.h"
[email protected]88269e472011-06-24 06:32:596
7#include "base/md5.h"
8#include "base/metrics/histogram.h"
9
10SpellCheckHostMetrics::SpellCheckHostMetrics()
[email protected]7e1f6652011-06-27 07:10:4311 : misspelled_word_count_(0),
12 spellchecked_word_count_(0),
13 suggestion_show_count_(0),
14 replaced_word_count_(0),
15 start_time_(base::Time::Now()) {
[email protected]88269e472011-06-24 06:32:5916 const uint64 kHistogramTimerDurationInMinutes = 30;
[email protected]d323a172011-09-02 18:23:0217 recording_timer_.Start(FROM_HERE,
[email protected]88269e472011-06-24 06:32:5918 base::TimeDelta::FromMinutes(kHistogramTimerDurationInMinutes),
19 this, &SpellCheckHostMetrics::OnHistogramTimerExpired);
[email protected]7e1f6652011-06-27 07:10:4320 RecordWordCounts();
[email protected]88269e472011-06-24 06:32:5921}
22
23SpellCheckHostMetrics::~SpellCheckHostMetrics() {
24}
25
26void SpellCheckHostMetrics::RecordCustomWordCountStats(size_t count) {
27 UMA_HISTOGRAM_COUNTS("SpellCheck.CustomWords", count);
28}
29
30void SpellCheckHostMetrics::RecordEnabledStats(bool enabled) {
31 UMA_HISTOGRAM_BOOLEAN("SpellCheck.Enabled", enabled);
32 // Because SpellCheckHost is instantiated lazily, the size of
33 // custom dictionary is unknown at this time. We mark it as -1 and
34 // record actual value later. See SpellCheckHost for more detail.
35 if (enabled)
36 RecordCustomWordCountStats(-1);
37}
38
39void SpellCheckHostMetrics::RecordCheckedWordStats(const string16& word,
40 bool misspell) {
41 spellchecked_word_count_++;
42 if (misspell) {
43 misspelled_word_count_++;
44 // If an user misspelled, that user should be counted as a part of
45 // the population. So we ensure to instantiate the histogram
46 // entries here at the first time.
47 if (misspelled_word_count_ == 1)
48 RecordReplacedWordStats(0);
49 }
50
51 int percentage = (100 * misspelled_word_count_) / spellchecked_word_count_;
52 UMA_HISTOGRAM_PERCENTAGE("SpellCheck.MisspellRatio", percentage);
53
54 // Collects actual number of checked words, excluding duplication.
[email protected]0ad1d2d62011-07-18 16:54:5855 base::MD5Digest digest;
56 base::MD5Sum(reinterpret_cast<const unsigned char*>(word.c_str()),
[email protected]88269e472011-06-24 06:32:5957 word.size() * sizeof(char16), &digest);
[email protected]0ad1d2d62011-07-18 16:54:5858 checked_word_hashes_.insert(base::MD5DigestToBase16(digest));
[email protected]7e1f6652011-06-27 07:10:4359
60 RecordWordCounts();
[email protected]88269e472011-06-24 06:32:5961}
62
63void SpellCheckHostMetrics::OnHistogramTimerExpired() {
64 if (0 < spellchecked_word_count_) {
65 // Collects word checking rate, which is represented
66 // as a word count per hour.
67 base::TimeDelta since_start = base::Time::Now() - start_time_;
68 size_t checked_words_per_hour = spellchecked_word_count_ *
69 base::TimeDelta::FromHours(1).InSeconds() / since_start.InSeconds();
70 UMA_HISTOGRAM_COUNTS("SpellCheck.CheckedWordsPerHour",
71 checked_words_per_hour);
72 }
73}
74
75void SpellCheckHostMetrics::RecordDictionaryCorruptionStats(bool corrupted) {
76 UMA_HISTOGRAM_BOOLEAN("SpellCheck.DictionaryCorrupted", corrupted);
77}
78
79void SpellCheckHostMetrics::RecordSuggestionStats(int delta) {
80 suggestion_show_count_ += delta;
[email protected]7e1f6652011-06-27 07:10:4381 // RecordReplacedWordStats() Calls RecordWordCounts() eventually.
[email protected]88269e472011-06-24 06:32:5982 RecordReplacedWordStats(0);
83}
84
85void SpellCheckHostMetrics::RecordReplacedWordStats(int delta) {
86 replaced_word_count_ += delta;
[email protected]88269e472011-06-24 06:32:5987
88 if (misspelled_word_count_) {
89 // zero |misspelled_word_count_| is possible when an extension
90 // gives the misspelling, which is not recorded as a part of this
91 // metrics.
92 int percentage = (100 * replaced_word_count_) / misspelled_word_count_;
93 UMA_HISTOGRAM_PERCENTAGE("SpellCheck.ReplaceRatio", percentage);
94 }
95
96 if (suggestion_show_count_) {
97 int percentage = (100 * replaced_word_count_) / suggestion_show_count_;
98 UMA_HISTOGRAM_PERCENTAGE("SpellCheck.SuggestionHitRatio", percentage);
99 }
[email protected]7e1f6652011-06-27 07:10:43100
101 RecordWordCounts();
102}
103
104void SpellCheckHostMetrics::RecordWordCounts() {
105 UMA_HISTOGRAM_COUNTS("SpellCheck.CheckedWords", spellchecked_word_count_);
106 UMA_HISTOGRAM_COUNTS("SpellCheck.MisspelledWords", misspelled_word_count_);
107 UMA_HISTOGRAM_COUNTS("SpellCheck.ReplacedWords", replaced_word_count_);
108 UMA_HISTOGRAM_COUNTS("SpellCheck.UniqueWords", checked_word_hashes_.size());
109 UMA_HISTOGRAM_COUNTS("SpellCheck.ShownSuggestions", suggestion_show_count_);
[email protected]88269e472011-06-24 06:32:59110}