OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/translate/translate_accept_languages_factory.h" | 5 #include "chrome/browser/translate/translate_accept_languages_factory.h" |
6 | 6 |
7 #include "base/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
8 #include "chrome/browser/profiles/incognito_helpers.h" | 8 #include "chrome/browser/profiles/incognito_helpers.h" |
9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
10 #include "chrome/common/pref_names.h" | 10 #include "chrome/common/pref_names.h" |
11 #include "components/keyed_service/content/browser_context_dependency_manager.h" | 11 #include "components/keyed_service/content/browser_context_dependency_manager.h" |
12 #include "components/keyed_service/core/keyed_service.h" | 12 #include "components/keyed_service/core/keyed_service.h" |
13 #include "components/translate/core/browser/translate_accept_languages.h" | 13 #include "components/translate/core/browser/translate_accept_languages.h" |
14 | 14 |
15 namespace { | 15 namespace { |
16 | 16 |
17 // TranslateAcceptLanguagesService is a thin container for | 17 // TranslateAcceptLanguagesService is a thin container for |
18 // TranslateAcceptLanguages to enable associating it with a BrowserContext. | 18 // TranslateAcceptLanguages to enable associating it with a BrowserContext. |
19 class TranslateAcceptLanguagesService : public KeyedService { | 19 class TranslateAcceptLanguagesService : public KeyedService { |
20 public: | 20 public: |
21 explicit TranslateAcceptLanguagesService(PrefService* prefs); | 21 explicit TranslateAcceptLanguagesService(PrefService* prefs); |
22 virtual ~TranslateAcceptLanguagesService(); | 22 virtual ~TranslateAcceptLanguagesService(); |
23 | 23 |
24 // Returns the associated TranslateAcceptLanguages. | 24 // Returns the associated TranslateAcceptLanguages. |
25 TranslateAcceptLanguages& accept_languages() { return accept_languages_; } | 25 translate::TranslateAcceptLanguages& accept_languages() { |
| 26 return accept_languages_; |
| 27 } |
26 | 28 |
27 private: | 29 private: |
28 TranslateAcceptLanguages accept_languages_; | 30 translate::TranslateAcceptLanguages accept_languages_; |
29 DISALLOW_COPY_AND_ASSIGN(TranslateAcceptLanguagesService); | 31 DISALLOW_COPY_AND_ASSIGN(TranslateAcceptLanguagesService); |
30 }; | 32 }; |
31 | 33 |
32 TranslateAcceptLanguagesService::TranslateAcceptLanguagesService( | 34 TranslateAcceptLanguagesService::TranslateAcceptLanguagesService( |
33 PrefService* prefs) | 35 PrefService* prefs) |
34 : accept_languages_(prefs, prefs::kAcceptLanguages) {} | 36 : accept_languages_(prefs, prefs::kAcceptLanguages) {} |
35 | 37 |
36 TranslateAcceptLanguagesService::~TranslateAcceptLanguagesService() {} | 38 TranslateAcceptLanguagesService::~TranslateAcceptLanguagesService() {} |
37 | 39 |
38 } // namespace | 40 } // namespace |
39 | 41 |
40 // static | 42 // static |
41 TranslateAcceptLanguagesFactory* | 43 TranslateAcceptLanguagesFactory* |
42 TranslateAcceptLanguagesFactory::GetInstance() { | 44 TranslateAcceptLanguagesFactory::GetInstance() { |
43 return Singleton<TranslateAcceptLanguagesFactory>::get(); | 45 return Singleton<TranslateAcceptLanguagesFactory>::get(); |
44 } | 46 } |
45 | 47 |
46 // static | 48 // static |
47 TranslateAcceptLanguages* TranslateAcceptLanguagesFactory::GetForBrowserContext( | 49 translate::TranslateAcceptLanguages* |
| 50 TranslateAcceptLanguagesFactory::GetForBrowserContext( |
48 content::BrowserContext* context) { | 51 content::BrowserContext* context) { |
49 TranslateAcceptLanguagesService* service = | 52 TranslateAcceptLanguagesService* service = |
50 static_cast<TranslateAcceptLanguagesService*>( | 53 static_cast<TranslateAcceptLanguagesService*>( |
51 GetInstance()->GetServiceForBrowserContext(context, true)); | 54 GetInstance()->GetServiceForBrowserContext(context, true)); |
52 return &service->accept_languages(); | 55 return &service->accept_languages(); |
53 } | 56 } |
54 | 57 |
55 TranslateAcceptLanguagesFactory::TranslateAcceptLanguagesFactory() | 58 TranslateAcceptLanguagesFactory::TranslateAcceptLanguagesFactory() |
56 : BrowserContextKeyedServiceFactory( | 59 : BrowserContextKeyedServiceFactory( |
57 "TranslateAcceptLanguagesService", | 60 "TranslateAcceptLanguagesService", |
58 BrowserContextDependencyManager::GetInstance()) {} | 61 BrowserContextDependencyManager::GetInstance()) {} |
59 | 62 |
60 TranslateAcceptLanguagesFactory::~TranslateAcceptLanguagesFactory() {} | 63 TranslateAcceptLanguagesFactory::~TranslateAcceptLanguagesFactory() {} |
61 | 64 |
62 KeyedService* TranslateAcceptLanguagesFactory::BuildServiceInstanceFor( | 65 KeyedService* TranslateAcceptLanguagesFactory::BuildServiceInstanceFor( |
63 content::BrowserContext* browser_context) const { | 66 content::BrowserContext* browser_context) const { |
64 Profile* profile = Profile::FromBrowserContext(browser_context); | 67 Profile* profile = Profile::FromBrowserContext(browser_context); |
65 return new TranslateAcceptLanguagesService(profile->GetPrefs()); | 68 return new TranslateAcceptLanguagesService(profile->GetPrefs()); |
66 } | 69 } |
67 | 70 |
68 content::BrowserContext* | 71 content::BrowserContext* |
69 TranslateAcceptLanguagesFactory::GetBrowserContextToUse( | 72 TranslateAcceptLanguagesFactory::GetBrowserContextToUse( |
70 content::BrowserContext* context) const { | 73 content::BrowserContext* context) const { |
71 return chrome::GetBrowserContextRedirectedInIncognito(context); | 74 return chrome::GetBrowserContextRedirectedInIncognito(context); |
72 } | 75 } |
OLD | NEW |