| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/spellchecker/spellcheck_factory.h" | 5 #include "chrome/browser/spellchecker/spellcheck_factory.h" |
| 6 | 6 |
| 7 #include "base/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
| 8 #include "chrome/browser/browser_process.h" | 8 #include "chrome/browser/browser_process.h" |
| 9 #include "chrome/browser/profiles/incognito_helpers.h" | 9 #include "chrome/browser/profiles/incognito_helpers.h" |
| 10 #include "chrome/browser/profiles/profile.h" | |
| 11 #include "chrome/browser/spellchecker/spellcheck_service.h" | 10 #include "chrome/browser/spellchecker/spellcheck_service.h" |
| 12 #include "chrome/common/pref_names.h" | 11 #include "chrome/common/pref_names.h" |
| 13 #include "components/browser_context_keyed_service/browser_context_dependency_ma
nager.h" | 12 #include "components/browser_context_keyed_service/browser_context_dependency_ma
nager.h" |
| 14 #include "components/user_prefs/pref_registry_syncable.h" | 13 #include "components/user_prefs/pref_registry_syncable.h" |
| 14 #include "components/user_prefs/user_prefs.h" |
| 15 #include "content/public/browser/render_process_host.h" | 15 #include "content/public/browser/render_process_host.h" |
| 16 #include "grit/locale_settings.h" | 16 #include "grit/locale_settings.h" |
| 17 | 17 |
| 18 // static | 18 // static |
| 19 SpellcheckService* SpellcheckServiceFactory::GetForProfile(Profile* profile) { | 19 SpellcheckService* SpellcheckServiceFactory::GetForContext( |
| 20 content::BrowserContext* context) { |
| 20 return static_cast<SpellcheckService*>( | 21 return static_cast<SpellcheckService*>( |
| 21 GetInstance()->GetServiceForBrowserContext(profile, true)); | 22 GetInstance()->GetServiceForBrowserContext(context, true)); |
| 22 } | 23 } |
| 23 | 24 |
| 24 // static | 25 // static |
| 25 SpellcheckService* SpellcheckServiceFactory::GetForRenderProcessId( | 26 SpellcheckService* SpellcheckServiceFactory::GetForRenderProcessId( |
| 26 int render_process_id) { | 27 int render_process_id) { |
| 27 content::RenderProcessHost* host = | 28 content::RenderProcessHost* host = |
| 28 content::RenderProcessHost::FromID(render_process_id); | 29 content::RenderProcessHost::FromID(render_process_id); |
| 29 if (!host) | 30 if (!host) |
| 30 return NULL; | 31 return NULL; |
| 31 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext()); | 32 content::BrowserContext* context = host->GetBrowserContext(); |
| 32 if (!profile) | 33 if (!context) |
| 33 return NULL; | 34 return NULL; |
| 34 return GetForProfile(profile); | 35 return GetForContext(context); |
| 35 } | |
| 36 | |
| 37 // static | |
| 38 SpellcheckService* SpellcheckServiceFactory::GetForProfileWithoutCreating( | |
| 39 Profile* profile) { | |
| 40 return static_cast<SpellcheckService*>( | |
| 41 GetInstance()->GetServiceForBrowserContext(profile, false)); | |
| 42 } | 36 } |
| 43 | 37 |
| 44 // static | 38 // static |
| 45 SpellcheckServiceFactory* SpellcheckServiceFactory::GetInstance() { | 39 SpellcheckServiceFactory* SpellcheckServiceFactory::GetInstance() { |
| 46 return Singleton<SpellcheckServiceFactory>::get(); | 40 return Singleton<SpellcheckServiceFactory>::get(); |
| 47 } | 41 } |
| 48 | 42 |
| 49 SpellcheckServiceFactory::SpellcheckServiceFactory() | 43 SpellcheckServiceFactory::SpellcheckServiceFactory() |
| 50 : BrowserContextKeyedServiceFactory( | 44 : BrowserContextKeyedServiceFactory( |
| 51 "SpellcheckService", | 45 "SpellcheckService", |
| 52 BrowserContextDependencyManager::GetInstance()) { | 46 BrowserContextDependencyManager::GetInstance()) { |
| 53 // TODO(erg): Uncomment these as they are initialized. | 47 // TODO(erg): Uncomment these as they are initialized. |
| 54 // DependsOn(RequestContextFactory::GetInstance()); | 48 // DependsOn(RequestContextFactory::GetInstance()); |
| 55 } | 49 } |
| 56 | 50 |
| 57 SpellcheckServiceFactory::~SpellcheckServiceFactory() {} | 51 SpellcheckServiceFactory::~SpellcheckServiceFactory() {} |
| 58 | 52 |
| 59 BrowserContextKeyedService* SpellcheckServiceFactory::BuildServiceInstanceFor( | 53 BrowserContextKeyedService* SpellcheckServiceFactory::BuildServiceInstanceFor( |
| 60 content::BrowserContext* context) const { | 54 content::BrowserContext* context) const { |
| 61 Profile* profile = static_cast<Profile*>(context); | 55 // Many variables are initialized from the |context| in the SpellcheckService. |
| 56 SpellcheckService* spellcheck = new SpellcheckService(context); |
| 62 | 57 |
| 63 // Many variables are initialized from the profile in the SpellcheckService. | 58 PrefService* prefs = user_prefs::UserPrefs::Get(context); |
| 64 DCHECK(profile); | 59 DCHECK(prefs); |
| 65 SpellcheckService* spellcheck = new SpellcheckService(profile); | |
| 66 | 60 |
| 67 // Instantiates Metrics object for spellchecking for use. | 61 // Instantiates Metrics object for spellchecking for use. |
| 68 spellcheck->StartRecordingMetrics( | 62 spellcheck->StartRecordingMetrics( |
| 69 profile->GetPrefs()->GetBoolean(prefs::kEnableContinuousSpellcheck)); | 63 prefs->GetBoolean(prefs::kEnableContinuousSpellcheck)); |
| 70 | 64 |
| 71 return spellcheck; | 65 return spellcheck; |
| 72 } | 66 } |
| 73 | 67 |
| 74 void SpellcheckServiceFactory::RegisterProfilePrefs( | 68 void SpellcheckServiceFactory::RegisterProfilePrefs( |
| 75 user_prefs::PrefRegistrySyncable* user_prefs) { | 69 user_prefs::PrefRegistrySyncable* user_prefs) { |
| 76 // TODO(estade): IDS_SPELLCHECK_DICTIONARY should be an ASCII string. | 70 // TODO(estade): IDS_SPELLCHECK_DICTIONARY should be an ASCII string. |
| 77 user_prefs->RegisterLocalizedStringPref( | 71 user_prefs->RegisterLocalizedStringPref( |
| 78 prefs::kSpellCheckDictionary, | 72 prefs::kSpellCheckDictionary, |
| 79 IDS_SPELLCHECK_DICTIONARY, | 73 IDS_SPELLCHECK_DICTIONARY, |
| (...skipping 17 matching lines...) Expand all Loading... |
| 97 } | 91 } |
| 98 | 92 |
| 99 content::BrowserContext* SpellcheckServiceFactory::GetBrowserContextToUse( | 93 content::BrowserContext* SpellcheckServiceFactory::GetBrowserContextToUse( |
| 100 content::BrowserContext* context) const { | 94 content::BrowserContext* context) const { |
| 101 return chrome::GetBrowserContextRedirectedInIncognito(context); | 95 return chrome::GetBrowserContextRedirectedInIncognito(context); |
| 102 } | 96 } |
| 103 | 97 |
| 104 bool SpellcheckServiceFactory::ServiceIsNULLWhileTesting() const { | 98 bool SpellcheckServiceFactory::ServiceIsNULLWhileTesting() const { |
| 105 return true; | 99 return true; |
| 106 } | 100 } |
| OLD | NEW |