BookmarkManager: Fix 'new folder text field size changes on clicking it' issue.
[chromium-blink-merge.git] / chrome / browser / translate / translate_accept_languages_factory.cc
blobeba67354c8f51e4c69e95a11b3d8d7b263909b4e
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
3 // found in the LICENSE file.
5 #include "chrome/browser/translate/translate_accept_languages_factory.h"
7 #include "base/prefs/pref_service.h"
8 #include "chrome/browser/profiles/incognito_helpers.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/common/pref_names.h"
11 #include "components/keyed_service/content/browser_context_dependency_manager.h"
12 #include "components/keyed_service/core/keyed_service.h"
13 #include "components/translate/core/browser/translate_accept_languages.h"
15 namespace {
17 // TranslateAcceptLanguagesService is a thin container for
18 // TranslateAcceptLanguages to enable associating it with a BrowserContext.
19 class TranslateAcceptLanguagesService : public KeyedService {
20 public:
21 explicit TranslateAcceptLanguagesService(PrefService* prefs);
22 ~TranslateAcceptLanguagesService() override;
24 // Returns the associated TranslateAcceptLanguages.
25 translate::TranslateAcceptLanguages& accept_languages() {
26 return accept_languages_;
29 private:
30 translate::TranslateAcceptLanguages accept_languages_;
31 DISALLOW_COPY_AND_ASSIGN(TranslateAcceptLanguagesService);
34 TranslateAcceptLanguagesService::TranslateAcceptLanguagesService(
35 PrefService* prefs)
36 : accept_languages_(prefs, prefs::kAcceptLanguages) {}
38 TranslateAcceptLanguagesService::~TranslateAcceptLanguagesService() {}
40 } // namespace
42 // static
43 TranslateAcceptLanguagesFactory*
44 TranslateAcceptLanguagesFactory::GetInstance() {
45 return base::Singleton<TranslateAcceptLanguagesFactory>::get();
48 // static
49 translate::TranslateAcceptLanguages*
50 TranslateAcceptLanguagesFactory::GetForBrowserContext(
51 content::BrowserContext* context) {
52 TranslateAcceptLanguagesService* service =
53 static_cast<TranslateAcceptLanguagesService*>(
54 GetInstance()->GetServiceForBrowserContext(context, true));
55 return &service->accept_languages();
58 TranslateAcceptLanguagesFactory::TranslateAcceptLanguagesFactory()
59 : BrowserContextKeyedServiceFactory(
60 "TranslateAcceptLanguagesService",
61 BrowserContextDependencyManager::GetInstance()) {}
63 TranslateAcceptLanguagesFactory::~TranslateAcceptLanguagesFactory() {}
65 KeyedService* TranslateAcceptLanguagesFactory::BuildServiceInstanceFor(
66 content::BrowserContext* browser_context) const {
67 Profile* profile = Profile::FromBrowserContext(browser_context);
68 return new TranslateAcceptLanguagesService(profile->GetPrefs());
71 content::BrowserContext*
72 TranslateAcceptLanguagesFactory::GetBrowserContextToUse(
73 content::BrowserContext* context) const {
74 return chrome::GetBrowserContextRedirectedInIncognito(context);