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"
16 #include "ui/base/l10n/l10n_util.h"
19 SpellcheckService
* SpellcheckServiceFactory::GetForContext(
20 content::BrowserContext
* context
) {
21 return static_cast<SpellcheckService
*>(
22 GetInstance()->GetServiceForBrowserContext(context
, true));
26 SpellcheckService
* SpellcheckServiceFactory::GetForRenderProcessId(
27 int render_process_id
) {
28 content::RenderProcessHost
* host
=
29 content::RenderProcessHost::FromID(render_process_id
);
32 content::BrowserContext
* context
= host
->GetBrowserContext();
35 return GetForContext(context
);
39 SpellcheckServiceFactory
* SpellcheckServiceFactory::GetInstance() {
40 return Singleton
<SpellcheckServiceFactory
>::get();
43 SpellcheckServiceFactory::SpellcheckServiceFactory()
44 : BrowserContextKeyedServiceFactory(
46 BrowserContextDependencyManager::GetInstance()) {
47 // TODO(erg): Uncomment these as they are initialized.
48 // DependsOn(RequestContextFactory::GetInstance());
51 SpellcheckServiceFactory::~SpellcheckServiceFactory() {}
53 KeyedService
* SpellcheckServiceFactory::BuildServiceInstanceFor(
54 content::BrowserContext
* context
) const {
55 // Many variables are initialized from the |context| in the SpellcheckService.
56 SpellcheckService
* spellcheck
= new SpellcheckService(context
);
58 PrefService
* prefs
= user_prefs::UserPrefs::Get(context
);
61 // Instantiates Metrics object for spellchecking for use.
62 spellcheck
->StartRecordingMetrics(
63 prefs
->GetBoolean(prefs::kEnableContinuousSpellcheck
));
68 void SpellcheckServiceFactory::RegisterProfilePrefs(
69 user_prefs::PrefRegistrySyncable
* user_prefs
) {
70 // TODO(estade): IDS_SPELLCHECK_DICTIONARY should be an ASCII string.
71 user_prefs
->RegisterStringPref(
72 prefs::kSpellCheckDictionary
,
73 l10n_util::GetStringUTF8(IDS_SPELLCHECK_DICTIONARY
),
74 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
75 user_prefs
->RegisterBooleanPref(
76 prefs::kSpellCheckUseSpellingService
,
78 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
79 user_prefs
->RegisterBooleanPref(
80 prefs::kEnableContinuousSpellcheck
,
82 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF
);
83 user_prefs
->RegisterBooleanPref(
84 prefs::kEnableAutoSpellCorrect
,
86 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF
);
89 content::BrowserContext
* SpellcheckServiceFactory::GetBrowserContextToUse(
90 content::BrowserContext
* context
) const {
91 return chrome::GetBrowserContextRedirectedInIncognito(context
);
94 bool SpellcheckServiceFactory::ServiceIsNULLWhileTesting() const {