/chromium-webcl/src/chrome/browser/spellchecker/spellcheck_factory.cc

https://bitbucket.org/peixuan/chromium_r197479_base · C++ · 85 lines · 60 code · 14 blank · 11 comment · 0 complexity · 183cf05103713603c98ed08daebb654e MD5 · raw file

  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
  3. // found in the LICENSE file.
  4. #include "chrome/browser/spellchecker/spellcheck_factory.h"
  5. #include "base/prefs/pref_service.h"
  6. #include "chrome/browser/browser_process.h"
  7. #include "chrome/browser/profiles/profile.h"
  8. #include "chrome/browser/profiles/profile_dependency_manager.h"
  9. #include "chrome/browser/spellchecker/spellcheck_service.h"
  10. #include "chrome/common/pref_names.h"
  11. #include "components/user_prefs/pref_registry_syncable.h"
  12. #include "grit/locale_settings.h"
  13. // static
  14. SpellcheckService* SpellcheckServiceFactory::GetForProfile(Profile* profile) {
  15. return static_cast<SpellcheckService*>(
  16. GetInstance()->GetServiceForProfile(profile, true));
  17. }
  18. // static
  19. SpellcheckService* SpellcheckServiceFactory::GetForProfileWithoutCreating(
  20. Profile* profile) {
  21. return static_cast<SpellcheckService*>(
  22. GetInstance()->GetServiceForProfile(profile, false));
  23. }
  24. // static
  25. SpellcheckServiceFactory* SpellcheckServiceFactory::GetInstance() {
  26. return Singleton<SpellcheckServiceFactory>::get();
  27. }
  28. SpellcheckServiceFactory::SpellcheckServiceFactory()
  29. : ProfileKeyedServiceFactory("SpellcheckService",
  30. ProfileDependencyManager::GetInstance()) {
  31. // TODO(erg): Uncomment these as they are initialized.
  32. // DependsOn(RequestContextFactory::GetInstance());
  33. }
  34. SpellcheckServiceFactory::~SpellcheckServiceFactory() {}
  35. ProfileKeyedService* SpellcheckServiceFactory::BuildServiceInstanceFor(
  36. content::BrowserContext* context) const {
  37. Profile* profile = static_cast<Profile*>(context);
  38. // Many variables are initialized from the profile in the SpellcheckService.
  39. DCHECK(profile);
  40. SpellcheckService* spellcheck = new SpellcheckService(profile);
  41. // Instantiates Metrics object for spellchecking for use.
  42. spellcheck->StartRecordingMetrics(
  43. profile->GetPrefs()->GetBoolean(prefs::kEnableContinuousSpellcheck));
  44. return spellcheck;
  45. }
  46. void SpellcheckServiceFactory::RegisterUserPrefs(
  47. PrefRegistrySyncable* user_prefs) {
  48. // TODO(estade): IDS_SPELLCHECK_DICTIONARY should be an ASCII string.
  49. user_prefs->RegisterLocalizedStringPref(
  50. prefs::kSpellCheckDictionary,
  51. IDS_SPELLCHECK_DICTIONARY,
  52. PrefRegistrySyncable::UNSYNCABLE_PREF);
  53. user_prefs->RegisterBooleanPref(prefs::kSpellCheckConfirmDialogShown,
  54. false,
  55. PrefRegistrySyncable::UNSYNCABLE_PREF);
  56. user_prefs->RegisterBooleanPref(prefs::kSpellCheckUseSpellingService,
  57. false,
  58. PrefRegistrySyncable::UNSYNCABLE_PREF);
  59. user_prefs->RegisterBooleanPref(prefs::kEnableContinuousSpellcheck,
  60. true,
  61. PrefRegistrySyncable::SYNCABLE_PREF);
  62. user_prefs->RegisterBooleanPref(prefs::kEnableAutoSpellCorrect,
  63. false,
  64. PrefRegistrySyncable::SYNCABLE_PREF);
  65. }
  66. bool SpellcheckServiceFactory::ServiceRedirectedInIncognito() const {
  67. return true;
  68. }
  69. bool SpellcheckServiceFactory::ServiceIsNULLWhileTesting() const {
  70. return true;
  71. }