diff options
author | morrita@chromium.org <morrita@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-06-20 05:46:20 +0000 |
---|---|---|
committer | morrita@chromium.org <morrita@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-06-20 05:46:20 +0000 |
commit | f07f1111e554690df5887373e6c322ac2066cd0a (patch) | |
tree | 4ca7716c68e169c236a8bc03905b336a19bfa543 | |
parent | 532e568335ccd1ed21907b5012b5ead084530588 (diff) | |
download | chromium_src-f07f1111e554690df5887373e6c322ac2066cd0a.zip chromium_src-f07f1111e554690df5887373e6c322ac2066cd0a.tar.gz chromium_src-f07f1111e554690df5887373e6c322ac2066cd0a.tar.bz2 |
Added more spellcheck related UMA histograms
This change added two more histograms:
- "SpellCheck.CheckedWordsPerHour", which indicates an approximated
number of the word which is checked by the spellchecker. And
- "SpellCheck.UniqueWords", which is the count of unique checked word
TEST=manual
BUG=none
Review URL: http://codereview.chromium.org/7148009
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@89638 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/profiles/profile_impl.cc | 4 | ||||
-rw-r--r-- | chrome/browser/spellcheck_host.cc | 6 | ||||
-rw-r--r-- | chrome/browser/spellcheck_host.h | 5 | ||||
-rw-r--r-- | chrome/browser/spellcheck_host_impl.cc | 45 | ||||
-rw-r--r-- | chrome/browser/spellcheck_host_impl.h | 20 | ||||
-rw-r--r-- | chrome/browser/spellcheck_message_filter.cc | 5 | ||||
-rw-r--r-- | chrome/browser/spellcheck_message_filter.h | 2 | ||||
-rw-r--r-- | chrome/common/spellcheck_messages.h | 3 | ||||
-rw-r--r-- | chrome/renderer/spellchecker/spellcheck_provider.cc | 2 |
9 files changed, 77 insertions, 15 deletions
diff --git a/chrome/browser/profiles/profile_impl.cc b/chrome/browser/profiles/profile_impl.cc index 3a00e7b..bc12846 100644 --- a/chrome/browser/profiles/profile_impl.cc +++ b/chrome/browser/profiles/profile_impl.cc @@ -40,6 +40,7 @@ #include "chrome/browser/history/history.h" #include "chrome/browser/history/top_sites.h" #include "chrome/browser/instant/instant_controller.h" +#include "chrome/browser/metrics/metrics_service.h" #include "chrome/browser/net/chrome_url_request_context.h" #include "chrome/browser/net/gaia/token_service.h" #include "chrome/browser/net/net_pref_observer.h" @@ -1254,7 +1255,8 @@ void ProfileImpl::ReinitializeSpellCheckHost(bool force) { spellcheck_host_ = SpellCheckHost::Create( this, prefs->GetString(prefs::kSpellCheckDictionary), - GetRequestContext()); + GetRequestContext(), + g_browser_process->metrics_service()->recording_active()); } else if (notify) { // The spellchecker has been disabled. SpellCheckHostInitialized(); diff --git a/chrome/browser/spellcheck_host.cc b/chrome/browser/spellcheck_host.cc index 6517da3..16e94b5 100644 --- a/chrome/browser/spellcheck_host.cc +++ b/chrome/browser/spellcheck_host.cc @@ -17,11 +17,13 @@ scoped_refptr<SpellCheckHost> SpellCheckHost::Create( SpellCheckHostObserver* observer, const std::string& language, - net::URLRequestContextGetter* request_context_getter) { + net::URLRequestContextGetter* request_context_getter, + bool metrics_enabled) { scoped_refptr<SpellCheckHostImpl> host = new SpellCheckHostImpl(observer, language, - request_context_getter); + request_context_getter, + metrics_enabled); if (!host) return NULL; diff --git a/chrome/browser/spellcheck_host.h b/chrome/browser/spellcheck_host.h index fe3b368..a174358 100644 --- a/chrome/browser/spellcheck_host.h +++ b/chrome/browser/spellcheck_host.h @@ -52,7 +52,8 @@ class SpellCheckHost static scoped_refptr<SpellCheckHost> Create( SpellCheckHostObserver* observer, const std::string& language, - net::URLRequestContextGetter* request_context_getter); + net::URLRequestContextGetter* request_context_getter, + bool metrics_enabled); // Collects the number of words in the custom dictionary, which is // to be uploaded via UMA @@ -86,7 +87,7 @@ class SpellCheckHost // Collects status of spellchecking enabling state, which is // to be uploaded via UMA - virtual void RecordCheckedWordStats(bool misspell) = 0; + virtual void RecordCheckedWordStats(const string16& word, bool misspell) = 0; // Collects a histogram for context menu showing as a spell correction // attempt to be uploaded via UMA. diff --git a/chrome/browser/spellcheck_host_impl.cc b/chrome/browser/spellcheck_host_impl.cc index 2bac0c8..53621b6 100644 --- a/chrome/browser/spellcheck_host_impl.cc +++ b/chrome/browser/spellcheck_host_impl.cc @@ -8,6 +8,7 @@ #include "base/file_util.h" #include "base/logging.h" +#include "base/md5.h" #include "base/metrics/histogram.h" #include "base/path_service.h" #include "base/string_split.h" @@ -82,17 +83,20 @@ FilePath GetFallbackFilePath(const FilePath& first_choice) { SpellCheckHostImpl::SpellCheckHostImpl( SpellCheckHostObserver* observer, const std::string& language, - net::URLRequestContextGetter* request_context_getter) + net::URLRequestContextGetter* request_context_getter, + bool metrics_enabled) : observer_(observer), language_(language), file_(base::kInvalidPlatformFileValue), tried_to_download_(false), use_platform_spellchecker_(false), request_context_getter_(request_context_getter), + metrics_enabled_(metrics_enabled), misspelled_word_count_(0), spellchecked_word_count_(0), suggestion_show_count_(0), - replaced_word_count_(0) { + replaced_word_count_(0), + start_time_(base::Time::Now()) { DCHECK(observer_); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); @@ -103,6 +107,12 @@ SpellCheckHostImpl::SpellCheckHostImpl( registrar_.Add(this, NotificationType::RENDERER_PROCESS_CREATED, NotificationService::AllSources()); + if (metrics_enabled) { + const uint64 kHistogramTimerDurationInMinutes = 30; + histogram_timer_.Start( + base::TimeDelta::FromMinutes(kHistogramTimerDurationInMinutes), + this, &SpellCheckHostImpl::OnHistogramTimerExpired); + } } SpellCheckHostImpl::~SpellCheckHostImpl() { @@ -301,7 +311,10 @@ void SpellCheckHostImpl::WriteWordToCustomDictionary(const std::string& word) { file_util::CloseFile(f); } -void SpellCheckHostImpl::RecordCheckedWordStats(bool misspell) { +void SpellCheckHostImpl::RecordCheckedWordStats(const string16& word, + bool misspell) { + if (!metrics_enabled_) + return; spellchecked_word_count_++; if (misspell) { misspelled_word_count_++; @@ -314,18 +327,44 @@ void SpellCheckHostImpl::RecordCheckedWordStats(bool misspell) { int percentage = (100 * misspelled_word_count_) / spellchecked_word_count_; UMA_HISTOGRAM_PERCENTAGE("SpellCheck.MisspellRatio", percentage); + + // Collects actual number of checked words, excluding duplication. + MD5Digest digest; + MD5Sum(reinterpret_cast<const unsigned char*>(word.c_str()), + word.size() * sizeof(char16), &digest); + checked_word_hashes_.insert(MD5DigestToBase16(digest)); + UMA_HISTOGRAM_COUNTS("SpellCheck.UniqueWords", checked_word_hashes_.size()); +} + +void SpellCheckHostImpl::OnHistogramTimerExpired() { + DCHECK(metrics_enabled_); + if (0 < spellchecked_word_count_) { + // Collects word checking rate, which is represented + // as a word count per hour. + base::TimeDelta since_start = base::Time::Now() - start_time_; + size_t checked_words_per_hour = spellchecked_word_count_ + * base::TimeDelta::FromHours(1).InSeconds() / since_start.InSeconds(); + UMA_HISTOGRAM_COUNTS("SpellCheck.CheckedWordsPerHour", + checked_words_per_hour); + } } void SpellCheckHostImpl::RecordDictionaryCorruptionStats(bool corrupted) { + if (!metrics_enabled_) + return; UMA_HISTOGRAM_BOOLEAN("SpellCheck.DictionaryCorrupted", corrupted); } void SpellCheckHostImpl::RecordSuggestionStats(int delta) { + if (!metrics_enabled_) + return; suggestion_show_count_ += delta; RecordReplacedWordStats(0); } void SpellCheckHostImpl::RecordReplacedWordStats(int delta) { + if (!metrics_enabled_) + return; replaced_word_count_ += delta; if (misspelled_word_count_) { diff --git a/chrome/browser/spellcheck_host_impl.h b/chrome/browser/spellcheck_host_impl.h index 316e94b..bf58c98 100644 --- a/chrome/browser/spellcheck_host_impl.h +++ b/chrome/browser/spellcheck_host_impl.h @@ -10,7 +10,10 @@ #include <vector> #include "base/file_path.h" +#include "base/hash_tables.h" #include "base/memory/scoped_ptr.h" +#include "base/time.h" +#include "base/timer.h" #include "chrome/browser/spellcheck_host.h" #include "chrome/browser/spellcheck_host_observer.h" #include "content/common/notification_observer.h" @@ -43,7 +46,8 @@ class SpellCheckHostImpl : public SpellCheckHost, public: SpellCheckHostImpl(SpellCheckHostObserver* observer, const std::string& language, - net::URLRequestContextGetter* request_context_getter); + net::URLRequestContextGetter* request_context_getter, + bool metrics_enabled); void Initialize(); @@ -91,9 +95,13 @@ class SpellCheckHostImpl : public SpellCheckHost, // to be uploaded via UMA void RecordDictionaryCorruptionStats(bool corrupted); + // Collects time-dependent spell stats. + // This method is invoked by |histogram_timer_|. + void OnHistogramTimerExpired(); + // Collects status of spellchecking enabling state, which is // to be uploaded via UMA - virtual void RecordCheckedWordStats(bool misspell); + virtual void RecordCheckedWordStats(const string16& word, bool misspell); // Collects a histogram for misspelled word replacement // to be uploaded via UMA @@ -157,6 +165,9 @@ class SpellCheckHostImpl : public SpellCheckHost, NotificationRegistrar registrar_; + // True if metrics recording is enabled. + bool metrics_enabled_; + // Number of corrected words of checked words. int misspelled_word_count_; // Number of checked words. @@ -165,6 +176,11 @@ class SpellCheckHostImpl : public SpellCheckHost, int suggestion_show_count_; // Number of misspelled words replaced by a user. int replaced_word_count_; + // Time when first spellcheck happened. + base::Time start_time_; + // Set of checked words in the hashed form. + base::hash_set<std::string> checked_word_hashes_; + base::RepeatingTimer<SpellCheckHostImpl> histogram_timer_; }; #endif // CHROME_BROWSER_SPELLCHECK_HOST_IMPL_H_ diff --git a/chrome/browser/spellcheck_message_filter.cc b/chrome/browser/spellcheck_message_filter.cc index c5f5e5f..475440f 100644 --- a/chrome/browser/spellcheck_message_filter.cc +++ b/chrome/browser/spellcheck_message_filter.cc @@ -110,12 +110,13 @@ void SpellCheckMessageFilter::OnSpellCheckerRequestDictionary() { } } -void SpellCheckMessageFilter::OnNotifyChecked(bool misspelled) { +void SpellCheckMessageFilter::OnNotifyChecked(const string16& word, + bool misspelled) { RenderProcessHost* host = RenderProcessHost::FromID(render_process_id_); if (!host) return; // Teardown. // Delegates to SpellCheckHost which tracks the stats of our spellchecker. Profile* profile = host->profile(); if (profile->GetSpellCheckHost()) - profile->GetSpellCheckHost()->RecordCheckedWordStats(misspelled); + profile->GetSpellCheckHost()->RecordCheckedWordStats(word, misspelled); } diff --git a/chrome/browser/spellcheck_message_filter.h b/chrome/browser/spellcheck_message_filter.h index 5e6dd5e..f9a2a790 100644 --- a/chrome/browser/spellcheck_message_filter.h +++ b/chrome/browser/spellcheck_message_filter.h @@ -33,7 +33,7 @@ class SpellCheckMessageFilter : public BrowserMessageFilter { int document_tag, const string16& text); void OnSpellCheckerRequestDictionary(); - void OnNotifyChecked(bool misspelled); + void OnNotifyChecked(const string16& word, bool misspelled); int render_process_id_; }; diff --git a/chrome/common/spellcheck_messages.h b/chrome/common/spellcheck_messages.h index d95a973..63e0cda 100644 --- a/chrome/common/spellcheck_messages.h +++ b/chrome/common/spellcheck_messages.h @@ -101,5 +101,6 @@ IPC_MESSAGE_ROUTED2(SpellCheckHostMsg_ToggleSpellCheck, bool /* checked */) // Tracks spell checking occurrence to collect histogram. -IPC_MESSAGE_ROUTED1(SpellCheckHostMsg_NotifyChecked, +IPC_MESSAGE_ROUTED2(SpellCheckHostMsg_NotifyChecked, + string16 /* word */, bool /* true if checked word is misspelled */) diff --git a/chrome/renderer/spellchecker/spellcheck_provider.cc b/chrome/renderer/spellchecker/spellcheck_provider.cc index 4d8584f..c92f47a3 100644 --- a/chrome/renderer/spellchecker/spellcheck_provider.cc +++ b/chrome/renderer/spellchecker/spellcheck_provider.cc @@ -113,7 +113,7 @@ void SpellCheckProvider::spellCheck( if (!optional_suggestions) { // If optional_suggestions is not requested, the API is called // for marking. So we use this for counting markable words. - Send(new SpellCheckHostMsg_NotifyChecked(routing_id(), 0 < length)); + Send(new SpellCheckHostMsg_NotifyChecked(routing_id(), word, 0 < length)); } } } |