Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(142)

Side by Side Diff: chrome/browser/spellchecker/spellcheck_service.cc

Issue 11293241: Cleaning up the custom dictionary code relative to the SpellcheckService to make the custom diction… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_service.h" 5 #include "chrome/browser/spellchecker/spellcheck_service.h"
6 6
7 #include "base/platform_file.h" 7 #include "base/platform_file.h"
8 #include "base/string_split.h" 8 #include "base/string_split.h"
9 #include "base/synchronization/waitable_event.h" 9 #include "base/synchronization/waitable_event.h"
10 #include "chrome/browser/api/prefs/pref_member.h" 10 #include "chrome/browser/api/prefs/pref_member.h"
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 186
187 WordList custom_words = GetCustomDictionary()->GetCustomWords(); 187 WordList custom_words = GetCustomDictionary()->GetCustomWords();
188 188
189 process->Send(new SpellCheckMsg_Init( 189 process->Send(new SpellCheckMsg_Init(
190 file, 190 file,
191 custom_words, 191 custom_words,
192 hunspell_dictionary_->GetLanguage(), 192 hunspell_dictionary_->GetLanguage(),
193 prefs->GetBoolean(prefs::kEnableAutoSpellCorrect))); 193 prefs->GetBoolean(prefs::kEnableAutoSpellCorrect)));
194 } 194 }
195 195
196 void SpellcheckService::AddWord(const std::string& word) {
197 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
198
199 GetCustomDictionary()->CustomWordAddedLocally(word);
200
201 // TODO(rlp): pass these on to the correct dictionary.
202 BrowserThread::PostTaskAndReply(BrowserThread::FILE, FROM_HERE,
203 base::Bind(&SpellcheckService::WriteWordToCustomDictionary,
204 base::Unretained(this), word),
205 base::Bind(&SpellcheckService::AddWordComplete,
206 weak_ptr_factory_.GetWeakPtr(), word));
207 }
208
209 const WordList& SpellcheckService::GetCustomWords() {
210 return GetCustomDictionary()->GetCustomWords();
211
212 }
213
214 void SpellcheckService::CustomWordAddedLocally(const std::string& word) {
215 GetCustomDictionary()->CustomWordAddedLocally(word);
216 }
217
218 void SpellcheckService::LoadDictionaryIntoCustomWordList(
219 WordList* custom_words){
220 GetCustomDictionary()->LoadDictionaryIntoCustomWordList(custom_words);
221 }
222
223 void SpellcheckService::WriteWordToCustomDictionary(const std::string& word){
224 GetCustomDictionary()->WriteWordToCustomDictionary(word);
225 }
226
227 void SpellcheckService::Observe(int type, 196 void SpellcheckService::Observe(int type,
228 const content::NotificationSource& source, 197 const content::NotificationSource& source,
229 const content::NotificationDetails& details) { 198 const content::NotificationDetails& details) {
230 DCHECK(type == content::NOTIFICATION_RENDERER_PROCESS_CREATED); 199 DCHECK(type == content::NOTIFICATION_RENDERER_PROCESS_CREATED);
231 content::RenderProcessHost* process = 200 content::RenderProcessHost* process =
232 content::Source<content::RenderProcessHost>(source).ptr(); 201 content::Source<content::RenderProcessHost>(source).ptr();
233 InitForRenderer(process); 202 InitForRenderer(process);
234 } 203 }
235 204
236 void SpellcheckService::OnPreferenceChanged(PrefServiceBase* prefs, 205 void SpellcheckService::OnPreferenceChanged(PrefServiceBase* prefs,
(...skipping 30 matching lines...) Expand all
267 } 236 }
268 237
269 const base::PlatformFile& SpellcheckService::GetDictionaryFile() const { 238 const base::PlatformFile& SpellcheckService::GetDictionaryFile() const {
270 return hunspell_dictionary_->GetDictionaryFile(); 239 return hunspell_dictionary_->GetDictionaryFile();
271 } 240 }
272 241
273 const std::string& SpellcheckService::GetLanguage() const { 242 const std::string& SpellcheckService::GetLanguage() const {
274 return hunspell_dictionary_->GetLanguage(); 243 return hunspell_dictionary_->GetLanguage();
275 } 244 }
276 245
277 void SpellcheckService::AddWordComplete(const std::string& word) {
278 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
279
280 for (content::RenderProcessHost::iterator i(
281 content::RenderProcessHost::AllHostsIterator());
282 !i.IsAtEnd(); i.Advance()) {
283 i.GetCurrentValue()->Send(new SpellCheckMsg_WordAdded(word));
284 }
285 }
286
287 // TODO(rlp): rename to something more logical. 246 // TODO(rlp): rename to something more logical.
288 void SpellcheckService::InformProfileOfInitializationWithCustomWords( 247 void SpellcheckService::InformProfileOfInitializationWithCustomWords(
289 WordList* custom_words) { 248 WordList* custom_words) {
290 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 249 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
291 250
292 if (custom_words) { 251 if (custom_words) {
293 GetCustomDictionary()->SetCustomWordList(custom_words); 252 GetCustomDictionary()->SetCustomWordList(custom_words);
294 } 253 }
295 254
296 for (content::RenderProcessHost::iterator i( 255 for (content::RenderProcessHost::iterator i(
297 content::RenderProcessHost::AllHostsIterator()); 256 content::RenderProcessHost::AllHostsIterator());
298 !i.IsAtEnd(); i.Advance()) { 257 !i.IsAtEnd(); i.Advance()) {
299 content::RenderProcessHost* process = i.GetCurrentValue(); 258 content::RenderProcessHost* process = i.GetCurrentValue();
300 if (process) 259 if (process)
301 InitForRenderer(process); 260 InitForRenderer(process);
302 } 261 }
303 } 262 }
OLDNEW
« no previous file with comments | « chrome/browser/spellchecker/spellcheck_service.h ('k') | chrome/browser/spellchecker/spellcheck_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698