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

Side by Side Diff: chrome/browser/extensions/api/language_settings_private/language_settings_private_api.cc

Issue 1373073003: Implement chrome.languageSettingsPrivate custom spell check functions (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@LanguagePage1EditIndividual
Patch Set: Created 5 years, 2 months 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/extensions/api/language_settings_private/language_setti ngs_private_api.h" 5 #include "chrome/browser/extensions/api/language_settings_private/language_setti ngs_private_api.h"
6 6
7 #include <map> 7 #include <map>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 LanguageSettingsPrivateGetSpellcheckWordsFunction:: 176 LanguageSettingsPrivateGetSpellcheckWordsFunction::
177 ~LanguageSettingsPrivateGetSpellcheckWordsFunction() { 177 ~LanguageSettingsPrivateGetSpellcheckWordsFunction() {
178 } 178 }
179 179
180 ExtensionFunction::ResponseAction 180 ExtensionFunction::ResponseAction
181 LanguageSettingsPrivateGetSpellcheckWordsFunction::Run() { 181 LanguageSettingsPrivateGetSpellcheckWordsFunction::Run() {
182 SpellcheckService* service = 182 SpellcheckService* service =
183 SpellcheckServiceFactory::GetForContext(browser_context()); 183 SpellcheckServiceFactory::GetForContext(browser_context());
184 SpellcheckCustomDictionary* dictionary = service->GetCustomDictionary(); 184 SpellcheckCustomDictionary* dictionary = service->GetCustomDictionary();
185 185
186 if (dictionary->IsLoaded())
187 return RespondNow(OneArgument(GetSpellcheckWords().release()));
188
189 dictionary->AddObserver(this);
190 AddRef(); // Balanced in OnCustomDictionaryLoaded().
191 return RespondLater();
192 }
193
194 void
195 LanguageSettingsPrivateGetSpellcheckWordsFunction::OnCustomDictionaryLoaded() {
196 SpellcheckService* service =
197 SpellcheckServiceFactory::GetForContext(browser_context());
198 service->GetCustomDictionary()->RemoveObserver(this);
199 Respond(OneArgument(GetSpellcheckWords().release()));
200 Release();
201 }
202
203 void
204 LanguageSettingsPrivateGetSpellcheckWordsFunction::OnCustomDictionaryChanged(
205 const SpellcheckCustomDictionary::Change& dictionary_change) {
stevenjb 2015/09/28 23:58:10 nit: NOTREACHED() << "SpellcheckCustomDictionary C
michaelpg 2015/09/29 00:27:24 Done.
206 }
207
208 scoped_ptr<base::ListValue>
209 LanguageSettingsPrivateGetSpellcheckWordsFunction::GetSpellcheckWords() const {
210 SpellcheckService* service =
211 SpellcheckServiceFactory::GetForContext(browser_context());
212 SpellcheckCustomDictionary* dictionary = service->GetCustomDictionary();
213 DCHECK(dictionary->IsLoaded());
214
215 // TODO(michaelpg): Sort using app locale.
186 scoped_ptr<base::ListValue> word_list(new base::ListValue()); 216 scoped_ptr<base::ListValue> word_list(new base::ListValue());
187 // TODO(michaelpg): observe the dictionary and respond later if not loaded. 217 const std::set<std::string>& words = dictionary->GetWords();
188 if (dictionary->IsLoaded()) { 218 for (const std::string& word : words)
189 const std::set<std::string>& words = dictionary->GetWords(); 219 word_list->AppendString(word);
190 for (const std::string& word : words) 220 return word_list.Pass();
191 word_list->AppendString(word); 221 }
192 } 222
193 return RespondNow(OneArgument(word_list.release())); 223 LanguageSettingsPrivateAddSpellcheckWordFunction::
224 LanguageSettingsPrivateAddSpellcheckWordFunction() {
225 }
226
227 LanguageSettingsPrivateAddSpellcheckWordFunction::
228 ~LanguageSettingsPrivateAddSpellcheckWordFunction() {
229 }
230
231 ExtensionFunction::ResponseAction
232 LanguageSettingsPrivateAddSpellcheckWordFunction::Run() {
233 scoped_ptr<language_settings_private::AddSpellcheckWord::Params> params =
234 language_settings_private::AddSpellcheckWord::Params::Create(*args_);
235 EXTENSION_FUNCTION_VALIDATE(params.get());
236
237 SpellcheckService* service =
238 SpellcheckServiceFactory::GetForContext(browser_context());
239 bool success = service->GetCustomDictionary()->AddWord(params->word);
240
241 return RespondNow(OneArgument(new base::FundamentalValue(success)));
242 }
243
244 LanguageSettingsPrivateRemoveSpellcheckWordFunction::
245 LanguageSettingsPrivateRemoveSpellcheckWordFunction() {
246 }
247
248 LanguageSettingsPrivateRemoveSpellcheckWordFunction::
249 ~LanguageSettingsPrivateRemoveSpellcheckWordFunction() {
250 }
251
252 ExtensionFunction::ResponseAction
253 LanguageSettingsPrivateRemoveSpellcheckWordFunction::Run() {
254 scoped_ptr<language_settings_private::RemoveSpellcheckWord::Params> params =
255 language_settings_private::RemoveSpellcheckWord::Params::Create(*args_);
256 EXTENSION_FUNCTION_VALIDATE(params.get());
257
258 SpellcheckService* service =
259 SpellcheckServiceFactory::GetForContext(browser_context());
260 bool success = service->GetCustomDictionary()->RemoveWord(params->word);
261
262 return RespondNow(OneArgument(new base::FundamentalValue(success)));
194 } 263 }
195 264
196 LanguageSettingsPrivateGetTranslateTargetLanguageFunction:: 265 LanguageSettingsPrivateGetTranslateTargetLanguageFunction::
197 LanguageSettingsPrivateGetTranslateTargetLanguageFunction() 266 LanguageSettingsPrivateGetTranslateTargetLanguageFunction()
198 : chrome_details_(this) { 267 : chrome_details_(this) {
199 } 268 }
200 269
201 LanguageSettingsPrivateGetTranslateTargetLanguageFunction:: 270 LanguageSettingsPrivateGetTranslateTargetLanguageFunction::
202 ~LanguageSettingsPrivateGetTranslateTargetLanguageFunction() { 271 ~LanguageSettingsPrivateGetTranslateTargetLanguageFunction() {
203 } 272 }
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 LanguageSettingsPrivateRemoveInputMethodFunction:: 311 LanguageSettingsPrivateRemoveInputMethodFunction::
243 ~LanguageSettingsPrivateRemoveInputMethodFunction() { 312 ~LanguageSettingsPrivateRemoveInputMethodFunction() {
244 } 313 }
245 314
246 ExtensionFunction::ResponseAction 315 ExtensionFunction::ResponseAction
247 LanguageSettingsPrivateRemoveInputMethodFunction::Run() { 316 LanguageSettingsPrivateRemoveInputMethodFunction::Run() {
248 return RespondNow(OneArgument(new base::FundamentalValue(true))); 317 return RespondNow(OneArgument(new base::FundamentalValue(true)));
249 } 318 }
250 319
251 } // namespace extensions 320 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698