| 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" | 10 #include "chrome/browser/profiles/profile.h" |
| 11 #include "chrome/browser/spellchecker/spellcheck_service.h" | 11 #include "chrome/browser/spellchecker/spellcheck_service.h" |
| 12 #include "chrome/common/pref_names.h" | 12 #include "chrome/common/pref_names.h" |
| 13 #include "components/browser_context_keyed_service/browser_context_dependency_ma
nager.h" | 13 #include "components/browser_context_keyed_service/browser_context_dependency_ma
nager.h" |
| 14 #include "components/user_prefs/pref_registry_syncable.h" | 14 #include "components/user_prefs/pref_registry_syncable.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::GetForProfile(Profile* profile) { |
| 20 return static_cast<SpellcheckService*>( | 20 return static_cast<SpellcheckService*>( |
| 21 GetInstance()->GetServiceForProfile(profile, true)); | 21 GetInstance()->GetServiceForBrowserContext(profile, true)); |
| 22 } | 22 } |
| 23 | 23 |
| 24 // static | 24 // static |
| 25 SpellcheckService* SpellcheckServiceFactory::GetForRenderProcessId( | 25 SpellcheckService* SpellcheckServiceFactory::GetForRenderProcessId( |
| 26 int render_process_id) { | 26 int render_process_id) { |
| 27 content::RenderProcessHost* host = | 27 content::RenderProcessHost* host = |
| 28 content::RenderProcessHost::FromID(render_process_id); | 28 content::RenderProcessHost::FromID(render_process_id); |
| 29 if (!host) | 29 if (!host) |
| 30 return NULL; | 30 return NULL; |
| 31 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext()); | 31 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext()); |
| 32 if (!profile) | 32 if (!profile) |
| 33 return NULL; | 33 return NULL; |
| 34 return GetForProfile(profile); | 34 return GetForProfile(profile); |
| 35 } | 35 } |
| 36 | 36 |
| 37 // static | 37 // static |
| 38 SpellcheckService* SpellcheckServiceFactory::GetForProfileWithoutCreating( | 38 SpellcheckService* SpellcheckServiceFactory::GetForProfileWithoutCreating( |
| 39 Profile* profile) { | 39 Profile* profile) { |
| 40 return static_cast<SpellcheckService*>( | 40 return static_cast<SpellcheckService*>( |
| 41 GetInstance()->GetServiceForProfile(profile, false)); | 41 GetInstance()->GetServiceForBrowserContext(profile, false)); |
| 42 } | 42 } |
| 43 | 43 |
| 44 // static | 44 // static |
| 45 SpellcheckServiceFactory* SpellcheckServiceFactory::GetInstance() { | 45 SpellcheckServiceFactory* SpellcheckServiceFactory::GetInstance() { |
| 46 return Singleton<SpellcheckServiceFactory>::get(); | 46 return Singleton<SpellcheckServiceFactory>::get(); |
| 47 } | 47 } |
| 48 | 48 |
| 49 SpellcheckServiceFactory::SpellcheckServiceFactory() | 49 SpellcheckServiceFactory::SpellcheckServiceFactory() |
| 50 : ProfileKeyedServiceFactory("SpellcheckService", | 50 : BrowserContextKeyedServiceFactory("SpellcheckService", |
| 51 ProfileDependencyManager::GetInstance()) { | 51 BrowserContextDependencyManager::GetInstance())
{ |
| 52 // TODO(erg): Uncomment these as they are initialized. | 52 // TODO(erg): Uncomment these as they are initialized. |
| 53 // DependsOn(RequestContextFactory::GetInstance()); | 53 // DependsOn(RequestContextFactory::GetInstance()); |
| 54 } | 54 } |
| 55 | 55 |
| 56 SpellcheckServiceFactory::~SpellcheckServiceFactory() {} | 56 SpellcheckServiceFactory::~SpellcheckServiceFactory() {} |
| 57 | 57 |
| 58 ProfileKeyedService* SpellcheckServiceFactory::BuildServiceInstanceFor( | 58 BrowserContextKeyedService* SpellcheckServiceFactory::BuildServiceInstanceFor( |
| 59 content::BrowserContext* context) const { | 59 content::BrowserContext* context) const { |
| 60 Profile* profile = static_cast<Profile*>(context); | 60 Profile* profile = static_cast<Profile*>(context); |
| 61 | 61 |
| 62 // Many variables are initialized from the profile in the SpellcheckService. | 62 // Many variables are initialized from the profile in the SpellcheckService. |
| 63 DCHECK(profile); | 63 DCHECK(profile); |
| 64 SpellcheckService* spellcheck = new SpellcheckService(profile); | 64 SpellcheckService* spellcheck = new SpellcheckService(profile); |
| 65 | 65 |
| 66 // Instantiates Metrics object for spellchecking for use. | 66 // Instantiates Metrics object for spellchecking for use. |
| 67 spellcheck->StartRecordingMetrics( | 67 spellcheck->StartRecordingMetrics( |
| 68 profile->GetPrefs()->GetBoolean(prefs::kEnableContinuousSpellcheck)); | 68 profile->GetPrefs()->GetBoolean(prefs::kEnableContinuousSpellcheck)); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 96 } | 96 } |
| 97 | 97 |
| 98 content::BrowserContext* SpellcheckServiceFactory::GetBrowserContextToUse( | 98 content::BrowserContext* SpellcheckServiceFactory::GetBrowserContextToUse( |
| 99 content::BrowserContext* context) const { | 99 content::BrowserContext* context) const { |
| 100 return chrome::GetBrowserContextRedirectedInIncognito(context); | 100 return chrome::GetBrowserContextRedirectedInIncognito(context); |
| 101 } | 101 } |
| 102 | 102 |
| 103 bool SpellcheckServiceFactory::ServiceIsNULLWhileTesting() const { | 103 bool SpellcheckServiceFactory::ServiceIsNULLWhileTesting() const { |
| 104 return true; | 104 return true; |
| 105 } | 105 } |
| OLD | NEW |