| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/spellchecker/spellcheck_host_impl.h" | 5 #include "chrome/browser/spellchecker/spellcheck_host_impl.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 #include "chrome/common/spellcheck_common.h" | 25 #include "chrome/common/spellcheck_common.h" |
| 26 #include "chrome/common/spellcheck_messages.h" | 26 #include "chrome/common/spellcheck_messages.h" |
| 27 #include "content/public/browser/notification_service.h" | 27 #include "content/public/browser/notification_service.h" |
| 28 #include "content/public/browser/notification_types.h" | 28 #include "content/public/browser/notification_types.h" |
| 29 #include "content/public/browser/render_process_host.h" | 29 #include "content/public/browser/render_process_host.h" |
| 30 #include "content/public/common/url_fetcher.h" | 30 #include "content/public/common/url_fetcher.h" |
| 31 #include "googleurl/src/gurl.h" | 31 #include "googleurl/src/gurl.h" |
| 32 #include "net/url_request/url_request_context_getter.h" | 32 #include "net/url_request/url_request_context_getter.h" |
| 33 #include "third_party/hunspell/google/bdict.h" | 33 #include "third_party/hunspell/google/bdict.h" |
| 34 #include "ui/base/l10n/l10n_util.h" | 34 #include "ui/base/l10n/l10n_util.h" |
| 35 #if defined(OS_MACOSX) | |
| 36 #include "base/metrics/histogram.h" | |
| 37 #endif | |
| 38 | 35 |
| 39 using content::BrowserThread; | 36 using content::BrowserThread; |
| 40 | 37 |
| 41 namespace { | 38 namespace { |
| 42 | 39 |
| 43 FilePath GetFirstChoiceFilePath(const std::string& language) { | 40 FilePath GetFirstChoiceFilePath(const std::string& language) { |
| 44 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 41 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 45 | 42 |
| 46 FilePath dict_dir; | 43 FilePath dict_dir; |
| 47 PathService::Get(chrome::DIR_APP_DICTIONARIES, &dict_dir); | 44 PathService::Get(chrome::DIR_APP_DICTIONARIES, &dict_dir); |
| 48 return SpellCheckCommon::GetVersionedFileName(language, dict_dir); | 45 return SpellCheckCommon::GetVersionedFileName(language, dict_dir); |
| 49 } | 46 } |
| 50 | 47 |
| 51 #if defined(OS_MACOSX) | |
| 52 // Collect metrics on how often Hunspell is used on OS X vs the native | |
| 53 // spellchecker. | |
| 54 void RecordSpellCheckStats(bool native_spellchecker_used, | |
| 55 const std::string& language) { | |
| 56 CR_DEFINE_STATIC_LOCAL(std::set<std::string>, languages_seen, ()); | |
| 57 | |
| 58 // Only count a language code once for each session.. | |
| 59 if (languages_seen.find(language) != languages_seen.end()) { | |
| 60 return; | |
| 61 } | |
| 62 languages_seen.insert(language); | |
| 63 | |
| 64 enum { | |
| 65 SPELLCHECK_OSX_NATIVE_SPELLCHECKER_USED = 0, | |
| 66 SPELLCHECK_HUNSPELL_USED = 1 | |
| 67 }; | |
| 68 | |
| 69 bool engine_used = native_spellchecker_used ? | |
| 70 SPELLCHECK_OSX_NATIVE_SPELLCHECKER_USED : | |
| 71 SPELLCHECK_HUNSPELL_USED; | |
| 72 | |
| 73 UMA_HISTOGRAM_COUNTS("SpellCheck.OSXEngineUsed", engine_used); | |
| 74 } | |
| 75 #endif | |
| 76 | |
| 77 #if defined(OS_WIN) | 48 #if defined(OS_WIN) |
| 78 FilePath GetFallbackFilePath(const FilePath& first_choice) { | 49 FilePath GetFallbackFilePath(const FilePath& first_choice) { |
| 79 FilePath dict_dir; | 50 FilePath dict_dir; |
| 80 PathService::Get(chrome::DIR_USER_DATA, &dict_dir); | 51 PathService::Get(chrome::DIR_USER_DATA, &dict_dir); |
| 81 return dict_dir.Append(first_choice.BaseName()); | 52 return dict_dir.Append(first_choice.BaseName()); |
| 82 } | 53 } |
| 83 #endif | 54 #endif |
| 84 | 55 |
| 85 void CloseDictionary(base::PlatformFile file) { | 56 void CloseDictionary(base::PlatformFile file) { |
| 86 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 57 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 base::Bind(&CloseDictionary, file_)); | 96 base::Bind(&CloseDictionary, file_)); |
| 126 file_ = base::kInvalidPlatformFileValue; | 97 file_ = base::kInvalidPlatformFileValue; |
| 127 } | 98 } |
| 128 } | 99 } |
| 129 | 100 |
| 130 void SpellCheckHostImpl::Initialize() { | 101 void SpellCheckHostImpl::Initialize() { |
| 131 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 102 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 132 | 103 |
| 133 if (SpellCheckerPlatform::SpellCheckerAvailable() && | 104 if (SpellCheckerPlatform::SpellCheckerAvailable() && |
| 134 SpellCheckerPlatform::PlatformSupportsLanguage(language_)) { | 105 SpellCheckerPlatform::PlatformSupportsLanguage(language_)) { |
| 135 #if defined(OS_MACOSX) | |
| 136 RecordSpellCheckStats(true, language_); | |
| 137 #endif | |
| 138 use_platform_spellchecker_ = true; | 106 use_platform_spellchecker_ = true; |
| 139 SpellCheckerPlatform::SetLanguage(language_); | 107 SpellCheckerPlatform::SetLanguage(language_); |
| 140 MessageLoop::current()->PostTask(FROM_HERE, | 108 MessageLoop::current()->PostTask(FROM_HERE, |
| 141 base::Bind(&SpellCheckHostImpl::InformProfileOfInitialization, | 109 base::Bind(&SpellCheckHostImpl::InformProfileOfInitialization, |
| 142 weak_ptr_factory_.GetWeakPtr())); | 110 weak_ptr_factory_.GetWeakPtr())); |
| 143 return; | 111 return; |
| 144 } | 112 } |
| 145 | 113 |
| 146 #if defined(OS_MACOSX) | |
| 147 RecordSpellCheckStats(false, language_); | |
| 148 #endif | |
| 149 | |
| 150 BrowserThread::PostTaskAndReply(BrowserThread::FILE, FROM_HERE, | 114 BrowserThread::PostTaskAndReply(BrowserThread::FILE, FROM_HERE, |
| 151 base::Bind(&SpellCheckHostImpl::InitializeDictionaryLocation, | 115 base::Bind(&SpellCheckHostImpl::InitializeDictionaryLocation, |
| 152 base::Unretained(this)), | 116 base::Unretained(this)), |
| 153 base::Bind(&SpellCheckHostImpl::InitializeDictionaryLocationComplete, | 117 base::Bind(&SpellCheckHostImpl::InitializeDictionaryLocationComplete, |
| 154 weak_ptr_factory_.GetWeakPtr())); | 118 weak_ptr_factory_.GetWeakPtr())); |
| 155 } | 119 } |
| 156 | 120 |
| 157 void SpellCheckHostImpl::UnsetProfile() { | 121 void SpellCheckHostImpl::UnsetProfile() { |
| 158 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 122 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 159 | 123 |
| (...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 480 | 444 |
| 481 void SpellCheckHostImpl::AddWordComplete(const std::string& word) { | 445 void SpellCheckHostImpl::AddWordComplete(const std::string& word) { |
| 482 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 446 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 483 | 447 |
| 484 for (content::RenderProcessHost::iterator i( | 448 for (content::RenderProcessHost::iterator i( |
| 485 content::RenderProcessHost::AllHostsIterator()); | 449 content::RenderProcessHost::AllHostsIterator()); |
| 486 !i.IsAtEnd(); i.Advance()) { | 450 !i.IsAtEnd(); i.Advance()) { |
| 487 i.GetCurrentValue()->Send(new SpellCheckMsg_WordAdded(word)); | 451 i.GetCurrentValue()->Send(new SpellCheckMsg_WordAdded(word)); |
| 488 } | 452 } |
| 489 } | 453 } |
| OLD | NEW |