OLD | NEW |
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_custom_dictionary.h" | 5 #include "chrome/browser/spellchecker/spellcheck_custom_dictionary.h" |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
9 #include "base/string_split.h" | 9 #include "base/string_split.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/browser/spellchecker/spellcheck_service.h" |
12 #include "chrome/common/chrome_constants.h" | 13 #include "chrome/common/chrome_constants.h" |
| 14 #include "chrome/common/spellcheck_messages.h" |
13 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
| 16 #include "content/public/browser/render_process_host.h" |
14 | 17 |
15 #include <functional> | 18 #include <functional> |
16 | 19 |
17 using content::BrowserThread; | 20 using content::BrowserThread; |
18 using chrome::spellcheck_common::WordList; | 21 using chrome::spellcheck_common::WordList; |
19 | 22 |
20 SpellcheckCustomDictionary::SpellcheckCustomDictionary(Profile* profile) | 23 SpellcheckCustomDictionary::SpellcheckCustomDictionary(Profile* profile) |
21 : SpellcheckDictionary(profile), | 24 : SpellcheckDictionary(profile), |
22 custom_dictionary_path_() { | 25 custom_dictionary_path_(), |
| 26 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
23 DCHECK(profile); | 27 DCHECK(profile); |
24 custom_dictionary_path_ = | 28 custom_dictionary_path_ = |
25 profile_->GetPath().Append(chrome::kCustomDictionaryFileName); | 29 profile_->GetPath().Append(chrome::kCustomDictionaryFileName); |
26 } | 30 } |
27 | 31 |
28 SpellcheckCustomDictionary::~SpellcheckCustomDictionary() { | 32 SpellcheckCustomDictionary::~SpellcheckCustomDictionary() { |
29 } | 33 } |
30 | 34 |
31 void SpellcheckCustomDictionary::LoadDictionaryIntoCustomWordList( | 35 void SpellcheckCustomDictionary::LoadDictionaryIntoCustomWordList( |
32 WordList* custom_words) { | 36 WordList* custom_words) { |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 return false; | 83 return false; |
80 custom_words_.clear(); | 84 custom_words_.clear(); |
81 std::swap(custom_words_, *custom_words); | 85 std::swap(custom_words_, *custom_words); |
82 return true; | 86 return true; |
83 } | 87 } |
84 | 88 |
85 const WordList& SpellcheckCustomDictionary::GetCustomWords() const { | 89 const WordList& SpellcheckCustomDictionary::GetCustomWords() const { |
86 return custom_words_; | 90 return custom_words_; |
87 } | 91 } |
88 | 92 |
| 93 void SpellcheckCustomDictionary::AddWord(const std::string& word) { |
| 94 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
89 | 95 |
| 96 CustomWordAddedLocally(word); |
| 97 |
| 98 BrowserThread::PostTaskAndReply(BrowserThread::FILE, FROM_HERE, |
| 99 base::Bind(&SpellcheckCustomDictionary::WriteWordToCustomDictionary, |
| 100 base::Unretained(this), word), |
| 101 base::Bind(&SpellcheckCustomDictionary::AddWordComplete, |
| 102 weak_ptr_factory_.GetWeakPtr(), word)); |
| 103 } |
| 104 |
| 105 void SpellcheckCustomDictionary::AddWordComplete(const std::string& word) { |
| 106 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 107 |
| 108 for (content::RenderProcessHost::iterator i( |
| 109 content::RenderProcessHost::AllHostsIterator()); |
| 110 !i.IsAtEnd(); i.Advance()) { |
| 111 i.GetCurrentValue()->Send(new SpellCheckMsg_WordAdded(word)); |
| 112 } |
| 113 } |
| 114 |
| 115 |
OLD | NEW |