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.
5 #include "chrome/browser/spellchecker/spellcheck_factory.h"
7 #include "base/prefs/pref_service.h"
8 #include "chrome/browser/profiles/incognito_helpers.h"
9 #include "chrome/browser/spellchecker/spellcheck_service.h"
10 #include "chrome/common/pref_names.h"
11 #include "chrome/grit/locale_settings.h"
12 #include "components/keyed_service/content/browser_context_dependency_manager.h"
13 #include "components/pref_registry/pref_registry_syncable.h"
14 #include "components/user_prefs/user_prefs.h"
15 #include "content/public/browser/render_process_host.h"
18 SpellcheckService
* SpellcheckServiceFactory::GetForContext(
19 content::BrowserContext
* context
) {
20 return static_cast<SpellcheckService
*>(
21 GetInstance()->GetServiceForBrowserContext(context
, true));
25 SpellcheckService
* SpellcheckServiceFactory::GetForRenderProcessId(
26 int render_process_id
) {
27 content::RenderProcessHost
* host
=
28 content::RenderProcessHost::FromID(render_process_id
);
31 content::BrowserContext
* context
= host
->GetBrowserContext();
34 return GetForContext(context
);
38 SpellcheckServiceFactory
* SpellcheckServiceFactory::GetInstance() {
39 return Singleton
<SpellcheckServiceFactory
>::get();
42 SpellcheckServiceFactory::SpellcheckServiceFactory()
43 : BrowserContextKeyedServiceFactory(
45 BrowserContextDependencyManager::GetInstance()) {
46 // TODO(erg): Uncomment these as they are initialized.
47 // DependsOn(RequestContextFactory::GetInstance());
50 SpellcheckServiceFactory::~SpellcheckServiceFactory() {}
52 KeyedService
* SpellcheckServiceFactory::BuildServiceInstanceFor(
53 content::BrowserContext
* context
) const {
54 // Many variables are initialized from the |context| in the SpellcheckService.
55 SpellcheckService
* spellcheck
= new SpellcheckService(context
);
57 PrefService
* prefs
= user_prefs::UserPrefs::Get(context
);
60 // Instantiates Metrics object for spellchecking for use.
61 spellcheck
->StartRecordingMetrics(
62 prefs
->GetBoolean(prefs::kEnableContinuousSpellcheck
));
67 void SpellcheckServiceFactory::RegisterProfilePrefs(
68 user_prefs::PrefRegistrySyncable
* user_prefs
) {
69 // TODO(estade): IDS_SPELLCHECK_DICTIONARY should be an ASCII string.
70 user_prefs
->RegisterLocalizedStringPref(
71 prefs::kSpellCheckDictionary
,
72 IDS_SPELLCHECK_DICTIONARY
,
73 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
74 user_prefs
->RegisterBooleanPref(
75 prefs::kSpellCheckUseSpellingService
,
77 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
78 user_prefs
->RegisterBooleanPref(
79 prefs::kEnableContinuousSpellcheck
,
81 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF
);
82 user_prefs
->RegisterBooleanPref(
83 prefs::kEnableAutoSpellCorrect
,
85 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF
);
88 content::BrowserContext
* SpellcheckServiceFactory::GetBrowserContextToUse(
89 content::BrowserContext
* context
) const {
90 return chrome::GetBrowserContextRedirectedInIncognito(context
);
93 bool SpellcheckServiceFactory::ServiceIsNULLWhileTesting() const {