diff options
author | morrita@chromium.org <morrita@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-16 02:56:58 +0000 |
---|---|---|
committer | morrita@chromium.org <morrita@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-16 02:56:58 +0000 |
commit | 500263ec2bfa08c78d303eb3966b1971a0ce0617 (patch) | |
tree | b3f7e71d33084b16365f08fd4e872c36f5a61b7a | |
parent | f3ee2bc3d9d21813b6339f47662ad763ba1c567a (diff) | |
download | chromium_src-500263ec2bfa08c78d303eb3966b1971a0ce0617.zip chromium_src-500263ec2bfa08c78d303eb3966b1971a0ce0617.tar.gz chromium_src-500263ec2bfa08c78d303eb3966b1971a0ce0617.tar.bz2 |
Added UMA histgrams for spellchecking.
Added items are:
- SpellCheck.Enabled
- SpellCheck.CustomWords
- SpellCheck.MisspellRatio
- SpellCheck.ShowSuggestion
- SpellCheck.ReplaceRatio
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/6995041
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@85458 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/profiles/profile_impl.cc | 6 | ||||
-rw-r--r-- | chrome/browser/spellcheck_host.cc | 16 | ||||
-rw-r--r-- | chrome/browser/spellcheck_host.h | 16 | ||||
-rw-r--r-- | chrome/browser/spellcheck_host_impl.cc | 35 | ||||
-rw-r--r-- | chrome/browser/spellcheck_host_impl.h | 15 | ||||
-rw-r--r-- | chrome/browser/spellcheck_message_filter.cc | 15 | ||||
-rw-r--r-- | chrome/browser/spellcheck_message_filter.h | 1 | ||||
-rw-r--r-- | chrome/browser/tab_contents/render_view_context_menu.cc | 10 | ||||
-rw-r--r-- | chrome/common/spellcheck_messages.h | 4 | ||||
-rw-r--r-- | chrome/renderer/spellchecker/spellcheck_provider.cc | 5 |
10 files changed, 119 insertions, 4 deletions
diff --git a/chrome/browser/profiles/profile_impl.cc b/chrome/browser/profiles/profile_impl.cc index b1afc14..4bf4a75 100644 --- a/chrome/browser/profiles/profile_impl.cc +++ b/chrome/browser/profiles/profile_impl.cc @@ -379,6 +379,12 @@ void ProfileImpl::DoFinalInit() { InstantController::RecordMetrics(this); + // Logs the spell-check enabled status. + // For simplicity, we check if spell-check is enabled only at start up + // time and don't track preferences change. + SpellCheckHost::RecordEnabledStats( + GetPrefs()->GetBoolean(prefs::kEnableSpellCheck)); + FilePath cookie_path = GetPath(); cookie_path = cookie_path.Append(chrome::kCookieFilename); FilePath cache_path = base_cache_path_; diff --git a/chrome/browser/spellcheck_host.cc b/chrome/browser/spellcheck_host.cc index aed3d9b..6517da3 100644 --- a/chrome/browser/spellcheck_host.cc +++ b/chrome/browser/spellcheck_host.cc @@ -4,6 +4,7 @@ #include "chrome/browser/spellcheck_host.h" +#include "base/metrics/histogram.h" #include "base/string_split.h" #include "chrome/browser/prefs/pref_member.h" #include "chrome/browser/profiles/profile.h" @@ -69,3 +70,18 @@ int SpellCheckHost::GetSpellCheckLanguages( } return -1; } + +// static +void SpellCheckHost::RecordCustomWordCountStats(size_t count) { + UMA_HISTOGRAM_COUNTS("SpellCheck.CustomWords", count); +} + +// static +void SpellCheckHost::RecordEnabledStats(bool enabled) { + UMA_HISTOGRAM_BOOLEAN("SpellCheck.Enabled", enabled); + // Because SpellCheckHost is instantiated lazily, the size of + // custom dictionary is unknown at this time. We mark it as -1 and + // record actual value later. See SpellCheckHost for more detail. + if (enabled) + RecordCustomWordCountStats(-1); +} diff --git a/chrome/browser/spellcheck_host.h b/chrome/browser/spellcheck_host.h index b09deff..27ccbc2 100644 --- a/chrome/browser/spellcheck_host.h +++ b/chrome/browser/spellcheck_host.h @@ -54,6 +54,14 @@ class SpellCheckHost const std::string& language, net::URLRequestContextGetter* request_context_getter); + // Collects the number of words in the custom dictionary, which is + // to be uploaded via UMA + static void RecordCustomWordCountStats(size_t count); + + // Collects status of spellchecking enabling state, which is + // to be uploaded via UMA + static void RecordEnabledStats(bool enabled); + // Clears an observer which is set on creation. // Used to prevent calling back to a deleted object. virtual void UnsetObserver() = 0; @@ -76,6 +84,14 @@ class SpellCheckHost virtual bool IsUsingPlatformChecker() const = 0; + // Collects status of spellchecking enabling state, which is + // to be uploaded via UMA + virtual void RecordCheckedWordStats(bool misspell) = 0; + + // Collects a histogram for misspelled word replacement + // to be uploaded via UMA + virtual void RecordReplacedWordStats(int delta) = 0; + // This function computes a vector of strings which are to be displayed in // the context menu over a text area for changing spell check languages. It // returns the index of the current spell check language in the vector. diff --git a/chrome/browser/spellcheck_host_impl.cc b/chrome/browser/spellcheck_host_impl.cc index c975740..d87d000 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/metrics/histogram.h" #include "base/path_service.h" #include "base/string_split.h" #include "base/threading/thread_restrictions.h" @@ -87,7 +88,10 @@ SpellCheckHostImpl::SpellCheckHostImpl( file_(base::kInvalidPlatformFileValue), tried_to_download_(false), use_platform_spellchecker_(false), - request_context_getter_(request_context_getter) { + request_context_getter_(request_context_getter), + misspelled_word_count_(0), + spellchecked_word_count_(0), + replaced_word_count_(0) { DCHECK(observer_); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); @@ -168,6 +172,7 @@ void SpellCheckHostImpl::AddWord(const std::string& word) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); custom_words_.push_back(word); + SpellCheckHost::RecordCustomWordCountStats(custom_words_.size()); BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, NewRunnableMethod(this, &SpellCheckHostImpl::WriteWordToCustomDictionary, word)); @@ -235,6 +240,7 @@ void SpellCheckHostImpl::InitializeInternal() { BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, NewRunnableMethod(this, &SpellCheckHostImpl::InformObserverOfInitialization)); + SpellCheckHost::RecordCustomWordCountStats(custom_words_.size()); } void SpellCheckHostImpl::InitializeOnFileThread() { @@ -294,6 +300,33 @@ void SpellCheckHostImpl::WriteWordToCustomDictionary(const std::string& word) { file_util::CloseFile(f); } +void SpellCheckHostImpl::RecordCheckedWordStats(bool misspell) { + spellchecked_word_count_++; + if (misspell) { + misspelled_word_count_++; + // If an user misspelled, that user should be counted as a part of + // the population. So we ensure to instantiate the histogram + // entries here at the first time. + if (misspelled_word_count_ == 1) + RecordReplacedWordStats(0); + } + + int percentage = (100 * misspelled_word_count_) / spellchecked_word_count_; + UMA_HISTOGRAM_PERCENTAGE("SpellCheck.MisspellRatio", percentage); +} + +void SpellCheckHostImpl::RecordReplacedWordStats(int delta) { + replaced_word_count_ += delta; + if (!misspelled_word_count_) { + // This is possible when an extension gives the misspelling, + // which is not recorded as a part of this metrics. + return; + } + + int percentage = (100 * replaced_word_count_) / misspelled_word_count_; + UMA_HISTOGRAM_PERCENTAGE("SpellCheck.ReplaceRatio", percentage); +} + void SpellCheckHostImpl::OnURLFetchComplete(const URLFetcher* source, const GURL& url, const net::URLRequestStatus& status, diff --git a/chrome/browser/spellcheck_host_impl.h b/chrome/browser/spellcheck_host_impl.h index b080505..f257e50 100644 --- a/chrome/browser/spellcheck_host_impl.h +++ b/chrome/browser/spellcheck_host_impl.h @@ -87,6 +87,14 @@ class SpellCheckHostImpl : public SpellCheckHost, // Write a custom dictionary addition to disk. void WriteWordToCustomDictionary(const std::string& word); + // Collects status of spellchecking enabling state, which is + // to be uploaded via UMA + virtual void RecordCheckedWordStats(bool misspell); + + // Collects a histogram for misspelled word replacement + // to be uploaded via UMA + virtual void RecordReplacedWordStats(int delta); + // URLFetcher::Delegate implementation. Called when we finish downloading the // spellcheck dictionary; saves the dictionary to |data_|. virtual void OnURLFetchComplete(const URLFetcher* source, @@ -140,6 +148,13 @@ class SpellCheckHostImpl : public SpellCheckHost, scoped_ptr<URLFetcher> fetcher_; NotificationRegistrar registrar_; + + // Number of corrected words of checked words. + int misspelled_word_count_; + // Number of checked words. + int spellchecked_word_count_; + // Number of misspelled words replaced by a user. + int replaced_word_count_; }; #endif // CHROME_BROWSER_SPELLCHECK_HOST_IMPL_H_ diff --git a/chrome/browser/spellcheck_message_filter.cc b/chrome/browser/spellcheck_message_filter.cc index 7cd1ad7..c5f5e5f 100644 --- a/chrome/browser/spellcheck_message_filter.cc +++ b/chrome/browser/spellcheck_message_filter.cc @@ -20,7 +20,8 @@ SpellCheckMessageFilter::~SpellCheckMessageFilter() { void SpellCheckMessageFilter::OverrideThreadForMessage( const IPC::Message& message, BrowserThread::ID* thread) { - if (message.type() == SpellCheckHostMsg_RequestDictionary::ID) + if (message.type() == SpellCheckHostMsg_RequestDictionary::ID || + message.type() == SpellCheckHostMsg_NotifyChecked::ID) *thread = BrowserThread::UI; } @@ -43,6 +44,8 @@ bool SpellCheckMessageFilter::OnMessageReceived(const IPC::Message& message, OnPlatformRequestTextCheck) IPC_MESSAGE_HANDLER(SpellCheckHostMsg_RequestDictionary, OnSpellCheckerRequestDictionary) + IPC_MESSAGE_HANDLER(SpellCheckHostMsg_NotifyChecked, + OnNotifyChecked) IPC_MESSAGE_UNHANDLED(handled = false) IPC_END_MESSAGE_MAP() return handled; @@ -106,3 +109,13 @@ void SpellCheckMessageFilter::OnSpellCheckerRequestDictionary() { profile->ReinitializeSpellCheckHost(false); } } + +void SpellCheckMessageFilter::OnNotifyChecked(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); +} diff --git a/chrome/browser/spellcheck_message_filter.h b/chrome/browser/spellcheck_message_filter.h index 4c1795a..9dd6246 100644 --- a/chrome/browser/spellcheck_message_filter.h +++ b/chrome/browser/spellcheck_message_filter.h @@ -33,6 +33,7 @@ class SpellCheckMessageFilter : public BrowserMessageFilter { int document_tag, const string16& text); void OnSpellCheckerRequestDictionary(); + void OnNotifyChecked(bool misspelled); int render_process_id_; }; diff --git a/chrome/browser/tab_contents/render_view_context_menu.cc b/chrome/browser/tab_contents/render_view_context_menu.cc index d7d5633..316dd30 100644 --- a/chrome/browser/tab_contents/render_view_context_menu.cc +++ b/chrome/browser/tab_contents/render_view_context_menu.cc @@ -1472,11 +1472,17 @@ void RenderViewContextMenu::ExecuteCommand(int id) { case IDC_SPELLCHECK_SUGGESTION_1: case IDC_SPELLCHECK_SUGGESTION_2: case IDC_SPELLCHECK_SUGGESTION_3: - case IDC_SPELLCHECK_SUGGESTION_4: + case IDC_SPELLCHECK_SUGGESTION_4: { source_tab_contents_->render_view_host()->Replace( params_.dictionary_suggestions[id - IDC_SPELLCHECK_SUGGESTION_0]); + SpellCheckHost* spellcheck_host = profile_->GetSpellCheckHost(); + if (!spellcheck_host) { + NOTREACHED(); + break; + } + spellcheck_host->RecordReplacedWordStats(1); break; - + } case IDC_CHECK_SPELLING_OF_THIS_FIELD: { RenderViewHost* view = source_tab_contents_->render_view_host(); view->Send(new SpellCheckMsg_ToggleSpellCheck(view->routing_id())); diff --git a/chrome/common/spellcheck_messages.h b/chrome/common/spellcheck_messages.h index 52ade79..d95a973 100644 --- a/chrome/common/spellcheck_messages.h +++ b/chrome/common/spellcheck_messages.h @@ -99,3 +99,7 @@ IPC_MESSAGE_CONTROL4(SpellCheckHostMsg_PlatformRequestTextCheck, IPC_MESSAGE_ROUTED2(SpellCheckHostMsg_ToggleSpellCheck, bool /* enabled */, bool /* checked */) + +// Tracks spell checking occurrence to collect histogram. +IPC_MESSAGE_ROUTED1(SpellCheckHostMsg_NotifyChecked, + bool /* true if checked word is misspelled */) diff --git a/chrome/renderer/spellchecker/spellcheck_provider.cc b/chrome/renderer/spellchecker/spellcheck_provider.cc index 871ecfd..4d8584f 100644 --- a/chrome/renderer/spellchecker/spellcheck_provider.cc +++ b/chrome/renderer/spellchecker/spellcheck_provider.cc @@ -110,6 +110,11 @@ void SpellCheckProvider::spellCheck( &offset, &length, optional_suggestions ? & suggestions : NULL); if (optional_suggestions) *optional_suggestions = suggestions; + 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)); + } } } |