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/browser_context.h"
16 #include "content/public/browser/render_process_host.h"
17 #include "ui/base/l10n/l10n_util.h"
20 SpellcheckService
* SpellcheckServiceFactory::GetForContext(
21 content::BrowserContext
* context
) {
22 return static_cast<SpellcheckService
*>(
23 GetInstance()->GetServiceForBrowserContext(context
, true));
27 SpellcheckService
* SpellcheckServiceFactory::GetForRenderProcessId(
28 int render_process_id
) {
29 content::RenderProcessHost
* host
=
30 content::RenderProcessHost::FromID(render_process_id
);
33 content::BrowserContext
* context
= host
->GetBrowserContext();
36 return GetForContext(context
);
40 SpellcheckServiceFactory
* SpellcheckServiceFactory::GetInstance() {
41 return base::Singleton
<SpellcheckServiceFactory
>::get();
44 SpellcheckServiceFactory::SpellcheckServiceFactory()
45 : BrowserContextKeyedServiceFactory(
47 BrowserContextDependencyManager::GetInstance()) {
48 // TODO(erg): Uncomment these as they are initialized.
49 // DependsOn(RequestContextFactory::GetInstance());
52 SpellcheckServiceFactory::~SpellcheckServiceFactory() {}
54 KeyedService
* SpellcheckServiceFactory::BuildServiceInstanceFor(
55 content::BrowserContext
* context
) const {
56 // Many variables are initialized from the |context| in the SpellcheckService.
57 SpellcheckService
* spellcheck
= new SpellcheckService(context
);
59 PrefService
* prefs
= user_prefs::UserPrefs::Get(context
);
62 // Instantiates Metrics object for spellchecking for use.
63 spellcheck
->StartRecordingMetrics(
64 prefs
->GetBoolean(prefs::kEnableContinuousSpellcheck
));
69 void SpellcheckServiceFactory::RegisterProfilePrefs(
70 user_prefs::PrefRegistrySyncable
* user_prefs
) {
71 user_prefs
->RegisterListPref(prefs::kSpellCheckDictionaries
,
73 // Continue registering kSpellCheckDictionary for preference migration.
74 // TODO(estade): IDS_SPELLCHECK_DICTIONARY should be an ASCII string.
75 user_prefs
->RegisterStringPref(
76 prefs::kSpellCheckDictionary
,
77 l10n_util::GetStringUTF8(IDS_SPELLCHECK_DICTIONARY
));
78 user_prefs
->RegisterBooleanPref(prefs::kSpellCheckUseSpellingService
, false);
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 {