diff options
author | jeremy@chromium.org <jeremy@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-17 06:26:09 +0000 |
---|---|---|
committer | jeremy@chromium.org <jeremy@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-17 06:26:09 +0000 |
commit | cacbd9f96c8d50038c57506ce7d1d533b1fff826 (patch) | |
tree | 9c0c938c4982e69ae5d2f787c050932991816e06 | |
parent | 1be1c84ac0a164e27a080e59a89cc38630b49c43 (diff) | |
download | chromium_src-cacbd9f96c8d50038c57506ce7d1d533b1fff826.zip chromium_src-cacbd9f96c8d50038c57506ce7d1d533b1fff826.tar.gz chromium_src-cacbd9f96c8d50038c57506ce7d1d533b1fff826.tar.bz2 |
OS X: Add metrics to temporarily count use of Hunspell vs OS X's native spellchecker.
* Fix bug where Polish would always use Hunspell, even when the OS X native dictionary already has Polish support.
* Spruce up comments in spell_checker_mac.cc
BUG=69944
TEST=None
Review URL: http://codereview.chromium.org/6515001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@75236 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/spellcheck_host.cc | 36 | ||||
-rw-r--r-- | chrome/browser/spellchecker_mac.mm | 17 |
2 files changed, 47 insertions, 6 deletions
diff --git a/chrome/browser/spellcheck_host.cc b/chrome/browser/spellcheck_host.cc index 4c59b56..0ea7ba8 100644 --- a/chrome/browser/spellcheck_host.cc +++ b/chrome/browser/spellcheck_host.cc @@ -6,8 +6,11 @@ #include <fcntl.h> +#include <set> + #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" @@ -40,6 +43,32 @@ FilePath GetFirstChoiceFilePath(const std::string& language) { return SpellCheckCommon::GetVersionedFileName(language, dict_dir); } +#if defined(OS_MACOSX) +// Collect metrics on how often Hunspell is used on OS X vs the native +// spellchecker. +void RecordSpellCheckStats(bool native_spellchecker_used, + const std::string& language) { + static std::set<std::string> languages_seen; + + // Only count a language code once for each session.. + if (languages_seen.find(language) != languages_seen.end()) { + return; + } + languages_seen.insert(language); + + enum { + SPELLCHECK_OSX_NATIVE_SPELLCHECKER_USED = 0, + SPELLCHECK_HUNSPELL_USED = 1 + }; + + bool engine_used = native_spellchecker_used ? + SPELLCHECK_OSX_NATIVE_SPELLCHECKER_USED : + SPELLCHECK_HUNSPELL_USED; + + UMA_HISTOGRAM_COUNTS("SpellCheck.OSXEngineUsed", engine_used); +} +#endif + #if defined(OS_WIN) FilePath GetFallbackFilePath(const FilePath& first_choice) { FilePath dict_dir; @@ -79,6 +108,9 @@ SpellCheckHost::~SpellCheckHost() { void SpellCheckHost::Initialize() { if (SpellCheckerPlatform::SpellCheckerAvailable() && SpellCheckerPlatform::PlatformSupportsLanguage(language_)) { +#if defined(OS_MACOSX) + RecordSpellCheckStats(true, language_); +#endif use_platform_spellchecker_ = true; SpellCheckerPlatform::SetLanguage(language_); MessageLoop::current()->PostTask(FROM_HERE, @@ -87,6 +119,10 @@ void SpellCheckHost::Initialize() { return; } +#if defined(OS_MACOSX) + RecordSpellCheckStats(false, language_); +#endif + BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, NewRunnableMethod(this, &SpellCheckHost::InitializeDictionaryLocation)); } diff --git a/chrome/browser/spellchecker_mac.mm b/chrome/browser/spellchecker_mac.mm index ead554f..24b6e15 100644 --- a/chrome/browser/spellchecker_mac.mm +++ b/chrome/browser/spellchecker_mac.mm @@ -20,7 +20,7 @@ namespace { // The number of characters in the first part of the language code. const unsigned int kShortLanguageCodeSize = 2; -// A private utility function to convert hunspell language codes to os x +// A private utility function to convert hunspell language codes to OS X // language codes. NSString* ConvertLanguageCodeToMac(const std::string& hunspell_lang_code) { NSString* whole_code = base::SysUTF8ToNSString(hunspell_lang_code); @@ -32,7 +32,7 @@ NSString* ConvertLanguageCodeToMac(const std::string& hunspell_lang_code) { NSString* region_code = [whole_code substringFromIndex:(kShortLanguageCodeSize + 1)]; - // Check for the special case of en-US and pt-PT, since os x lists these + // Check for the special case of en-US and pt-PT, since OS X lists these // as just en and pt respectively. // TODO(pwicks): Find out if there are other special cases for languages // not installed on the system by default. Are there others like pt-PT? @@ -45,12 +45,16 @@ NSString* ConvertLanguageCodeToMac(const std::string& hunspell_lang_code) { // Otherwise, just build a string that uses an underscore instead of a // dash between the language and the region code, since this is the - // format that os x uses. + // format that OS X uses. NSString* os_x_language = [NSString stringWithFormat:@"%@_%@", lang_code, region_code]; return os_x_language; } else { - // This is just a language code with the same format as os x + // Special case for Polish. + if ([whole_code isEqualToString:@"pl"]) { + return @"pl_PL"; + } + // This is just a language code with the same format as OS X // language code. return whole_code; } @@ -61,6 +65,7 @@ std::string ConvertLanguageCodeFromMac(NSString* lang_code) { // Guards for strange cases. if ([lang_code isEqualToString:@"en"]) return std::string("en-US"); if ([lang_code isEqualToString:@"pt"]) return std::string("pt-PT"); + if ([lang_code isEqualToString:@"pl_PL"]) return std::string("pl"); if ([lang_code length] > kShortLanguageCodeSize && [lang_code characterAtIndex:kShortLanguageCodeSize] == '_') { @@ -128,7 +133,7 @@ void Init() { } bool PlatformSupportsLanguage(const std::string& current_language) { - // First, convert Language to an osx lang code NSString. + // First, convert the language to an OS X language code. NSString* mac_lang_code = ConvertLanguageCodeToMac(current_language); // Then grab the languages available. @@ -136,7 +141,7 @@ bool PlatformSupportsLanguage(const std::string& current_language) { availableLanguages = [[NSSpellChecker sharedSpellChecker] availableLanguages]; - // Return true if the given languange is supported by os x. + // Return true if the given language is supported by OS X. return [availableLanguages containsObject:mac_lang_code]; } |